ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_console.c File Reference

Multi-channel console log store implementation (see board_console.h). More...

#include "board_console.h"
#include <stdint.h>
#include "ra8_attributes.h"
Include dependency graph for board_console.c:

Go to the source code of this file.

Data Structures

struct  console_ring_t
 One channel's scrollback ring. More...

Functions

const char * board_console_name (board_console_ch_t ch)
 Short display name for a channel (the tab caption).
static void internal_slot_copy (char *dst, const char *src)
 Copy a bounded, NUL-terminated string into a ring slot.
static void internal_ring_push (console_ring_t *ring, const char *line)
 Append one already-formed line to a single ring.
static void internal_format_all_line (board_console_ch_t ch, const char *line, char *out)
 Build the "<NAME> <line>" form an ALL-ring entry stores.
void board_console_push (board_console_ch_t ch, const char *line)
 Append one completed line to a channel ring and the ALL ring.
uint32_t board_console_count (board_console_ch_t ch)
 Count of lines currently retained in a channel ring.
uint32_t board_console_total (board_console_ch_t ch)
 Monotonic count of lines ever pushed to a channel.
const char * board_console_line (board_console_ch_t ch, uint32_t back)
 Fetch a retained line by age (0 = newest) from a channel.
void board_console_reset (void)
 Clear every channel ring (called on a warm reboot).

Variables

static console_ring_t s_rings [k_board_console_ch_count]
 One ring per channel, including the aggregate ALL ring at index 0.
static const char *const s_k_channel_names [k_board_console_ch_count]
 Tab captions, indexed by board_console_ch_t (also the ALL prefix).

Detailed Description

Multi-channel console log store implementation (see board_console.h).

One fixed-capacity ring per channel plus an aggregate ALL ring. A source lane (UART / ITM / ...) receives a line verbatim via board_console_push, which also mirrors a "<NAME> <line>" prefixed copy into the ALL ring so the aggregate view labels each line's origin. All storage is static (no malloc after init); a back-index walk converts an age (0 = newest) to a ring slot the same way the SCI scrollback ring did before this store subsumed it.

Since
0.1.0

Definition in file board_console.c.

Function Documentation

◆ board_console_count()

uint32_t board_console_count ( board_console_ch_t ch)

Count of lines currently retained in a channel ring.

Saturates at k_board_console_ring_depth once the ring wraps. This is the number of valid back-indices for board_console_line on ch.

Parameters
[in]chChannel to query.
Returns
Lines held (0 .. k_board_console_ring_depth).
Return values
0ch is out of range or no line has been pushed yet.
Precondition
ch is a board_console_ch_t value.
The store has been zero-initialised (static lifetime guarantees it).
Postcondition
The store is left unchanged (pure query).
The result never exceeds k_board_console_ring_depth.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 207 of file board_console.c.

References k_board_console_ch_count, and s_rings.

Referenced by internal_fill_console_tabs(), and internal_fill_status_console().

◆ board_console_line()

const char * board_console_line ( board_console_ch_t ch,
uint32_t back )

Fetch a retained line by age (0 = newest) from a channel.

back counts backwards from the newest retained line: 0 is the most recent, 1 the one before it, up to board_console_count - 1. Older lines have aged out of the ring.

Parameters
[in]chChannel to read.
[in]backAge index (0 = newest).
Returns
Borrowed NUL-terminated line text, or NULL if back is too old.
Return values
NULLch out of range, or back >= board_console_count.
Precondition
ch is a board_console_ch_t value.
The returned pointer is used before the next board_console_push.
Postcondition
The store is left unchanged (pure query).
A non-NULL result points into the channel's static ring storage.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 223 of file board_console.c.

References console_ring_t::count, console_ring_t::head, k_board_console_ch_count, k_board_console_ring_depth, console_ring_t::lines, and s_rings.

Referenced by internal_fill_status_console(), and internal_run_stop_banner().

◆ board_console_name()

const char * board_console_name ( board_console_ch_t ch)

Short display name for a channel (the tab caption).

Returns a borrowed static string ("ALL" / "UART" / "ITM" / ...). The same names prefix each line in the ALL ring so the aggregate view stays legible, and the board view draws them as the tab captions.

Parameters
[in]chChannel to name (k_board_console_ch_all .. count-1).
Returns
Borrowed NUL-terminated name, or "?" if ch is out of range.
Return values
?ch is >= k_board_console_ch_count.
Precondition
ch is a board_console_ch_t value.
The returned pointer is read-only and outlives the call (static storage).
Postcondition
The returned pointer is never NULL.
The store is left unchanged (pure query).
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 66 of file board_console.c.

References k_board_console_ch_count, and s_k_channel_names.

Referenced by internal_fill_console_tabs(), and internal_format_all_line().

◆ board_console_push()

void board_console_push ( board_console_ch_t ch,
const char * line )

Append one completed line to a channel ring and the ALL ring.

Copies line (bounded to k_board_console_line_cap, NUL-terminated) into the channel ch ring, then copies a "<NAME> <line>" prefixed form into the ALL ring so the aggregate view shows which endpoint each line came from. Calling with k_board_console_ch_all is rejected (ALL is populated only as the mirror of the source lanes, never directly).

Parameters
[in]chSource lane (must not be k_board_console_ch_all).
[in]lineCompleted line text (no trailing newline); copied, not retained.
Returns
Nothing.
Precondition
ch is a source lane in (k_board_console_ch_all, k_board_console_ch_count).
line is a valid NUL-terminated string.
Postcondition
On a valid call the channel ring and the ALL ring each gain one line.
Invalid ch / NULL line leave every ring unchanged.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 190 of file board_console.c.

References internal_format_all_line(), internal_ring_push(), k_board_console_ch_all, k_board_console_ch_count, k_board_console_line_cap, and s_rings.

Referenced by board_net_on_tx(), board_net_poll_rx(), internal_adc_convert_group(), internal_board_sd_begin_write(), internal_board_sd_stage_block(), internal_canfd_console_frame(), internal_ceu_do_capture(), internal_dac_write(), internal_dmac_run_transfer(), internal_dtc_run_transfer(), internal_eth_tx_kick_queue(), internal_i3c_close_transfer(), internal_npu_console_job(), internal_on_itm_stim_write(), internal_pdm_console_maybe(), internal_port_trace_leds(), internal_riic_close_transfer(), internal_rtt_line_feed(), internal_sci_capture_tx_line(), internal_sdhi_begin_read(), internal_sdhi_begin_write(), internal_spi_report(), internal_ssie_report(), internal_xspi_do_program(), internal_xspi_do_read(), and priv_usb_log_line().

◆ board_console_reset()

void board_console_reset ( void )

Clear every channel ring (called on a warm reboot).

Zeroes the head / count / total bookkeeping for all channels so a rebooted firmware starts with an empty console, matching the peripheral models' reset hooks. The line storage itself is left as-is (count gates all reads).

Returns
Nothing.
Precondition
Called from the single-threaded reset path (no concurrent push).
The store has been zero-initialised at least once (static lifetime).
Postcondition
Every channel reports board_console_count and board_console_total 0.
Subsequent board_console_line calls return NULL until a new push.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 238 of file board_console.c.

References k_board_console_ch_count, and s_rings.

Referenced by warm_reboot().

◆ board_console_total()

uint32_t board_console_total ( board_console_ch_t ch)

Monotonic count of lines ever pushed to a channel.

Unlike board_console_count (which caps at the ring depth) this keeps climbing, so the view can detect new arrivals while paused and hold its absolute scroll position.

Parameters
[in]chChannel to query.
Returns
Total lines ever pushed to ch since the last reset.
Return values
0ch is out of range or nothing has been pushed.
Precondition
ch is a board_console_ch_t value.
The store has been zero-initialised (static lifetime guarantees it).
Postcondition
The store is left unchanged (pure query).
The result is monotonic non-decreasing between resets.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 215 of file board_console.c.

References k_board_console_ch_count, and s_rings.

Referenced by emu_view_select_console_tab(), internal_fill_status_console(), and route_click().

◆ internal_format_all_line()

void internal_format_all_line ( board_console_ch_t ch,
const char * line,
char * out )
static

Build the "<NAME> <line>" form an ALL-ring entry stores.

Prefixes line with the source channel's name and a space so the aggregate view labels each line's origin, truncating to the slot capacity.

Parameters
[in]chSource channel whose name prefixes the line.
[in]lineSource line text (may be NULL -> name only).
[out]outDestination buffer (k_board_console_line_cap bytes).
Returns
Nothing.
Precondition
out points at a k_board_console_line_cap-byte buffer.
ch is a source lane with a valid board_console_name.
Postcondition
out is NUL-terminated within its capacity.
out begins with the channel name followed by a space.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 159 of file board_console.c.

References board_console_name(), and k_board_console_line_cap.

Referenced by board_console_push().

◆ internal_ring_push()

void internal_ring_push ( console_ring_t * ring,
const char * line )
static

Append one already-formed line to a single ring.

Copies line into the head slot, advances head modulo the ring depth, saturates count at the depth, and bumps the monotonic total.

Parameters
[in,out]ringRing to push into.
[in]lineLine text to copy (bounded; may be NULL -> empty).
Returns
Nothing.
Precondition
ring is a valid console_ring_t with head < ring depth.
ring has space for the copy (a ring is never full – it overwrites).
Postcondition
ring gains one line; count <= k_board_console_ring_depth.
total increased by one.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 125 of file board_console.c.

References console_ring_t::count, console_ring_t::head, internal_slot_copy(), k_board_console_ring_depth, console_ring_t::lines, RA8_INTERNAL, and console_ring_t::total.

Referenced by board_console_push().

◆ internal_slot_copy()

void internal_slot_copy ( char * dst,
const char * src )
static

Copy a bounded, NUL-terminated string into a ring slot.

Writes at most k_board_console_line_cap - 1 chars from src into dst then NUL-terminates, so an over-length line is truncated rather than overrunning the slot. A NULL src yields an empty string.

Parameters
[out]dstDestination ring slot (k_board_console_line_cap bytes).
[in]srcSource text (may be NULL).
Returns
Nothing.
Precondition
dst points at a k_board_console_line_cap-byte buffer.
The copy is bounded by k_board_console_line_cap (no overrun possible).
Postcondition
dst is NUL-terminated within its capacity.
At most k_board_console_line_cap - 1 source chars are copied.
Note
Not thread-safe; ra8_emulator is single-threaded.
Since
0.1.0

Definition at line 91 of file board_console.c.

References k_board_console_line_cap, and RA8_INTERNAL.

Referenced by internal_ring_push().

Variable Documentation

◆ s_k_channel_names

const char* const s_k_channel_names[k_board_console_ch_count]
static
Initial value:
= {
"ALL",
"UART",
"ITM",
"RTT",
"SPI",
"I2C",
"CAN",
"USB",
"SD",
"OSPI",
"I2S",
"ADC",
"DAC",
"GPIO",
"DMA",
"NET",
}

Tab captions, indexed by board_console_ch_t (also the ALL prefix).

Definition at line 47 of file board_console.c.

Referenced by board_console_name().

◆ s_rings

One ring per channel, including the aggregate ALL ring at index 0.

Definition at line 44 of file board_console.c.

Referenced by board_console_count(), board_console_line(), board_console_push(), board_console_reset(), and board_console_total().