Added watchdog function (incomplete)

This commit is contained in:
Ziver Koc 2016-05-04 16:20:20 +02:00
parent 4cf9170616
commit 2ba3c42a5e
2 changed files with 40 additions and 0 deletions

View file

@ -30,6 +30,7 @@ ISR(WDT_vect) { }
void Interrupt::wakeUp() void Interrupt::wakeUp()
{ {
wakeUpNow = true; wakeUpNow = true;
} }
@ -95,6 +96,44 @@ void Interrupt::setupPinInterrupt(int pin)
interrupts(); // enable all interrupts interrupts(); // enable all interrupts
} }
void Interrupt::setupWatchDogInterrupt(unsigned int milliseconds)
{
noInterrupts();
wdt_reset();
MCUSR &= ~(1 << WDRF); // reset status flag
/* WDCE = Watchdog Change Enable
*
* WDTON(1) WDE WDIE Mode
* 1 0 0 Stopped
* 1 0 1 Interrupt
* 1 1 0 Reset
* 1 1 1 Interrupt first, reset on second trigger
* 0 x x Reset
*/
WDTCSR = 0x00;
WDTCSR |= (1 << WDCE) | (1 << WDIE);
/* WDP3 WDP2 WDP1 WDP0 Number of cycles Typical Time-out time (VCC = 5.0V)
* 0 0 0 0 2K (2048) 16 ms
* 0 0 0 1 4K (4096) 32 ms
* 0 0 1 0 8K (8192) 64 ms
* 0 0 1 1 16K (16384) 0.125 s
* 0 1 0 0 32K (32768) 0.25 s
* 0 1 0 1 64K (65536) 0.5 s
* 0 1 1 0 128K (131072) 1.0 s
* 0 1 1 1 256K (262144) 2.0 s
* 1 0 0 0 512K (524288) 4.0 s
* 1 0 0 1 1024K (1048576) 8.0 s
*/
WDTCSR = (1<< WDP0) | (1 << WDP1) | (1 << WDP2); // set the prescalar = 7
//wdt_disable();
interrupts();
}
void Interrupt::setupTimerInterrupt(unsigned int milliseconds) void Interrupt::setupTimerInterrupt(unsigned int milliseconds)
{ {
noInterrupts(); // disable all interrupts noInterrupts(); // disable all interrupts

View file

@ -10,6 +10,7 @@ public:
static void wakeUp(); static void wakeUp();
static void sleep(); static void sleep();
static void setupPinInterrupt(int pin); static void setupPinInterrupt(int pin);
static void setupWatchDogInterrupt(unsigned int milliseconds);
static void setupTimerInterrupt(unsigned int milliseconds); static void setupTimerInterrupt(unsigned int milliseconds);
static void setCallback(InterruptFunction callback){ Interrupt::callback = callback;} static void setCallback(InterruptFunction callback){ Interrupt::callback = callback;}