From 80b2733de54c06e367389b930ad0d257bfbb4680 Mon Sep 17 00:00:00 2001 From: Emil Muratov Date: Sat, 14 Dec 2024 23:32:26 +0900 Subject: [PATCH] make _async_service_task's watchdog constantly watching with periodic feed --- src/AsyncTCP.cpp | 29 ++++++++++++++++++----------- src/AsyncTCP.h | 7 +++++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index ae79d4c..00ac960 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -158,8 +158,14 @@ static inline bool _get_async_event(lwip_event_packet_t** e) { return false; } +#if CONFIG_ASYNC_TCP_USE_WDT + // need to return periodically to feed the dog + if (xQueueReceive(_async_queue, e, pdMS_TO_TICKS(1000)) != pdPASS) + return false; +#else if (xQueueReceive(_async_queue, e, portMAX_DELAY) != pdPASS) return false; +#endif /* Let's try to coalesce two (or more) consecutive poll events into one @@ -175,7 +181,7 @@ static inline bool _get_async_event(lwip_event_packet_t** e) { if (xQueueReceive(_async_queue, &next_pkt, 0) == pdPASS){ free(next_pkt); next_pkt = NULL; - log_w("coalescing polls, async callback might be too slow!"); + log_d("coalescing polls, async callback might be too slow!"); } else return true; } else @@ -255,22 +261,23 @@ static void _handle_async_event(lwip_event_packet_t* e) { } static void _async_service_task(void* pvParameters) { +#if CONFIG_ASYNC_TCP_USE_WDT + if (esp_task_wdt_add(NULL) != ESP_OK) { + log_w("Failed to add async task to WDT"); + } +#endif lwip_event_packet_t* packet = NULL; for (;;) { if (_get_async_event(&packet)) { -#if CONFIG_ASYNC_TCP_USE_WDT - if (esp_task_wdt_add(NULL) != ESP_OK) { - log_e("Failed to add async task to WDT"); - } -#endif _handle_async_event(packet); -#if CONFIG_ASYNC_TCP_USE_WDT - if (esp_task_wdt_delete(NULL) != ESP_OK) { - log_e("Failed to remove loop task from WDT"); - } -#endif } +#if CONFIG_ASYNC_TCP_USE_WDT + esp_task_wdt_reset(); +#endif } +#if CONFIG_ASYNC_TCP_USE_WDT + esp_task_wdt_delete(NULL); +#endif vTaskDelete(NULL); _async_service_task_handle = NULL; } diff --git a/src/AsyncTCP.h b/src/AsyncTCP.h index ab2609f..2df01c7 100644 --- a/src/AsyncTCP.h +++ b/src/AsyncTCP.h @@ -48,13 +48,16 @@ extern "C" { #include } #define CONFIG_ASYNC_TCP_RUNNING_CORE -1 // any available core - #define CONFIG_ASYNC_TCP_USE_WDT 0 #endif // If core is not defined, then we are running in Arduino or PIO #ifndef CONFIG_ASYNC_TCP_RUNNING_CORE #define CONFIG_ASYNC_TCP_RUNNING_CORE -1 // any available core - #define CONFIG_ASYNC_TCP_USE_WDT 1 // if enabled, adds between 33us and 200us per event +#endif + +// guard AsyncTCP task with watchdog +#ifndef CONFIG_ASYNC_TCP_USE_WDT + #define CONFIG_ASYNC_TCP_USE_WDT 1 #endif #ifndef CONFIG_ASYNC_TCP_STACK_SIZE