make _async_service_task's watchdog constantly watching with periodic feed

This commit is contained in:
Emil Muratov
2024-12-14 23:32:26 +09:00
parent afa162b73a
commit 80b2733de5
2 changed files with 23 additions and 13 deletions

View File

@@ -158,8 +158,14 @@ static inline bool _get_async_event(lwip_event_packet_t** e) {
return false; 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) if (xQueueReceive(_async_queue, e, portMAX_DELAY) != pdPASS)
return false; return false;
#endif
/* /*
Let's try to coalesce two (or more) consecutive poll events into one 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){ if (xQueueReceive(_async_queue, &next_pkt, 0) == pdPASS){
free(next_pkt); free(next_pkt);
next_pkt = NULL; next_pkt = NULL;
log_w("coalescing polls, async callback might be too slow!"); log_d("coalescing polls, async callback might be too slow!");
} else } else
return true; return true;
} else } else
@@ -255,22 +261,23 @@ static void _handle_async_event(lwip_event_packet_t* e) {
} }
static void _async_service_task(void* pvParameters) { 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; lwip_event_packet_t* packet = NULL;
for (;;) { for (;;) {
if (_get_async_event(&packet)) { 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); _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");
} }
#if CONFIG_ASYNC_TCP_USE_WDT
esp_task_wdt_reset();
#endif #endif
} }
} #if CONFIG_ASYNC_TCP_USE_WDT
esp_task_wdt_delete(NULL);
#endif
vTaskDelete(NULL); vTaskDelete(NULL);
_async_service_task_handle = NULL; _async_service_task_handle = NULL;
} }

View File

@@ -48,13 +48,16 @@ extern "C" {
#include <semphr.h> #include <semphr.h>
} }
#define CONFIG_ASYNC_TCP_RUNNING_CORE -1 // any available core #define CONFIG_ASYNC_TCP_RUNNING_CORE -1 // any available core
#define CONFIG_ASYNC_TCP_USE_WDT 0
#endif #endif
// If core is not defined, then we are running in Arduino or PIO // If core is not defined, then we are running in Arduino or PIO
#ifndef CONFIG_ASYNC_TCP_RUNNING_CORE #ifndef CONFIG_ASYNC_TCP_RUNNING_CORE
#define CONFIG_ASYNC_TCP_RUNNING_CORE -1 // any available 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 #endif
#ifndef CONFIG_ASYNC_TCP_STACK_SIZE #ifndef CONFIG_ASYNC_TCP_STACK_SIZE