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
spiExchange from ISR context
Moderator: RoccoMarco
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: spiExchange from ISR context
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:
The reason for those lock/unlock is in the system states and API classes sections of "Kernel Concepts" in the kernel documentation.
Giovanni
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
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
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?
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: spiExchange from ISR context
You cannot wait in ISR context, this is why functions have classes, some combinations make no sense.
Giovanni
Giovanni