Change TIMSK1 atomically in mm::IsrSetEnabled

pull/206/head
Yuri D'Elia 2022-09-22 14:46:58 +02:00
parent dd7042e567
commit 29249bead2
1 changed files with 4 additions and 2 deletions

View File

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