There are several posts that discuss turning interrupts off and on and the need for non-interrupt code to disable interrupts at appropriate times.
Saving the SREG is suggested for a routine that might be called from either an ISR or a non-ISR context.
uint8_t SaveSREG = SREG; // save interrupt flag noInterrupts(); // disable interrupts // do the protected task SREG = SaveSREG; // restore the interrupt flag
I expected to find a more standard way to do this task so I could write a routine that could be used on multiple platforms. My code would look like this:
bool interruptsWereOn = areInterruptsOn(); noInterrupts(); // do the protected task if (interruptsWereOn) interrupts();
What I can not find is a standard way of testing if interrupts are on. I expected this to be part of the noInterrupts(), interrupts() suite of library routines. That people would implement for each platform.
Hopefully I am wrong and there is a standard way, but, if not can I suggest that we add one?