55 */
66#include <log.h>
77
8+ #if defined(STUB_LOG_ENABLED )
9+
810#include <stdint.h>
911#include <stdarg.h>
1012#include <stddef.h>
@@ -18,30 +20,27 @@ extern void ets_printf(const char *fmt, ...);
1820extern void ets_install_putc1 (void (* p )(char c ));
1921extern void ets_install_putc2 (void (* p )(char c ));
2022
21- static enum stub_lib_log_destination s_log_dest = STUB_LIB_LOG_DEST_BUF ;
22-
23- static struct stub_lib_log_buf g_stub_lib_log_buf ;
24-
25- static void log_buf_write (char c )
23+ #if defined(STUB_LIB_LOG_BUF )
24+ struct stub_lib_log_buf g_stub_lib_log_buf ;
25+ static void stub_lib_log_buf_write_internal (char c )
2626{
2727 g_stub_lib_log_buf .buf [g_stub_lib_log_buf .count ] = c ;
2828 g_stub_lib_log_buf .count = (g_stub_lib_log_buf .count + 1 ) & (STUB_LIB_LOG_BUF_SIZE - 1 );
2929}
30+ #endif // defined(STUB_LIB_LOG_BUF)
3031
31- void stub_lib_log_init (enum stub_lib_log_destination dest )
32+ void stub_lib_log_init ()
3233{
33- if (dest == STUB_LIB_LOG_DEST_UART ) {
34- stub_target_uart_init (0 , 115200 );
35- //fixme: call ets_install_putc1(0)/putc2(0) here?
36- ets_install_uart_printf ();
37- s_log_dest = STUB_LIB_LOG_DEST_UART ;
38- } else if (dest == STUB_LIB_LOG_DEST_BUF ) {
39- ets_install_putc1 (log_buf_write );
40- ets_install_putc2 (NULL );
41- s_log_dest = STUB_LIB_LOG_DEST_BUF ;
42- } else {
43- s_log_dest = STUB_LIB_LOG_DEST_NONE ;
44- }
34+ #if defined(STUB_LIB_LOG_UART )
35+ stub_target_uart_init (0 , 115200 );
36+ //fixme: call ets_install_putc1(0)/putc2(0) here?
37+ ets_install_uart_printf ();
38+ #elif defined(STUB_LIB_LOG_BUF )
39+ ets_install_putc1 (stub_lib_log_buf_write_internal );
40+ ets_install_putc2 (NULL );
41+ #else
42+ #error "STUB_LIB_LOG_X destination should be defined"
43+ #endif
4544}
4645
4746// This function is designed to avoid implementing vprintf() to reduce code size.
@@ -99,3 +98,5 @@ void stub_lib_log_printf(const char *fmt, ...)
9998 }
10099 va_end (args );
101100}
101+
102+ #endif // defined(STUB_LOG_ENABLED)
0 commit comments