关闭

i2c关键结构体分析

1167人阅读 评论(0) 收藏 举报
1、总线配置结构体:
struct s3c2410_platform_i2c {
    int        bus_num; //总线条数
    unsigned int    flags;
    unsigned int    slave_addr;//从机地址
    unsigned long    frequency;//频率
    unsigned int    sda_delay;//sda传送延时

    void    (*cfg_gpio)(struct platform_device *dev);
};

2、总线描述结构体:
struct s3c24xx_i2c {
        spinlock_t              lock;        //自选锁(防止总线资源被并发访问)
        wait_queue_head_t       wait;        //等待队列(当有数据需要收/发时启动总线,然后守候在等待队列,直到数据收/发结束后被唤醒返回)

        struct i2c_msg          *msg;        //i2c信息指针
        unsigned int            msg_num;    //需要传输的i2c msg数
        unsigned int            msg_idx;    //成功传输的i2c msg数
        unsigned int            msg_ptr;    //当前i2c msg内指针

        unsigned int            tx_setup;    //延时值(保证总线启动时数据已经传输到总线上)

        enum s3c24xx_i2c_state  state;        //i2c总线状态

        void __iomem            *regs;:
        struct clk              *clk;
        struct device           *dev;
        struct resource         *irq;
        struct resource         *ioarea;
        struct i2c_adapter      adap;        //总线适配器(个人觉得它更像设备驱动中的设备而非驱动)
};

3、总线适配器:
struct i2c_adapter {
        struct module *owner;
        unsigned int id;
        unsigned int class;
        const struct i2c_algorithm *algo;             //i2c总线访问算法
        void *algo_data;                    //用来保存struct s3c24xx_i2c结构指针

        /* --- administration stuff. */
        int (*client_register)(struct i2c_client *);
        int (*client_unregister)(struct i2c_client *);

        /* data fields that are valid for all devices   */
        u8 level;                                   //nesting level for lockdep
        struct mutex bus_lock;
        struct mutex clist_lock;

        int timeout;
        int retries;
        struct device dev;                          //the adapter device

        int nr;
        struct list_head clients;
        struct list_head list;
        char name[48];
        struct completion dev_released;
};

4、总线访问算法:
struct i2c_algorithm {
        /* If an adapter algorithm can't do I2C-level access, set master_xfer
           to NULL. If an adapter algorithm can do SMBus access, set
           smbus_xfer. If set to NULL, the SMBus protocol is simulated
           using common I2C messages */
        /* master_xfer should return the number of messages successfully
           processed, or a negative value on error */
        int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg *msgs,    //i2c msg发送函数
                           int num);
        int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
                           unsigned short flags, char read_write,
                           u8 command, int size, union i2c_smbus_data * data);

        /* --- ioctl like call to set div. parameters. */
        int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long);

        /* To determine what the adapter supports */
        u32 (*functionality) (struct i2c_adapter *);                //标志i2c适配器所支持的功能
};

struct i2c_msg {
        __u16 addr;     /* slave address                        */
        __u16 flags;
#define I2C_M_TEN       0x10    /* we have a ten bit chip address       */
#define I2C_M_RD        0x01
#define I2C_M_NOSTART   0x4000
#define I2C_M_REV_DIR_ADDR      0x2000
#define I2C_M_IGNORE_NAK        0x1000
#define I2C_M_NO_RD_ACK         0x0800
#define I2C_M_RECV_LEN          0x0400 /* length will be first received byte */
        __u16 len;              /* msg length                           */
        __u8 *buf;              /* pointer to msg data                  */
};
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:378466次
    • 积分:3889
    • 等级:
    • 排名:第8439名
    • 原创:111篇
    • 转载:19篇
    • 译文:3篇
    • 评论:16条
    个人简介
    12年毕业,linux、网络、c、内核,三年安防研发,最近进入通信行业,网络内核研发
    最新评论