88#include <logging/log_core.h>
99#include <logging/log_msg.h>
1010#include <logging/log_output.h>
11+ #include <logging/log_output_dict.h>
1112#include <logging/log_backend_std.h>
1213#include <device.h>
1314#include <drivers/uart.h>
1415#include <sys/__assert.h>
1516
17+ /* Fixed size to avoid auto-added trailing '\0'.
18+ * Used if CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY_HEX.
19+ */
20+ static const char LOG_HEX_SEP [10 ] = "##ZLOGV1##" ;
21+
1622static const struct device * uart_dev ;
1723
1824static int char_out (uint8_t * data , size_t length , void * ctx )
1925{
2026 ARG_UNUSED (ctx );
2127
2228 for (size_t i = 0 ; i < length ; i ++ ) {
29+ #if defined(CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY_HEX )
30+ char c ;
31+ uint8_t x ;
32+
33+ /* upper 8-bit */
34+ x = data [i ] >> 4 ;
35+ (void )hex2char (x , & c );
36+ uart_poll_out (uart_dev , c );
37+
38+ /* lower 8-bit */
39+ x = data [i ] & 0x0FU ;
40+ (void )hex2char (x , & c );
41+ uart_poll_out (uart_dev , c );
42+ #else
2343 uart_poll_out (uart_dev , data [i ]);
44+ #endif
2445 }
2546
2647 return length ;
@@ -44,13 +65,29 @@ static void process(const struct log_backend *const backend,
4465{
4566 uint32_t flags = log_backend_std_get_flags ();
4667
47- log_output_msg2_process (& log_output_uart , & msg -> log , flags );
68+ if (IS_ENABLED (CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY )) {
69+ log_dict_output_msg2_process (& log_output_uart ,
70+ & msg -> log , flags );
71+ } else {
72+ log_output_msg2_process (& log_output_uart , & msg -> log , flags );
73+ }
4874}
4975
5076static void log_backend_uart_init (struct log_backend const * const backend )
5177{
5278 uart_dev = device_get_binding (CONFIG_UART_CONSOLE_ON_DEV_NAME );
5379 __ASSERT_NO_MSG ((void * )uart_dev );
80+
81+ if (IS_ENABLED (CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY_HEX )) {
82+ /* Print a separator so the output can be fed into
83+ * log parser directly. This is useful when capturing
84+ * from UART directly where there might be other output
85+ * (e.g. bootloader).
86+ */
87+ for (int i = 0 ; i < sizeof (LOG_HEX_SEP ); i ++ ) {
88+ uart_poll_out (uart_dev , LOG_HEX_SEP [i ]);
89+ }
90+ }
5491}
5592
5693static void panic (struct log_backend const * const backend )
@@ -62,7 +99,11 @@ static void dropped(const struct log_backend *const backend, uint32_t cnt)
6299{
63100 ARG_UNUSED (backend );
64101
65- log_backend_std_dropped (& log_output_uart , cnt );
102+ if (IS_ENABLED (CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY )) {
103+ log_dict_output_dropped_process (& log_output_uart , cnt );
104+ } else {
105+ log_backend_std_dropped (& log_output_uart , cnt );
106+ }
66107}
67108
68109static void sync_string (const struct log_backend * const backend ,
0 commit comments