Bläddra i källkod

esp32s2beta: task_wdt

Closes: IDF-753
KonstantinKondrashov 6 år sedan
förälder
incheckning
d1173c8f09
2 ändrade filer med 30 tillägg och 17 borttagningar
  1. 3 6
      components/esp32s2beta/cpu_start.c
  2. 27 11
      components/esp32s2beta/task_wdt.c

+ 3 - 6
components/esp32s2beta/cpu_start.c

@@ -373,20 +373,17 @@ static void main_task(void* args)
 
 
     //Initialize task wdt if configured to do so
     //Initialize task wdt if configured to do so
 #ifdef CONFIG_ESP_TASK_WDT_PANIC
 #ifdef CONFIG_ESP_TASK_WDT_PANIC
-    //ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, true))
+    ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, true));
 #elif CONFIG_ESP_TASK_WDT
 #elif CONFIG_ESP_TASK_WDT
-    //ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, false))
+    ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, false));
 #endif
 #endif
 
 
     //Add IDLE 0 to task wdt
     //Add IDLE 0 to task wdt
-// TODO: cpu_start.c: re-enable task WDT - IDF-753
-#if 0
 #ifdef CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
 #ifdef CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
     TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0);
     TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0);
     if(idle_0 != NULL){
     if(idle_0 != NULL){
-        ESP_ERROR_CHECK(esp_task_wdt_add(idle_0))
+        ESP_ERROR_CHECK(esp_task_wdt_add(idle_0));
     }
     }
-#endif
 #endif
 #endif
 
 
     // Now that the application is about to start, disable boot watchdog
     // Now that the application is about to start, disable boot watchdog

+ 27 - 11
components/esp32s2beta/task_wdt.c

@@ -28,12 +28,14 @@
 #include "esp_intr_alloc.h"
 #include "esp_intr_alloc.h"
 #include "esp_attr.h"
 #include "esp_attr.h"
 #include "esp_freertos_hooks.h"
 #include "esp_freertos_hooks.h"
-#include "soc/timer_group_struct.h"
-#include "soc/timer_group_reg.h"
+#include "soc/timer_periph.h"
 #include "esp_log.h"
 #include "esp_log.h"
 #include "driver/timer.h"
 #include "driver/timer.h"
 #include "driver/periph_ctrl.h"
 #include "driver/periph_ctrl.h"
 #include "esp_task_wdt.h"
 #include "esp_task_wdt.h"
+#include "esp_private/system_internal.h"
+
+static const char *TAG = "task_wdt";
 
 
 //Assertion macro where, if 'cond' is false, will exit the critical section and return 'ret'
 //Assertion macro where, if 'cond' is false, will exit the critical section and return 'ret'
 #define ASSERT_EXIT_CRIT_RETURN(cond, ret)  ({                              \
 #define ASSERT_EXIT_CRIT_RETURN(cond, ret)  ({                              \
@@ -114,13 +116,24 @@ static void reset_hw_timer(void)
     }
     }
 }
 }
 
 
+/*
+ * This function is called by task_wdt_isr function (ISR for when TWDT times out).
+ * It can be redefined in user code to handle twdt events.
+ * Note: It has the same limitations as the interrupt function.
+ *       Do not use ESP_LOGI functions inside.
+ */
+void __attribute__((weak)) esp_task_wdt_isr_user_handler(void)
+{
+
+}
+
 /*
 /*
  * ISR for when TWDT times out. Checks for which tasks have not reset. Also
  * ISR for when TWDT times out. Checks for which tasks have not reset. Also
  * triggers panic if configured to do so
  * triggers panic if configured to do so
  */
  */
 static void task_wdt_isr(void *arg)
 static void task_wdt_isr(void *arg)
 {
 {
-    portENTER_CRITICAL(&twdt_spinlock);
+    portENTER_CRITICAL_ISR(&twdt_spinlock);
     twdt_task_t *twdttask;
     twdt_task_t *twdttask;
     const char *cpu;
     const char *cpu;
     //Reset hardware timer so that 2nd stage timeout is not reached (will trigger system reset)
     //Reset hardware timer so that 2nd stage timeout is not reached (will trigger system reset)
@@ -129,7 +142,7 @@ static void task_wdt_isr(void *arg)
     TIMERG0.wdt_wprotect=0;
     TIMERG0.wdt_wprotect=0;
     //Acknowledge interrupt
     //Acknowledge interrupt
     TIMERG0.int_clr.wdt=1;
     TIMERG0.int_clr.wdt=1;
-    //We are taking a spinlock while doing I/O (ets_printf) here. Normally, that is a pretty
+    //We are taking a spinlock while doing I/O (ESP_EARLY_LOGE) here. Normally, that is a pretty
     //bad thing, possibly (temporarily) hanging up the 2nd core and stopping FreeRTOS. In this case,
     //bad thing, possibly (temporarily) hanging up the 2nd core and stopping FreeRTOS. In this case,
     //something bad already happened and reporting this is considered more important
     //something bad already happened and reporting this is considered more important
     //than the badness caused by a spinlock here.
     //than the badness caused by a spinlock here.
@@ -138,26 +151,29 @@ static void task_wdt_isr(void *arg)
     ASSERT_EXIT_CRIT_RETURN((twdt_config->list != NULL), VOID_RETURN);
     ASSERT_EXIT_CRIT_RETURN((twdt_config->list != NULL), VOID_RETURN);
 
 
     //Watchdog got triggered because at least one task did not reset in time.
     //Watchdog got triggered because at least one task did not reset in time.
-    ets_printf("Task watchdog got triggered. The following tasks did not reset the watchdog in time:\n");
+    ESP_EARLY_LOGE(TAG, "Task watchdog got triggered. The following tasks did not reset the watchdog in time:");
     for (twdttask=twdt_config->list; twdttask!=NULL; twdttask=twdttask->next) {
     for (twdttask=twdt_config->list; twdttask!=NULL; twdttask=twdttask->next) {
         if (!twdttask->has_reset) {
         if (!twdttask->has_reset) {
             cpu=xTaskGetAffinity(twdttask->task_handle)==0?DRAM_STR("CPU 0"):DRAM_STR("CPU 1");
             cpu=xTaskGetAffinity(twdttask->task_handle)==0?DRAM_STR("CPU 0"):DRAM_STR("CPU 1");
             if (xTaskGetAffinity(twdttask->task_handle)==tskNO_AFFINITY) cpu=DRAM_STR("CPU 0/1");
             if (xTaskGetAffinity(twdttask->task_handle)==tskNO_AFFINITY) cpu=DRAM_STR("CPU 0/1");
-            ets_printf(" - %s (%s)\n", pcTaskGetTaskName(twdttask->task_handle), cpu);
+            ESP_EARLY_LOGE(TAG, " - %s (%s)", pcTaskGetTaskName(twdttask->task_handle), cpu);
         }
         }
     }
     }
-    ets_printf(DRAM_STR("Tasks currently running:\n"));
+    ESP_EARLY_LOGE(TAG, "%s", DRAM_STR("Tasks currently running:"));
     for (int x=0; x<portNUM_PROCESSORS; x++) {
     for (int x=0; x<portNUM_PROCESSORS; x++) {
-        ets_printf("CPU %d: %s\n", x, pcTaskGetTaskName(xTaskGetCurrentTaskHandleForCPU(x)));
+        ESP_EARLY_LOGE(TAG, "CPU %d: %s", x, pcTaskGetTaskName(xTaskGetCurrentTaskHandleForCPU(x)));
     }
     }
 
 
+    esp_task_wdt_isr_user_handler();
     if (twdt_config->panic){     //Trigger Panic if configured to do so
     if (twdt_config->panic){     //Trigger Panic if configured to do so
-        ets_printf("Aborting.\n");
-        portEXIT_CRITICAL(&twdt_spinlock);
+        ESP_EARLY_LOGE(TAG, "Aborting.");
+        portEXIT_CRITICAL_ISR(&twdt_spinlock);
+        // TODO: Add support reset reason for esp32s2beta.
+        // esp_reset_reason_set_hint(ESP_RST_TASK_WDT);
         abort();
         abort();
     }
     }
 
 
-    portEXIT_CRITICAL(&twdt_spinlock);
+    portEXIT_CRITICAL_ISR(&twdt_spinlock);
 }
 }
 
 
 /*
 /*