Hannes Ovrén
Hannes Ovrén

Reputation: 21851

Linux Driver real time constraints

I need to build a platform for logging some sensor data. And possibly later doing some calculations on this logged data.

The Raspberry Pi seem like an interesting (and cheap!) device for this.

I have a gyroscope that can sample at 800 Hz which is equivalent to one sample every 1.25 ms. The gyroscope has a built-in FIFO that can store 32 samples. This means that the FIFO has to be emptied at least every 32 * 1.25 = 40 ms, otherwise samples will be dropped.

So my question is: Can I be 100% certain that my kernel driver will be able to extract the data from this FIFO within the specified time?

The gyroscope communicates with the host via i2c, and it can also trigger an interrupt pin on a "almost full"-event if that would make things simpler. But it would be easiest if I could just have a loop in the driver that retrieves the data at regular intervals.

I can live with storing the data in kernel space, and move it to user space more infrequently (no constraint on time).

I can also live with sampling the gyroscope at lower sample rates (400 or 200 Hz is acceptable).

This is with regards to the stock kernel, and not the special real-time kernel as it seems like this is currently not supported for the Raspberry Pi.

Upvotes: 2

Views: 2224

Answers (1)

Frobbit
Frobbit

Reputation: 1722

You will need a real-time linux environment for tight timing:

You could try Xenomai on Raspberry Pi: http://diy.powet.eu/2012/07/25/raspberry-pi-xenomai/

However, following along this blog: http://linuxcnc.mah.priv.at/rpi/rpi-rtperf.html (dead, and I could not find it in wayback or google cache)

It seems he is getting repeatable +/- 20µS timing out of the stock kernel. As your timing resolution is 1250µS you may be fine with the stock kernel if you willing to lose a sample once in a blue moon YMMV.

I have not tested this yet myself but I have been reading up in an attempt to try to drive a ws2811 LED controller with the Raspberry Pi and this was looking the most promising to me.

There is also the RT linux patch: https://rt.wiki.kernel.org/index.php/Main_Page
Which has at lest one pi version: https://github.com/licaon-kter/raspi-rt
However I have run into a bunch of nay-sayers when looking deeper into this patch.

Your best bet it to read the MS timer and log or light an LED if you miss an interval and then try some of the solutions. Happy Hacking..

Upvotes: 2

Related Questions