From 29249bead2542ff30cf07b8b86d561b7fd0f4b2c Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 22 Sep 2022 14:46:58 +0200 Subject: [PATCH] Change TIMSK1 atomically in mm::IsrSetEnabled --- src/modules/motion.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/motion.cpp b/src/modules/motion.cpp index f545d74..cea504f 100644 --- a/src/modules/motion.cpp +++ b/src/modules/motion.cpp @@ -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 }