久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2538|回復: 0
收起左側

exynos4412 I2C EEPROM測試程序

[復制鏈接]
ID:170856 發表于 2017-3-15 11:32 | 顯示全部樓層 |閱讀模式
這是的exynos4412  I2C  EEPROM測試程序。

  1. /***************************************************************************
  2.     copyright            : (C) by 2003-2004 Stefano Barbato
  3.     email                : [url=mailto:stefano@codesink.org]stefano@codesink.org[/url]
  4.     $Id: 24cXX.c,v 1.5 02/29 11:05:28 tat Exp $
  5. ***************************************************************************/
  6. /***************************************************************************
  7. *                                                                         *
  8. *   This program is free software; you can redistribute it and/or modify  *
  9. *   it under the terms of the GNU General Public License as published by  *
  10. *   the Free Software Foundation; either version 2 of the License, or     *
  11. *   (at your option) any later version.                                   *
  12. *                                                                         *
  13. ***************************************************************************/
  14. #include <stdio.h>
  15. #include <fcntl.h>
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18. #include <linux/fs.h>
  19. #include <sys/types.h>
  20. #include <sys/ioctl.h>
  21. #include <errno.h>
  22. #include <assert.h>
  23. #include <string.h>
  24. #include <linux/i2c-dev.h>
  25. #include <linux/i2c.h>
  26. static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
  27.                                      int size, union i2c_smbus_data *data)
  28. {
  29. struct i2c_smbus_ioctl_data args;
  30. args.read_write = read_write;
  31. args.command = command;
  32. args.size = size;
  33. args.data = data;
  34. return ioctl(file,I2C_SMBUS,&args);
  35. }

  36. static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
  37. {
  38. return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
  39. }

  40. static inline __s32 i2c_smbus_read_byte(int file)
  41. {
  42. union i2c_smbus_data data;
  43. if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
  44.   return -1;
  45. else
  46.   return 0x0FF & data.byte;
  47. }
  48. static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
  49. {
  50. return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
  51.                          I2C_SMBUS_BYTE,NULL);
  52. }
  53. static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
  54. {
  55. union i2c_smbus_data data;
  56. if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
  57.                       I2C_SMBUS_BYTE_DATA,&data))
  58.   return -1;
  59. else
  60.   return 0x0FF & data.byte;
  61. }
  62. static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,
  63.                                               __u8 value)
  64. {
  65. union i2c_smbus_data data;
  66. data.byte = value;
  67. return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
  68.                          I2C_SMBUS_BYTE_DATA, &data);
  69. }
  70. static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
  71. {
  72. union i2c_smbus_data data;
  73. if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
  74.                       I2C_SMBUS_WORD_DATA,&data))
  75.   return -1;
  76. else
  77.   return 0x0FFFF & data.word;
  78. }
  79. static inline __s32 i2c_smbus_write_word_data(int file, __u8 command,
  80.                                               __u16 value)
  81. {
  82. union i2c_smbus_data data;
  83. data.word = value;
  84. return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
  85.                          I2C_SMBUS_WORD_DATA, &data);
  86. }
  87. static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
  88. {
  89. union i2c_smbus_data data;
  90. data.word = value;
  91. if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
  92.                       I2C_SMBUS_PROC_CALL,&data))
  93.   return -1;
  94. else
  95.   return 0x0FFFF & data.word;
  96. }

  97. /* Returns the number of read bytes */
  98. static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
  99.                                               __u8 *values)
  100. {
  101. union i2c_smbus_data data;
  102. int i;
  103. if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
  104.                       I2C_SMBUS_BLOCK_DATA,&data))
  105.   return -1;
  106. else {
  107.   for (i = 1; i <= data.block[0]; i++)
  108.    values[i-1] = data.block[i];
  109.   return data.block[0];
  110. }
  111. }
  112. static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
  113.                                                __u8 length, __u8 *values)
  114. {
  115. union i2c_smbus_data data;
  116. int i;
  117. if (length > 32)
  118.   length = 32;
  119. for (i = 1; i <= length; i++)
  120.   data.block[i] = values[i-1];
  121. data.block[0] = length;
  122. return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
  123.                          I2C_SMBUS_BLOCK_DATA, &data);
  124. }
  125. /* Returns the number of read bytes */
  126. static inline __s32 i2c_smbus_read_i2c_block_data(int file, __u8 command,
  127.                                                   __u8 *values)
  128. {
  129. union i2c_smbus_data data;
  130. int i;
  131. if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
  132.                        I2C_SMBUS_I2C_BLOCK_DATA,&data))
  133.   return -1;
  134. else {
  135.   for (i = 1; i <= data.block[0]; i++)
  136.    values[i-1] = data.block[i];
  137.   return data.block[0];
  138. }
  139. }
  140. static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
  141.                                                __u8 length, __u8 *values)
  142. {
  143. union i2c_smbus_data data;
  144. int i;
  145. if (length > 32)
  146.   length = 32;
  147. for (i = 1; i <= length; i++)
  148.   data.block[i] = values[i-1];
  149. data.block[0] = length;
  150. return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
  151.                          I2C_SMBUS_I2C_BLOCK_DATA, &data);
  152. }
  153. /* Returns the number of read bytes */
  154. static inline __s32 i2c_smbus_block_process_call(int file, __u8 command,
  155.                                                  __u8 length, __u8 *values)
  156. {
  157. union i2c_smbus_data data;
  158. int i;
  159. if (length > 32)
  160.   length = 32;
  161. for (i = 1; i <= length; i++)
  162.   data.block[i] = values[i-1];
  163. data.block[0] = length;
  164. if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
  165.                       I2C_SMBUS_BLOCK_PROC_CALL,&data))
  166.   return -1;
  167. else {
  168.   for (i = 1; i <= data.block[0]; i++)
  169.    values[i-1] = data.block[i];
  170.   return data.block[0];
  171. }
  172. }
  173. #define CHECK_I2C_FUNC( var, label ) \
  174. do {  if(0 == (var & label)) { \
  175.   fprintf(stderr, "\nError: " \
  176.    #label " function is required. Program halted.\n\n"); \
  177.   exit(1); } \
  178. } while(0);
  179. int main(int argc, char** argv)
  180. {
  181. int funcs, fd, r;
  182.         //int addr = 0x68;
  183.         int addr = 0x50;
  184. fd = 0;
  185.         __u8 buf[2];
  186.         __u8 dat[2];

  187. fd = open("/dev/i2c/0", O_RDWR);
  188. if(fd <= 0)
  189. {
  190.   fprintf(stderr, "Error sensor_open: %s\n", strerror(errno));
  191.   return -1;
  192. }
  193. if((r = ioctl(fd, I2C_FUNCS, &funcs) < 0))
  194. {
  195.   fprintf(stderr, "Error sensor_open: %s\n", strerror(errno));
  196.   return -1;
  197. }

  198. // check for req funcs
  199. CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_READ_BYTE );
  200. CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_WRITE_BYTE );
  201. CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_READ_BYTE_DATA );
  202. CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_WRITE_BYTE_DATA );
  203. CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_READ_WORD_DATA );
  204. CHECK_I2C_FUNC( funcs, I2C_FUNC_SMBUS_WRITE_WORD_DATA );
  205. // set working device
  206. if( ( r = ioctl(fd, I2C_SLAVE, addr)) < 0)
  207. {
  208.   fprintf(stderr, "Error sensor_open: %s\n", strerror(errno));
  209.   return -1;
  210. }
  211. #if 0
  212.         buf[0] = 0x1A;
  213.         buf[1] = 0x07;
  214.         i2c_write_2b(fd, buf);
  215.         i2c_write_1b(fd, 0x41);
  216. dat[1] = i2c_smbus_read_byte(fd);
  217.         i2c_write_1b(fd, 0x42);
  218. dat[0] = i2c_smbus_read_byte(fd);
  219. #endif
  220.         
  221.         printf("begin to test...\n");
  222.         buf[0] = 0x01;
  223.         buf[1] = 0x6c;
  224.         r = i2c_smbus_write_byte_data(fd, buf[0], buf[1]);
  225.         if(r < 0){printf(" current smbus_wirte_byte_data error.\n");};
  226.         printf("write data ok.\n");
  227.         usleep(1000);
  228.         fflush(stdout);
  229.      
  230.         r = i2c_smbus_read_byte_data(fd, 0x01);
  231.         if(r < 0){
  232.   printf("current smbus_wirte_byte error1.\n");
  233.         }else{
  234.          printf("set high address ok.\n");
  235.         }


  236. …………余下代碼請下載附件…………
  237. }
復制代碼
下載:
exynos4412 I2C EEPROM測試程序.rar (1.8 KB, 下載次數: 5)
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美日韩视频一区二区 | 九色 在线 | 国产aa| 中文字幕一区二区三区精彩视频 | av看看| 欧美色综合一区二区三区 | 新超碰97| 蜜桃av人人夜夜澡人人爽 | 999免费观看视频 | 黄网站在线观看 | 亚洲福利精品 | 中文字幕av一区 | 日韩视频国产 | 久久久久一区二区 | 天堂av中文 | 人人鲁人人莫人人爱精品 | 国产成人免费视频网站高清观看视频 | 日韩精品无码一区二区三区 | av中文字幕网 | 四虎影| 欧美亚洲视频 | 国产电影一区二区在线观看 | 亚洲午夜av久久乱码 | 欧美一区二区三区视频在线观看 | 91精品国产91久久久久久丝袜 | 亚洲综合二区 | 九九久久免费视频 | 自拍视频国产 | 欧美寡妇偷汉性猛交 | 国产日韩欧美中文 | 欧产日产国产精品视频 | 一区二区免费 | 欧美成视频在线观看 | 午夜影院在线观看视频 | 国产免费人成xvideos视频 | 日本一区二区三区视频在线 | 视频一区在线观看 | 亚洲国产精品一区二区三区 | 欧美一级欧美一级在线播放 | 亚洲欧美日韩电影 | 久久久久久久久久久久久久国产 |