i2c_master_recv()/i2c_msg {}

inti2c_master_recv(struct i2c_client *client, char *buf ,int count)  

int i2c_master_recv(struct i2c_client *client, char *buf ,int count)//从芯片中读取数据,并存入buf

{
    struct i2c_adapter *adap=client->adapter;//获得设备的适配器结构
    struct i2c_msg msg;//获得一个读写数据用的结构,下文有详述
    int ret;
    msg.addr = client->addr;//从client中读到芯片地址
    msg.flags = client->flags & I2C_M_TEN;//这个暂且不知
    msg.flags |= I2C_M_RD;
    msg.len = count;//数写最大字节数
    msg.buf = buf;//读或写的buf
    ret = i2c_transfer(adap, &msg, 1);//调用函数传关数据
    /* If everything went ok (i.e. 1 msg transmitted), return #bytes
       transmitted, else error code. */
    return (ret == 1) ? count : ret;//看看是不是搞定了。
}

EXPORT_SYMBOL(i2c_master_recv);//导出符号


Name

struct i2c_msg — an I2C transaction segment beginning with START

Synopsis

struct i2c_msg {
  __u16 addr;
  __u16 flags;
#define I2C_M_TEN		0x0010
#define I2C_M_RD		0x0001
#define I2C_M_NOSTART		0x4000
#define I2C_M_REV_DIR_ADDR	0x2000
#define I2C_M_IGNORE_NAK	0x1000
#define I2C_M_NO_RD_ACK		0x0800
#define I2C_M_RECV_LEN		0x0400
  __u16 len;
  __u8 * buf;
};  

Members

addr

Slave address, either seven or ten bits. When this is a ten bit address, I2C_M_TEN must be set in flags and the adapter must support I2C_FUNC_10BIT_ADDR.

flags

I2C_M_RD is handled by all adapters. No other flags may be provided unless the adapter exported the relevant I2C_FUNC_* flags through i2c_check_functionality.

len

Number of data bytes in buf being read from or written to the I2C slave address. For read transactions where I2C_M_RECV_LEN is set, the caller guarantees that this buffer can hold up to 32 bytes in addition to the initial length byte sent by the slave (plus, if used, the SMBus PEC); and this value will be incremented by the number of block data bytes received.

buf

The buffer into which data is read, or from which it's written.

Description

An i2c_msg is the low level representation of one segment of an I2C transaction. It is visible to drivers in the i2c_transfer() procedure, to userspace from i2c-dev, and to I2C adapter drivers through the i2c_adapter.master_xfer() method.

Except when I2C “protocol mangling” is used, all I2C adapters implement the standard rules for I2C transactions. Each transaction begins with a START. That is followed by the slave address, and a bit encoding read versus write. Then follow all the data bytes, possibly including a byte with SMBus PEC. The transfer terminates with a NAK, or when all those bytes have been transferred and ACKed. If this is the last message in a group, it is followed by a STOP. Otherwise it is followed by the next i2c_msg transaction segment, beginning with a (repeated) START.

Alternatively, when the adapter supports I2C_FUNC_PROTOCOL_MANGLING then passing certain flags may have changed those standard protocol behaviors. Those flags are only for use with broken/nonconforming slaves, and with adapters which are known to support the specific mangling options they need (one or more of IGNORE_NAK, NO_RD_ACK, NOSTART, and REV_DIR_ADDR).

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值