2020-10-30 04:07:50 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 17:12:04 +08:00
|
|
|
#include <zephyr/logging/log_backend.h>
|
|
|
|
#include <zephyr/logging/log_core.h>
|
|
|
|
#include <zephyr/logging/log_output.h>
|
|
|
|
#include <zephyr/logging/log_backend_std.h>
|
2020-10-30 04:07:50 +08:00
|
|
|
|
2022-04-06 03:40:55 +08:00
|
|
|
/*
|
|
|
|
* A lock is needed as log_process() and log_panic() have no internal locks
|
|
|
|
* to prevent concurrency. Meaning if log_process is called after
|
|
|
|
* log_panic was called previously, log_process may happen from another
|
|
|
|
* CPU and calling context than the log processing thread running in
|
|
|
|
* the background. On an SMP system this is a race.
|
|
|
|
*
|
|
|
|
* This caused a race on the output trace such that the logging output
|
|
|
|
* was garbled and useless.
|
|
|
|
*/
|
|
|
|
static struct k_spinlock lock;
|
|
|
|
|
2022-02-02 05:03:08 +08:00
|
|
|
static uint32_t log_format_current = CONFIG_LOG_BACKEND_ADSP_OUTPUT_DEFAULT;
|
2022-08-11 04:12:28 +08:00
|
|
|
void winstream_console_trace_out(int8_t *str, size_t len);
|
2020-10-30 04:07:50 +08:00
|
|
|
|
|
|
|
static int char_out(uint8_t *data, size_t length, void *ctx)
|
|
|
|
{
|
2022-08-11 04:12:28 +08:00
|
|
|
winstream_console_trace_out(data, length);
|
2020-10-30 04:07:50 +08:00
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2022-04-06 03:40:55 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 80 bytes seems to catch most sensibly sized log message lines
|
|
|
|
* in one go letting the trace out call output whole complete
|
|
|
|
* lines. This avoids the overhead of a spin lock in the trace_out
|
|
|
|
* more often as well as avoiding entwined characters from printk if
|
|
|
|
* LOG_PRINTK=n.
|
2020-10-30 04:07:50 +08:00
|
|
|
*/
|
2022-04-06 03:40:55 +08:00
|
|
|
#define LOG_BUF_SIZE 80
|
|
|
|
static uint8_t log_buf[LOG_BUF_SIZE];
|
2020-10-30 04:07:50 +08:00
|
|
|
|
2022-04-06 03:40:55 +08:00
|
|
|
LOG_OUTPUT_DEFINE(log_output_adsp, char_out, log_buf, sizeof(log_buf));
|
2020-10-30 04:07:50 +08:00
|
|
|
|
|
|
|
static uint32_t format_flags(void)
|
|
|
|
{
|
|
|
|
uint32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
|
|
|
|
flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
|
|
|
|
}
|
2022-04-20 01:38:52 +08:00
|
|
|
|
2020-10-30 04:07:50 +08:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void panic(struct log_backend const *const backend)
|
|
|
|
{
|
2022-04-06 03:40:55 +08:00
|
|
|
k_spinlock_key_t key = k_spin_lock(&lock);
|
|
|
|
|
2020-10-30 04:07:50 +08:00
|
|
|
log_backend_std_panic(&log_output_adsp);
|
2022-04-06 03:40:55 +08:00
|
|
|
|
|
|
|
k_spin_unlock(&lock, key);
|
2020-10-30 04:07:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void dropped(const struct log_backend *const backend,
|
|
|
|
uint32_t cnt)
|
|
|
|
{
|
|
|
|
log_output_dropped_process(&log_output_adsp, cnt);
|
|
|
|
}
|
|
|
|
|
2021-01-28 16:54:16 +08:00
|
|
|
static void process(const struct log_backend *const backend,
|
2022-06-21 17:51:38 +08:00
|
|
|
union log_msg_generic *msg)
|
2021-01-28 16:54:16 +08:00
|
|
|
{
|
2022-02-02 05:03:08 +08:00
|
|
|
log_format_func_t log_output_func = log_format_func_t_get(log_format_current);
|
|
|
|
|
2022-04-06 03:40:55 +08:00
|
|
|
k_spinlock_key_t key = k_spin_lock(&lock);
|
|
|
|
|
2022-02-02 05:03:08 +08:00
|
|
|
log_output_func(&log_output_adsp, &msg->log, format_flags());
|
2022-04-06 03:40:55 +08:00
|
|
|
|
|
|
|
k_spin_unlock(&lock, key);
|
2022-02-02 05:03:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int format_set(const struct log_backend *const backend, uint32_t log_type)
|
|
|
|
{
|
|
|
|
log_format_current = log_type;
|
|
|
|
return 0;
|
2021-01-28 16:54:16 +08:00
|
|
|
}
|
|
|
|
|
2020-10-30 04:07:50 +08:00
|
|
|
const struct log_backend_api log_backend_adsp_api = {
|
2022-06-13 22:40:59 +08:00
|
|
|
.process = process,
|
2022-01-12 22:52:48 +08:00
|
|
|
.dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped,
|
2020-10-30 04:07:50 +08:00
|
|
|
.panic = panic,
|
2022-06-13 22:40:59 +08:00
|
|
|
.format_set = format_set,
|
2020-10-30 04:07:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
LOG_BACKEND_DEFINE(log_backend_adsp, log_backend_adsp_api, true);
|