i2c acces threadsafe ?

This forum is for topics specific to the Raspberry Pi and Arch Linux ARM

i2c acces threadsafe ?

Postby oklitz » Sat Dec 07, 2013 2:14 pm

Hi !

I dont know.... or i'm not really sure if the i2c acces is threadsafe

Heres my problem:

process 1:

ioctl(fd, I2C_SLAVE, DEVICE_1_ADDR)
...
byte = i2c_smbus_read_byte_data(fd, reg);

at the same time:

process 2:

ioctl(fd, I2C_SLAVE, DEVICE_2_ADDR)
...
byte = i2c_smbus_read_byte_data(fd, reg);

What if process 2 is running after the ioctl which sets the slave adress of process 1?
When this is safe, because of different fd's (perhaps i dont know) , what if this are two threads with the same fd ?
Should i protect i2c acces with semaphores or mutexes ?

I want to make *REALLY* sure that i can have multiple threads and processes accessing multiple slave devices
at the same time.
I don't know how the i2c access is implementet in the kernel.

Can anybody tell me please something about it or point to some docs/links ?

mfg Marco Oklitz
oklitz
 
Posts: 10
Joined: Sun Jul 07, 2013 10:48 am

Re: i2c acces threadsafe ?

Postby oklitz » Sun Dec 08, 2013 6:06 pm

Ok its bound to the fd
I have tested it with a process forking and using the same fd -> didnt work
I have to call open in every thread or process then it worked fine
oklitz
 
Posts: 10
Joined: Sun Jul 07, 2013 10:48 am

Re: i2c acces threadsafe ?

Postby crashmaster » Mon Dec 09, 2013 5:03 am

$this->bbcode_second_pass_quote('oklitz', '
')I have to call open in every thread or process then it worked fine

That it won't work with the same fd is evident and i'm pretty sure it won't work for the same i2c bus although two fd's will be used. You communicate with two i2c busses which shouldn't be a problem using an own fd for each.
crashmaster
 
Posts: 119
Joined: Wed Mar 13, 2013 1:00 am


Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 1 guest