Skip to content

Commit

Permalink
Merge pull request #85 from PiR43/master
Browse files Browse the repository at this point in the history
Sleepy::loseSomeTime() shouldn't deactivate watchdog
  • Loading branch information
jcw committed Sep 10, 2015
2 parents bf17905 + c276393 commit f097c00
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,19 +1099,21 @@ const word* ColorPlug::chromaCCT () {
// ISR(WDT_vect) { Sleepy::watchdogEvent(); }

static volatile byte watchdogCounter;
static byte backupMode = 0;

void Sleepy::watchdogInterrupts (char mode) {
#ifndef WDTCSR
#define WDTCSR WDTCR
#endif
// correct for the fact that WDP3 is *not* in bit position 3!
if (mode & bit(3))
mode ^= bit(3) | bit(WDP3);
// pre-calculate the WDTCSR value, can't do it inside the timed sequence
// we only generate interrupts, no reset
byte wdtcsr = mode >= 0 ? bit(WDIE) | mode : 0;
byte wdtcsr = mode >= 0 ? bit(WDIE) | mode : backupMode;
if(mode>=0) backupMode = WDTCSR;
MCUSR &= ~(1<<WDRF);
ATOMIC_BLOCK(ATOMIC_FORCEON) {
#ifndef WDTCSR
#define WDTCSR WDTCR
#endif
WDTCSR |= (1<<WDCE) | (1<<WDE); // timed sequence
WDTCSR = wdtcsr;
}
Expand Down

0 comments on commit f097c00

Please sign in to comment.