First of al this patch works only with 2.6 kernel
You have to copy & paste the contents of boxes in two files (i2c.c
and etraxi2c.h) and then replace the orginals devboard files.
i2c.c is located in $YOURDEVBOADPATH/os/linux-2.6/arch/cris/drivers/i2c.c
etraxi2c.h is located in
$YOURDEVBOADPATH/os/linux-2.6/include/asm/etraxi2c.h
After that you have to rebuild the new fimage and download it to the fox.
This is the test code that i have used to test the devices.
// -----------------------------------------------------------------
#define SLAVE_COMPASS_ADDR 0xC0
#define SLAVE_SONAR_ADDR 0xE0
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/ioctl.h"
#include "fcntl.h"
#include "time.h"
#include "string.h"
#include <asm/etraxi2c.h>
#include <asm/i2c_errno.h>
extern errno;
// Global variables
int fd_i2c;
int I2C_Open(void) {
fd_i2c = open("/dev/i2c", O_RDWR);
if (fd_i2c <= 0) {
perror("i2c");
printf("I2C: open error on /dev/i2c %d %d\n",fd_i2c,errno);
return(-1);
}
return(0);
}
void I2C_Close(void) {
close(fd_i2c);
}
int main(int argc, char **argv) {
int retcode; int i,j; unsigned char ch;
retcode = I2C_Open();
if (retcode != 0) {
exit(1);
}
unsigned long arg;
int range;
// Get sonar firmware version
arg=I2C_READARG(SLAVE_SONAR_ADDR,0x00);
arg=ioctl(fd_i2c,_IO(ETRAXI2C_IOCTYPE,I2C_READREG),arg);
printf("Sonar firmware version: %d\n",arg);
// Get compass firmware version
arg=I2C_READARG(SLAVE_COMPASS_ADDR,0x00);
arg=ioctl(fd_i2c,_IO(ETRAXI2C_IOCTYPE,I2C_READREG),arg);
printf("Compass firmware version: %d\n",arg);
// First sonar shot
arg=I2C_WRITEARG(0xE0,0x00,0x51);
ioctl(fd_i2c,_IO(ETRAXI2C_IOCTYPE,I2C_WRITEREG),arg);
usleep(100000);
while(1) {
arg=I2C_READARG(0xC0,0x02);
arg=ioctl(fd_i2c,_IO(ETRAXI2C_IOCTYPE,I2C_READREG),arg);
range=arg << 8;
arg=I2C_READARG(0xC0,0x03);
arg=ioctl(fd_i2c,_IO(ETRAXI2C_IOCTYPE,I2C_READREG),arg);
range+=arg;
printf("Compass value 0xC0 %d\n",range);
arg=I2C_READARG(0xE0,0x02);
arg=ioctl(fd_i2c,_IO(ETRAXI2C_IOCTYPE,I2C_READREG),arg);
range=arg << 8;
arg=I2C_READARG(0xE0,0x03);
arg=ioctl(fd_i2c,_IO(ETRAXI2C_IOCTYPE,I2C_READREG),arg);
range+=arg;
printf("Sonar value 0xE0 %d\n",range);
arg=I2C_WRITEARG(0xE0,0x00,0x51);
ioctl(fd_i2c,_IO(ETRAXI2C_IOCTYPE,I2C_WRITEREG),arg);
usleep(65000);
}
I2C_Close();
return(0);
}
Bye
Stefano
// -----------------------------------------------------------------
--- In [email protected], "Paolo Pinto" <[EMAIL PROTECTED]> wrote:
>
> Hello Stefano,
>
> Thanks very much for your suggestion.
>
> Please could you explain to me how to use the source you submitted:
>
http://developer.axis.com/wiki/doku.php?id=contributions#i2c_driver_update
> Do I have to recompile the kernel or what else ?
>
> Thanks a lot
>
> Paolo