ESP32: Optionally disable lookup-tables for esp_err_to_name

This commit is contained in:
Roland Dobai 2018-02-22 13:46:55 +01:00
parent 12b4e416e6
commit f891eac827
3 changed files with 34 additions and 2 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;