Search code examples
linuxdriverdevice

Handling IRQ delay in linux driver


I've build a linux driver for an SPI device. The SPI device sends an IRQ to the processor when a new data is ready to be read.

The IRQ fires about every 3 ms, then the driver goes to read 2 bytes with SPI.

The problem I have is that sometimes, there's more than 6 ms between the IRQ has been fired and the moment where SPI transfer starts, which means I lost 2 bytes of the SPI device.

In addition, there's a uncertain delay between the 2 bytes; sometime it's close to 0, sometime it's up to 300us..

Then my question is : how can I reduce the latency between IRQ and SPI readings ?

And how to avoid latency between the 2 bytes ?

I've tried compiling the kernel with premptive option, it does not change things that much.

As for the hardware, I'm using a mini2440 board running at 400 MHz, using a hardware SPI port (not i/o simulated SPI).

Thanks for help.

BR, Vincent.


Solution

  • The thing is Linux SPI stack uses queues for transmitting the messages.

    This means that there is no guarantee about the delay between the moment you ask to send the SPI message, and the moment where it is effectively sent.

    Finally, to fullfill my 3ms requirements between each SPI message, I had to stop using Linux SPI stack, and directly write into the CPU's register inside my own IRQ.

    That's highly dirty, but it's the only way to make it work with small delays.