linux下i2c从设备可以主动发数据,Linux Kernel 设备驱动之I2C之host之数据传输
/* To determine what the adapter supports */ u32 (*functionality) (struct i2c_adapter *);
#if IS_ENABLED(CONFIG_I2C_SLAVE) int (*reg_slave)(struct i2c_client *client); int (*unreg_slave)(struct i2c_client *client);#endif};由于这些跟具体的host相关,所以,在理解host ic之上实现这些函数。
其实根据上面两个函数master_xfer和smbus_xfer就可以明白,I2C支持两个类别的传输。对此
内核封装两个函数:i2c_smbus_xfer和__i2c_transfer(),对于后者,其提供封装接口i2c_transfer()
/** * __i2c_transfer - unlocked flavor of i2c_transfer * @adap: Handle to I2C bus * @msgs: One or more messages to execute before STOP is issued to * terminate the operation; each message begins with a START. * @num: Number of messages to be executed. * * Returns negative errno, else the number of messages executed. * * Adapter lock must be held when calling this function. No debug logging * takes place. adap->algo->master_xfer existence isn't checked. */int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num){ unsigned long orig_jiffies; int ret, try;
if (adap->quirks && i2c_check_for_quirks(adap, msgs, num)) return -EOPNOTSUPP;
/* i2c_trace_msg gets enabled when tracepoint i2c_transfer gets * enabled. This is an efficient way of keeping the for-loop from * being executed when not needed. */ if (static_key_false(&i2c_trace_msg)) { int i; for (i = 0; i < num; i++) if (msgs[i].flags & I2C_M_RD) trace_i2c_read(adap, &msgs[i], i); else trace_i2c_write(adap, &msgs[i], i); }
/* Retry automatically on arbitration loss */ orig_jiffies = jiffies; for (ret = 0, try = 0; try <= adap->retries; try++) { ret = adap->algo->master_xfer(adap, msgs, num); if (ret != -EAGAIN) break; if (time_after(jiffies, orig_jiffies + adap->timeout)) break; }
if (static_key_false(&i2c_trace_msg)) { int i; for (i = 0; i < ret; i++) if (msgs[i].flags & I2C_M_RD) trace_i2c_reply(adap, &msgs[i], i); trace_i2c_result(adap, i, ret); }
return ret;}
/** * i2c_smbus_xfer - execute SMBus protocol operations * @adapter: Handle to I2C bus * @addr: Address of SMBus slave on that bus * @flags: I2C_CLIENT_* flags (usually zero or I2C_CLIENT_PEC) * @read_write: I2C_SMBUS_READ or I2C_SMBUS_WRITE * @command: Byte interpreted by slave, for protocols which use such bytes * @protocol: SMBus protocol operation to execute, such as I2C_SMBUS_PROC_CALL * @data: Data to be read or written * * This executes an SMBus protocol operation, and returns a negative * errno code else zero on success. */s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, char read_write, u8 command, int protocol, union i2c_smbus_data *data){ unsigned long orig_jiffies; int try; s32 res;
/* If enabled, the following two tracepoints are conditional on * read_write and protocol. */ trace_smbus_write(adapter, addr, flags, read_write, command, protocol, data); trace_smbus_read(adapter, addr, flags, read_write, command, protocol);
flags &= I2C_M_TEN | I2C_CLIENT_PEC | I2C_CLIENT_SCCB;
if (adapter->algo->smbus_xfer) { i2c_lock_bus(adapter, I2C_LOCK_SEGMENT);
/* Retry automatically on arbitration loss */ orig_jiffies = jiffies; for (res = 0, try = 0; try <= adapter->retries; try++) { res = adapter->algo->smbus_xfer(adapter, addr, flags, read_write, command, protocol, data); if (res != -EAGAIN) break; if (time_after(jiffies, orig_jiffies + adapter->timeout)) break; } i2c_unlock_bus(adapter, I2C_LOCK_SEGMENT);
if (res != -EOPNOTSUPP || !adapter->algo->master_xfer) goto trace; /* * Fall back to i2c_smbus_xfer_emulated if the adapter doesn't * implement native support for the SMBus operation. */ }
res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, command, protocol, data);
trace: /* If enabled, the reply tracepoint is conditional on read_write. */ trace_smbus_reply(adapter, addr, flags, read_write, command, protocol, data); trace_smbus_result(adapter, addr, flags, read_write, command, protocol, res);
return res;}
linux下i2c从设备可以主动发数据,Linux Kernel 设备驱动之I2C之host之数据传输相关推荐
- linux运行隐藏文件,Linux下如何隐藏文件_网站服务器运行维护,Linux,隐藏文件
linux系统怎样安装软件_网站服务器运行维护 linux系统安装软件的方法:1.使用apt命令进行安装,如[apt install app_name]:2.使用rpm命令进行安装,如[rpm -i ...
- linux系统电脑的权限设置,Linux下的文件权限设置修改详解linux操作系统 -电脑资料...
在linux中更改所属用户组是使用chgrp,更改文件拥有者, chown,更改9个属性, chmod这三种常用的问题,在linxu中这三个命令就是对文件目录权限的控制命令了,下面我来介绍它们的用法与 ...
- 在AIX或Linux下,如何查看磁盘是否包含数据?
在AIX或Linux下,如何查看磁盘是否包含数据? 真题1.在AIX或Linux下,如何查看磁盘是否包含数据? 答案:在AIX下,可以使用lquerypv -h来查看磁盘是否包含数据,或磁盘头是否被d ...
- Linux下安装tuned以使用tuned-adm命令优化Linux系统性能
本文介绍在RHEL.CentOS 8/7.Ubuntu.Debian Linux下安装tuned以使用tuned-adm命令优化Linux系统性能.作为系统管理员,您应该能够通过调整各种设置来优化Li ...
- Linux下安装mysql以及配置用户与数据导入
Linux下安装mysql以及配置用户与数据导入 yun安装mysql linux下有一个很神奇的东西叫yum,只要有源,用yum来安装是一件非常容易的事,什么都不用管,它会为你解决好一些软件依赖的问 ...
- 在Linux下安装tuned以使用tuned-adm命令优化Linux系统性能
本文介绍在RHEL.CentOS 8/7.Ubuntu.Debian Linux下安装tuned以使用tuned-adm命令优化Linux系统性能.作为系统管理员,您应该能够通过调整各种设置来优化Li ...
- 视频教程-Linux下Shell从入门到精通完整版-Linux
Linux下Shell从入门到精通完整版 京东商城运维架构师,京峰Linux云计算教学总监,担任国内多家知名社区运维专家网站Linux版主,专注Linux自动化运维,熟练LVS.Nginx,前端架构及 ...
- Linux下配置用msmtp和mutt发邮件
Linux下可以直接用mail命令发送邮件,但是发件人是user@servername,如果机器没有外网的dns,其他人就无法回复.此时,有一个可以使用网络免费邮箱服务的邮件发送程序就比较重要了.ms ...
- 把windows装到linux下,如何将WSL(Windows Subsystem for Linux 2)安装到Windows 10?
原标题:如何将WSL(Windows Subsystem for Linux 2)安装到Windows 10? Windows 10凭借大受欢迎的WSL(Windows Subsystem for L ...
最新文章
- Docker无法修改devicemapper(四)
- Leet Code OJ 203. Remove Linked List Elements [Difficulty: Easy]
- html5 微格式,HTML5 微格式和相关的属性名称
- 构建高性能.NET应用之配置高可用IIS服务器-第五篇 IIS常见问题之:工作进程回收机制(中)...
- day02:关于惯性导航工具箱的学习与使用:use of the progen
- Advanced clustering methods (Cure, Chameleon, Rock, Jarvis-Petrich)
- NGFF(M.2) m.2中Bkey接口Mkey接口有什么不同
- 最新版最简单SPSS 26安装详细教程
- MTK7621 uboot编译与烧写
- 草莓派Raspberry3B
- JAVA长方形正方形_正方形不是长方形的终极解决办法
- 斑马打印机 ZPL打印
- 【2020GAN】对抗生成网络论文收录(1月-6月)
- c语言购买电影票程序,求助,怎么改把程序产生数据写入文件里,电影票管理系统,大佬们...
- 缺陷管理工具--Mantis
- r语言实现关联分析--关联规则挖掘(Apriori算法) (r语言预测学习笔记)
- ODBC连接达梦数据库
- 中望CAD的lisp编辑器_巧用中望CAD2017自定义工具选项板
- 点到超平面的距离公式推导
- 什么是私约、助记词和密码?