From 965fc47ff88b76e60093f59b2555930f94eeb891 Mon Sep 17 00:00:00 2001 From: Zhang Jun Hao Date: Mon, 28 Jan 2019 15:03:51 +0800 Subject: [PATCH] feat(log): add esp_log to internal wifi lib --- components/esp8266/Kconfig | 121 ++++++++++++++++++ components/esp8266/component.mk | 5 + .../include/internal/esp_wifi_internal.h | 65 ++++++++++ components/esp8266/ld/esp8266.common.ld | 12 ++ components/esp8266/source/esp_wifi.c | 68 +++++++++- .../esp8266/include/freertos/FreeRTOSConfig.h | 4 + components/log/include/esp_log.h | 14 ++ components/log/log.c | 2 +- 8 files changed, 289 insertions(+), 2 deletions(-) diff --git a/components/esp8266/Kconfig b/components/esp8266/Kconfig index 019d406f..8233ad1f 100644 --- a/components/esp8266/Kconfig +++ b/components/esp8266/Kconfig @@ -288,6 +288,127 @@ config WIFI_TX_RATE_SEQUENCE_FROM_HIGH If this option is enabled, Wifi will try to send packets first from high rate(54M). If it fails, it will try at low rate until the transmission is successful. +config ESP8266_WIFI_DEBUG_LOG_ENABLE + bool "Enable WiFi debug log" + default n + help + Select this option to enable WiFi debug log + +choice ESP8266_WIFI_DEBUG_LOG_LEVEL + depends on ESP8266_WIFI_DEBUG_LOG_ENABLE + prompt "The DEBUG level is enabled" + default ESP8266_WIFI_DEBUG_LOG_ERROR + help + The WiFi log is divided into the following levels: ERROR,WARNING,INFO,DEBUG,VERBOSE. + The ERROR level is enabled by default, and the WARNING,INFO,DEBUG,VERBOSE levels can be enabled here. + + config ESP8266_WIFI_DEBUG_LOG_ERROR + bool "Error" + config ESP8266_WIFI_DEBUG_LOG_WARNING + bool "Warning" + config ESP8266_WIFI_DEBUG_LOG_INFO + bool "Info" + config ESP8266_WIFI_DEBUG_LOG_DEBUG + bool "Debug" + config ESP8266_WIFI_DEBUG_LOG_VERBOSE + bool "Verbose" +endchoice + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE + depends on ESP8266_WIFI_DEBUG_LOG_ENABLE + bool "WiFi debug log submodule" + default n + help + Enable this option to set the WiFi debug log submodule. + Currently the log submodule contains the following parts: INIT,IOCTL,CONN,SCAN. + The INIT submodule indicates the initialization process.The IOCTL submodule indicates the API calling + process. + The CONN submodule indicates the connecting process.The SCAN submodule indicates the scaning process. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_CORE + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "core" + default n + help + When this option is enabled, log for core module will be enabled.. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_SCAN + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "scan" + default n + help + When this option is enabled, log for scan module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_PM + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "power management" + default n + help + When this option is enabled, log for power management module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_NVS + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "NVS" + default n + help + When this option is enabled, log for NVS module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_TRC + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "TRC" + default n + help + When this option is enabled, log for TRC module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_EBUF + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "EBUF" + default n + help + When this option is enabled, log for EBUF module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_NET80211 + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "NET80211" + default n + help + When this option is enabled, log for net80211 module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_TIMER + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "TIMER" + default n + help + When this option is enabled, log for timer module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_ESPNOW + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "ESPNOW" + default n + help + When this option is enabled, log for espnow module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_MAC + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "MAC layer" + default n + help + When this option is enabled, log for mac layer module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_WPA + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "wpa" + default n + help + When this option is enabled, log for wpa module will be enabled. + +config ESP8266_WIFI_DEBUG_LOG_SUBMODULE_WPS + depends on ESP8266_WIFI_DEBUG_LOG_SUBMODULE + bool "wps" + default n + help + When this option is enabled, log for wps module will be enabled. + endmenu menu PHY diff --git a/components/esp8266/component.mk b/components/esp8266/component.mk index 6b7d027e..88ebe41f 100644 --- a/components/esp8266/component.mk +++ b/components/esp8266/component.mk @@ -11,8 +11,13 @@ COMPONENT_SRCDIRS := driver source LIBS ?= ifndef CONFIG_NO_BLOBS +ifndef CONFIG_ESP8266_WIFI_DEBUG_LOG_ENABLE LIBS += gcc hal core net80211 \ phy pp smartconfig ssc wpa espnow wps +else +LIBS += gcc hal core_dbg net80211_dbg \ + phy pp_dbg smartconfig ssc wpa_dbg espnow_dbg wps_dbg +endif endif #Linker scripts used to link the final application. diff --git a/components/esp8266/include/internal/esp_wifi_internal.h b/components/esp8266/include/internal/esp_wifi_internal.h index f3eb9c74..99a39584 100644 --- a/components/esp8266/include/internal/esp_wifi_internal.h +++ b/components/esp8266/include/internal/esp_wifi_internal.h @@ -24,6 +24,36 @@ typedef enum { WIFI_RX_PBUF_DRAM, /** save rx buffer to dram and upload to tcpip */ } wifi_rx_pbuf_mem_type_t; +/** + * @brief WiFi log level + * + */ +typedef enum { + WIFI_LOG_ERROR = 0, /*enabled by default*/ + WIFI_LOG_WARNING, /*can be set in menuconfig*/ + WIFI_LOG_INFO, /*can be set in menuconfig*/ + WIFI_LOG_DEBUG, /*can be set in menuconfig*/ + WIFI_LOG_VERBOSE, /*can be set in menuconfig*/ +} wifi_log_level_t; + +/** + * @brief WiFi log submodule definition + * + */ +#define WIFI_LOG_SUBMODULE_NULL (0) +#define WIFI_LOG_SUBMODULE_CORE (1<<0) +#define WIFI_LOG_SUBMODULE_SCAN (1<<1) +#define WIFI_LOG_SUBMODULE_PM (1<<2) +#define WIFI_LOG_SUBMODULE_NVS (1<<3) +#define WIFI_LOG_SUBMODULE_TRC (1<<4) +#define WIFI_LOG_SUBMODULE_EBUF (1<<5) +#define WIFI_LOG_SUBMODULE_NET80211 (1<<6) +#define WIFI_LOG_SUBMODULE_TIMER (1<<7) +#define WIFI_LOG_SUBMODULE_ESPNOW (1<<8) +#define WIFI_LOG_SUBMODULE_MAC (1<<9) +#define WIFI_LOG_SUBMODULE_WPA (1<<10) +#define WIFI_LOG_SUBMODULE_WPS (1<<11) + /** * @brief Set WIFI received TCP/IP data cache ram type * @@ -106,6 +136,41 @@ typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb); */ esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn); +/** + * @brief Set current WiFi log level + * + * @param level Log level. + * + * @return + * - ESP_OK: succeed + * - ESP_FAIL: level is invalid + */ +esp_err_t esp_wifi_internal_set_log_level(wifi_log_level_t level); + +/** + * @brief Set current log module and submodule + * + * @param module Log module + * @param submodule Log submodule + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init + * - ESP_ERR_WIFI_ARG: invalid argument + */ +esp_err_t esp_wifi_internal_set_log_mod(uint32_t submodule); + +/** + * @brief Get current WiFi log info + * + * @param log_level the return log level. + * @param log_mod the return log module and submodule + * + * @return + * - ESP_OK: succeed + */ +esp_err_t esp_wifi_internal_get_log(wifi_log_level_t *log_level, uint32_t *log_mod); + #ifdef __cplusplus } #endif diff --git a/components/esp8266/ld/esp8266.common.ld b/components/esp8266/ld/esp8266.common.ld index 02a8b592..8dabdd8b 100644 --- a/components/esp8266/ld/esp8266.common.ld +++ b/components/esp8266/ld/esp8266.common.ld @@ -106,7 +106,11 @@ SECTIONS *(.init) *(.iram1 .iram1.*) *libspi_flash.a:spi_flash_raw.o(.literal .text .literal.* .text.*) +#ifdef CONFIG_ESP8266_WIFI_DEBUG_LOG_ENABLE + *libpp_dbg.a:(.literal .text .literal.* .text.*) +#else *libpp.a:(.literal .text .literal.* .text.*) +#endif *libphy.a:(.literal .text .literal.* .text.*) *(.literal .text .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) *(.fini.literal) @@ -122,8 +126,12 @@ SECTIONS #endif #ifdef CONFIG_ESP8266_CORE_GLOBAL_DATA_LINK_IRAM +#ifdef CONFIG_ESP8266_WIFI_DEBUG_LOG_ENABLE + *libcore_dbg.a:(.bss .data .bss.* .data.* COMMON) +#else *libcore.a:(.bss .data .bss.* .data.* COMMON) #endif +#endif #ifdef CONFIG_FREERTOS_GLOBAL_DATA_LINK_IRAM *libfreertos.a:tasks.o(.bss .data .bss.* .data.* COMMON) @@ -157,7 +165,11 @@ SECTIONS .rodata : ALIGN(4) { _rodata_start = ABSOLUTE(.); +#ifdef CONFIG_ESP8266_WIFI_DEBUG_LOG_ENABLE + *libpp_dbg.a:(.rodata.* .rodata) +#else *libpp.a:(.rodata.* .rodata) +#endif *liblog.a:(.rodata.* .rodata) *(.gnu.linkonce.r.*) *(.rodata1) diff --git a/components/esp8266/source/esp_wifi.c b/components/esp8266/source/esp_wifi.c index 3fc90cc5..058b11b8 100644 --- a/components/esp8266/source/esp_wifi.c +++ b/components/esp8266/source/esp_wifi.c @@ -23,6 +23,68 @@ const size_t _g_esp_wifi_ppt_task_stk_size = CONFIG_WIFI_PPT_TASKSTACK_SIZE; esp_err_t esp_wifi_init_internal(const wifi_init_config_t *config); +static void esp_wifi_set_debug_log() +{ + /* set WiFi log level and module */ +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_ENABLE + uint32_t wifi_log_level = WIFI_LOG_ERROR; + uint32_t wifi_log_submodule = WIFI_LOG_SUBMODULE_NULL; +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_WARNING + wifi_log_level = WIFI_LOG_WARNING; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_INFO + wifi_log_level = WIFI_LOG_INFO; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_DEBUG + wifi_log_level = WIFI_LOG_DEBUG; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_VERBOSE + wifi_log_level = WIFI_LOG_VERBOSE; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_CORE + wifi_log_submodule |= WIFI_LOG_SUBMODULE_CORE; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_SCAN + wifi_log_submodule |= WIFI_LOG_SUBMODULE_SCAN; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_PM + wifi_log_submodule |= WIFI_LOG_SUBMODULE_PM; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_NVS + wifi_log_submodule |= WIFI_LOG_SUBMODULE_NVS; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_TRC + wifi_log_submodule |= WIFI_LOG_SUBMODULE_TRC; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_EBUF + wifi_log_submodule |= WIFI_LOG_SUBMODULE_EBUF; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_NET80211 + wifi_log_submodule |= WIFI_LOG_SUBMODULE_NET80211; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_TIMER + wifi_log_submodule |= WIFI_LOG_SUBMODULE_TIMER; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_ESPNOW + wifi_log_submodule |= WIFI_LOG_SUBMODULE_ESPNOW; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_MAC + wifi_log_submodule |= WIFI_LOG_SUBMODULE_MAC; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_WPA + wifi_log_submodule |= WIFI_LOG_SUBMODULE_WPA; +#endif +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_SUBMODULE_WPS + wifi_log_submodule |= WIFI_LOG_SUBMODULE_WPS; +#endif + esp_wifi_internal_set_log_level(wifi_log_level); + esp_wifi_internal_set_log_mod(wifi_log_submodule); +#else + esp_wifi_internal_set_log_level(WIFI_LOG_ERROR); + esp_wifi_internal_set_log_mod(WIFI_LOG_SUBMODULE_NULL); +#endif /* CONFIG_ESP8266_WIFI_DEBUG_LOG_ENABLE*/ +} + /** * @brief Init WiFi * Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer, @@ -45,7 +107,11 @@ esp_err_t esp_wifi_init_internal(const wifi_init_config_t *config); esp_err_t esp_wifi_init(const wifi_init_config_t *config) { esp_event_set_default_wifi_handlers(); - return esp_wifi_init_internal(config); + esp_err_t result = esp_wifi_init_internal(config); + if (result == ESP_OK) { + esp_wifi_set_debug_log(); + } + return result; } void esp_deep_sleep_set_rf_option(uint8_t option) diff --git a/components/freertos/port/esp8266/include/freertos/FreeRTOSConfig.h b/components/freertos/port/esp8266/include/freertos/FreeRTOSConfig.h index beacd5d2..81396405 100644 --- a/components/freertos/port/esp8266/include/freertos/FreeRTOSConfig.h +++ b/components/freertos/port/esp8266/include/freertos/FreeRTOSConfig.h @@ -58,7 +58,11 @@ #define configCPU_CLOCK_HZ ( ( unsigned long ) 80000000 ) #define configTICK_RATE_HZ ( ( portTickType ) CONFIG_FREERTOS_HZ ) #define configMAX_PRIORITIES 15 +#if CONFIG_ESP8266_WIFI_DEBUG_LOG_ENABLE +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 2048 ) +#else #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 768 ) +#endif //#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 17 * 1024 ) ) #define configMAX_TASK_NAME_LEN ( 16 ) diff --git a/components/log/include/esp_log.h b/components/log/include/esp_log.h index 50fc3907..f5e214c8 100644 --- a/components/log/include/esp_log.h +++ b/components/log/include/esp_log.h @@ -78,6 +78,20 @@ void esp_log_level_set(const char* tag, esp_log_level_t level); */ putchar_like_t esp_log_set_putchar(putchar_like_t func); +/** + * @brief Function which returns timestamp to be used in log output + * + * This function is used in expansion of ESP_LOGx macros. + * In the 2nd stage bootloader, and at early application startup stage + * this function uses CPU cycle counter as time source. Later when + * FreeRTOS scheduler start running, it switches to FreeRTOS tick count. + * + * For now, we ignore millisecond counter overflow. + * + * @return timestamp, in milliseconds + */ +uint32_t esp_log_timestamp(void); + /** * @brief Function which returns timestamp to be used in log output * diff --git a/components/log/log.c b/components/log/log.c index 8f8cb3e9..6d039efc 100644 --- a/components/log/log.c +++ b/components/log/log.c @@ -190,7 +190,7 @@ static int esp_log_write_str(const char *s) return ret; } -static uint32_t esp_log_timestamp() +uint32_t esp_log_timestamp() { static uint32_t base = 0;