|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Default log sink implementation. More...
#include "ra8_log.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_scb.h"#include "ra8_err.h"Go to the source code of this file.
Data Structures | |
| struct | ra8_err_name_entry_t |
| Single (code, name) pair in the ra8_err_to_str() lookup table. More... | |
Enumerations | |
| enum | ra8_itm_addr_t : uintptr_t { k_ra8_itm_stim_base = 0xE0000000UL , k_ra8_itm_tcr_addr = 0xE0000E80UL , k_ra8_itm_tenr_addr = 0xE0000E00UL } |
| enum | ra8_log_u32_t : uint8_t { k_ra8_u32_max_digits = 10U , k_ra8_decimal_base = 10U } |
| Emit an unsigned decimal integer over ITM port 0. More... | |
Functions | |
| void | ra8_log_set_byte_sink (ra8_log_byte_sink_fn_t fn, void *ctx) |
| Install (or clear) an optional byte sink for log output. | |
| static volatile uint32_t * | internal_itm_stim0 (void) |
| Get the ITM stimulus-port-0 register. | |
| static volatile uint32_t * | internal_itm_tcr (void) |
| Get the ITM Trace Control Register. | |
| static volatile uint32_t * | internal_itm_tenr (void) |
| Get the ITM Trace Enable Register. | |
| static bool | internal_itm_ready (void) |
| Check whether ITM port 0 is enabled and ready to accept bytes. | |
| static void | internal_itm_putc (uint8_t byte) |
| Blocking-but-bounded write of a single byte to ITM port 0. | |
| static void | internal_itm_puts (const char *s) |
| Emit a NUL-terminated string over ITM port 0. | |
| static void | internal_itm_put_u32 (uint32_t value) |
| static void | internal_itm_put_i32 (int32_t value) |
| Emit a signed decimal integer over ITM port 0. | |
| void | ra8_log_init (void) |
| Default log backend init – no-op for the ITM sink. | |
| static void | internal_emit_line (const char *level, const char *tag, const char *msg) |
| Common tagged-line emit helper. | |
| static void | internal_emit_line_u (const char *level, const char *tag, const char *msg, uint32_t value) |
| Common tagged-line-with-value emit helper (unsigned). | |
| static void | internal_emit_line_i (const char *level, const char *tag, const char *msg, int32_t value) |
| Common tagged-line-with-value emit helper (signed). | |
| void | ra8_log_emit_error (const char *tag, const char *message) |
| Emit an ERROR-level log line with only a tag and a message. | |
| void | ra8_log_emit_warn (const char *tag, const char *message) |
| Emit a WARN-level log line with only a tag and a message. | |
| void | ra8_log_emit_info (const char *tag, const char *message) |
| Emit an INFO-level log line with only a tag and a message. | |
| void | ra8_log_emit_debug (const char *tag, const char *message) |
| Emit a DEBUG-level log line with only a tag and a message. | |
| void | ra8_log_emit_error_val (const char *tag, const char *message, uint32_t value) |
| ERROR-level log emitter that also reports a uint32 value. | |
| void | ra8_log_emit_warn_val (const char *tag, const char *message, uint32_t value) |
| WARN-level log emitter that also reports a uint32 value. | |
| void | ra8_log_emit_info_val (const char *tag, const char *message, uint32_t value) |
| INFO-level log emitter that also reports a uint32 value. | |
| void | ra8_log_emit_debug_val (const char *tag, const char *message, int32_t value) |
| DEBUG-level log emitter that also reports a signed int32 value. | |
| const char * | ra8_err_to_str (ra8_err_t err) |
| Implementation of ra8_err_to_str() – linear-scan lookup. | |
Variables | |
| static ra8_log_byte_sink_fn_t | s_byte_sink = nullptr |
| Active log byte sink, or nullptr to use the default ITM port. | |
| static void * | s_byte_sink_ctx = nullptr |
| Opaque cookie passed back to s_byte_sink on every byte. | |
| static const ra8_err_name_entry_t | s_ra8_err_names [] |
| Lookup table backing ra8_err_to_str(). | |
| static const uint32_t | s_ra8_err_names_count |
| Number of entries in s_ra8_err_names. | |
Default log sink implementation.
Minimal log backend for the bare-metal bring-up phase. Every log function is a weak symbol that writes a single line to the ARM Cortex-M85 ITM (Instrumented Trace Macrocell) stimulus port 0. With an attached J-Link the output shows up in SWV Console (e2 studio), JLinkRTTViewer, or JLinkSWOViewer without any extra wiring.
Why ITM:
A UART-backed log sink for boards without a J-Link can be plugged in later by overriding the ra8_log_emit_* functions with non-weak definitions elsewhere in the project.
Definition in file ra8_log.c.
| enum ra8_itm_addr_t : uintptr_t |
| enum ra8_log_u32_t : uint8_t |
Emit an unsigned decimal integer over ITM port 0.
Hand-rolled itoa for uint32_t. Avoids snprintf (which would drag in vararg + nano stdio).
| [in] | value | Value to emit. |
| None |
| Enumerator | |
|---|---|
| k_ra8_u32_max_digits | Max decimal digits in a uint32_t. |
| k_ra8_decimal_base | Decimal radix. |
|
static |
Common tagged-line emit helper.
Writes [tag] level: msg\r\n. Bails out early if the ITM backend is not ready.
| [in] | level | String like "ERROR" or "INFO". Must be non-NULL. |
| [in] | tag | Component tag. Must be non-NULL. |
| [in] | msg | Free-form message. Must be non-NULL. |
Definition at line 405 of file ra8_log.c.
References internal_itm_putc(), internal_itm_puts(), internal_itm_ready(), and RA8_INTERNAL.
Referenced by ra8_log_emit_debug(), ra8_log_emit_error(), ra8_log_emit_info(), and ra8_log_emit_warn().
|
static |
Common tagged-line-with-value emit helper (signed).
Writes [tag] level: msg=<signed-decimal>\r\n.
| [in] | level | String like "DEBUG". Must be non-NULL. |
| [in] | tag | Component tag. Must be non-NULL. |
| [in] | msg | Free-form message. Must be non-NULL. |
| [in] | value | Signed numeric companion value. |
Definition at line 481 of file ra8_log.c.
References internal_itm_put_i32(), internal_itm_putc(), internal_itm_puts(), and internal_itm_ready().
Referenced by ra8_log_emit_debug_val().
|
static |
Common tagged-line-with-value emit helper (unsigned).
Writes [tag] level: msg=<decimal>\r\n.
| [in] | level | String like "ERROR". Must be non-NULL. |
| [in] | tag | Component tag. Must be non-NULL. |
| [in] | msg | Free-form message. Must be non-NULL. |
| [in] | value | Unsigned numeric companion value. |
Definition at line 442 of file ra8_log.c.
References internal_itm_put_u32(), internal_itm_putc(), internal_itm_puts(), and internal_itm_ready().
Referenced by ra8_log_emit_error_val(), ra8_log_emit_info_val(), and ra8_log_emit_warn_val().
|
inlinestatic |
Emit a signed decimal integer over ITM port 0.
Emits a leading - for negative values then forwards to internal_itm_put_u32. Negation goes through int64_t to avoid signed-overflow UB at INT32_MIN.
| [in] | value | Value to emit. |
Definition at line 348 of file ra8_log.c.
References internal_itm_put_u32(), internal_itm_putc(), and RA8_INTERNAL.
Referenced by internal_emit_line_i().
|
inlinestatic |
Definition at line 310 of file ra8_log.c.
References internal_itm_putc(), k_ra8_decimal_base, k_ra8_u32_max_digits, and RA8_INTERNAL.
Referenced by internal_emit_line_u(), and internal_itm_put_i32().
|
inlinestatic |
Blocking-but-bounded write of a single byte to ITM port 0.
An installed byte sink takes the byte and the function returns. Otherwise, on target, polls the FIFO-ready bit up to k_ra8_itm_poll_limit times, then either writes the byte or gives up silently. Hosted (RA8_OFF_TARGET) builds compile that ITM fallback out entirely and drop the byte, so no host build holds a reference to a target MMIO address.
| [in] | byte | Character to emit. |
< RA8 itm poll limit.
Definition at line 229 of file ra8_log.c.
References internal_itm_stim0(), k_ra8_itm_stim_base, RA8_INTERNAL, s_byte_sink, and s_byte_sink_ctx.
Referenced by internal_emit_line(), internal_emit_line_i(), internal_emit_line_u(), internal_itm_put_i32(), internal_itm_put_u32(), and internal_itm_puts().
|
inlinestatic |
Emit a NUL-terminated string over ITM port 0.
Walks s and forwards each byte through internal_itm_putc.
| [in] | s | String to emit (must be non-NULL). |
Definition at line 277 of file ra8_log.c.
References internal_itm_putc(), and RA8_INTERNAL.
Referenced by internal_emit_line(), internal_emit_line_i(), and internal_emit_line_u().
|
inlinestatic |
Check whether ITM port 0 is enabled and ready to accept bytes.
Reads TCR, TENR, and the STIM0 FIFO register directly on target. Hosted builds use only an explicitly injected byte sink and otherwise report the backend unavailable, so a test never dereferences target-only addresses.
| true | ITMENA, port-0 enable, and FIFO-ready bits all set. |
| false | Any of the above is clear. |
Definition at line 162 of file ra8_log.c.
References internal_itm_stim0(), internal_itm_tcr(), internal_itm_tenr(), RA8_INTERNAL, ra8_scb_trace_enabled(), and s_byte_sink.
Referenced by internal_emit_line(), internal_emit_line_i(), and internal_emit_line_u().
|
inlinestatic |
Get the ITM stimulus-port-0 register.
Trivial address-cast helper. Always inlined.
| (volatile | uint32_t*)k_ra8_itm_stim_base |
Definition at line 91 of file ra8_log.c.
References k_ra8_itm_stim_base, RA8_HW_REGISTER_ACCESS, and RA8_INTERNAL.
Referenced by internal_itm_putc(), and internal_itm_ready().
|
inlinestatic |
Get the ITM Trace Control Register.
Trivial address-cast helper for the ITM TCR.
| (volatile | uint32_t*)k_ra8_itm_tcr_addr |
Definition at line 113 of file ra8_log.c.
References k_ra8_itm_tcr_addr, RA8_HW_REGISTER_ACCESS, and RA8_INTERNAL.
Referenced by internal_itm_ready().
|
inlinestatic |
Get the ITM Trace Enable Register.
Trivial address-cast helper for the ITM TENR.
| (volatile | uint32_t*)k_ra8_itm_tenr_addr |
Definition at line 135 of file ra8_log.c.
References k_ra8_itm_tenr_addr, RA8_HW_REGISTER_ACCESS, and RA8_INTERNAL.
Referenced by internal_itm_ready().
| const char * ra8_err_to_str | ( | ra8_err_t | err | ) |
Implementation of ra8_err_to_str() – linear-scan lookup.
Human-readable string for an error code.
Walks s_ra8_err_names and returns the matching name. Returns the literal "unknown" if no entry matches.
| [in] | err | Error code to look up. |
| ok | Returned for k_ra8_ok. |
| <name> | Returned for any known k_ra8_err_* code. |
| unknown | Returned for any code not in the table. |
Definition at line 737 of file ra8_log.c.
References s_ra8_err_names, and s_ra8_err_names_count.
Referenced by c6_cam_camera_report_last_error(), c6_fwver_phase_caps(), c6_fwver_phase_request(), c6_fwver_worker_entry(), c6_hosted_worker_entry(), c6_join_phase_ip(), c6_join_phase_ready(), c6_join_report_fault(), c6_join_worker_entry(), c6_wifi_phase_ready(), c6_wifi_report_fault(), c6_wifi_worker_entry(), internal_c6_cam_http_frame(), internal_c6_cam_join(), internal_c6_cam_prepare_camera(), internal_c6_cam_prepare_link(), internal_c6_cam_prepare_media(), internal_c6_cam_report_fault(), internal_c6_cam_worker_entry(), internal_fail(), internal_report_sccb_state(), sensor_report_register(), wifi_hal_report(), wifi_hal_run(), and wifi_hal_worker_entry().
| void ra8_log_emit_debug | ( | const char * | tag, |
| const char * | message ) |
Emit a DEBUG-level log line with only a tag and a message.
Backend entry point for the ra8_log_debug() macro.
| [in] | tag | Short component tag; must not be NULL. |
| [in] | message | Free-form ASCII message; must not be NULL. |
Definition at line 517 of file ra8_log.c.
References internal_emit_line().
| void ra8_log_emit_debug_val | ( | const char * | tag, |
| const char * | message, | ||
| int32_t | value ) |
DEBUG-level log emitter that also reports a signed int32 value.
Emit a DEBUG log line with an int32_t companion value.
Weak default backend. Forwards to internal_emit_line_i with the fixed level string "DEBUG".
| [in] | tag | NUL-terminated module tag. |
| [in] | message | NUL-terminated short event description. |
| [in] | value | int32 datum appended as "=NNN" (sign preserved). |
Definition at line 595 of file ra8_log.c.
References internal_emit_line_i().
| void ra8_log_emit_error | ( | const char * | tag, |
| const char * | message ) |
Emit an ERROR-level log line with only a tag and a message.
Backend entry point for the ra8_log_error() macro.
| [in] | tag | Short component tag; must not be NULL. |
| [in] | message | Free-form ASCII message; must not be NULL. |
| void ra8_log_emit_error_val | ( | const char * | tag, |
| const char * | message, | ||
| uint32_t | value ) |
ERROR-level log emitter that also reports a uint32 value.
Emit an ERROR log line with a uint32_t companion value.
Weak default backend. Forwards to internal_emit_line_u with the fixed level string "ERROR".
| [in] | tag | NUL-terminated module tag (e.g. "ra8_log"). |
| [in] | message | NUL-terminated short event description. |
| [in] | value | uint32 datum appended as "=NNN" to the line. |
| void ra8_log_emit_info | ( | const char * | tag, |
| const char * | message ) |
Emit an INFO-level log line with only a tag and a message.
Backend entry point for the ra8_log_info() macro.
| [in] | tag | Short component tag; must not be NULL. |
| [in] | message | Free-form ASCII message; must not be NULL. |
Definition at line 512 of file ra8_log.c.
References internal_emit_line().
| void ra8_log_emit_info_val | ( | const char * | tag, |
| const char * | message, | ||
| uint32_t | value ) |
INFO-level log emitter that also reports a uint32 value.
Emit an INFO log line with a uint32_t companion value.
Weak default backend. Forwards to internal_emit_line_u with the fixed level string "INFO".
| [in] | tag | NUL-terminated module tag. |
| [in] | message | NUL-terminated short event description. |
| [in] | value | uint32 datum appended as "=NNN" to the line. |
Definition at line 576 of file ra8_log.c.
References internal_emit_line_u().
| void ra8_log_emit_warn | ( | const char * | tag, |
| const char * | message ) |
Emit a WARN-level log line with only a tag and a message.
Backend entry point for the ra8_log_warn() macro.
| [in] | tag | Short component tag; must not be NULL. |
| [in] | message | Free-form ASCII message; must not be NULL. |
Definition at line 507 of file ra8_log.c.
References internal_emit_line().
| void ra8_log_emit_warn_val | ( | const char * | tag, |
| const char * | message, | ||
| uint32_t | value ) |
WARN-level log emitter that also reports a uint32 value.
Emit a WARN log line with a uint32_t companion value.
Weak default backend. Forwards to internal_emit_line_u with the fixed level string "WARN".
| [in] | tag | NUL-terminated module tag. |
| [in] | message | NUL-terminated short event description. |
| [in] | value | uint32 datum appended as "=NNN" to the line. |
Definition at line 557 of file ra8_log.c.
References internal_emit_line_u().
| void ra8_log_init | ( | void | ) |
Default log backend init – no-op for the ITM sink.
Initialise the logging backend.
ITM is enabled by the debugger when it attaches; the firmware does not need to programme any control registers.
Definition at line 379 of file ra8_log.c.
Referenced by internal_output_init(), main(), and ra8_infrastructure_init().
| void ra8_log_set_byte_sink | ( | ra8_log_byte_sink_fn_t | fn, |
| void * | ctx ) |
Install (or clear) an optional byte sink for log output.
Pass a non-NULL fn to redirect all subsequent log bytes to fn; pass NULL to restore the default ITM backend. Off by default, so existing behaviour is unchanged until a sink is installed.
| [in] | fn | Byte sink callback, or NULL to restore the ITM default. |
| [in] | ctx | Opaque cookie passed back to fn (may be NULL). |
Definition at line 56 of file ra8_log.c.
References s_byte_sink, and s_byte_sink_ctx.
Referenced by internal_output_init(), main(), main(), ra8_io_log_attach(), ra8_io_log_detach(), and ra8_nsc_periph_init().
|
static |
Active log byte sink, or nullptr to use the default ITM port.
Definition at line 47 of file ra8_log.c.
Referenced by internal_itm_putc(), internal_itm_ready(), and ra8_log_set_byte_sink().
|
static |
Opaque cookie passed back to s_byte_sink on every byte.
Definition at line 54 of file ra8_log.c.
Referenced by internal_itm_putc(), and ra8_log_set_byte_sink().
|
static |
Lookup table backing ra8_err_to_str().
One row per k_ra8_err_* value defined in ra8_err.h. The table lives in .rodata (static const) and is scanned linearly by ra8_err_to_str(). Adding a new error code is a one-line addition here – no switch arm to update.
Definition at line 648 of file ra8_log.c.
Referenced by ra8_err_to_str().
|
static |
Number of entries in s_ra8_err_names.
Computed at compile time from sizeof so the table and loop bound stay in sync.
Definition at line 712 of file ra8_log.c.
Referenced by ra8_err_to_str().