Add watchdog timer to miner task

Set a 120s timeout for the watchdog to catch a starving miner task.
If the miner task fails to reset the watchdog, the ESP32 will reboot.
This commit is contained in:
Stefan Berger 2023-07-11 17:12:02 +02:00
parent 35474c1bc5
commit 146d0497d6
2 changed files with 12 additions and 3 deletions

View File

@ -20,6 +20,8 @@
//3 seconds WDT //3 seconds WDT
#define WDT_TIMEOUT 3 #define WDT_TIMEOUT 3
//120 seconds WDT for miner task
#define WDT_MINER_TIMEOUT 120
OneButton button1(PIN_BUTTON_1); OneButton button1(PIN_BUTTON_1);
OneButton button2(PIN_BUTTON_2); OneButton button2(PIN_BUTTON_2);
@ -56,6 +58,7 @@ void setup()
Serial.setTimeout(0); Serial.setTimeout(0);
delay(100); delay(100);
esp_task_wdt_init(WDT_MINER_TIMEOUT, true);
// Idle task that would reset WDT never runs, because core 0 gets fully utilized // Idle task that would reset WDT never runs, because core 0 gets fully utilized
disableCore0WDT(); disableCore0WDT();
//disableCore1WDT(); //disableCore1WDT();
@ -137,8 +140,11 @@ void setup()
// Start mining tasks // Start mining tasks
//BaseType_t res = xTaskCreate(runWorker, name, 35000, (void*)name, 1, NULL); //BaseType_t res = xTaskCreate(runWorker, name, 35000, (void*)name, 1, NULL);
xTaskCreate(runMiner, "Miner0", 15000, NULL, 1, NULL); TaskHandle_t minerTask1, minerTask2 = NULL;
xTaskCreate(runMiner, "Miner1", 15000, NULL, 1, NULL); xTaskCreate(runMiner, "Miner0", 15000, NULL, 1, &minerTask1);
xTaskCreate(runMiner, "Miner1", 15000, NULL, 1, &minerTask2);
esp_task_wdt_add(minerTask1);
esp_task_wdt_add(minerTask2);
/******** MONITOR SETUP *****/ /******** MONITOR SETUP *****/
setup_monitor(); setup_monitor();

View File

@ -1,6 +1,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <WiFi.h> #include <WiFi.h>
#include <esp_task_wdt.h>
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip #include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
#include <wolfssl/wolfcrypt/sha256.h> #include <wolfssl/wolfcrypt/sha256.h>
#include "media/Free_Fonts.h" #include "media/Free_Fonts.h"
@ -338,6 +339,8 @@ void runMiner(void * name){
} }
uint32_t duration = micros() - startT; uint32_t duration = micros() - startT;
if (esp_task_wdt_reset() == ESP_OK)
Serial.print(">>> Resetting watchdog timer");
} }
} }