1

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I implemented it using queue_delayed_work but the result is identical. The whole machine freezes every single case when execution reaches I2C communication.
For a sanity check, can you talk to the I2C device from userspace? Also, what happens if you try to do a read during the device probe.
I can use the device from both user and kernel space, if there is no timer / work queue. Even the I2C read/write in probe works, and everything is fine until the update function called by the timer / work queue.
The result after the timer / wq calls the update function is an oops: pastebin.com/JzDmDmuC
That's a simple null pointer dereference. Probably test114_i2c is null. Two things to try: printk the pointer value before using it, and be sure you initialise the variable before you queue the first work item.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.