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

EK-RA8D2 BSP – bind the debug console into an ra8_io byte stream. More...

#include "ra8_board_ek_ra8d2_console_stream.h"
#include <stdint.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_board_ek_ra8d2_internal.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_io_stream.h"
#include "ra8_io_stream_uart.h"
Include dependency graph for ra8_board_ek_ra8d2_console_stream.c:

Go to the source code of this file.

Functions

ra8_err_t ra8_board_console_stream (ra8_io_stream_t *out)
 Bind the J-Link OB VCOM console into a caller-owned stream handle.

Variables

static const char *const s_tag = "ra8_board.console_stream"
 Module log tag.
static ra8_io_stream_uart_state_t s_console_sink = {}
 Sink state backing every stream handle bound to the board console.

Detailed Description

EK-RA8D2 BSP – bind the debug console into an ra8_io byte stream.

Tag
[Ring 5 / BSP] {World: S}

The whole translation unit is the board half of one question: which SCI channel is the console, and has it been brought up? ra8_io_stream_uart already knows how to write bytes at a channel by polling, so this unit adds no second copy of that – it answers the board question and forwards.

Compiled into an application only when that application declares ra8_io in its LIBS (see cmake/ra8_app/sources.cmake); it is the one BSP unit that reaches outside the libraries every app already links.

Touches no MCU registers: ra8_io_stream_uart -> ra8_sci owns the HUM citations for the transmit path.

Since
0.1.0

Definition in file ra8_board_ek_ra8d2_console_stream.c.

Function Documentation

◆ ra8_board_console_stream()

ra8_err_t ra8_board_console_stream ( ra8_io_stream_t * out)
nodiscard

Bind the J-Link OB VCOM console into a caller-owned stream handle.

Hands back an ra8_io_stream_t whose sink is the board's debug console, so every ra8_io_stream_* writer lands on the same UART that ra8_board_uart_console_write() drives. The board supplies the two facts the application would otherwise have to know: that the console is SCI channel k_ra8_board_uart_console_sci_channel, and that ra8_board_uart_console_init() has already routed PD02 / PD03 and programmed the bit-rate register for the live PCLKA.

The sink state lives in this module (the console is a board singleton, so there is exactly one), which is why the caller supplies only the handle. Binding twice is harmless and yields two handles onto the same console.

Parameters
[out]outCaller-owned stream handle to bind; zero-initialise (= {}) before the call. On success it writes to the console.
Returns
ra8_err_t Error code.
Return values
k_ra8_okout is bound and usable.
k_ra8_err_null_ptrout was null.
k_ra8_err_not_initializedra8_board_uart_console_init() has not succeeded, so there is no console to bind.
Precondition
ra8_board_uart_console_init() returned k_ra8_ok.
out out-lives every write made through it.
Postcondition
On success out carries a sink aimed at the board console.
On any non-ok return out is left exactly as the caller passed it.
Note
Not thread-safe with respect to the console; one writer at a time.
Warning
Bytes written through the returned stream reach the SCI channel directly. Interleaving them with ra8_board_uart_console_write() from an interrupt would interleave on the wire.
See also
ra8_board_uart_console_init Brings the console up; call it first.
ra8_io_stream_puts One of the writers this unlocks.
Since
0.1.0

Definition at line 59 of file ra8_board_ek_ra8d2_console_stream.c.

References k_ra8_board_uart_console_sci_channel, k_ra8_err_not_initialized, priv_ra8_board_uart_console_is_up(), RA8_CHECK_NULL_PTR, ra8_io_stream_uart_init(), s_console_sink, and s_tag.

Referenced by internal_demo_setup_or_halt().

Variable Documentation

◆ s_console_sink

ra8_io_stream_uart_state_t s_console_sink = {}
static

Sink state backing every stream handle bound to the board console.

The console is a board singleton – one J-Link OB VCOM bridge on one SCI channel – so its sink state is module-owned rather than caller-supplied. That is what lets ra8_board_console_stream take only a handle. Two handles bound from this module share these bytes and therefore address the same console, which is the intended behaviour.

Note
Written only by ra8_board_console_stream, from a single-threaded application context.
Warning
Do not write this directly; ra8_io_stream_uart_init owns its layout.
Since
0.1.0

Definition at line 57 of file ra8_board_ek_ra8d2_console_stream.c.

Referenced by ra8_board_console_stream().

◆ s_tag

const char* const s_tag = "ra8_board.console_stream"
static

Module log tag.

Definition at line 38 of file ra8_board_ek_ra8d2_console_stream.c.