-
Notifications
You must be signed in to change notification settings - Fork 8.3k
logging: backend: added semihosting support #79013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mmahadevan108
merged 1 commit into
zephyrproject-rtos:main
from
arifbalik:log_backend_semihost
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Copyright (c) 2024 Contributors to the logging subsystem. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config LOG_BACKEND_SEMIHOST | ||
| bool "Semihost as backend" | ||
| depends on SEMIHOST | ||
| select LOG_OUTPUT | ||
| select LOG_BACKEND_SUPPORTS_FORMAT_TIMESTAMP | ||
| help | ||
| Enable backend in semihost (using host stdout) | ||
|
|
||
| if LOG_BACKEND_SEMIHOST | ||
|
|
||
| config LOG_BACKEND_SEMIHOST_BUFFER_SIZE | ||
| int "Size of reserved up-buffer for logger output." | ||
| default 256 | ||
| help | ||
| Specify reserved size of up-buffer used for logger output. | ||
|
|
||
| config LOG_BACKEND_SEMIHOST_AUTOSTART | ||
| bool "Autostart semihost backend" | ||
| default y | ||
| help | ||
| Enable semihost backend to start automatically. | ||
|
|
||
| backend = SEMIHOST | ||
| backend-str = semihost | ||
| source "subsys/logging/Kconfig.template.log_format_config" | ||
|
|
||
| endif # LOG_BACKEND_SEMIHOST |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* Copyright (c) 2024 Contributors to the logging subsystem. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #include <stdio.h> | ||
| #include <stddef.h> | ||
| #include <zephyr/logging/log_backend.h> | ||
| #include <zephyr/logging/log_backend_std.h> | ||
| #include <zephyr/logging/log_core.h> | ||
| #include <zephyr/logging/log_output.h> | ||
| #include <zephyr/arch/common/semihost.h> | ||
|
|
||
| static uint8_t buf[CONFIG_LOG_BACKEND_SEMIHOST_BUFFER_SIZE]; | ||
| static uint32_t log_format_current = CONFIG_LOG_BACKEND_SEMIHOST_OUTPUT_DEFAULT; | ||
|
|
||
| static int char_out(uint8_t *data, size_t length, void *ctx) | ||
| { | ||
| ARG_UNUSED(ctx); | ||
| #define SEMIHOST_STDOUT (1) | ||
| int ret = semihost_write(SEMIHOST_STDOUT, data, length); | ||
|
|
||
| if (ret) { | ||
| return ret; | ||
| } | ||
|
|
||
| return length; | ||
| } | ||
|
|
||
| LOG_OUTPUT_DEFINE(log_output_semihost, char_out, buf, sizeof(buf)); | ||
|
|
||
| static void panic(struct log_backend const *const backend) | ||
| { | ||
| ARG_UNUSED(backend); | ||
|
|
||
| log_output_flush(&log_output_semihost); | ||
| } | ||
|
|
||
| static void dropped(const struct log_backend *const backend, uint32_t cnt) | ||
| { | ||
| ARG_UNUSED(backend); | ||
|
|
||
| log_output_dropped_process(&log_output_semihost, cnt); | ||
| } | ||
|
|
||
| static void process(const struct log_backend *const backend, union log_msg_generic *msg) | ||
| { | ||
| ARG_UNUSED(backend); | ||
|
|
||
| uint32_t flags = log_backend_std_get_flags(); | ||
|
|
||
| log_format_func_t log_output_func = log_format_func_t_get(log_format_current); | ||
|
|
||
arifbalik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| log_output_func(&log_output_semihost, &msg->log, flags); | ||
| } | ||
|
|
||
| static int format_set(const struct log_backend *const backend, uint32_t log_type) | ||
| { | ||
| ARG_UNUSED(backend); | ||
|
|
||
| log_format_current = log_type; | ||
| return 0; | ||
| } | ||
|
|
||
| const struct log_backend_api log_backend_semihost_api = { | ||
| .process = process, | ||
| .panic = panic, | ||
| .dropped = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ? NULL : dropped, | ||
| .format_set = format_set, | ||
| }; | ||
|
|
||
| LOG_BACKEND_DEFINE(log_backend_semihost, log_backend_semihost_api, | ||
| IS_ENABLED(CONFIG_LOG_BACKEND_SEMIHOST_AUTOSTART)); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.