Page 1 of 1

chBSemWaitTimeout

Posted: Fri Jan 10, 2020 3:46 pm
by Tabulous
can one use chBSemWaitTimeout in interrupt context ?

ive got a shared data structure

A thread fills it with data.

RTC callback uses the data to update clk .


so need to protect the shared data structure, chBSemWaitTimeout fails in RTC callback

Re: chBSemWaitTimeout

Posted: Fri Jan 10, 2020 3:58 pm
by Giovanni
Hi,

You can't "wait" in an ISR, the state checker would block this with an error. From ISR you can call only functions with the "I" suffix.

There are several approaches you could use, the most common are:

1) Use a critical zone for accessing your data from thread and ISR context: chSysLock, chSysUnlock, chSysLockFromISR, chSysUnlockFromISR.

2) Wake up a thread from the ISR and let the thread do the data handling, this is obviously heavier but could be required if your operation is too complex to be performed within a critical zone.

Giovanni

Re: chBSemWaitTimeout

Posted: Fri Jan 10, 2020 4:10 pm
by Tabulous
was just about to comment that i've found that it needs to be do with lock/unlock

thanks for the reply :-)