28 #if defined(COSMOS_LINUX_OS) 29 #include <linux/types.h> 30 #include <sys/ioctl.h> 42 #define I2C_M_TEN 0x10 44 #define I2C_M_NOSTART 0x4000 45 #define I2C_M_REV_DIR_ADDR 0x2000 46 #define I2C_M_IGNORE_NAK 0x1000 47 #define I2C_M_NO_RD_ACK 0x0800 54 #define I2C_FUNC_I2C 0x00000001 55 #define I2C_FUNC_10BIT_ADDR 0x00000002 56 #define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 57 #define I2C_FUNC_SMBUS_PEC 0x00000008 58 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 59 #define I2C_FUNC_SMBUS_QUICK 0x00010000 60 #define I2C_FUNC_SMBUS_READ_BYTE 0x00020000 61 #define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000 62 #define I2C_FUNC_SMBUS_READ_BYTE_DATA 0x00080000 63 #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA 0x00100000 64 #define I2C_FUNC_SMBUS_READ_WORD_DATA 0x00200000 65 #define I2C_FUNC_SMBUS_WRITE_WORD_DATA 0x00400000 66 #define I2C_FUNC_SMBUS_PROC_CALL 0x00800000 67 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000 68 #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000 69 #define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 70 #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 72 #define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \ 73 I2C_FUNC_SMBUS_WRITE_BYTE) 74 #define I2C_FUNC_SMBUS_BYTE_DATA (I2C_FUNC_SMBUS_READ_BYTE_DATA | \ 75 I2C_FUNC_SMBUS_WRITE_BYTE_DATA) 76 #define I2C_FUNC_SMBUS_WORD_DATA (I2C_FUNC_SMBUS_READ_WORD_DATA | \ 77 I2C_FUNC_SMBUS_WRITE_WORD_DATA) 78 #define I2C_FUNC_SMBUS_BLOCK_DATA (I2C_FUNC_SMBUS_READ_BLOCK_DATA | \ 79 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA) 80 #define I2C_FUNC_SMBUS_I2C_BLOCK (I2C_FUNC_SMBUS_READ_I2C_BLOCK | \ 81 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK) 84 #define I2C_FUNC_SMBUS_HWPEC_CALC I2C_FUNC_SMBUS_PEC 89 #define I2C_SMBUS_BLOCK_MAX 32 90 #define I2C_SMBUS_I2C_BLOCK_MAX 32 91 union i2c_smbus_data {
94 __u8 block[I2C_SMBUS_BLOCK_MAX + 2];
99 #define I2C_SMBUS_READ 1 100 #define I2C_SMBUS_WRITE 0 104 #define I2C_SMBUS_QUICK 0 105 #define I2C_SMBUS_BYTE 1 106 #define I2C_SMBUS_BYTE_DATA 2 107 #define I2C_SMBUS_WORD_DATA 3 108 #define I2C_SMBUS_PROC_CALL 4 109 #define I2C_SMBUS_BLOCK_DATA 5 110 #define I2C_SMBUS_I2C_BLOCK_BROKEN 6 111 #define I2C_SMBUS_BLOCK_PROC_CALL 7 112 #define I2C_SMBUS_I2C_BLOCK_DATA 8 121 #define I2C_RETRIES 0x0701 124 #define I2C_TIMEOUT 0x0702 128 #define I2C_SLAVE 0x0703 130 #define I2C_SLAVE_FORCE 0x0706 134 #define I2C_TENBIT 0x0704 136 #define I2C_FUNCS 0x0705 137 #define I2C_RDWR 0x0707 138 #define I2C_PEC 0x0708 140 #define I2C_SMBUS 0x0720 148 struct i2c_smbus_ioctl_data {
152 union i2c_smbus_data *data;
156 struct i2c_rdwr_ioctl_data {
157 struct i2c_msg *msgs;
162 static inline __s32 i2c_smbus_access(
int file,
char read_write, __u8
command,
163 int size,
union i2c_smbus_data *data)
165 struct i2c_smbus_ioctl_data args;
167 args.read_write = read_write;
171 return ioctl(file,I2C_SMBUS,&args);
175 static inline __s32 i2c_smbus_write_quick(
int file, __u8 value)
177 return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
180 static inline __s32 i2c_smbus_read_byte(
int file)
182 union i2c_smbus_data data;
183 if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
186 return 0x0FF & data.byte;
189 static inline __s32 i2c_smbus_write_byte(
int file, __u8 value)
191 return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
192 I2C_SMBUS_BYTE,NULL);
195 static inline __s32 i2c_smbus_read_byte_data(
int file, __u8
command)
197 union i2c_smbus_data data;
198 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
199 I2C_SMBUS_BYTE_DATA,&data))
202 return 0x0FF & data.byte;
205 static inline __s32 i2c_smbus_write_byte_data(
int file, __u8 command,
208 union i2c_smbus_data data;
210 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
211 I2C_SMBUS_BYTE_DATA, &data);
214 static inline __s32 i2c_smbus_read_word_data(
int file, __u8 command)
216 union i2c_smbus_data data;
217 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
218 I2C_SMBUS_WORD_DATA,&data))
221 return 0x0FFFF & data.word;
224 static inline __s32 i2c_smbus_write_word_data(
int file, __u8 command,
227 union i2c_smbus_data data;
229 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
230 I2C_SMBUS_WORD_DATA, &data);
233 static inline __s32 i2c_smbus_process_call(
int file, __u8 command, __u16 value)
235 union i2c_smbus_data data;
237 if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
238 I2C_SMBUS_PROC_CALL,&data))
241 return 0x0FFFF & data.word;
246 static inline __s32 i2c_smbus_read_block_data(
int file, __u8 command,
249 union i2c_smbus_data data;
251 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
252 I2C_SMBUS_BLOCK_DATA,&data))
255 for (i = 1; i <= data.block[0]; i++)
256 values[i-1] = data.block[i];
257 return data.block[0];
261 static inline __s32 i2c_smbus_write_block_data(
int file, __u8 command,
262 __u8
length,
const __u8 *values)
264 union i2c_smbus_data data;
268 for (i = 1; i <=
length; i++)
269 data.block[i] = values[i-1];
270 data.block[0] = length;
271 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
272 I2C_SMBUS_BLOCK_DATA, &data);
279 static inline __s32 i2c_smbus_read_i2c_block_data(
int file, __u8 command,
280 __u8 length, __u8 *values)
282 union i2c_smbus_data data;
288 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
289 length == 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN :
290 I2C_SMBUS_I2C_BLOCK_DATA,&data))
293 for (i = 1; i <= data.block[0]; i++)
294 values[i-1] = data.block[i];
295 return data.block[0];
299 static inline __s32 i2c_smbus_write_i2c_block_data(
int file, __u8 command,
303 union i2c_smbus_data data;
307 for (i = 1; i <=
length; i++)
308 data.block[i] = values[i-1];
309 data.block[0] = length;
310 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
311 I2C_SMBUS_I2C_BLOCK_BROKEN, &data);
315 static inline __s32 i2c_smbus_block_process_call(
int file, __u8 command,
316 __u8 length, __u8 *values)
318 union i2c_smbus_data data;
322 for (i = 1; i <=
length; i++)
323 data.block[i] = values[i-1];
324 data.block[0] = length;
325 if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
326 I2C_SMBUS_BLOCK_PROC_CALL,&data))
329 for (i = 1; i <= data.block[0]; i++)
330 values[i-1] = data.block[i];
331 return data.block[0];
int i
Definition: rw_test.cpp:37
string command
Definition: add_radio.cpp:27
png_uint_32 length
Definition: png.c:2173
char buf[128]
Definition: rw_test.cpp:40