freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

iic設(shè)備驅(qū)動程序培訓(xùn)課程-在線瀏覽

2024-08-17 11:51本頁面
  

【正文】 針,指向?qū)崿F(xiàn)IIC總線通信協(xié)議的函數(shù),用來確定適配器支持那些傳輸類型 int i2c_adapter *adap, u16 short flags, char i2c_smbus_dataSMBus和IIC之間可以通過軟件方式兼容,所以這里提供了一個函數(shù),但是一般都賦值為NULL u32 i2c_adapter *)。設(shè)備層包括一個重要的數(shù)據(jù)結(jié)構(gòu),i2c_client。一個i2c_algorithm結(jié)構(gòu)表示適配器對應(yīng)的傳輸數(shù)據(jù)方法。IIC設(shè)備層次結(jié)構(gòu)較為簡單,但是寫IIC設(shè)備驅(qū)動程序卻相當(dāng)復(fù)雜。初始化函數(shù):static int __init i2c_init(void){ retval = bus_register(amp。 //注冊一條IIC的BUS總線 i2c_adapter_class)。if (retval) goto bus_err。retval = i2c_add_driver(amp。 //將一個空驅(qū)動程序注冊到IIC總線中 class_err: i2c_adapter_class)。 //類注銷bus_err: i2c_bus_type)。 //總線注銷 }.name = i2c, = i2c_dev_attrs, .uevent = i2c_device_uevent, .remove = i2c_device_remove, = i2c_device_shutdown, = i2c_device_suspend, static struct class i2c_adapter_class = { = THIS_MODULE, = i2cadapter, static struct i2c_driver dummy_driver = { = dummy, .remove = dummy_remove, = dummy_id,}。IIC子系統(tǒng)退出函數(shù):static void __exit i2c_exit(void){ dummy_driver)。 //注銷IIC設(shè)備驅(qū)動程序,主要功能是去掉總線中的該設(shè)備驅(qū)動程序 i2c_adapter_class)。 //注銷適配器類 i2c_bus_type)。適配器驅(qū)動程序是IIC設(shè)備驅(qū)動程序需要實現(xiàn)的主要驅(qū)動程序,這個驅(qū)動程序需要根據(jù)具體的適配器硬件來編寫。但i2c_adapter結(jié)構(gòu)體只是所有適配器的共有屬性,并不能代表所有類型的適配器spinlock_t lock。wait_queue_head_t //等待隊列頭。該隊列用來放阻塞的進(jìn)程 //設(shè)備是否掛起 //從適配器到設(shè)備一次傳輸?shù)膯挝?,用這個結(jié)構(gòu)體將數(shù)據(jù)包裝起來便于操作 , //表示消息的個數(shù) 當(dāng)完成一個消息后,該值增加 unsigned int tx_setup。unsigned int irq。enum s3c24xx_i2c_state unsigned long clkrate。void __iomem *regs。 //IIC設(shè)備寄存器地址 //對應(yīng)的時鐘 //適配器對應(yīng)的設(shè)備結(jié)構(gòu)體 struct i2c_adapter struct notifier_block endif}。STATE_IDLE, STATE_READ, STATE_STOP}。struct 這個字段說明一個適配器在獲得總線控制權(quán)后,可以與多個IIC設(shè)備進(jìn)行交互。define //這是有10位地址芯片define 0x0001 //表示從 從機(jī)到主機(jī)讀數(shù)據(jù)define // FUNC_PROTOCOL_MANLING協(xié)議的相關(guān)標(biāo)志define //FUNC_PROTOCOL_MANLING協(xié)議的相關(guān)標(biāo)志define I2C_M_NO_RD_ACK 0x0800 //FUNC_PROTOCOL_MANLING協(xié)議的相關(guān)標(biāo)志define 0x0400 __u16 __u8 * buf。這個結(jié)構(gòu)體已經(jīng)在第一步初始化了:int i2c_add_adapter(struct i2c_adapter *adapter){ id, res = 0。if (idr_pre_get(amp。 //內(nèi)存分配失敗 core_lock)。/* above here means above or equal to, sigh */ i2c_adapter_idr, adapter, __i2c_first_dynamic_bus_num, amp。mutex_unlock(amp。 //釋放內(nèi)核鎖 goto retry。 adapternr = id。return i2c_register_adapter(adapter)。關(guān)于IDR機(jī)制,請參考:static DEFINE_IDR(i2c_adapter_idr)。struct i2c_adapter *adapter。 //適配器指針 core_lock)。adapter = (struct i2c_adapter *)idr_find(amp。if (adapter amp。 !try_module_get(adapterowner)) core_lock)。 //釋放內(nèi)核鎖 }適配器卸載函數(shù):主要任務(wù):注銷適配器的數(shù)據(jù)結(jié)構(gòu),刪除總線上的所有設(shè)備的I2c_client數(shù)據(jù)結(jié)構(gòu)和對應(yīng)的i2c_driver驅(qū)動程序,并減少其代表總線上所有設(shè)備的相應(yīng)驅(qū)動程序數(shù)據(jù)結(jié)構(gòu)的引用計數(shù)(如果到達(dá)0,則卸載設(shè)備驅(qū)動程序):int i2c_del_adapter(struct i2c_adapter *adap){ core_lock)。/* First make sure that this adapter was ever added */ i2c_adapter_idr, adapnr) != adap) { adapter [%s]\n, adapname)。 goto out_unlock。} res = bus_for_each_drv(amp。 i2c_do_del_adapter)。if (res) goto out_unlock。/* detach any active clients. This must be done first, because in which case we give up. */ adapclients, list) { struct i2c_driver driver = clientdriver。 i2c_unregister_device(client)。 continue。 dev_err(amp。 } /* clean up the sysfs representation */ adapdev_released)。device_unregister(amp。 設(shè)備注銷 wait_for_pletion(amp。 idr_remove(amp。dev_dbg(amp。 added again */ adapdev, 0, sizeof(adapdev))。out_unlock: core_lock)。return res。.master_xfer = s3c24xx_i2c_xfer, 這里只實現(xiàn)了IIC總線通信協(xié)議通信方法因不同的適配器有所不同,要跟據(jù)具體的硬件來實現(xiàn)協(xié)議支持函數(shù)s3c24xx_i2c_func()該函數(shù)返回總線支持的協(xié)議,如I2C_FUNC_I2C、I2C_FUNC_SMBUS_EMUL、I2C_FUNC_PROTOCOL_MANGLING協(xié)議:static u32 s3c24xx_i2c_func(struct i2c_adapter *adap){ }傳輸函數(shù)s3c24xx_i2c_xfer():static int s3c24xx_i2c_xfer(struct i2c_adapter *adap, struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adapalgo_data。 //從適配器的私有數(shù)據(jù)中獲得適配器s3c24xx_i2c結(jié)構(gòu)體 //傳輸錯誤重發(fā)次數(shù) for (retry = 0。 retry++) { ret = s3c24xx_i2c_doxfer(i2c, msgs, num)。 return ret。 } // I/O錯誤}真正的傳輸函數(shù):static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int num){ int ret。 //返回值,傳輸消息的個數(shù) //如果適配器處于掛起省電狀態(tài),則返回 return EIO。ret = s3c24xx_i2c_set_master(i2c)。 //將適配器設(shè)為主機(jī)發(fā)送狀態(tài),判斷總線忙閑狀態(tài) //如果總線繁忙,則傳輸失敗 dev_err(i2cdev, cannot get bus (error %d)\n, ret)。 goto out。} i2clock)。i2cmsg = msgs。i2cmsg_num = num。i2cmsg_ptr = 0。i2cmsg_idx = 0。i2cstate = STATE_START。s3c24xx_i2c_enable_irq(i2c)。 //啟動適配器中斷信號,允許適配器發(fā)出中斷 //當(dāng)調(diào)用該函數(shù)啟動 數(shù)據(jù)發(fā)送后,當(dāng)前進(jìn)程進(jìn)入睡眠狀態(tài),等待中斷到來,所以通過wait_event_timeout(),直到等待的條件i2cmsg_num == 0為真,或者5s超時后才能喚醒。 i2clock)。timeout = wait_event_timeout(i2cwait, i2cmsg_num == 0, HZ * 5)。ret = i2cmsg_idx。/* having these next two as dev_err() makes life very if (
點擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1