Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to check whether it was the WDT interrupt which wok… #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion LowPower.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* LowPower Library
* Version: 1.60
* Version: 1.70
* Date: 01-04-2016
* Author: Lim Phang Moh
* Company: Rocket Scream Electronics
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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__)
Expand Down
6 changes: 4 additions & 2 deletions LowPower.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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__)
Expand Down