磨蹭了这么久。。写了一个相对看的过去的eeprom的应用程序。。
板子是fl2440。。跑的是Linux3.0。。主机是centos6.5。。
eeprom.h头文件
14 #include<stdio.h>
15 #include<string.h>
16 #include<unistd.h>
17 #include<sys/ioctl.h>
18 #include<stdlib.h>
19 #include<fcntl.h>
20 #include<sys/io.h>
21 #include <getopt.h>
22
23 #define SN_LEN 12 //定义的sn数据的长度
24 #define MAC_LEN 17 //定义的mac数据的长度
25 #define OWN_LEN 20 //定义的own数据的长度
26 //这里的sn和mac是定长的。。而own是变长的最大长度为20
27 #define SN_OFFSET 0 //各个数据的偏移量
28 #define MAC_OFFSET SN_OFFSET + SN_LEN
29 #define OWN_OFFSET MAC_OFFSET + MAC_LEN
eeprom.c直接操作eeprom的函数文件
14 #include "eeprom.h"
15
16 int open_eeprom(void) //打开设备节点。。并返回文件描述符
17 {
18 int fd;
19
20 fd = open("/sys/devices/platform/s3c2440-i2c/i2c-0/0-0050/eeprom", O_RDWR);
21 if(fd < 0)
22 {
23 printf("open 24c02 fail\n");
24 return -1;
25 }
26
27 return fd;
28 }
29
30 int close_eeprom(void) //关闭文件节点的函数
31 {
32
33 return 0;
34 }
35
36 int read_eeprom(int offset, char *buf, int len) //读eeprom。。参数是偏移。。buf。。长度
37 {
38 int fd;
39 int ret;
40
41 fd = open_eeprom();
42 lseek(fd, offset, SEEK_SET); //设置偏移
43
44 ret = read(fd, buf, len); /