Change TIMSK1 atomically in mm::IsrSetEnabled

pull/205/head
Yuri D'Elia 2022-09-22 14:46:58 +02:00 committed by DRracer
parent dd7042e567
commit 1007402b24
1 changed files with 4 additions and 2 deletions

View File

@ -20,10 +20,12 @@ Motion motion;
/// ISR state manipulation
static inline void IsrSetEnabled(bool state) {
#ifdef __AVR__
// NOTE: ATOMIC_BLOCK is split across branches to split the function into two optimal calls at
// compile-time
if (state)
TIMSK1 |= (1 << OCIE1A);
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { TIMSK1 |= (1 << OCIE1A); }
else
TIMSK1 &= ~(1 << OCIE1A);
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { TIMSK1 &= ~(1 << OCIE1A); }
#endif
}