1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/cpu/esp_common/lib_printf.c

103 lines
2.7 KiB
C
Raw Normal View History

/*
* Copyright (C) 2019 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_esp_common
* @{
*
* @file
* @brief printf functions for SDK libraries
*
* @author Gunar Schorcht <gunar@schorcht.net>
*
* This file contains library-specific printf functions used by ESP SDK
* libraries. These functions are used to intercept the output generated
* by the SDK libraries and redirect it to RIOT's LOG macros.
*
* @}
*/
#include <stdarg.h>
#include "cpu_conf.h"
#include "esp_common_log.h"
#define LIB_PRINTF(name, level, tag) \
int name ## _printf(const char *format, ...) { \
va_list arg; \
va_start(arg, format); \
int res = _lib_printf(level, tag, format, arg); \
va_end(arg); \
return res; \
}
static char _printf_buf[PRINTF_BUFSIZ];
static int _lib_printf(int level, const char* tag, const char* format, va_list arg)
{
if (level > LOG_LEVEL) {
return 0;
}
int len = vsnprintf(_printf_buf, PRINTF_BUFSIZ - 1, format, arg);
2024-04-18 17:18:01 +02:00
if (len < 0) {
ESP_EARLY_LOGI(tag, "Failed to format print");
return 0;
}
/* Did the output get truncated? */
if ((unsigned) len > PRINTF_BUFSIZ - 1) {
len = PRINTF_BUFSIZ - 1;
}
/*
* Since ESP_EARLY_LOG macros add a line break at the end, a terminating
* line break in the output must be removed if there is one.
*/
_printf_buf[PRINTF_BUFSIZ - 1] = 0;
int i;
for (i = len - 1; i >= 0; --i) {
if (_printf_buf[i] != '\n' && _printf_buf[i] != '\r' && _printf_buf[i] != ' ') {
break;
}
_printf_buf[i] = 0;
}
if (i > 0) {
ESP_EARLY_LOGI(tag, "%s", _printf_buf);
}
va_end(arg);
return len;
}
LIB_PRINTF(coexist, LOG_DEBUG, "coexist")
LIB_PRINTF(core, LOG_DEBUG, "core")
LIB_PRINTF(espnow, LOG_DEBUG, "espnow")
LIB_PRINTF(net80211, LOG_DEBUG, "net80211")
LIB_PRINTF(phy, LOG_DEBUG, "phy")
LIB_PRINTF(pp, LOG_DEBUG, "pp")
LIB_PRINTF(sc, LOG_DEBUG, "smartconfig")
esp8266: Download Espressif RTOS SDK as a new RIOT PKG RIOT-OS uses part of Espressif ESP8266 RTOS SDK to build support for this CPU. The SDK includes some vendor-provided closed source pre-compiled libraries that we need to modify to adapt to RIOT-OS usage. This library modifications was done once and uploaded to a fork of the vendor repository and was provided as an environment variable. This patch changes two things: 1. It installs the SDK as a RIOT PKG from the new pkg/esp8266_sdk directory instead of requiring the user to download it separately. 2. It performs the library modifications (symbol renames) on the pkg Makefile removing the need to use a fork with the modifications applied and simplifying the SDK update and future modifications. This change sets the SDK package version (git SHA) to the same one that our fork was using as a parent in the vendor repository, meaning that the output libraries are exactly the same as before. Tested with ``` ESP8266_RTOS_SDK_DIR=/dev/null USEMODULE=esp_log_startup make -C tests/shell BOARD=esp8266-esp-12x flash ``` and verified that the program works. The boot message now includes: ``` ESP8266-RTOS-SDK Version v3.1-51-g913a06a9 ``` confirming the SDK version used. `/dev/null` in the test is just to make sure that no evaluation of `ESP8266_RTOS_SDK_DIR` in make is affected by the environment variable value which would be set to the SDK for people who followed the set up instructions before this change. Tested the checkout size: ```bash $ du -hs build/pkg/esp8266_sdk/ 124M build/pkg/esp8266_sdk/ ```
2021-05-01 15:39:25 +02:00
/* The ESP8266 SDK uses smartconfig_printf but the ESP32 one uses sc_printf. */
int smartconfig_printf(const char *format, ...)
__attribute__((alias("sc_printf")));
LIB_PRINTF(ssc, LOG_DEBUG, "ssc")
LIB_PRINTF(wpa, LOG_DEBUG, "wpa")
LIB_PRINTF(wpa2, LOG_DEBUG, "wpa")
LIB_PRINTF(wps, LOG_DEBUG, "wps")
LIB_PRINTF(core_ets, LOG_DEBUG, "core")
LIB_PRINTF(espnow_ets, LOG_DEBUG, "espnow")
LIB_PRINTF(pp_ets, LOG_DEBUG, "pp")
LIB_PRINTF(wpa_ets, LOG_DEBUG, "wpa")
int rtc_printf(const char* format, ...)
{
/* librtc.a printf temporary disabled due to UART baud rate switching bug. */
return 0;
}