您的位置:首页 > 运维架构 > Linux

Linux Kernel 设备驱动之I2C之client之发送消息格式

2017-03-09 14:49 302 查看
前面host两种传输方式对应了两种消息格式:i2c_msg和i2c_smbus_data

/**
*structi2c_msg-anI2CtransactionsegmentbeginningwithSTART
*@addr:Slaveaddress,eithersevenortenbits.Whenthisisaten
*bitaddress,I2C_M_TENmustbesetin@flagsandtheadapter
*mustsupportI2C_FUNC_10BIT_ADDR.
*@flags:I2C_M_RDishandledbyalladapters.Nootherflagsmaybe
*providedunlesstheadapterexportedtherelevantI2C_FUNC_*
*flagsthroughi2c_check_functionality().
*@len:Numberofdatabytesin@bufbeingreadfromorwrittentothe
*I2Cslaveaddress.ForreadtransactionswhereI2C_M_RECV_LEN
*isset,thecallerguaranteesthatthisbuffercanholdupto
*32bytesinadditiontotheinitiallengthbytesentbythe
*slave(plus,ifused,theSMBusPEC);andthisvaluewillbe
*incrementedbythenumberofblockdatabytesreceived.
*@buf:Thebufferintowhichdataisread,orfromwhichit'swritten.
*
*Ani2c_msgisthelowlevelrepresentationofonesegmentofanI2C
*transaction.Itisvisibletodriversinthe@i2c_transfer()procedure,
*touserspacefromi2c-dev,andtoI2Cadapterdriversthroughthe
*@i2c_adapter.@master_xfer()method.
*
*ExceptwhenI2C"protocolmangling"isused,allI2Cadaptersimplement
*thestandardrulesforI2Ctransactions.Eachtransactionbeginswitha
*START.Thatisfollowedbytheslaveaddress,andabitencodingread
*versuswrite.Thenfollowallthedatabytes,possiblyincludingabyte
*withSMBusPEC.ThetransferterminateswithaNAK,orwhenallthose
*byteshavebeentransferredandACKed.Ifthisisthelastmessageina
*group,itisfollowedbyaSTOP.Otherwiseitisfollowedbythenext
*@i2c_msgtransactionsegment,beginningwitha(repeated)START.
*
*Alternatively,whentheadaptersupportsI2C_FUNC_PROTOCOL_MANGLINGthen
*passingcertain@flagsmayhavechangedthosestandardprotocolbehaviors.
*Thoseflagsareonlyforusewithbroken/nonconformingslaves,andwith
*adapterswhichareknowntosupportthespecificmanglingoptionsthey
*need(oneormoreofIGNORE_NAK,NO_RD_ACK,NOSTART,andREV_DIR_ADDR).
*/
structi2c_msg{
__u16addr;/*slaveaddress*/
__u16flags;
#defineI2C_M_RD0x0001/*readdata,fromslavetomaster*/
/*I2C_M_RDisguaranteedtobe0x0001!*/
#defineI2C_M_TEN0x0010/*thisisatenbitchipaddress*/
#defineI2C_M_RECV_LEN0x0400/*lengthwillbefirstreceivedbyte*/
#defineI2C_M_NO_RD_ACK0x0800/*ifI2C_FUNC_PROTOCOL_MANGLING*/
#defineI2C_M_IGNORE_NAK0x1000/*ifI2C_FUNC_PROTOCOL_MANGLING*/
#defineI2C_M_REV_DIR_ADDR0x2000/*ifI2C_FUNC_PROTOCOL_MANGLING*/
#defineI2C_M_NOSTART0x4000/*ifI2C_FUNC_NOSTART*/
#defineI2C_M_STOP0x8000/*ifI2C_FUNC_PROTOCOL_MANGLING*/
__u16len;/*msglength*/
__u8*buf;/*pointertomsgdata*/
};


/*
*DataforSMBusMessages
*/
#defineI2C_SMBUS_BLOCK_MAX32/*AsspecifiedinSMBusstandard*/
unioni2c_smbus_data{
__u8byte;
__u16word;
__u8block[I2C_SMBUS_BLOCK_MAX+2];/*block[0]isusedforlength*/
/*andonemoreforuser-spacecompatibility*/
};


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: