[En-Nut-Discussion] SPI in IRQ

Harald Kipp harald.kipp at egnite.de
Thu Feb 16 10:29:34 CET 2012

Hi Klaus,

On 16.02.2012 08:22, Klaus Kloos wrote:
> So I tried to use the NutOS functions. (*spiBus1At91.bus_alloc) and (*spiBus1At91.bus_release) are called outside the IRQ,  (*spiBus1At91.bus_transfer) is called at IRQ time.
> The transfer of the 3 bytes last ca. 12us using 10MHz SPI. It is working, but unreliable. Sometimes my device freezes.

Probably. In general, it is not allowed to call API functions in
interrupt context, except NutEventPostFromIrq(). As a special exception
it is possible to use stdio functions on a polling device, usually devDebug.

> What are my possibilities? Is there a recommended way to solve such time-critical SPI-requests?
> Can I get the Nut/OS functions IRQ save somehow?

Nut/OS allows to use native interrupt handlers. For the AT91 you can use

static void MySpiIrqHandler(void) __attribute__ ((naked));
void MySpiIrqHandler(void)
...your code here...

In your main code you need to write the address of the handler into the
related AIC service routine register.

outr(AIC_SVR(SPI0_ID), (unsigned int) MySpiIrqHandler);

And...not to forget...it is always a good idea to check the datasheet. ;-)



More information about the En-Nut-Discussion mailing list