From 3d8962b188cd99f6fb82c806fc0aa1a4e92d3998 Mon Sep 17 00:00:00 2001 From: Erick Ahmed Date: Fri, 10 Oct 2025 23:59:14 +0200 Subject: [PATCH] Initialize basic watchdog --- firmware/esp32/source/main.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/firmware/esp32/source/main.cpp b/firmware/esp32/source/main.cpp index a1fe59f..51856d1 100644 --- a/firmware/esp32/source/main.cpp +++ b/firmware/esp32/source/main.cpp @@ -1,3 +1,27 @@ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include "esp_log.h" +#include "esp_pm.h" + +volatile bool critical_error_flag = false; + +static void watchdogTask(void pvParameters*) { + const TickType_t keepAlivePeriod = pdMS_TO_TICKS(30000); + + for(;;) { + if (critical_error_flag) { + ESPLOGE("Critical error flag raised. Rebooting."); + esp_restart(); + } + esp_task_wdt_reset(); + + vTaskDelay(keepAlivePeriod); + } +} + extern "C" void app_main(void) { + xTaskCreate(watchdogTask, "wdt", 256, NULL, configMAX_PRIORITIES-1, NULL); }