Page 1 of 1

spiExchange from ISR context

Posted: Sat Jun 14, 2014 2:53 pm
by aspnair
Hi,

Will it be possible to use spiExchange from a call back, a timer handler to be precise? I couldn't find any spiExchangeI implementation. If this is not possible, what are the other options to do spi tx and rx together from this timer handler?

Thanks.

Anand

Re: spiExchange from ISR context

Posted: Sat Jun 14, 2014 5:10 pm
by Giovanni
Hi,

It is possible, the SPI driver (and most other drivers) have two sets of API: synchronous or asynchronous.

Synchronous form: spiExchange()
Asynchronous form: spiStartExchangeI()

The asynch one returns immediately and signals the transfer end using a callback (defined in the configuration structure).

Example:

Code: Select all

  chSysLockFromIsr();
  spiStartExchangeI(....);
  chSysUnlockFromIsrt();


The reason for those lock/unlock is in the system states and API classes sections of "Kernel Concepts" in the kernel documentation.

Giovanni

Re: spiExchange from ISR context

Posted: Mon Mar 30, 2015 1:27 am
by russian
Giovanni wrote:Hi,

It is possible, the SPI driver (and most other drivers) have two sets of API: synchronous or asynchronous.

Synchronous form: spiExchange()
Asynchronous form: spiStartExchangeI()

Right, but spiExchange and spiStartExchangeI are slightly different functions. Say spiSelect and spiSelectI do _exactly_ the same thing, just with or withing locking. Is there a reason why there is no synchronous, non-locking function spiExchangeI()?

My usecase: I have some code which I now want to move from main thread into a timer callback. Timer callback would be executed under lock, so I need to move from the non-I functions to the I functions. But there is no synchronous spiExchangeI() and suddenly I need to make further changes...

I will just add a spiExchangeI() method for myself for now.

Re: spiExchange from ISR context

Posted: Mon Mar 30, 2015 1:36 am
by russian
russian wrote: Is there a reason why there is no synchronous, non-locking function spiExchangeI()?

I guess I know the answer now: that's because you cannot really wait() if the context is not right?

Re: spiExchange from ISR context

Posted: Mon Mar 30, 2015 8:04 am
by Giovanni
You cannot wait in ISR context, this is why functions have classes, some combinations make no sense.

Giovanni