spiExchange from ISR context

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
aspnair
Posts: 2
Joined: Wed Oct 02, 2013 10:43 am

spiExchange from ISR context

Post 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
User avatar
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

Post 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
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

Re: spiExchange from ISR context

Post 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.
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

Re: spiExchange from ISR context

Post 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?
User avatar
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

Post by Giovanni »

You cannot wait in ISR context, this is why functions have classes, some combinations make no sense.

Giovanni
Post Reply