So it's probably much better to save SREG before cli() and restore SREG later than to just throw cli() and sei() in as needed?
3 steps instead of 2, for better code.
You sarcasm isn't helpful.
You are not understanding that interrupts are not always enabled and so you can't simply blindly mask
them and blindly turn them on.
If you were to do that then interrupts would be turned on when they were disabled before this function were
called.
ISR routines are allowed to call functions like pinMode() and digitalWrite().
Libraries like the servo library, and IRremote call these functions from their ISR.
The issue is that given the way the core code is currently implemented, it uses a |= operation using non compile
time constants, which means it has to mask interrupts to protect the updates that an ISR may do to a port bit
from the foreground port bit updates.
It also has to save and restore the interrupt mask in the status register to ensure that it
doesn't accidentally re-enable interrupts when they are disabled.
Given the way the core code is implemented, there is no way around this.
--- bill