mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 04:02:27 +00:00
Disable brown-out WDT, fix thread WDT, add panic reason indication to _xt_panic()
This commit is contained in:
@@ -33,6 +33,7 @@ This uses the TIMERG0 WDT.
|
||||
#include <esp_types.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_intr.h"
|
||||
#include "esp_attr.h"
|
||||
#include "soc/timer_group_struct.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
@@ -42,7 +43,6 @@ This uses the TIMERG0 WDT.
|
||||
|
||||
static const char* TAG = "task_wdt";
|
||||
|
||||
|
||||
typedef struct wdt_task_t wdt_task_t;
|
||||
struct wdt_task_t {
|
||||
TaskHandle_t task_handle;
|
||||
@@ -50,16 +50,35 @@ struct wdt_task_t {
|
||||
wdt_task_t *next;
|
||||
};
|
||||
|
||||
|
||||
static wdt_task_t *wdt_task_list=NULL;
|
||||
|
||||
//We use this interrupt number on whatever task calls task_wdt_init.
|
||||
#define WDT_INT_NUM 24
|
||||
|
||||
|
||||
#define WDT_WRITE_KEY 0x50D83AA1
|
||||
|
||||
static void task_wdt_isr(void *arg) {
|
||||
static void IRAM_ATTR task_wdt_isr(void *arg) {
|
||||
wdt_task_t *wdttask;
|
||||
const char *cpu;
|
||||
//Feed the watchdog so we do not reset
|
||||
TIMERG0.wdt_wprotect=WDT_WRITE_KEY;
|
||||
TIMERG0.wdt_feed=1;
|
||||
TIMERG0.wdt_wprotect=0;
|
||||
//Ack interrupt
|
||||
TIMERG0.int_clr_timers.wdt=1;
|
||||
//Watchdog got triggered because at least one task did not report in.
|
||||
ets_printf("Task watchdog got triggered. The following tasks did not feed the watchdog in time:\n");
|
||||
for (wdttask=wdt_task_list; wdttask!=NULL; wdttask=wdttask->next) {
|
||||
if (!wdttask->fed_watchdog) {
|
||||
cpu=xTaskGetAffinity(wdttask->task_handle)==0?"CPU 0":"CPU 1";
|
||||
if (xTaskGetAffinity(wdttask->task_handle)==tskNO_AFFINITY) cpu="CPU 0/1";
|
||||
printf(" - %s (%s)\n", pcTaskGetTaskName(wdttask->task_handle), cpu);
|
||||
}
|
||||
}
|
||||
#if CONFIG_TASK_WDT_PANIC
|
||||
ets_printf("Aborting.\n");
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +88,7 @@ void task_wdt_feed() {
|
||||
TaskHandle_t handle=xTaskGetCurrentTaskHandle();
|
||||
//Walk the linked list of wdt tasks to find this one, as well as see if we need to feed
|
||||
//the real watchdog timer.
|
||||
while (wdttask!=NULL) {
|
||||
for (wdttask=wdt_task_list; wdttask!=NULL; wdttask=wdttask->next) {
|
||||
//See if we are at the current task.
|
||||
if (wdttask->task_handle == handle) {
|
||||
wdttask->fed_watchdog=true;
|
||||
@@ -77,8 +96,6 @@ void task_wdt_feed() {
|
||||
}
|
||||
//If even one task in the list doesn't have the do_feed_wdt var set, we do not feed the watchdog.
|
||||
if (!wdttask->fed_watchdog) do_feed_wdt=false;
|
||||
//Next entry.
|
||||
wdttask=wdttask->next;
|
||||
}
|
||||
|
||||
if (!found_task) {
|
||||
@@ -91,9 +108,8 @@ void task_wdt_feed() {
|
||||
if (wdt_task_list == NULL) {
|
||||
wdt_task_list=newtask;
|
||||
} else {
|
||||
wdttask=wdt_task_list;
|
||||
while (!(wdttask->next == NULL)) wdttask=wdttask->next;
|
||||
wdttask->next=wdttask;
|
||||
for (wdttask=wdt_task_list; wdttask->next!=NULL; wdttask=wdttask->next) ;
|
||||
wdttask->next=newtask;
|
||||
}
|
||||
}
|
||||
if (do_feed_wdt) {
|
||||
@@ -101,6 +117,8 @@ void task_wdt_feed() {
|
||||
TIMERG0.wdt_wprotect=WDT_WRITE_KEY;
|
||||
TIMERG0.wdt_feed=1;
|
||||
TIMERG0.wdt_wprotect=0;
|
||||
//Reset fed_watchdog status
|
||||
for (wdttask=wdt_task_list; wdttask->next!=NULL; wdttask=wdttask->next) wdttask->fed_watchdog=false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,12 +161,13 @@ void task_wdt_init() {
|
||||
TIMERG0.wdt_feed=1;
|
||||
TIMERG0.wdt_wprotect=0;
|
||||
ESP_INTR_DISABLE(ETS_T0_WDT_INUM);
|
||||
intr_matrix_set(xPortGetCoreID(), ETS_TG1_WDT_LEVEL_INTR_SOURCE, ETS_T0_WDT_INUM);
|
||||
intr_matrix_set(xPortGetCoreID(), ETS_TG0_WDT_LEVEL_INTR_SOURCE, ETS_T0_WDT_INUM);
|
||||
xt_set_interrupt_handler(ETS_T0_WDT_INUM, task_wdt_isr, NULL);
|
||||
TIMERG0.int_clr_timers.wdt=1;
|
||||
TIMERG0.int_ena.wdt=1;
|
||||
ESP_INTR_ENABLE(ETS_T0_WDT_INUM);
|
||||
}
|
||||
|
||||
|
||||
#if CONFIG_TASK_WDT_CHECK_IDLE_TASK
|
||||
void vApplicationIdleHook(void) {
|
||||
task_wdt_feed();
|
||||
|
Reference in New Issue
Block a user