Skip to content

Commit

Permalink
Merge pull request #12998 from gschorcht/cpu/esp/common_sdk_log_output
Browse files Browse the repository at this point in the history
cpu/esp: cleanup of ESP SDK log outputs
  • Loading branch information
benpicco authored Jan 15, 2020
2 parents da703b9 + 53139c0 commit 3672502
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 277 deletions.
1 change: 1 addition & 0 deletions cpu/esp32/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ PSEUDOMODULES += esp_wifi_any

export TARGET_ARCH ?= xtensa-esp32-elf

USEMODULE += esp_common
USEMODULE += esp_idf
USEMODULE += esp_idf_driver
USEMODULE += esp_idf_esp32
Expand Down
61 changes: 54 additions & 7 deletions cpu/esp32/esp-wifi/esp_wifi_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
DEBUG("[esp_wifi] %s: " f "\n", __func__, ## __VA_ARGS__)

#define ESP_WIFI_LOG_INFO(f, ...) \
LOG_INFO("[esp_wifi] " f "\n", ## __VA_ARGS__)
LOG_TAG_INFO("esp_wifi", f "\n", ## __VA_ARGS__)

#define ESP_WIFI_LOG_ERROR(f, ...) \
LOG_ERROR("[esp_wifi] " f "\n", ## __VA_ARGS__)
LOG_TAG_ERROR("esp_wifi", f "\n", ## __VA_ARGS__)

#define MAC_STR "%02x:%02x:%02x:%02x:%02x:%02x"
#define MAC_STR_ARG(m) m[0], m[1], m[2], m[3], m[4], m[5]
Expand Down Expand Up @@ -171,13 +171,52 @@ esp_err_t _esp_wifi_rx_cb(void *buffer, uint16_t len, void *eb)
return ESP_OK;
}

#define REASON_BEACON_TIMEOUT (200)
#define REASON_HANDSHAKE_TIMEOUT (204)
#define INDEX_BEACON_TIMEOUT (REASON_BEACON_TIMEOUT - 24)

static const char *_esp_wifi_disc_reasons [] = {
"INVALID", /* 0 */
"UNSPECIFIED", /* 1 */
"AUTH_EXPIRE", /* 2 */
"AUTH_LEAVE", /* 3 */
"ASSOC_EXPIRE", /* 4 */
"ASSOC_TOOMANY", /* 5 */
"NOT_AUTHED", /* 6 */
"NOT_ASSOCED", /* 7 */
"ASSOC_LEAVE", /* 8 */
"ASSOC_NOT_AUTHED", /* 9 */
"DISASSOC_PWRCAP_BAD", /* 10 (11h) */
"DISASSOC_SUPCHAN_BAD", /* 11 (11h) */
"IE_INVALID", /* 13 (11i) */
"MIC_FAILURE", /* 14 (11i) */
"4WAY_HANDSHAKE_TIMEOUT", /* 15 (11i) */
"GROUP_KEY_UPDATE_TIMEOUT", /* 16 (11i) */
"IE_IN_4WAY_DIFFERS", /* 17 (11i) */
"GROUP_CIPHER_INVALID", /* 18 (11i) */
"PAIRWISE_CIPHER_INVALID", /* 19 (11i) */
"AKMP_INVALID", /* 20 (11i) */
"UNSUPP_RSN_IE_VERSION", /* 21 (11i) */
"INVALID_RSN_IE_CAP", /* 22 (11i) */
"802_1X_AUTH_FAILED", /* 23 (11i) */
"CIPHER_SUITE_REJECTED", /* 24 (11i) */
"BEACON_TIMEOUT", /* 200 */
"NO_AP_FOUND", /* 201 */
"AUTH_FAIL", /* 202 */
"ASSOC_FAIL", /* 203 */
"HANDSHAKE_TIMEOUT" /* 204 */
};

/*
* Event handler for esp system events.
*/
static esp_err_t IRAM_ATTR _esp_system_event_handler(void *ctx, system_event_t *event)
{
esp_err_t result;

uint8_t reason;
const char* reason_str = "UNKNOWN";

switch(event->event_id) {
case SYSTEM_EVENT_STA_START:
ESP_WIFI_DEBUG("WiFi started");
Expand All @@ -193,8 +232,9 @@ static esp_err_t IRAM_ATTR _esp_system_event_handler(void *ctx, system_event_t *
break;

case SYSTEM_EVENT_STA_CONNECTED:
ESP_WIFI_DEBUG("WiFi connected to ssid %s",
event->event_info.connected.ssid);
ESP_WIFI_LOG_INFO("WiFi connected to ssid %s, channel %d",
event->event_info.connected.ssid,
event->event_info.connected.channel);

/* register RX callback function */
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, _esp_wifi_rx_cb);
Expand All @@ -206,9 +246,16 @@ static esp_err_t IRAM_ATTR _esp_system_event_handler(void *ctx, system_event_t *
break;

case SYSTEM_EVENT_STA_DISCONNECTED:
ESP_WIFI_DEBUG("WiFi disconnected from ssid %s, reason %d",
event->event_info.disconnected.ssid,
event->event_info.disconnected.reason);
reason = event->event_info.disconnected.reason;
if (reason < REASON_BEACON_TIMEOUT) {
reason_str = _esp_wifi_disc_reasons[reason];
}
else if (reason <= REASON_HANDSHAKE_TIMEOUT) {
reason_str = _esp_wifi_disc_reasons[reason - INDEX_BEACON_TIMEOUT];
}
ESP_WIFI_LOG_INFO("Wifi disconnected from ssid %s, reason %d (%s)",
event->event_info.disconnected.ssid,
event->event_info.disconnected.reason, reason_str);

/* unregister RX callback function */
esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, NULL);
Expand Down
1 change: 1 addition & 0 deletions cpu/esp32/include/esp_common_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ extern int ets_printf(const char *fmt, ...);
#define LOG_TAG_WARNING(tag, format, ...) LOG_TAG(LOG_WARNING, W, tag, format, ##__VA_ARGS__)
#define LOG_TAG_INFO(tag, format, ...) LOG_TAG(LOG_INFO , I, tag, format, ##__VA_ARGS__)
#define LOG_TAG_DEBUG(tag, format, ...) LOG_TAG(LOG_DEBUG , D, tag, format, ##__VA_ARGS__)
#define LOG_TAG_ALL(tag, format, ...) LOG_TAG(LOG_ALL , V, tag, format, ##__VA_ARGS__)

/** definitions for source code compatibility with ESP-IDF */
#define ESP_EARLY_LOGE(tag, format, ...) LOG_TAG_EARLY(LOG_ERROR , E, tag, format "\n", ##__VA_ARGS__)
Expand Down
7 changes: 6 additions & 1 deletion cpu/esp32/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "driver/periph_ctrl.h"
#include "esp/common_macros.h"
#include "heap/esp_heap_caps_init.h"
#include "log/esp_log.h"
#include "rom/cache.h"
#include "rom/ets_sys.h"
#include "rom/rtc.h"
Expand Down Expand Up @@ -177,7 +178,7 @@ NORETURN void IRAM call_start_cpu0 (void)
#ifdef MODULE_ESP_IDF_HEAP
/* init heap */
heap_caps_init();
#ifdef ENABLE_DEBUG
#if ENABLE_DEBUG
ets_printf("Heap free: %u byte\n", get_free_heap_size());
#endif /* ENABLE_DEBUG */
#endif /* MODULE_ESP_IDF_HEAP */
Expand Down Expand Up @@ -294,6 +295,10 @@ static NORETURN void IRAM system_init (void)
extern void __libc_init_array(void);
__libc_init_array();

/* set log levels for SDK library outputs */
extern void esp_log_level_set(const char* tag, esp_log_level_t level);
esp_log_level_set("wifi", LOG_DEBUG);

/* init watchdogs */
system_wdt_init();

Expand Down
Loading

0 comments on commit 3672502

Please sign in to comment.