sza2
sza2

Reputation: 13

Linux kernel driver async I2C (on Raspberry PI)

I'd like to write an I2C driver for a sensor device. There is a non-zero conversion time, and I don't want to waste kernel time to wait and poll busy state until the device is busy.

I thought I setup a timer and call the update time to time.

However the whole system freezes when execution reaches any I2C function.

I prepared a really simplified example, which is not working. Everything fine until the I2C access.

http://pastebin.com/kP5LCK2c

Without I2C stuff, the code works. Without the timer stuff, I2C works.

I did not find how to use I2C in an asynchronous (non-blocking) manner.

Upvotes: 1

Views: 2376

Answers (1)

Adrian Cox
Adrian Cox

Reputation: 6334

As the i2c functions sleep, they can't be called from a timer. Luckily, timers aren't the only way to schedule work into the future. Look at work queues:

In particular, look at queue_delayed_work, which will allow you to run a function in the future, in a process context able to sleep.

Upvotes: 2

Related Questions