From f891eac827a5a0dd70519634d37639a1f96132d3 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Thu, 22 Feb 2018 13:46:55 +0100 Subject: [PATCH] ESP32: Optionally disable lookup-tables for esp_err_to_name --- components/esp32/Kconfig | 10 ++++++++++ components/esp32/esp_err_to_name.c | 13 ++++++++++++- components/esp32/esp_err_to_name.c.in | 13 ++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index 4ac1685d0f..739bfa7fc0 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -802,6 +802,16 @@ config COMPATIBLE_PRE_V2_1_BOOTLOADERS Enabling this setting adds approximately 1KB to the app's IRAM usage. +config ESP_ERR_TO_NAME_LOOKUP + bool "Enable lookup of error code strings" + default "y" + help + Functions esp_err_to_name() and esp_err_to_name_r() return string + representations of error codes from a pre-generated lookup table. + This option can be used to turn off the use of the look-up table in + order to save memory but this comes at the price of sacrificing + distinguishable (meaningful) output string representations. + endmenu # ESP32-Specific menu Wi-Fi diff --git a/components/esp32/esp_err_to_name.c b/components/esp32/esp_err_to_name.c index a706a68a58..594c30203c 100644 --- a/components/esp32/esp_err_to_name.c +++ b/components/esp32/esp_err_to_name.c @@ -38,6 +38,7 @@ #include "tcpip_adapter.h" #endif +#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP #define ERR_TBL_IT(err) {err, #err} typedef struct { @@ -359,11 +360,18 @@ static const esp_err_msg_t esp_err_msg_table[] = { ERR_TBL_IT(ESP_ERR_FLASH_OP_TIMEOUT), /* 65554 0x10012 */ # endif }; +#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP -static const char esp_unknown_msg[] = "UNKNOWN ERROR"; +static const char esp_unknown_msg[] = +#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP + "ERROR"; +#else + "UNKNOWN ERROR"; +#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP const char *esp_err_to_name(esp_err_t code) { +#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP int i; for (i = 0; i < sizeof(esp_err_msg_table)/sizeof(esp_err_msg_table[0]); ++i) { @@ -371,12 +379,14 @@ const char *esp_err_to_name(esp_err_t code) return esp_err_msg_table[i].msg; } } +#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP return esp_unknown_msg; } const char *esp_err_to_name_r(esp_err_t code, char *buf, size_t buflen) { +#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP int i; for (i = 0; i < sizeof(esp_err_msg_table)/sizeof(esp_err_msg_table[0]); ++i) { @@ -385,6 +395,7 @@ const char *esp_err_to_name_r(esp_err_t code, char *buf, size_t buflen) return buf; } } +#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP if (strerror_r(code, buf, buflen) == 0) { return buf; diff --git a/components/esp32/esp_err_to_name.c.in b/components/esp32/esp_err_to_name.c.in index 86085bb885..b6b87312e9 100644 --- a/components/esp32/esp_err_to_name.c.in +++ b/components/esp32/esp_err_to_name.c.in @@ -6,6 +6,7 @@ #endif @HEADERS@ +#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP #define ERR_TBL_IT(err) {err, #err} typedef struct { @@ -16,11 +17,18 @@ typedef struct { static const esp_err_msg_t esp_err_msg_table[] = { @ERROR_ITEMS@ }; +#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP -static const char esp_unknown_msg[] = "UNKNOWN ERROR"; +static const char esp_unknown_msg[] = +#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP + "ERROR"; +#else + "UNKNOWN ERROR"; +#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP const char *esp_err_to_name(esp_err_t code) { +#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP int i; for (i = 0; i < sizeof(esp_err_msg_table)/sizeof(esp_err_msg_table[0]); ++i) { @@ -28,12 +36,14 @@ const char *esp_err_to_name(esp_err_t code) return esp_err_msg_table[i].msg; } } +#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP return esp_unknown_msg; } const char *esp_err_to_name_r(esp_err_t code, char *buf, size_t buflen) { +#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP int i; for (i = 0; i < sizeof(esp_err_msg_table)/sizeof(esp_err_msg_table[0]); ++i) { @@ -42,6 +52,7 @@ const char *esp_err_to_name_r(esp_err_t code, char *buf, size_t buflen) return buf; } } +#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP if (strerror_r(code, buf, buflen) == 0) { return buf;