1@COMMENT@ 2 3#include <string.h> 4#include "esp_err.h" 5#if __has_include("soc/soc.h") 6#include "soc/soc.h" 7#endif 8@HEADERS@ 9 10#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP 11#define ERR_TBL_IT(err) {err, #err} 12 13typedef struct { 14 esp_err_t code; 15 const char *msg; 16} esp_err_msg_t; 17 18static const esp_err_msg_t esp_err_msg_table[] = { 19@ERROR_ITEMS@ 20}; 21#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP 22 23static const char esp_unknown_msg[] = 24#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP 25 "ERROR"; 26#else 27 "UNKNOWN ERROR"; 28#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP 29 30const char *esp_err_to_name(esp_err_t code) 31{ 32#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP 33 size_t i; 34 35 for (i = 0; i < sizeof(esp_err_msg_table)/sizeof(esp_err_msg_table[0]); ++i) { 36 if (esp_err_msg_table[i].code == code) { 37 return esp_err_msg_table[i].msg; 38 } 39 } 40#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP 41 42 return esp_unknown_msg; 43} 44 45const char *esp_err_to_name_r(esp_err_t code, char *buf, size_t buflen) 46{ 47#ifdef CONFIG_ESP_ERR_TO_NAME_LOOKUP 48 size_t i; 49 50 for (i = 0; i < sizeof(esp_err_msg_table)/sizeof(esp_err_msg_table[0]); ++i) { 51 if (esp_err_msg_table[i].code == code) { 52 strlcpy(buf, esp_err_msg_table[i].msg, buflen); 53 return buf; 54 } 55 } 56#endif //CONFIG_ESP_ERR_TO_NAME_LOOKUP 57 58 if (strerror_r(code, buf, buflen) == 0) { 59 return buf; 60 } 61 62 snprintf(buf, buflen, "%s 0x%x(%d)", esp_unknown_msg, code, code); 63 64 return buf; 65} 66