Skip to content

Commit

Permalink
make _async_service_task's watchdog constantly watching with periodic…
Browse files Browse the repository at this point in the history
… feed
  • Loading branch information
vortigont committed Dec 15, 2024
1 parent afa162b commit 80b2733
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
27 changes: 17 additions & 10 deletions src/AsyncTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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");
}
esp_task_wdt_reset();
#endif
}
}
#if CONFIG_ASYNC_TCP_USE_WDT
esp_task_wdt_delete(NULL);
#endif
vTaskDelete(NULL);
_async_service_task_handle = NULL;
}
Expand Down
7 changes: 5 additions & 2 deletions src/AsyncTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ extern "C" {
#include <semphr.h>
}
#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
Expand Down

0 comments on commit 80b2733

Please sign in to comment.