|
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 OR MIT |
5 | 5 | */ |
6 | | -#include <stdint.h> |
| 6 | +#include <log.h> |
| 7 | + |
| 8 | +#if defined(STUB_LOG_ENABLED) |
| 9 | + |
7 | 10 | #include <stdarg.h> |
| 11 | +extern void ets_printf(const char *fmt, ...); |
8 | 12 |
|
9 | | -#include <target/esp_rom_caps.h> |
| 13 | +#if defined(STUB_LIB_LOG_UART) |
10 | 14 | #include <target/uart.h> |
11 | | - |
12 | | -// These functions are defined in the ROM |
13 | 15 | extern void ets_install_uart_printf(void); |
14 | | -extern void ets_printf(const char *fmt, ...); |
| 16 | +#elif defined(STUB_LIB_LOG_BUF) |
| 17 | +#include <stddef.h> |
| 18 | +extern void ets_install_putc1(void (*p)(char c)); |
| 19 | +extern void ets_install_putc2(void (*p)(char c)); |
| 20 | +#endif // defined(STUB_LIB_LOG_BUF) |
15 | 21 |
|
16 | | -void stub_lib_log_init(uint8_t uart_num, uint32_t baudrate) |
| 22 | +#if defined(STUB_LIB_LOG_BUF) |
| 23 | +static struct stub_lib_log_buf g_stub_lib_log_buf; |
| 24 | +static void stub_lib_log_buf_write_internal(char c) |
17 | 25 | { |
18 | | - stub_target_uart_init(uart_num, baudrate); |
| 26 | + g_stub_lib_log_buf.buf[g_stub_lib_log_buf.count] = c; |
| 27 | + g_stub_lib_log_buf.count = (g_stub_lib_log_buf.count + 1) % STUB_LIB_LOG_BUF_SIZE; |
| 28 | +} |
| 29 | +#endif // defined(STUB_LIB_LOG_BUF) |
| 30 | + |
| 31 | +void stub_lib_log_init() |
| 32 | +{ |
| 33 | +#if defined(STUB_LIB_LOG_UART) |
| 34 | + stub_target_uart_init(0, 115200); |
19 | 35 | ets_install_uart_printf(); |
| 36 | +#elif defined(STUB_LIB_LOG_BUF) |
| 37 | + ets_install_putc1(stub_lib_log_buf_write_internal); |
| 38 | + ets_install_putc2(NULL); |
| 39 | +#endif |
20 | 40 | } |
21 | 41 |
|
22 | 42 | // This function is designed to avoid implementing vprintf() to reduce code size. |
@@ -74,3 +94,5 @@ void stub_lib_log_printf(const char *fmt, ...) |
74 | 94 | } |
75 | 95 | va_end(args); |
76 | 96 | } |
| 97 | + |
| 98 | +#endif // defined(STUB_LOG_ENABLED) |
0 commit comments