linux i2c驱动相关结构体

本文深入探讨Linux I2C驱动中的四个核心结构体:struct i2c_adapter、struct i2c_algorithm、struct i2c_driver和struct i2c_client,详细阐述它们的内容及相互关系。面对复杂的驱动代码,作者感叹驱动开发的挑战,同时也表达了对掌握高级代码设计的期待。
摘要由CSDN通过智能技术生成

i2c驱动看下来感觉就像一张找不到头的网,繁复错杂,千丝万缕,很难理清。这还只是一个简单的子系统,还有复杂的USB总线,更别提内核的复杂了,哎,路漫漫其修远兮...anyway,加油!

函数指针和链表在驱动中随处可见,这些也是C语言的精华所在,看着都觉费力,什么时候才能设计出这种高水平的代码来...

1 结构体内容

1.1 struct i2c_adapter

i2c适配器的描述结构体。
/*
 * i2c_adapter is the structure used to identify a physical i2c bus along
 * with the access algorithms necessary to access it.
 */
struct i2c_adapter {
	struct module *owner;		  /*该结构体所属模块*/
	unsigned int id __deprecated;
	unsigned int class;		  /* classes to allow probing for */
	const struct i2c_algorithm *algo; /* the algorithm to access the bus */
	void *algo_data;

	/* data fields that are valid for all devices	*/
	struct rt_mutex bus_lock;	  /*控制并发访问的自旋锁*/

	int timeout;			  /* in jiffies */
	int retries;			  /*重试次数*/
	struct device dev;		  /* the adapter device */

	int nr;
	char name[48];			  /*适配器的名称*/
	struct completion dev_released;	  /*完成量,用于同步*/

	struct mutex userspace_clients_lock;
	struct list_head userspace_clients;  /*client链表头*/
};


1.2 struct i2c_algorithm

i2c适配器的通信接口结构体
/*
 * The following structs are for those who like to implement new bus drivers:
 * i2c_algorithm is the interface to a class of hardware solutions which can
 * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584
 * to name two of the most common.
 */
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_xfe
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值