]> granicus.if.org Git - esp-idf/commitdiff
ESP32: Optionally disable lookup-tables for esp_err_to_name
authorRoland Dobai <dobai.roland@gmail.com>
Thu, 22 Feb 2018 12:46:55 +0000 (13:46 +0100)
committerRoland Dobai <dobai.roland@gmail.com>
Tue, 13 Mar 2018 13:26:54 +0000 (14:26 +0100)
components/esp32/Kconfig
components/esp32/esp_err_to_name.c
components/esp32/esp_err_to_name.c.in

index 4ac1685d0f35790a1a2392405de7eb15e9703404..739bfa7fc036d93244bdf97287b33d127e22ccd9 100644 (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
index a706a68a58778bc9c87c0907f874385784be5dd1..594c30203c30bdfa2f104ec411318c75719ddd30 100644 (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;
index 86085bb885719d023fc21ba2a33fa1e75ef5317c..b6b87312e9838bd0164bc0bcc824df63597e002d 100644 (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;