From 160b95ff76c8b1eaed418147e35a980c50618b9f Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Oct 2023 12:46:07 -0400 Subject: [PATCH 1/4] reflect idf v5 and up, keep backwards compat --- library.properties | 2 +- utility/WatchdogESP32.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index ebd907a..81d6f9a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit SleepyDog Library -version=1.6.4 +version=1.6.5 author=Adafruit maintainer=Adafruit sentence=Arduino library to use the watchdog timer for system reset and low power sleep. diff --git a/utility/WatchdogESP32.cpp b/utility/WatchdogESP32.cpp index 006fc34..8921841 100644 --- a/utility/WatchdogESP32.cpp +++ b/utility/WatchdogESP32.cpp @@ -18,10 +18,24 @@ int WatchdogESP32::enable(int maxPeriodMS) { // ESP32 expects TWDT in seconds uint32_t maxPeriod = maxPeriodMS / 1000; + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) + // Initialize the wdt configuration for ESP-IDF v5.x and above + esp_task_wdt_config_t wdt_config = { + .timeout_ms = maxPeriod, + .idle_core_mask = (1 << portNUM_PROCESSORS) - 1, // Bitmask of all cores + .trigger_panic = true, + }; + // Enable the TWDT and execute the esp32 panic handler when TWDT times out + esp_err_t err = esp_task_wdt_init(&wdt_config); +#else + // For ESP-IDF v4.x and below // Enable the TWDT and execute the esp32 panic handler when TWDT times out esp_err_t err = esp_task_wdt_init(maxPeriod, true); +#endif + if (err != ESP_OK) - return 0; // Initialization failed due to lack of memory + return 0; // Failed to initialize TWDT // NULL to subscribe the current running task to the TWDT err = esp_task_wdt_add(NULL); From 686f77d8261cc8a28eb988a2da2b2f569a064ece Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Oct 2023 13:06:05 -0400 Subject: [PATCH 2/4] reconfigure, use ms --- utility/WatchdogESP32.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/utility/WatchdogESP32.cpp b/utility/WatchdogESP32.cpp index 8921841..be618f1 100644 --- a/utility/WatchdogESP32.cpp +++ b/utility/WatchdogESP32.cpp @@ -16,20 +16,18 @@ int WatchdogESP32::enable(int maxPeriodMS) { if (maxPeriodMS < 0) return 0; - // ESP32 expects TWDT in seconds - uint32_t maxPeriod = maxPeriodMS / 1000; - #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) // Initialize the wdt configuration for ESP-IDF v5.x and above esp_task_wdt_config_t wdt_config = { - .timeout_ms = maxPeriod, - .idle_core_mask = (1 << portNUM_PROCESSORS) - 1, // Bitmask of all cores + .timeout_ms = maxPeriodMS, + .idle_core_mask = 0, // Subscribe to the idle task on the APP CPU .trigger_panic = true, }; - // Enable the TWDT and execute the esp32 panic handler when TWDT times out - esp_err_t err = esp_task_wdt_init(&wdt_config); + // TWDT already initialized, let's just reconfigure it + esp_err_t err = esp_task_wdt_reconfigure(&wdt_config); #else - // For ESP-IDF v4.x and below + // IDF V4.x and below expect TWDT in seconds + uint32_t maxPeriod = maxPeriodMS / 1000; // Enable the TWDT and execute the esp32 panic handler when TWDT times out esp_err_t err = esp_task_wdt_init(maxPeriod, true); #endif From f24c0af02a7f2115d5d71fdefea4700c382b1d1a Mon Sep 17 00:00:00 2001 From: brentru Date: Thu, 19 Oct 2023 13:08:51 -0400 Subject: [PATCH 3/4] fix comment --- utility/WatchdogESP32.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utility/WatchdogESP32.cpp b/utility/WatchdogESP32.cpp index be618f1..2fd7565 100644 --- a/utility/WatchdogESP32.cpp +++ b/utility/WatchdogESP32.cpp @@ -23,7 +23,7 @@ int WatchdogESP32::enable(int maxPeriodMS) { .idle_core_mask = 0, // Subscribe to the idle task on the APP CPU .trigger_panic = true, }; - // TWDT already initialized, let's just reconfigure it + // TWDT already initialized by the RTOS, reconfigure it esp_err_t err = esp_task_wdt_reconfigure(&wdt_config); #else // IDF V4.x and below expect TWDT in seconds From e2eeeb9e4082a3c6b0dc901983ed9abecbd012b0 Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 20 Oct 2023 11:56:21 -0400 Subject: [PATCH 4/4] uint match warn --- utility/WatchdogESP32.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utility/WatchdogESP32.cpp b/utility/WatchdogESP32.cpp index 2fd7565..2b983eb 100644 --- a/utility/WatchdogESP32.cpp +++ b/utility/WatchdogESP32.cpp @@ -19,7 +19,7 @@ int WatchdogESP32::enable(int maxPeriodMS) { #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) // Initialize the wdt configuration for ESP-IDF v5.x and above esp_task_wdt_config_t wdt_config = { - .timeout_ms = maxPeriodMS, + .timeout_ms = (uint32_t)maxPeriodMS, .idle_core_mask = 0, // Subscribe to the idle task on the APP CPU .trigger_panic = true, };