博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LINUX驱动之IIC子系统之三I2C的数…
阅读量:4051 次
发布时间:2019-05-25

本文共 2674 字,大约阅读时间需要 8 分钟。

 

LINUX驱动之IIC子系统之三I2C的数据结构

仍然是按照老的规矩,讲一下I2C的数据结构,让大家在学习I2C前,形成一个整体上的知识结构的认知。它的数据结构也不多,主要的有下面几个:(I2C.h)

1、i2c总线类型结构体:

struct bus_type i2c_bus_type = {

    .name      = "i2c",

    .match     = i2c_device_match,

    .probe     = i2c_device_probe,

    .remove       = i2c_device_remove,

    .shutdown  = i2c_device_shutdown,

    .suspend   = i2c_device_suspend,

    .resume       = i2c_device_resume,

};

2、I2C从设备数据结构体:

struct i2c_client {

    unsigned short flags;      

    unsigned short addr;    

                 

                 

    char name[I2C_NAME_SIZE];

    struct i2c_adapter *adapter;   

    struct i2c_driver *driver; 

    struct device dev;      

    int irq;         

    struct list_head detected;

};

3、I2C从设备驱动结构体:

struct i2c_driver {

    unsigned int class;

 

   

    int (*attach_adapter)(struct i2c_adapter *);

    int (*detach_adapter)(struct i2c_adapter *);

 

   

    int (*probe)(struct i2c_client *, const struct i2c_device_id *);

    int (*remove)(struct i2c_client *);

 

   

    void (*shutdown)(struct i2c_client *);

    int (*suspend)(struct i2c_client *, pm_message_t mesg);

    int (*resume)(struct i2c_client *);

 

   

    int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);

 

    struct device_driver driver;

    const struct i2c_device_id *id_table;

 

   

    int (*detect)(struct i2c_client *, int kind, struct i2c_board_info *);

    const struct i2c_client_address_data *address_data;

    struct list_head clients;

};

4、表征I2C设备的一些特征的数据结构体,组成链表的基本单元:

struct i2c_board_info {

    char       type[I2C_NAME_SIZE];

    unsigned short    flags;

    unsigned short    addr;

    void       *platform_data;

    struct dev_archdata  *archdata;

    int    irq;

};

在SPI里大家也发有这么一个吧,而且它还有一个管理这个的链表结构,这里就不再讲那个了,因为i2C直接使用的链表没有新建立一个类似的结构。

5、I2C传输数据的一种算法

struct i2c_algorithm {

   

   

    int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,

              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);

 

   

    u32 (*functionality) (struct i2c_adapter *);

};

I2C的通信最终都必须调用该结构中master_xfer的方法来实现。这套通信方法是跟底层I2C控制器硬件相关的。

6、I2C主设备数据结构:

struct i2c_adapter {

    struct module *owner;

    unsigned int id;

    unsigned int class;       

    const struct i2c_algorithm *algo;

    void *algo_data;

 

   

    u8 level;        

    struct mutex bus_lock;

 

    int timeout;        

    int retries;

    struct device dev;      

 

    int nr;

    char name[48];

    struct completion dev_released;

};

这个叫控制器也叫适配器,大家一定要记清。

7、I2C消息数据结构体:

struct i2c_msg {

    __u16 addr;  

    __u16 flags;

#define I2C_M_TEN    0x0010

#define I2C_M_RD     0x0001

#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

    __u16 len;   

    __u8 *buf;   

};

看着它发现与SPI有相类似的地方没有。

8、smbus数据结构体(一种通信算法)

union i2c_smbus_data {

    __u8 byte;

    __u16 word;

    __u8 block[I2C_SMBUS_BLOCK_MAX + 2];

                 

};

这些个数据结构会自始至终的跟在整个I2C设备的通信过程中,大家一定要有一个清楚的认识,别弄混了,象SPI里就有一个设备的遍历和驱动的遍历,很容易把人弄糊涂了。

先讲这么一点点,明天开始讲注册部分。

注重一个字,恒!

转载地址:http://jyvci.baihongyu.com/

你可能感兴趣的文章
使用file查看可执行文件的平台性,x86 or arm ?
查看>>
qt 创建异形窗体
查看>>
简单Linux C线程池
查看>>
内存池
查看>>
GNU hello代码分析
查看>>
Qt继电器控制板代码
查看>>
wpa_supplicant控制脚本
查看>>
gstreamer相关工具集合
查看>>
RS232 四入四出模块控制代码
查看>>
linux 驱动开发 头文件
查看>>
container_of()传入结构体中的成员,返回该结构体的首地址
查看>>
ipconfig,ifconfig,iwconfig
查看>>
opensuse12.2 PL2303 minicom
查看>>
网络视频服务器移植
查看>>
Encoding Schemes
查看>>
移植QT
查看>>
如此调用
查看>>
计算机的发展史
查看>>
带WiringPi库的交叉编译如何处理一
查看>>
带WiringPi库的交叉笔译如何处理二之软链接概念
查看>>