]> granicus.if.org Git - esp-idf/commitdiff
esp32: Add macro to check a condition without abort
authorRoland Dobai <dobai.roland@gmail.com>
Mon, 24 Sep 2018 06:49:39 +0000 (08:49 +0200)
committerRoland Dobai <dobai.roland@gmail.com>
Tue, 9 Oct 2018 06:57:23 +0000 (08:57 +0200)
Closes https://github.com/espressif/esp-idf/issues/2325

components/esp32/cpu_start.c
components/esp32/include/esp_err.h
components/esp32/panic.c
components/esp32/task_wdt.c
examples/peripherals/can/can_self_test/main/can_self_test_example_main.c

index bda8b8cc82b9c1e077537903a57ac6ecb0b9e253..c815b60d3635d01a9ecbc74f8e54d0bba2660333 100644 (file)
@@ -455,23 +455,23 @@ static void main_task(void* args)
 
     //Initialize task wdt if configured to do so
 #ifdef CONFIG_TASK_WDT_PANIC
-    ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_TASK_WDT_TIMEOUT_S, true))
+    ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_TASK_WDT_TIMEOUT_S, true));
 #elif CONFIG_TASK_WDT
-    ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_TASK_WDT_TIMEOUT_S, false))
+    ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_TASK_WDT_TIMEOUT_S, false));
 #endif
 
     //Add IDLE 0 to task wdt
 #ifdef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0
     TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0);
     if(idle_0 != NULL){
-        ESP_ERROR_CHECK(esp_task_wdt_add(idle_0))
+        ESP_ERROR_CHECK(esp_task_wdt_add(idle_0));
     }
 #endif
     //Add IDLE 1 to task wdt
 #ifdef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1
     TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1);
     if(idle_1 != NULL){
-        ESP_ERROR_CHECK(esp_task_wdt_add(idle_1))
+        ESP_ERROR_CHECK(esp_task_wdt_add(idle_1));
     }
 #endif
 
index 8000825e791c2473f475f5a98b3a59b4ae1e0387..6672f233a1986c4500e9e67786d3eeb7d37495ec 100644 (file)
@@ -78,6 +78,9 @@ const char *esp_err_to_name_r(esp_err_t code, char *buf, size_t buflen);
 /** @cond */
 void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression) __attribute__((noreturn));
 
+/** @cond */
+void _esp_error_check_failed_without_abort(esp_err_t rc, const char *file, int line, const char *function, const char *expression);
+
 #ifndef __ASSERT_FUNC
 /* This won't happen on IDF, which defines __ASSERT_FUNC in assert.h, but it does happen when building on the host which
    uses /usr/include/assert.h or equivalent.
@@ -119,6 +122,27 @@ void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const cha
     } while(0);
 #endif
 
+/**
+ * Macro which can be used to check the error code. Prints the error code, error location, and the failed statement to
+ * serial output.
+ * In comparison with ESP_ERROR_CHECK(), this prints the same error message but isn't terminating the program.
+ */
+#ifdef NDEBUG
+#define ESP_ERROR_CHECK_WITHOUT_ABORT(x) ({                                         \
+        esp_err_t __err_rc = (x);                                                   \
+        __err_rc;                                                                   \
+    })
+#else
+#define ESP_ERROR_CHECK_WITHOUT_ABORT(x) ({                                         \
+        esp_err_t __err_rc = (x);                                                   \
+        if (__err_rc != ESP_OK) {                                                   \
+            _esp_error_check_failed_without_abort(__err_rc, __FILE__, __LINE__,     \
+                                    __ASSERT_FUNC, #x);                             \
+        }                                                                           \
+        __err_rc;                                                                   \
+    })
+#endif //NDEBUG
+
 #ifdef __cplusplus
 }
 #endif
index 6217c65e8196424ab94dec9d5d06e078e753a6d8..08192afae7d98a21298ad81e4f72d3e7cc27aa5a 100644 (file)
@@ -663,9 +663,9 @@ void esp_clear_watchpoint(int no)
     }
 }
 
-void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
+static void esp_error_check_failed_print(const char *msg, esp_err_t rc, const char *file, int line, const char *function, const char *expression)
 {
-    ets_printf("ESP_ERROR_CHECK failed: esp_err_t 0x%x", rc);
+    ets_printf("%s failed: esp_err_t 0x%x", msg, rc);
 #ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP
     ets_printf(" (%s)", esp_err_to_name(rc));
 #endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP
@@ -673,5 +673,15 @@ void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const cha
     if (spi_flash_cache_enabled()) { // strings may be in flash cache
         ets_printf("file: \"%s\" line %d\nfunc: %s\nexpression: %s\n", file, line, function, expression);
     }
+}
+
+void _esp_error_check_failed_without_abort(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
+{
+    esp_error_check_failed_print("ESP_ERROR_CHECK_WITHOUT_ABORT", rc, file, line, function, expression);
+}
+
+void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
+{
+    esp_error_check_failed_print("ESP_ERROR_CHECK", rc, file, line, function, expression);
     invoke_abort();
 }
index 30585373039f90b017b0025334903972124e4b7d..0c302082a411ec211edb14f8d0e26162a20ba832 100644 (file)
@@ -196,7 +196,7 @@ esp_err_t esp_task_wdt_init(uint32_t timeout, bool panic)
         twdt_config->panic = panic;
 
         //Register Interrupt and ISR
-        ESP_ERROR_CHECK(esp_intr_alloc(ETS_TG0_WDT_LEVEL_INTR_SOURCE, 0, task_wdt_isr, NULL, &twdt_config->intr_handle))
+        ESP_ERROR_CHECK(esp_intr_alloc(ETS_TG0_WDT_LEVEL_INTR_SOURCE, 0, task_wdt_isr, NULL, &twdt_config->intr_handle));
 
         //Configure hardware timer
         periph_module_enable(PERIPH_TIMG0_MODULE);
@@ -244,7 +244,7 @@ esp_err_t esp_task_wdt_deinit()
     TIMERG0.wdt_config0.en=0;                   //Disable timer
     TIMERG0.wdt_wprotect=0;                     //Enable write protection
 
-    ESP_ERROR_CHECK(esp_intr_free(twdt_config->intr_handle))  //Unregister interrupt
+    ESP_ERROR_CHECK(esp_intr_free(twdt_config->intr_handle));  //Unregister interrupt
     free(twdt_config);                      //Free twdt_config
     twdt_config = NULL;
     portEXIT_CRITICAL(&twdt_spinlock);
@@ -286,7 +286,7 @@ esp_err_t esp_task_wdt_add(TaskHandle_t handle)
     //If idle task, register the idle hook callback to appropriate core
     for(int i = 0; i < portNUM_PROCESSORS; i++){
         if(handle == xTaskGetIdleTaskHandleForCPU(i)){
-            ESP_ERROR_CHECK(esp_register_freertos_idle_hook_for_cpu(idle_hook_cb, i))
+            ESP_ERROR_CHECK(esp_register_freertos_idle_hook_for_cpu(idle_hook_cb, i));
             break;
         }
     }
index a00a46ad85c5b273f79130e6011aff284a12aa12..bb17722cc6a6cf0719ccc5538b3806af2eb18d8a 100644 (file)
@@ -77,7 +77,7 @@ static void can_receive_task(void *arg)
         xSemaphoreTake(rx_sem, portMAX_DELAY);
         for (int i = 0; i < NO_OF_MSGS; i++) {
             //Receive message and print message data
-            ESP_ERROR_CHECK(can_receive(&rx_message, portMAX_DELAY))
+            ESP_ERROR_CHECK(can_receive(&rx_message, portMAX_DELAY));
             ESP_LOGI(EXAMPLE_TAG, "Msg received - Data = %d", rx_message.data[0]);
         }
         //Indicate to control task all messages received for this iteration