鸿蒙系统 I2C 通信代码阅读理解

HdfDriverEntry驱动入口数据结构:

struct HdfDriverEntry {
    int moduleVersion;
    int32_t (*Bind)(struct HdfDeviceObject *device);
    int32_t (*I2cManagerInit)(struct HdfDeviceObject *device);
    void (*Release)(struct HdfDeviceObject *device);
    char *moduleName;
};

内核层驱动入口:g_i2cManagerEntry:

struct HdfDriverEntry g_i2cManagerEntry = {

.moduleVersion = 1,

.Bind = I2cManagerBind,

.Init = I2cManagerInit,

.Release = I2cManagerRelease,

.moduleName = "HDF_PLATFORM_I2C_MANAGER",

};

内核层驱动入口,会维护一个静态全局的 i2c 管理器 g_i2cManager ,数据结构为 I2cManager:

struct I2cManager {
    struct IDeviceIoService service;
    struct HdfDeviceObject *device;
    struct I2cCntlr *cntlrs[I2C_BUS_MAX];
    struct OsalMutex lock;
};

static struct I2cManager *g_i2cManager = NULL;

内核层驱动的 bind 函数,会将输入的 device 指针,绑定到 i2c 管理器 g_i2cManager 上面。

struct i2c_adapter :

根据 struct device dev 地址,加上 offset,可以获取到 struct i2c_adapter 的地址。

struct i2c_adapter {
	struct module *owner;
	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	*/
	const struct i2c_lock_operations *lock_ops;
	struct rt_mutex bus_lock;
	struct rt_mutex mux_lock;

	int timeout;			/* in jiffies */
	int retries;
	struct device dev;		/* the adapter device */
	unsigned long locked_flags;	/* owned by the I2C core */
#define I2C_ALF_IS_SUSPENDED		0
#define I2C_ALF_SUSPEND_REPORTED	1

	int nr;
	char name[48];
	struct completion dev_released;

	struct mutex userspace_clients_lock;
	struct list_head userspace_clients;

	struct i2c_bus_recovery_info *bus_recovery_info;
	const struct i2c_adapter_quirks *quirks;

	struct irq_domain *host_notify_domain;
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值