I stumbled upon this piece in digitalWrite.
I'm unsure why clearing interrupts and setting/resetting SREG is neccesary here.
Can anyone shed a light on this?
uint8_t oldSREG = SREG;
cli();
if (val == LOW) {
*out &= ~bit;
} else {
*out |= bit;
}
SREG = oldSREG;
I figure they don't want an interrupt to possibly change any of the bits in the output register while it executes *out = *out & ~bit?
And what would the SREG have to do with it? Could the code affect SREG and why would that matter?
When speed matters, I often use the direct port manipulation, I'd like to get an idea if it's neccesary for me to include these "precautions".
ATOMIC_BLOCKfrom#include <util/atomic.h>http://www.nongnu.org/avr-libc/user-manual/group__util__atomic.html – BrettFolkins Jun 05 '16 at 20:30