From 705febfc9c9a7ce97d385c3553c107856d431ded Mon Sep 17 00:00:00 2001 From: sysshad Date: Wed, 22 Aug 2018 22:22:21 +0200 Subject: [PATCH] Added possibility to check whether it was the WDT interrupt which woke the MCU Added possibility to check whether it was the WDT interrupt which woke the MCU. Quite useful if you have multiple wakeup sources and wants to know which one it was. --- LowPower.cpp | 23 ++++++++++++++++++++++- LowPower.h | 6 ++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/LowPower.cpp b/LowPower.cpp index 4e14e1a..94f26fb 100644 --- a/LowPower.cpp +++ b/LowPower.cpp @@ -1,6 +1,6 @@ /******************************************************************************* * LowPower Library -* Version: 1.60 +* Version: 1.70 * Date: 01-04-2016 * Author: Lim Phang Moh * Company: Rocket Scream Electronics @@ -13,6 +13,8 @@ * * Revision Description * ======== =========== +* 1.70 Added possibility to check whether it was the WDT interrupt which +* woke the MCU. Contributed by Sysshad. * 1.60 Added support for ATmega256RFR2. Contributed by Rodmg. * 1.50 Fixed compiler optimization (Arduino IDE 1.6.x branch) on BOD enable * function that causes the function to be over optimized. @@ -1119,6 +1121,22 @@ void LowPowerClass::powerExtStandby(period_t period, adc_t adc, bod_t bod, #endif } +/******************************************************************************* + * Function to call to know if it was the WDT interrupt that woke the MCU + * Good if you have multiple wakeup sources like BOD, IO INT, etc... and + * wants to know which one occured. + * Note: Clears the event (sets it to false) so next call will return false + * unless another WDT event occured meanwhile. + *******************************************************************************/ +bool LowPowerClass::getWDTEventStatus() +{ + bool ret = LowPower._wdtEvent; + + LowPower._wdtEvent = false; + + return ret; +} + /******************************************************************************* * Name: ISR (WDT_vect) * Description: Watchdog Timer interrupt service routine. This routine is @@ -1130,6 +1148,9 @@ ISR (WDT_vect) { // WDIE & WDIF is cleared in hardware upon entering this ISR wdt_disable(); + + // Inform that an WDT event occured! + LowPower._wdtEvent = true; } #elif defined (__arm__) diff --git a/LowPower.h b/LowPower.h index ac4054c..5d10fdc 100644 --- a/LowPower.h +++ b/LowPower.h @@ -119,7 +119,8 @@ class LowPowerClass { public: #if defined (__AVR__) - + volatile bool _wdtEvent = false; + #if defined (__AVR_ATmega328P__) || defined (__AVR_ATmega168__) void idle(period_t period, adc_t adc, timer2_t timer2, timer1_t timer1, timer0_t timer0, spi_t spi, @@ -152,7 +153,8 @@ class LowPowerClass void powerSave(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1"))); void powerStandby(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1"))); void powerExtStandby(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1"))); - + bool getWDTEventStatus(); + #elif defined (__arm__) #if defined (__SAMD21G18A__)