Hi All,
I wanted to test an i2c peripheral using the user space i2c dev method. See Documentation/i2c/dev-interface.
This is supposed to provide a simple user space API for reading and writing data to an i2c client on an i2c bus. I've used this before on other ARM based boards, but the MV kernel seems to be NQR in this regard. When I try to build my (very simple) app, I get;
$ arm_v5t_le-gcc -O2 -o touchpad main.c
In file included from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/timex.h:58,
from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/sched.h:11,
from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/module.h:10,
from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/i2c.h:31,
from main.c:5:
/opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/time.h:12: error: redefinition of `struct timespec'
/opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/time.h:18: error: redefinition of `struct timeval'
In file included from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/timex.h:61,
from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/sched.h:11,
from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/module.h:10,
from /opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/linux/i2c.h:31,
from main.c:5:
/opt/mv_pro_4.0.1/montavista/pro/devkit/arm/v5t_le/bin/../target/usr/include/asm/timex.h:16:28: asm/arch/timex.h: No such file or directory
<snip - this goes on for ages>
So it looks like my MV tools are NQR, as this compiles ok using my desktop kernel.
From the source:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
int main(int argc, char **argv)
{
int ret;
int addr = 5;
int reg = 0;
char buf[4];
int fd = open("/dev/i2c/0", O_RDWR);
if (fd < 0) {
perror("open");
return 1;
}
ret = ioctl(fd, I2C_SLAVE, addr);
if (ret < 0) {
perror("ioctl");
return 1;
}
buf[0] = 0;
ret = write(fd, buf, 1);
if (ret < 0) {
perror("write");
return 1;
}
ret = read(fd, buf, 2);
if (ret < 0) {
perror("read");
return 1;
}
fprintf(stderr, "read: %04x\n", *(unsigned short *)buf);
close(fd);
return 0;
}
Has anyone else seen this type of thing?
James.