IIC驅動程式分析(二)

2021-06-09 14:50:47 字數 1442 閱讀 7549

在上一節的實驗中,我們採用的是normal_i2c 的方式,即:要發出s訊號和裝置位址並得到ack訊號,才能確定存在這個裝置。那麼如果本身不存在這個裝置當然啊不會給出應答訊號,這是就不會呼叫i2c_probe(adapter, &addr_data, at24cxx_detect)函式中的at24cxx_detect函式。如果我們目前沒有接上這個裝置,但是我們今後打算把它安裝上去,所以我們想要呼叫i2c_probe(adapter, &addr_data, at24cxx_detect)函式中的at24cxx_detect函式,那怎麼辦呢?這時就不能用normal_i2c方式,而應該採用forces方式。

#include #include #include #include #include #include #include static unsigned short ignore      = ;

static unsigned short normal_addr = ; /* 位址值是7位 */

/* 改為0x60的話, 由於不存在裝置位址為0x60的裝置, 所以at24cxx_detect不被呼叫 */

/* 這裡any_i2c_bus表示在任意一條匯流排上查詢該裝置,0x60表示要發出的裝置位址 */

static unsigned short force_addr = ;

static unsigned short * forces = ;

static struct i2c_client_address_data addr_data = ;

static int at24cxx_detect(struct i2c_adapter *adapter, int address, int kind)

static int at24cxx_attach(struct i2c_adapter *adapter)

static int at24cxx_detach(struct i2c_client *client)

static struct i2c_driver at24cxx_driver = ,

.attach_adapter = at24cxx_attach,

.detach_client = at24cxx_detach,

};static int at24cxx_init(void)

static void at24cxx_exit(void)

module_init(at24cxx_init);

module_exit(at24cxx_exit);

module_license("gpl");

在這個程式裡面,即便不存在裝置位址為0x60的裝置,也會呼叫i2c_probe(adapter, &addr_data, at24cxx_detect)函式中的at24cxx_detect函式,因為這裡採用的是強制的方式。具體原因等到以後在來研究,目前只是先有個輪廓!

IIC驅動程式分析(一)

根據上一節課的分析,我們來解讀這段 include include include include include include include static unsigned short ignore static unsigned short normal addr 位址值是7位 static...

IIC匯流排驅動程式框架分析

我們首先從 drivers i2c chips eeprom.c來分析,這是驅動那一塊的 static struct i2c driver eeprom driver id i2c driverid eeprom,attach adapter eeprom attach adapter,detach...

USB驅動程式分析

1.對於每個pc來說,都有乙個或者多個稱為主機 host 控制器的裝置,該主機控制器和乙個根集線器 hub 作為乙個整體。2.每個host控制器其實就是乙個pci裝置,掛載在pci匯流排上。驅動開發人員應該給host控制器提供驅動程式,用usb hcd結構體表示。3.usb host控制器都會自帶乙...