Chat freely about anything...

User avatar
By hinay
#85218 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
User avatar
By eriksl
#86473 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.