device reset after failed DHCP request to recognize dead ethernet module
This commit is contained in:
@ -15,6 +15,7 @@
|
||||
#include <Metro.h>
|
||||
#include "config.h"
|
||||
#include "info.h"
|
||||
#include "reset.h"
|
||||
|
||||
|
||||
const uint8_t POWER_LED = 4;
|
||||
@ -36,21 +37,6 @@ static OverCurrentProt overCurrentProt;
|
||||
Metro wdogTick = Metro(1000);
|
||||
Metro dhcpTick = Metro(60 * 1000);
|
||||
|
||||
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"
|
||||
|
||||
void setup() {
|
||||
pinMode(POWER_LED, OUTPUT);
|
||||
@ -87,27 +73,14 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint16_t maxTmroutl = 0;
|
||||
|
||||
// watchdog refresh
|
||||
cli();
|
||||
WDOG_REFRESH = 0xa602;
|
||||
WDOG_REFRESH = 0xb480;
|
||||
sei();
|
||||
|
||||
|
||||
if (wdogTick.check() == 1) {
|
||||
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;
|
||||
}
|
||||
watchdogReset();
|
||||
|
||||
if (dhcpTick.check() == 1) {
|
||||
byte r = Ethernet.maintain();
|
||||
Serial << "Ethernet.maintain: " << r << endl;
|
||||
if ((r == DHCP_CHECK_REBIND_FAIL) || (r == DHCP_CHECK_RENEW_FAIL)) {
|
||||
resetDevice();
|
||||
}
|
||||
}
|
||||
|
||||
//Serial << "*** 1" << endl;
|
||||
|
Reference in New Issue
Block a user