device reset after failed DHCP request to recognize dead ethernet module
This commit is contained in:
61
reset.cpp
Normal file
61
reset.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 = 0xea60;
|
||||
WDOG_TOVALH = 0;
|
||||
WDOG_PRESC = 0;
|
||||
|
||||
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN | WDOG_STCTRLH_ALLOWUPDATE | WDOG_STCTRLH_STOPEN | WDOG_STCTRLH_WAITEN;
|
||||
}
|
||||
} // extern "C"
|
Reference in New Issue
Block a user