diff options
author | Rob Barnes <robbarnes@google.com> | 2022-09-12 15:06:42 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-15 16:22:45 +0000 |
commit | 6bff94908b4cda15d31baa2e152d76fe45b08ca1 (patch) | |
tree | c79d058ebcc0a36260817443f4ecd95e7416a2db /zephyr/shim/src/log_backend_console_buffer.c | |
parent | db3db9e9cb9c2ccbc18b7ecef88700c3c735ad0f (diff) | |
download | chrome-ec-stabilize-15120.B-main.tar.gz |
zephyr/console: Add console buffer logging backendstabilize-15120.B-main
Add a zephyr logging backend for the console buffer. This allows the AP
to access the logs sent to the zephyr logging subsystem.
This backend will not run in LOG_MODE_MINIMAL, so it may not be usable
for some EC OS projects.
BUG=b:243709788
BRANCH=None
TEST='ectool console' on Skyrim in immediate and deferred logging mode.
Signed-off-by: Rob Barnes <robbarnes@google.com>
Change-Id: I24d9ffeb5c90c99982c70ac2bcbdc0f814b45b01
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3853303
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr/shim/src/log_backend_console_buffer.c')
-rw-r--r-- | zephyr/shim/src/log_backend_console_buffer.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/zephyr/shim/src/log_backend_console_buffer.c b/zephyr/shim/src/log_backend_console_buffer.c new file mode 100644 index 0000000000..cafb690b87 --- /dev/null +++ b/zephyr/shim/src/log_backend_console_buffer.c @@ -0,0 +1,56 @@ +/* Copyright 2022 The ChromiumOS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/logging/log_backend.h> +#include <zephyr/logging/log_output.h> +#include <zephyr/logging/log_backend_std.h> + +#include "console.h" + +static uint8_t + char_out_buf[CONFIG_PLATFORM_EC_LOG_BACKEND_CONSOLE_BUFFER_TMP_BUF_SIZE]; + +static int char_out(uint8_t *data, size_t length, void *ctx) +{ + /* + * console_buf_notify_chars uses a mutex, which may not be + * locked in ISRs. + */ + if (k_is_in_isr()) + return 0; + return console_buf_notify_chars(data, length); +} +LOG_OUTPUT_DEFINE(log_output_console_buffer, char_out, char_out_buf, + sizeof(char_out_buf)); + +static void process(const struct log_backend *const backend, + union log_msg_generic *msg) +{ + uint32_t flags = log_backend_std_get_flags(); + log_format_func_t log_output_func = + log_format_func_t_get(LOG_OUTPUT_TEXT); + log_output_func(&log_output_console_buffer, &msg->log, flags); +} + +static void panic(struct log_backend const *const backend) +{ + log_backend_std_panic(&log_output_console_buffer); +} + +static void dropped(const struct log_backend *const backend, uint32_t cnt) +{ + log_backend_std_dropped(&log_output_console_buffer, cnt); +} + +const struct log_backend_api log_backend_console_buffer_api = { + .process = process, + .panic = panic, + .dropped = IS_ENABLED(CONFIG_LOG_MODE_DEFERRED) ? dropped : NULL, + /* TODO(b/244170593): Support switching output formats */ + .format_set = NULL, +}; + +LOG_BACKEND_DEFINE(log_backend_console_buffer, log_backend_console_buffer_api, + true); |