-->
Page 1 of 1

Proper way to implement nested critical sections

PostPosted: Mon Jun 04, 2018 9:00 pm
by dalbert
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?

I'm used to a function that disables interrupts and returns the prior interrupt state that you restore when you exit the section. Is there something similar for ESP8266?

Re: Proper way to implement nested critical sections

PostPosted: Thu Sep 20, 2018 7:41 pm
by dalbert
Although it hasn't solved all of my issues, the InterruptLock class is quite elegant for managing critical sections:
Code: Select all#include <interrupts.h>

{
   InterruptLock lock;
   criticalStuff();
}