From e9b54b6b456c103f7d95b6a033d7c8c65e8aae85 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 26 Sep 2016 01:34:05 +0800 Subject: [PATCH] components/esp32: add ESP_ERROR_CHECK Convenience macro to do error check and assert in cases when error recovery is not expected --- components/esp32/include/esp_err.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/esp32/include/esp_err.h b/components/esp32/include/esp_err.h index 6ea176991..4f013f91a 100644 --- a/components/esp32/include/esp_err.h +++ b/components/esp32/include/esp_err.h @@ -15,6 +15,7 @@ #define __ESP_ERR_H__ #include +#include #ifdef __cplusplus extern "C" { @@ -31,6 +32,12 @@ typedef int32_t esp_err_t; #define ESP_ERR_INVALID_ARG 0x102 #define ESP_ERR_INVALID_STATE 0x103 +/** + * Macro which can be used to check the error code, + * and terminate the program in case the code is not ESP_OK. + * Prints the failed statement to serial output. + */ +#define ESP_ERROR_CHECK(x) do { esp_err_t rc = (x); if (rc != ESP_OK) { assert(0 && #x);} } while(0); #ifdef __cplusplus }