Skip to content

Commit 88c34c5

Browse files
committed
[SW WD] Count SW watchdog and feed HW watchdog
As suggested here: letscontrolit#2477
1 parent 1b61458 commit 88c34c5

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

src/ESPEasy-Globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,7 @@ float loop_usec_duration_total = 0.0;
18901890
unsigned long countFindPluginId = 0;
18911891

18921892
unsigned long dailyResetCounter = 0;
1893+
volatile unsigned long sw_watchdog_callback_count = 0;
18931894

18941895
String eventBuffer = "";
18951896

src/ESPEasy.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ void preinit() {
117117
}
118118
#endif
119119

120+
/*********************************************************************************************\
121+
* ISR call back function for handling the watchdog.
122+
\*********************************************************************************************/
123+
void sw_watchdog_callback(void *arg)
124+
{
125+
yield(); // feed the WD
126+
++sw_watchdog_callback_count;
127+
}
128+
120129
/*********************************************************************************************\
121130
* SETUP
122131
\*********************************************************************************************/
@@ -131,6 +140,9 @@ void setup()
131140
run_compiletime_checks();
132141
lowestFreeStack = getFreeStackWatermark();
133142
lowestRAM = FreeMem();
143+
#ifndef ESP32
144+
ets_isr_attach(8, sw_watchdog_callback, NULL); // Set a callback for feeding the watchdog.
145+
#endif
134146

135147
resetPluginTaskData();
136148
Plugin_id.resize(PLUGIN_MAX);

src/StringProvider.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ String getLabel(LabelType::Enum label) {
2828
case LabelType::BOOT_COUNT: return F("Boot Count");
2929
case LabelType::RESET_REASON: return F("Reset Reason");
3030
case LabelType::LAST_TASK_BEFORE_REBOOT: return F("Last Task");
31+
case LabelType::SW_WD_COUNT: return F("SW WD count");
32+
3133

3234
case LabelType::WIFI_CONNECTION: return F("WiFi Connection");
3335
case LabelType::WIFI_RSSI: return F("RSSI");
@@ -125,6 +127,7 @@ String getValue(LabelType::Enum label) {
125127
case LabelType::BOOT_COUNT: break;
126128
case LabelType::RESET_REASON: return getResetReasonString();
127129
case LabelType::LAST_TASK_BEFORE_REBOOT: return decodeSchedulerId(lastMixedSchedulerId_beforereboot);
130+
case LabelType::SW_WD_COUNT: return String(sw_watchdog_callback_count);
128131

129132
case LabelType::WIFI_CONNECTION: break;
130133
case LabelType::WIFI_RSSI: return String(WiFi.RSSI());

src/StringProviderTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum Enum : short {
2727
BOOT_COUNT, // 0
2828
RESET_REASON, // Software/System restart
2929
LAST_TASK_BEFORE_REBOOT, // Last scheduled task.
30+
SW_WD_COUNT,
3031

3132
WIFI_CONNECTION, // 802.11G
3233
WIFI_RSSI, // -67

src/WebServer.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6867,6 +6867,7 @@ void handle_sysinfo() {
68676867
TXBuffer += ')';
68686868
addRowLabelValue(LabelType::RESET_REASON);
68696869
addRowLabelValue(LabelType::LAST_TASK_BEFORE_REBOOT);
6870+
addRowLabelValue(LabelType::SW_WD_COUNT);
68706871

68716872
addTableSeparator(F("Network"), 2, 3, F("Wifi"));
68726873

0 commit comments

Comments
 (0)