logging: Add support to backends to switch log format at runtime.

Adding mechanism to all the backends to switch the logging formats
at runtime while leveraging the function pointer table based upon
the Kconfigs which also cleans up the logging backend design.
Also demonstrate the working API with the changes
to syst sample. Clean up Kconfig for backends and add a standard
template to generate the Kconfigs for logging formats to be used
by all backends.

Signed-off-by: Aastha Grover <aastha.grover@intel.com>
This commit is contained in:
Aastha Grover 2022-02-01 13:03:08 -08:00 committed by Maureen Helm
parent 9fcbace639
commit c0d7e10beb
13 changed files with 226 additions and 105 deletions

View file

@ -3,7 +3,7 @@ CONFIG_ASSERT=n
CONFIG_LOG_PRINTK=y
CONFIG_LOG_BACKEND_UART=y
CONFIG_LOG_MIPI_SYST_ENABLE=y
CONFIG_LOG_BACKEND_UART_SYST_ENABLE=y
CONFIG_LOG_BACKEND_UART_OUTPUT_SYST=y
CONFIG_SOC_LOG_LEVEL_OFF=y
CONFIG_ARCH_LOG_LEVEL_OFF=y
CONFIG_KERNEL_LOG_LEVEL_OFF=y

View file

@ -7,6 +7,8 @@
#include <zephyr.h>
#include <logging/log.h>
#include <sys/printk.h>
#include <logging/log_ctrl.h>
#include <logging/log_output.h>
#define DATA_MAX_DLEN 8
#define LOG_MODULE_NAME syst
@ -29,7 +31,7 @@ struct test_frame {
};
} __packed;
void main(void)
void log_msgs(void)
{
struct test_frame frame = { 0 };
const uint8_t data[DATA_MAX_DLEN] = { 0x01, 0x02, 0x03, 0x04,
@ -104,3 +106,23 @@ void main(void)
#endif
}
void main(void)
{
log_msgs();
#ifndef CONFIG_LOG1
uint32_t log_type = LOG_OUTPUT_TEXT;
log_backend_format_set(log_backend_get_by_name("log_backend_uart"), log_type);
log_msgs();
log_type = LOG_OUTPUT_SYST;
log_backend_format_set(log_backend_get_by_name("log_backend_uart"), log_type);
log_msgs();
#endif
}

View file

@ -17,45 +17,30 @@ config LOG_BACKEND_UART_ASYNC
depends on UART_ASYNC_API
depends on !LOG_BACKEND_UART_OUTPUT_DICTIONARY_HEX
config LOG_BACKEND_UART_OUTPUT_DICTIONARY
bool
depends on LOG2
select LOG_DICTIONARY_SUPPORT
help
UART backend is in dictionary-based logging output mode.
backend = UART
backend-str = uart
source "subsys/logging/Kconfig.template.log_format_config"
choice LOG_BACKEND_UART_OUTPUT
prompt "UART Backend Output Mode"
default LOG_BACKEND_UART_OUTPUT_TEXT
if LOG_BACKEND_UART_OUTPUT_DICTIONARY
config LOG_BACKEND_UART_OUTPUT_TEXT
bool "Text"
help
Output in text.
config LOG_BACKEND_UART_SYST_ENABLE
bool "MIPI SyS-T"
depends on LOG_BACKEND_UART
depends on LOG_MIPI_SYST_ENABLE
help
When enabled backend is using UART to output syst format logs.
config LOG_BACKEND_UART_OUTPUT_DICTIONARY_HEX
bool "Dictionary (hexadecimal)"
depends on LOG2
select LOG_BACKEND_UART_OUTPUT_DICTIONARY
help
Dictionary-based logging output in hexadecimal.
choice
prompt "Dictionary mode output format"
default LOG_BACKEND_UART_OUTPUT_DICTIONARY_BIN
config LOG_BACKEND_UART_OUTPUT_DICTIONARY_BIN
bool "Dictionary (binary)"
depends on LOG2
select LOG_BACKEND_UART_OUTPUT_DICTIONARY
help
Dictionary-based logging output in binary.
config LOG_BACKEND_UART_OUTPUT_DICTIONARY_HEX
bool "Dictionary (hexadecimal)"
help
Dictionary-based logging output in hexadecimal. Supported only for UART backend.
endchoice
endif # LOG_BACKEND_UART_OUTPUT_DICTIONARY
endif # LOG_BACKEND_UART
config LOG_BACKEND_SWO
@ -81,11 +66,9 @@ config LOG_BACKEND_SWO_FREQ_HZ
reset. To ensure flawless operation the frequency configured here and
by the SWO viewer program has to match.
config LOG_BACKEND_SWO_SYST_ENABLE
bool "Enable SWO syst backend"
depends on LOG_MIPI_SYST_ENABLE
help
When enabled backend is using SWO to output syst format logs.
backend = SWO
backend-str = swo
source "subsys/logging/Kconfig.template.log_format_config"
endif # LOG_BACKEND_SWO
@ -120,12 +103,6 @@ config LOG_BACKEND_RTT_MODE_BLOCK
help
Waits until there is enough space in the up-buffer for a message.
config LOG_BACKEND_RTT_SYST_ENABLE
bool "Enable RTT syst backend"
depends on LOG_MIPI_SYST_ENABLE
help
When enabled backend is using RTT to output syst format logs.
config LOG_BACKEND_RTT_MODE_OVERWRITE
bool "Overwrite messages if up-buffer full"
help
@ -134,6 +111,10 @@ config LOG_BACKEND_RTT_MODE_OVERWRITE
endchoice
backend = RTT
backend-str = rtt
source "subsys/logging/Kconfig.template.log_format_config"
config LOG_BACKEND_RTT_MESSAGE_SIZE
int "Size of internal buffer for storing messages."
range 32 256
@ -214,6 +195,10 @@ config LOG_BACKEND_SPINEL_BUFFER_SIZE
help
Specify reserved size of up-buffer used for logger output.
backend = SPINEL
backend-str = spinel
source "subsys/logging/Kconfig.template.log_format_config"
endif # LOG_BACKEND_SPINEL
config LOG_BACKEND_NATIVE_POSIX
@ -222,6 +207,14 @@ config LOG_BACKEND_NATIVE_POSIX
help
Enable backend in native_posix
if LOG_BACKEND_NATIVE_POSIX
backend = NATIVE_POSIX
backend-str = native_posix
source "subsys/logging/Kconfig.template.log_format_config"
endif # LOG_BACKEND_NATIVE_POSIX
config LOG_BACKEND_XTENSA_SIM
bool "Enable xtensa simulator backend"
depends on SOC_XTENSA_SAMPLE_CONTROLLER || SOC_FAMILY_INTEL_ADSP
@ -236,6 +229,14 @@ config LOG_BACKEND_XTENSA_OUTPUT_BUFFER_SIZE
Buffer is used by log_output module for preparing output data (e.g.
string formatting).
if LOG_BACKEND_XTENSA_SIM
backend = XTENSA_SIM
backend-str = xtensa_sim
source "subsys/logging/Kconfig.template.log_format_config"
endif # LOG_BACKEND_XTENSA_SIM
# Immediate mode cannot be used with network backend as it would cause the sent
# rsyslog message to be malformed.
config LOG_BACKEND_NET
@ -283,12 +284,6 @@ config LOG_BACKEND_NET_MAX_BUF_SIZE
IPv6 the size is 1180 octets. As each buffer will use RAM, the value
should be selected so that typical messages will fit the buffer.
config LOG_BACKEND_NET_SYST_ENABLE
bool "Enable networking syst backend"
depends on LOG_MIPI_SYST_ENABLE
help
When enabled backend is using networking to output syst format logs.
config LOG_BACKEND_NET_AUTOSTART
bool "Automatically start networking backend"
default y if NET_CONFIG_NEED_IPV4 || NET_CONFIG_NEED_IPV6
@ -299,6 +294,10 @@ config LOG_BACKEND_NET_AUTOSTART
started by the application later on. Otherwise the logging
thread might block.
backend = NET
backend-str = net
source "subsys/logging/Kconfig.template.log_format_config"
endif # LOG_BACKEND_NET
config LOG_BACKEND_ADSP
@ -308,6 +307,14 @@ config LOG_BACKEND_ADSP
Enable backend for the host trace protocol of the Intel ADSP
family of audio processors
if LOG_BACKEND_ADSP
backend = ADSP
backend-str = adsp
source "subsys/logging/Kconfig.template.log_format_config"
endif # LOG_BACKEND_ADSP
config LOG_BACKEND_FS
bool "Enable file system backend"
depends on FILE_SYSTEM
@ -319,30 +326,9 @@ config LOG_BACKEND_FS
if LOG_BACKEND_FS
config LOG_BACKEND_FS_OUTPUT_DICTIONARY
bool
depends on LOG2
select LOG_DICTIONARY_SUPPORT
help
FS backend is in dictionary-based logging output mode.
choice LOG_BACKEND_FS_OUTPUT
prompt "FS Backend Output Mode"
default LOG_BACKEND_FS_OUTPUT_TEXT
config LOG_BACKEND_FS_OUTPUT_TEXT
bool "Text"
help
Output in text.
config LOG_BACKEND_FS_OUTPUT_DICTIONARY_BIN
bool "Dictionary (binary)"
depends on LOG2
select LOG_BACKEND_FS_OUTPUT_DICTIONARY
help
Dictionary-based logging output in binary.
endchoice
backend = FS
backend-str = fs
source "subsys/logging/Kconfig.template.log_format_config"
config LOG_BACKEND_FS_OVERWRITE
bool "Enable old log files overwrite"

View file

@ -0,0 +1,37 @@
# Copyright (c) 2022 Intel Corporation.
# SPDX-License-Identifier: Apache-2.0
choice "LOG_BACKEND_$(backend)_OUTPUT"
prompt "Backend Output Mode"
default LOG_BACKEND_$(backend)_OUTPUT_TEXT
config LOG_BACKEND_$(backend)_OUTPUT_TEXT
bool "Text"
help
Output in text.
config LOG_BACKEND_$(backend)_OUTPUT_SYST
bool "MIPI SyS-T"
depends on LOG_MIPI_SYST_ENABLE
help
When enabled backend is used to output syst format logs.
config LOG_BACKEND_$(backend)_OUTPUT_DICTIONARY
bool "Dictionary"
depends on LOG2
select LOG_DICTIONARY_SUPPORT
help
Backend is in dictionary-based logging output mode.
endchoice
# The numbering of the format types should be consistent across
# all the backends in the Kconfig and their values must match
# LOG_OUTPUT_XXX type in C files.
# Example : LOG_BACKEND_XXX_OUTPUT_TEXT should be numbered 0 across all backends
# and should match the value of LOG_OUTPUT_TEXT defined in log_output.h
config LOG_BACKEND_$(backend)_OUTPUT_DEFAULT
int
default 0 if LOG_BACKEND_$(backend)_OUTPUT_TEXT
default 1 if LOG_BACKEND_$(backend)_OUTPUT_SYST
default 2 if LOG_BACKEND_$(backend)_OUTPUT_DICTIONARY

View file

@ -10,6 +10,7 @@
#include <logging/log_output.h>
#include <logging/log_backend_std.h>
static uint32_t log_format_current = CONFIG_LOG_BACKEND_ADSP_OUTPUT_DEFAULT;
void intel_adsp_trace_out(int8_t *str, size_t len);
static int char_out(uint8_t *data, size_t length, void *ctx)
@ -73,7 +74,15 @@ static inline void put_sync_hexdump(const struct log_backend *const backend,
static void process(const struct log_backend *const backend,
union log_msg2_generic *msg)
{
log_output_msg2_process(&log_output_adsp, &msg->log, format_flags());
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
log_output_func(&log_output_adsp, &msg->log, format_flags());
}
static int format_set(const struct log_backend *const backend, uint32_t log_type)
{
log_format_current = log_type;
return 0;
}
const struct log_backend_api log_backend_adsp_api = {
@ -85,6 +94,7 @@ const struct log_backend_api log_backend_adsp_api = {
.put = IS_ENABLED(CONFIG_LOG1_DEFERRED) ? put : NULL,
.dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped,
.panic = panic,
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
};
LOG_BACKEND_DEFINE(log_backend_adsp, log_backend_adsp_api, true);

View file

@ -31,6 +31,9 @@ static int file_ctr, newest, oldest;
static int allocate_new_file(struct fs_file_t *file);
static int del_oldest_log(void);
static int get_log_file_id(struct fs_dirent *ent);
#ifndef CONFIG_LOG_BACKEND_FS_TESTSUITE
static uint32_t log_format_current = CONFIG_LOG_BACKEND_FS_OUTPUT_DEFAULT;
#endif
static int check_log_volumen_available(void)
{
@ -465,12 +468,15 @@ static void process(const struct log_backend *const backend,
{
uint32_t flags = log_backend_std_get_flags();
if (IS_ENABLED(CONFIG_LOG_BACKEND_FS_OUTPUT_DICTIONARY)) {
log_dict_output_msg2_process(&log_output,
&msg->log, flags);
} else {
log_output_msg2_process(&log_output, &msg->log, flags);
}
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
log_output_func(&log_output, &msg->log, flags);
}
static int format_set(const struct log_backend *const backend, uint32_t log_type)
{
log_format_current = log_type;
return 0;
}
static const struct log_backend_api log_backend_fs_api = {
@ -481,6 +487,7 @@ static const struct log_backend_api log_backend_fs_api = {
.panic = panic,
.init = log_backend_fs_init,
.dropped = dropped,
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
};

View file

@ -18,6 +18,7 @@
#define _STDOUT_BUF_SIZE 256
static char stdout_buff[_STDOUT_BUF_SIZE];
static int n_pend; /* Number of pending characters in buffer */
static uint32_t log_format_current = CONFIG_LOG_BACKEND_NATIVE_POSIX_OUTPUT_DEFAULT;
static void preprint_char(int c)
{
@ -140,7 +141,15 @@ static void process(const struct log_backend *const backend,
{
uint32_t flags = log_backend_std_get_flags();
log_output_msg2_process(&log_output_posix, &msg->log, flags);
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
log_output_func(&log_output_posix, &msg->log, flags);
}
static int format_set(const struct log_backend *const backend, uint32_t log_type)
{
log_format_current = log_type;
return 0;
}
const struct log_backend_api log_backend_native_posix_api = {
@ -152,6 +161,7 @@ const struct log_backend_api log_backend_native_posix_api = {
sync_hexdump : NULL,
.panic = panic,
.dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped,
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
};
LOG_BACKEND_DEFINE(log_backend_native_posix,

View file

@ -35,6 +35,7 @@ static uint8_t output_buf[CONFIG_LOG_BACKEND_NET_MAX_BUF_SIZE];
static bool net_init_done;
struct sockaddr server_addr;
static bool panic_mode;
static uint32_t log_format_current = CONFIG_LOG_BACKEND_NET_OUTPUT_DEFAULT;
const struct log_backend *log_backend_net_get(void);
@ -188,7 +189,7 @@ static void send_output(const struct log_backend *const backend,
log_output_msg_process(&log_output_net, msg,
LOG_OUTPUT_FLAG_FORMAT_SYSLOG |
LOG_OUTPUT_FLAG_TIMESTAMP |
(IS_ENABLED(CONFIG_LOG_BACKEND_NET_SYST_ENABLE) ?
(IS_ENABLED(CONFIG_LOG_BACKEND_NET_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0));
log_msg_put(msg);
@ -207,7 +208,15 @@ static void process(const struct log_backend *const backend,
net_init_done = true;
}
log_output_msg2_process(&log_output_net, &msg->log, flags);
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
log_output_func(&log_output_net, &msg->log, flags);
}
static int format_set(const struct log_backend *const backend, uint32_t log_type)
{
log_format_current = log_type;
return 0;
}
static void init_net(struct log_backend const *const backend)
@ -239,7 +248,7 @@ static void sync_string(const struct log_backend *const backend,
{
uint32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_FORMAT_SYSLOG |
LOG_OUTPUT_FLAG_TIMESTAMP |
(IS_ENABLED(CONFIG_LOG_BACKEND_NET_SYST_ENABLE) ?
(IS_ENABLED(CONFIG_LOG_BACKEND_NET_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0);
uint32_t key;
@ -265,6 +274,7 @@ const struct log_backend_api log_backend_net_api = {
* this can be revisited if needed.
*/
.put_sync_hexdump = NULL,
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
};
/* Note that the backend can be activated only after we have networking

View file

@ -72,6 +72,7 @@ static int data_out_drop_mode(uint8_t *data, size_t length, void *ctx);
static int char_out_drop_mode(uint8_t data);
static int line_out_drop_mode(void);
static uint32_t log_format_current = CONFIG_LOG_BACKEND_RTT_OUTPUT_DEFAULT;
static inline bool is_sync_mode(void)
{
@ -257,7 +258,7 @@ LOG_OUTPUT_DEFINE(log_output_rtt,
static void put(const struct log_backend *const backend,
struct log_msg *msg)
{
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_SYST_ENABLE) ?
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_backend_std_put(&log_output_rtt, flag, msg);
@ -297,7 +298,7 @@ static void sync_string(const struct log_backend *const backend,
struct log_msg_ids src_level, uint32_t timestamp,
const char *fmt, va_list ap)
{
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_SYST_ENABLE) ?
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_backend_std_sync_string(&log_output_rtt, flag, src_level,
@ -308,7 +309,7 @@ static void sync_hexdump(const struct log_backend *const backend,
struct log_msg_ids src_level, uint32_t timestamp,
const char *metadata, const uint8_t *data, uint32_t length)
{
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_SYST_ENABLE) ?
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_RTT_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_backend_std_sync_hexdump(&log_output_rtt, flag, src_level,
@ -320,9 +321,15 @@ static void process(const struct log_backend *const backend,
{
uint32_t flags = log_backend_std_get_flags();
flags |= IS_ENABLED(CONFIG_LOG_BACKEND_RTT_SYST_ENABLE) ? LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
log_output_msg2_process(&log_output_rtt, &msg->log, flags);
log_output_func(&log_output_rtt, &msg->log, flags);
}
static int format_set(const struct log_backend *const backend, uint32_t log_type)
{
log_format_current = log_type;
return 0;
}
const struct log_backend_api log_backend_rtt_api = {
@ -335,6 +342,7 @@ const struct log_backend_api log_backend_rtt_api = {
.panic = panic,
.init = log_backend_rtt_init,
.dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped,
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
};
LOG_BACKEND_DEFINE(log_backend_rtt, log_backend_rtt_api, true);

View file

@ -18,6 +18,7 @@
static uint8_t char_buf[CONFIG_LOG_BACKEND_SPINEL_BUFFER_SIZE];
static bool panic_mode;
static uint16_t last_log_level;
static uint32_t log_format_current = CONFIG_LOG_BACKEND_SPINEL_OUTPUT_DEFAULT;
static int write(uint8_t *data, size_t length, void *ctx);
@ -45,7 +46,15 @@ static void process(const struct log_backend *const backend,
/* prevent adding CRLF, which may crash spinel decoding */
uint32_t flags = LOG_OUTPUT_FLAG_CRLF_NONE | log_backend_std_get_flags();
log_output_msg2_process(&log_output_spinel, &msg->log, flags);
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
log_output_func(&log_output_spinel, &msg->log, flags);
}
static int format_set(const struct log_backend *const backend, uint32_t log_type)
{
log_format_current = log_type;
return 0;
}
static void sync_string(const struct log_backend *const backend,
@ -136,6 +145,7 @@ const struct log_backend_api log_backend_spinel_api = {
.panic = panic,
.init = log_backend_spinel_init,
.dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped,
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
};
LOG_BACKEND_DEFINE(log_backend_spinel, log_backend_spinel_api, true);

View file

@ -59,6 +59,7 @@
#endif
static uint8_t buf[1];
static uint32_t log_format_current = CONFIG_LOG_BACKEND_SWO_OUTPUT_DEFAULT;
static int char_out(uint8_t *data, size_t length, void *ctx)
{
@ -76,7 +77,7 @@ LOG_OUTPUT_DEFINE(log_output_swo, char_out, buf, sizeof(buf));
static void log_backend_swo_put(const struct log_backend *const backend,
struct log_msg *msg)
{
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_SWO_SYST_ENABLE) ?
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_SWO_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_backend_std_put(&log_output_swo, flag, msg);
@ -87,9 +88,15 @@ static void log_backend_swo_process(const struct log_backend *const backend,
{
uint32_t flags = log_backend_std_get_flags();
flags |= IS_ENABLED(CONFIG_LOG_BACKEND_SWO_SYST_ENABLE) ? LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
log_output_msg2_process(&log_output_swo, &msg->log, flags);
log_output_func(&log_output_swo, &msg->log, flags);
}
static int format_set(const struct log_backend *const backend, uint32_t log_type)
{
log_format_current = log_type;
return 0;
}
static void log_backend_swo_init(struct log_backend const *const backend)
@ -134,7 +141,7 @@ static void log_backend_swo_sync_string(const struct log_backend *const backend,
struct log_msg_ids src_level, uint32_t timestamp,
const char *fmt, va_list ap)
{
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_SWO_SYST_ENABLE) ?
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_SWO_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_backend_std_sync_string(&log_output_swo, flag, src_level,
@ -146,7 +153,7 @@ static void log_backend_swo_sync_hexdump(
struct log_msg_ids src_level, uint32_t timestamp,
const char *metadata, const uint8_t *data, uint32_t length)
{
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_SWO_SYST_ENABLE) ?
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_SWO_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_backend_std_sync_hexdump(&log_output_swo, flag, src_level,
@ -163,6 +170,7 @@ const struct log_backend_api log_backend_swo_api = {
.panic = log_backend_swo_panic,
.init = log_backend_swo_init,
.dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped,
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
};
LOG_BACKEND_DEFINE(log_backend_swo, log_backend_swo_api, true);

View file

@ -25,6 +25,7 @@ static const struct device *uart_dev;
static struct k_sem sem;
static volatile bool in_panic;
static bool use_async;
static uint32_t log_format_current = CONFIG_LOG_BACKEND_UART_OUTPUT_DEFAULT;
static void uart_callback(const struct device *dev,
struct uart_event *evt,
@ -92,7 +93,7 @@ LOG_OUTPUT_DEFINE(log_output_uart, char_out, uart_output_buf, sizeof(uart_output
static void put(const struct log_backend *const backend,
struct log_msg *msg)
{
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_UART_SYST_ENABLE) ?
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_UART_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_backend_std_put(&log_output_uart, flag, msg);
@ -103,14 +104,15 @@ static void process(const struct log_backend *const backend,
{
uint32_t flags = log_backend_std_get_flags();
flags |= IS_ENABLED(CONFIG_LOG_BACKEND_UART_SYST_ENABLE) ? LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
if (IS_ENABLED(CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY)) {
log_dict_output_msg2_process(&log_output_uart,
&msg->log, flags);
} else {
log_output_msg2_process(&log_output_uart, &msg->log, flags);
}
log_output_func(&log_output_uart, &msg->log, flags);
}
static int format_set(const struct log_backend *const backend, uint32_t log_type)
{
log_format_current = log_type;
return 0;
}
static void log_backend_uart_init(struct log_backend const *const backend)
@ -165,7 +167,7 @@ static void sync_string(const struct log_backend *const backend,
struct log_msg_ids src_level, uint32_t timestamp,
const char *fmt, va_list ap)
{
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_UART_SYST_ENABLE) ?
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_UART_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_backend_std_sync_string(&log_output_uart, flag, src_level,
@ -176,7 +178,7 @@ static void sync_hexdump(const struct log_backend *const backend,
struct log_msg_ids src_level, uint32_t timestamp,
const char *metadata, const uint8_t *data, uint32_t length)
{
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_UART_SYST_ENABLE) ?
uint32_t flag = IS_ENABLED(CONFIG_LOG_BACKEND_UART_OUTPUT_SYST) ?
LOG_OUTPUT_FLAG_FORMAT_SYST : 0;
log_backend_std_sync_hexdump(&log_output_uart, flag, src_level,
@ -193,6 +195,7 @@ const struct log_backend_api log_backend_uart_api = {
.panic = panic,
.init = log_backend_uart_init,
.dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped,
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
};
LOG_BACKEND_DEFINE(log_backend_uart, log_backend_uart_api, true);

View file

@ -19,6 +19,7 @@
1 : CONFIG_LOG_BACKEND_XTENSA_OUTPUT_BUFFER_SIZE)
static uint8_t xtensa_log_buf[CHAR_BUF_SIZE];
static uint32_t log_format_current = CONFIG_LOG_BACKEND_XTENSA_SIM_OUTPUT_DEFAULT;
static int char_out(uint8_t *data, size_t length, void *ctx)
{
@ -49,7 +50,15 @@ static void process(const struct log_backend *const backend,
{
uint32_t flags = log_backend_std_get_flags();
log_output_msg2_process(&log_output_xsim, &msg->log, flags);
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
log_output_func(&log_output_xsim, &msg->log, flags);
}
static int format_set(const struct log_backend *const backend, uint32_t log_type)
{
log_format_current = log_type;
return 0;
}
static void panic(struct log_backend const *const backend)
@ -89,6 +98,7 @@ const struct log_backend_api log_backend_xtensa_sim_api = {
sync_hexdump : NULL,
.panic = panic,
.dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped,
.format_set = IS_ENABLED(CONFIG_LOG1) ? NULL : format_set,
};
LOG_BACKEND_DEFINE(log_backend_xtensa_sim, log_backend_xtensa_sim_api, true);