基于S3c2440的I2C驱动与测试程序追踪交叉分析.doc

上传人:白大夫 文档编号:3411816 上传时间:2019-08-22 格式:DOC 页数:4 大小:22.50KB
返回 下载 相关 举报
基于S3c2440的I2C驱动与测试程序追踪交叉分析.doc_第1页
第1页 / 共4页
亲,该文档总共4页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《基于S3c2440的I2C驱动与测试程序追踪交叉分析.doc》由会员分享,可在线阅读,更多相关《基于S3c2440的I2C驱动与测试程序追踪交叉分析.doc(4页珍藏版)》请在三一文库上搜索。

1、基于S3c2440的I2C驱动与测试程序追踪交叉分析VMware虚拟机+Fedora10, 硬件平台TQ2440, 内核2.6.30.4对应的驱动程序豁然开朗, 然后自己添加了一些dev_dbg后, 对于不理解的地方也有了一定的参考提示, 记录下来与大家分享。测试程序如下:/*i2c_test.c* hongtao_liu*/#include#include#include#include#include#include#include#include#define I2C_RETRIES 0x0701#define I2C_TIMEOUT 0x0702#define I2C_RDWR 0x0

2、707/*定义struct i2c_rdwr_ioctl_data和struct i2c_msg,要和内核一致*/struct i2c_msgunsigned short addr;unsigned short flags;#define I2C_M_TEN 0x0010#define I2C_M_RD 0x0001unsigned short len;unsigned char *buf;struct i2c_rdwr_ioctl_datastruct i2c_msg *msgs;int nmsgs;/* nmsgs这个数量决定了有多少开始信号,对于“单开始时序”,取1*/;/*主程序*/i

3、nt main()int fd,ret;struct i2c_rdwr_ioctl_data e2prom_data;fd=open(“/dev/i2c-0”,O_RDWR);/*dev/i2c-0是在注册i2c-dev.c后产生的,代表一个可操作的适配器。如果不使用i2c-dev.c*的方式,就没有,也不需要这个节点。*/if(fd0)perror(“open error”);e2prom_data.nmsgs=2;/*因为操作时序中,最多是用到2个开始信号(字节读操作中),所以此将*e2prom_data.nmsgs配置为2*/e2prom_data.msgs=(struct i2c_ms

4、g*)malloc(e2prom_data.nmsgs*sizeof(struct i2c_msg);if(!e2prom_data.msgs)perror(“malloc error”);exit(1);ioctl(fd,I2C_TIMEOUT,1);/*超时时间*/ioctl(fd,I2C_RETRIES,2);/*重复次数*/*write data to e2prom*/e2prom_data.nmsgs=1;(e2prom_data.msgs0).len=2; /1个 e2prom 写入目标的地址和1个数据(e2prom_data.msgs0).addr=0x50;/e2prom 设备

5、地址(e2prom_data.msgs0).flags=0; /write(e2prom_data.msgs0).buf=(unsigned char*)malloc(2);(e2prom_data.msgs0).buf0=0x10;/ e2prom 写入目标的地址(e2prom_data.msgs0).buf1=0x58;/the data to writeret=ioctl(fd,I2C_RDWR,(unsigned long)if(ret0)perror(“ioctl error1”);sleep(1);/*read data from e2prom*/e2prom_data.nmsgs

6、=2;(e2prom_data.msgs0).len=1; /e2prom 目标数据的地址(e2prom_data.msgs0).addr=0x50; / e2prom 设备地址(e2prom_data.msgs0).flags=0;/write(e2prom_data.msgs0).buf0=0x10;/e2prom数据地址(e2prom_data.msgs1).len=1;/读出的数据(e2prom_data.msgs1).addr=0x50;/ e2prom 设备地址(e2prom_data.msgs1).flags=I2C_M_RD;/read(e2prom_data.msgs1).buf=(unsigned char*)malloc(1);/存放返回值的地址。(e2prom_data.msgs1).buf0=0;/初始化读缓冲ret=ioctl(fd,I2C_RDWR,(unsigned long)if(ret0)perror(“ioctl error2”);printf(“buff0=%xn”,(e2prom_data.msgs1).buf0);/*打印读出的值,没错的话,就应该是前面写的0x58了*/close(fd);return 0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1