From bffc87fe93739f2f19211aae37c1e7e6ba6daf1c Mon Sep 17 00:00:00 2001 From: Embedded Innovation Date: Mon, 3 Apr 2017 21:08:10 +0200 Subject: [PATCH] Fix clear pending ints for AVR (#816) Support full AVR range --- core/MyHwAVR.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/MyHwAVR.cpp b/core/MyHwAVR.cpp index 4bc80bc..fd65a47 100644 --- a/core/MyHwAVR.cpp +++ b/core/MyHwAVR.cpp @@ -27,7 +27,7 @@ bool hwInit(void) return true; } -#define WDTO_SLEEP_FOREVER (0xFFu) +#define WDTO_SLEEP_FOREVER (0xFFu) #define INVALID_INTERRUPT_NUM (0xFFu) volatile uint8_t _wokeUpByInterrupt = @@ -66,6 +66,11 @@ inline bool interruptWakeUp() return _wokeUpByInterrupt != INVALID_INTERRUPT_NUM; } +void clearPendingInterrupt(const uint8_t interrupt) +{ + EIFR = _BV(interrupt); +} + // Watchdog Timer interrupt service routine. This routine is required // to allow automatic WDIF and WDIE bit clearance in hardware. ISR (WDT_vect) @@ -163,11 +168,11 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo // to prevent waking immediately again. // Ref: https://forum.arduino.cc/index.php?topic=59217.0 if (interrupt1 != INVALID_INTERRUPT_NUM) { - EIFR = _BV(interrupt1 == 0 ? INTF0 : INTF1); + clearPendingInterrupt(interrupt1); attachInterrupt(interrupt1, wakeUp1, mode1); } if (interrupt2 != INVALID_INTERRUPT_NUM) { - EIFR = _BV(interrupt2 == 0 ? INTF0 : INTF1); + clearPendingInterrupt(interrupt2); attachInterrupt(interrupt2, wakeUp2, mode2); }