60 lines
1.2 KiB
C++
Raw Permalink Normal View History

/*
* reset.cpp
*
* Created on: 14.05.2015
* Author: wn
*/
#include <Streaming.h>
const uint8_t POWER_LED = 4;
void resetDevice() {
while (true) {
digitalWrite(POWER_LED, LOW);
delay(100);
digitalWrite(POWER_LED, HIGH);
delay(100);
}
}
void watchdogReset() {
static uint32_t last = 0;
static uint16_t maxTmroutl = 0;
// watchdog refresh
cli();
WDOG_REFRESH = 0xa602;
WDOG_REFRESH = 0xb480;
sei();
uint32_t now = millis();
if (last + 1000 < now) {
last = now;
uint16_t h = WDOG_TMROUTH;
uint16_t l = WDOG_TMROUTL;
maxTmroutl = (maxTmroutl > l) ? maxTmroutl : l;
uint16_t c = WDOG_RSTCNT;
Serial << "WDog, h: " << _HEX(h) << ", l: " << _HEX(l) << ", c: " << _HEX(c) << ", m: " << _HEX(maxTmroutl) << endl;
}
}
extern "C" {
void startup_early_hook( ) __attribute__ ((weak));
void startup_early_hook() {
// enable watchdog
WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
// one minute
WDOG_TOVALL = 60000;
WDOG_TOVALH = 0;
WDOG_PRESC = 0;
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN | WDOG_STCTRLH_ALLOWUPDATE | WDOG_STCTRLH_STOPEN | WDOG_STCTRLH_WAITEN;
}
} // extern "C"