Hi,
If I want to write to shared data from a normal IRQ (non-"fast") what is the correct way to access it safely without using chSysLockFromIsr? I want to use a semaphore but my code keeps crashing, so maybe I am using the wrong calls. (chBSemWait & chBSemSignal use chSysLock internally instead of chSysLockFromIsr, for example). The reason I want to use a semaphore instead of chSysLock is that I am copying a chunk of data and I don't want to affect latency in other IRQs. With a semaphore the latency hit should be minimal.
To summarize: what are the correct semaphore calls ( *I vs *S vs neither) ? Should I do it differently?
Thanks,
~t
Proper way to access shared data from IRQ
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Proper way to access shared data from IRQ
The correct way is to use chSysLockFromIsr/chSysUnlockFromIsr from the ISR side and chSysLock/chSysUnlock from the thread size. You cannot use a semaphore nor a mutex because you cannot "wait" into an ISR.
Alternatively you may consider a mailbox where to insert the data to be passed to the thread without having to wait (until there is room of course).
Another approach is to use a worker thread doing the copying, this is done in the STM32 OTG driver but it is VERY complex to implement.
Giovanni
Alternatively you may consider a mailbox where to insert the data to be passed to the thread without having to wait (until there is room of course).
Another approach is to use a worker thread doing the copying, this is done in the STM32 OTG driver but it is VERY complex to implement.
Giovanni