device reset after failed DHCP request to recognize dead ethernet module
This commit is contained in:
parent
b0bb23dcad
commit
3cb834208d
@ -15,6 +15,7 @@
|
||||
#include <Print.h>
|
||||
#include "cmd.h"
|
||||
#include "config.h"
|
||||
#include "reset.h"
|
||||
|
||||
|
||||
char MQTT_BROKER_DEFAULT[] = "192.168.75.1";
|
||||
@ -145,7 +146,7 @@ String MqttConfig::exec(String params) {
|
||||
} else if (params.equalsIgnoreCase("reset")) {
|
||||
configReset();
|
||||
*out << "Stopping gateway, wait for reset" << endl;
|
||||
while (true);
|
||||
resetDevice();
|
||||
res = "done";
|
||||
}
|
||||
return res;
|
||||
|
@ -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;
|
||||
|
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"
|
Loading…
x
Reference in New Issue
Block a user