-->
Page 1 of 1

Nested Critical Section Impliment Help Needed

PostPosted: Thu Jan 09, 2020 3:50 pm
by hinay
Hi team,
I have two devices sharing the HSPI bus. They are both interrupt driven (interrupt drives a GPIO pin) and may also be accessed from the user context. What is the preferred/proper way to disable interrupts (e.g. ETS_GPIO_INTR_DISABLE()) in a way that can be nested so that user-context code can safely access the shared resources?

Regards,
Hinay

Re: Nested Critical Section Impliment Help Needed

PostPosted: Sun Apr 12, 2020 6:37 am
by eriksl
I think you need to supply more information here. Are the external devices masters or slaves? If they're slaves and the ESP is master, the timing should be quite predictable. Also if the SPI bus speed is not too slow, it may be feasable to not use an interrupt for the completion but simply busy wait.

If that's impossible, I'd say implement a semaphore. Also live by the golden rule that you shouldn't do real work in code coming from an interrupt, it's asking for trouble. Have the interrupt code queue a task call and have that code perform the work. If you do so, it will be inherently serialised too.