Skip to content

Non-blocking clear() and reboot() method #8

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

Open
wants to merge 2 commits 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
24 changes: 18 additions & 6 deletions WDTZero/src/WDTZero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,29 @@ WDTZeroCounter = _ewtcounter; // SET Software EWT counter - used in I
}

void WDTZero::clear() {
WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY; // Clear WTD bit
while(WDT->STATUS.bit.SYNCBUSY);
WDTZeroCounter = _ewtcounter; // Reset the early warning downcounter value
if (WDT->STATUS.bit.SYNCBUSY == false)
{ // synchronization is not busy, meaning it is synchronized
WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY; // Clear WDT bit (reset watchdog timer)
WDTZeroCounter = _ewtcounter; // Reset the early warning downcounter value
}
}

void WDTZero::reboot()
{
WDT_ForceShutdown();
}

void WDT_ForceShutdown()
{
WDT->CLEAR.reg = 0xFF; // value different than WDT_CLEAR_CLEAR_KEY causes reset
while (true);
}

void WDT_Handler(void) { // ISR for watchdog early warning, DO NOT RENAME!, need to clear
WDTZeroCounter--; // EWT down counter, makes multi cycle WDT possible
if (WDTZeroCounter<=0) { // Software EWT counter run out of time : Reset
if (WDT_Shutdown != NULL) WDT_Shutdown(); // run extra Shutdown functions if defined
WDT->CLEAR.reg = 0xFF; // value different than WDT_CLEAR_CLEAR_KEY causes reset
while(true);
WDT_ForceShutdown();
}
else {
WDT->INTFLAG.bit.EW = 1; // Clear INT EW Flag
Expand All @@ -113,4 +125,4 @@ void WDTZero::attachShutdown(voidFuncPtr callback)
void WDTZero::detachShutdown()
{
WDT_Shutdown = NULL;
}
}
2 changes: 2 additions & 0 deletions WDTZero/src/WDTZero.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
# define WDT_SOFTCYCLE16M 0xF4BA // EW on, @8192cycles/1024 x 2^7 = 1024S " 111 1 -> 17 minutes to be precise ...


void WDT_ForceShutdown(void); // Global Method for immediate shutdown
void WDT_Handler(void); // ISR HANDLER FOR WDT EW INTERRUPT
extern int WDTZeroCounter; // SOFT COUNTER FOR EXTENDING WDT TIME VIA EW INTERRUPT

Expand All @@ -56,6 +57,7 @@ class WDTZero
public:
WDTZero();
void clear();
void reboot();
void setup(unsigned int wdtzerosetup);
void attachShutdown(voidFuncPtr callback);
void detachShutdown();
Expand Down