Task WDT: add method to retrieve task names for pre-crash storage

This commit is contained in:
Michael Balzer 2020-07-14 19:44:39 +02:00
parent 7b89c38034
commit 7ca3bc1e48
2 changed files with 31 additions and 0 deletions

View file

@ -157,6 +157,15 @@ esp_err_t esp_task_wdt_status(TaskHandle_t handle);
*/
void esp_task_wdt_feed() __attribute__ ((deprecated));
/**
* @brief Get names of tasks that triggered the WDT
*
* Intended to be called in an error callback (see xt_set_error_handler_callback()).
* Fills the buffer with a pipe ('|') separated list of the names of the tasks that
* failed to reset the watchdog in time. The result is zero-terminated (C string).
*/
void esp_task_wdt_get_trigger_tasknames(char *buf, size_t bufsize);
#ifdef __cplusplus
}

View file

@ -177,6 +177,28 @@ static void task_wdt_isr(void *arg)
portEXIT_CRITICAL_ISR(&twdt_spinlock);
}
void esp_task_wdt_get_trigger_tasknames(char *buf, size_t bufsize)
{
twdt_task_t *twdttask;
char *wpos = buf;
if (!buf || !bufsize)
return;
*wpos = 0;
if (!twdt_config)
return;
for (twdttask=twdt_config->list; twdttask!=NULL; twdttask=twdttask->next) {
if (!twdttask->has_reset) {
if (wpos != buf) {
*wpos++ = '|';
*wpos = 0;
}
wpos += strlcpy(wpos, pcTaskGetTaskName(twdttask->task_handle), (bufsize-(wpos-buf)));
if (wpos - buf >= bufsize - 2)
break;
}
}
}
/*
* Initializes the TWDT by allocating memory for the config data
* structure, obtaining the idle task handles/registering idle hooks, and