Skip to content

Commit f49c854

Browse files
authored
Update IDF to 97eecfa, enable reboot on WDT and add WDT API (espressif#2248)
* Update IDF to 97eecfa and enable reboot on WDT * Add API to enable/disable WDT for Core 1 and Arduino Loop
1 parent 879388e commit f49c854

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+656
-395
lines changed

Diff for: cores/esp32/esp32-hal-misc.c

+42
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "soc/rtc.h"
2929
#include "soc/rtc_cntl_reg.h"
3030
#include "rom/rtc.h"
31+
#include "esp_task_wdt.h"
3132
#include "esp32-hal.h"
3233

3334
//Undocumented!!! Get chip temperature in Farenheit
@@ -44,6 +45,47 @@ void yield()
4445
vPortYield();
4546
}
4647

48+
#if CONFIG_AUTOSTART_ARDUINO
49+
50+
extern TaskHandle_t loopTaskHandle;
51+
extern bool loopTaskWDTEnabled;
52+
53+
void enableLoopWDT(){
54+
if(loopTaskHandle != NULL){
55+
if(esp_task_wdt_add(loopTaskHandle) != ESP_OK){
56+
log_e("Failed to add loop task to WDT");
57+
} else {
58+
loopTaskWDTEnabled = true;
59+
}
60+
}
61+
}
62+
63+
void disableLoopWDT(){
64+
if(loopTaskHandle != NULL && loopTaskWDTEnabled){
65+
loopTaskWDTEnabled = false;
66+
if(esp_task_wdt_delete(loopTaskHandle) != ESP_OK){
67+
log_e("Failed to remove loop task from WDT");
68+
}
69+
}
70+
}
71+
#endif
72+
73+
#ifndef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1
74+
void enableCore1WDT(){
75+
TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1);
76+
if(idle_1 == NULL || esp_task_wdt_add(idle_1) != ESP_OK){
77+
log_e("Failed to add Core 1 IDLE task to WDT");
78+
}
79+
}
80+
81+
void disableCore1WDT(){
82+
TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1);
83+
if(idle_1 == NULL || esp_task_wdt_delete(idle_1) != ESP_OK){
84+
log_e("Failed to remove Core 1 IDLE task from WDT");
85+
}
86+
}
87+
#endif
88+
4789
static uint32_t _cpu_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ;
4890
static uint32_t _sys_time_multiplier = 1;
4991

Diff for: cores/esp32/esp32-hal.h

+12
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ void yield(void);
7272
//returns chip temperature in Celsius
7373
float temperatureRead();
7474

75+
#if CONFIG_AUTOSTART_ARDUINO
76+
//enable/disable WDT for Arduino's setup and loop functions
77+
void enableLoopWDT();
78+
void disableLoopWDT();
79+
#endif
80+
81+
#ifndef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1
82+
//enable/disable WDT for the IDLE task on Core 1
83+
void enableCore1WDT();
84+
void disableCore1WDT();
85+
#endif
86+
7587
//function takes the following frequencies as valid values:
7688
// 240, 160, 80 <<< For all XTAL types
7789
// 40, 20, 13, 10, 8, 5, 4, 3, 2, 1 <<< For 40MHz XTAL

Diff for: cores/esp32/main.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#include "freertos/FreeRTOS.h"
22
#include "freertos/task.h"
3+
#include "esp_task_wdt.h"
34
#include "Arduino.h"
45

6+
TaskHandle_t loopTaskHandle = NULL;
7+
58
#if CONFIG_AUTOSTART_ARDUINO
69

710
#if CONFIG_FREERTOS_UNICORE
@@ -10,18 +13,24 @@
1013
#define ARDUINO_RUNNING_CORE 1
1114
#endif
1215

16+
bool loopTaskWDTEnabled;
17+
1318
void loopTask(void *pvParameters)
1419
{
1520
setup();
1621
for(;;) {
22+
if(loopTaskWDTEnabled){
23+
esp_task_wdt_reset();
24+
}
1725
loop();
1826
}
1927
}
2028

2129
extern "C" void app_main()
2230
{
31+
loopTaskWDTEnabled = false;
2332
initArduino();
24-
xTaskCreatePinnedToCore(loopTask, "loopTask", 8192, NULL, 1, NULL, ARDUINO_RUNNING_CORE);
33+
xTaskCreatePinnedToCore(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, ARDUINO_RUNNING_CORE);
2534
}
2635

2736
#endif

0 commit comments

Comments
 (0)