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

SCI_B UART peripheral-block model for the board emulator. More...

#include <stdint.h>
#include <stdio.h>
#include "board_console.h"
#include "board_periph.h"
#include "board_periph_block.h"
#include "board_periph_modem.h"
#include "board_periph_sd.h"
#include "emu_host_io_internal.h"
Include dependency graph for board_periph_sci.c:

Go to the source code of this file.

Data Structures

struct  sci_state_t
 One SCI_B channel: control shadow + a host-fed RX byte queue. More...

Enumerations

enum  sci_map_t : uint64_t {
  k_sci_base = 0x40358000UL ,
  k_sci_stride = 0x100UL ,
  k_sci_count = 10UL ,
  k_sci_span = 0x100UL * 10UL ,
  k_sci_off_rdr = 0x00UL ,
  k_sci_off_tdr = 0x04UL ,
  k_sci_off_ccr0 = 0x08UL ,
  k_sci_off_csr = 0x48UL ,
  k_sci_off_frsr = 0x50UL ,
  k_sci_off_ftsr = 0x54UL ,
  k_sci_off_cfclr = 0x68UL ,
  k_sci_off_ffclr = 0x70UL
}
 SCI_B block geometry (ra8_sci_regs.h, 32-bit-register variant). More...
enum  sci_ccr0_bit_t : uint32_t {
  k_sci_ccr0_re = 0x00000001U ,
  k_sci_ccr0_te = 0x00000010U ,
  k_sci_ccr0_rie = 0x00010000U ,
  k_sci_ccr0_tie = 0x00100000U ,
  k_sci_ccr0_teie = 0x00200000U
}
 SCI_B CCR0 interrupt/enable bits (ra8_sci_ccr0_bit_t). More...
enum  sci_csr_bit_t : uint32_t {
  k_sci_csr_rxdmon = 0x00008000U ,
  k_sci_csr_tdre = 0x20000000U ,
  k_sci_csr_tend = 0x40000000U ,
  k_sci_csr_rdrf = 0x80000000U
}
 SCI_B CSR status bits (ra8_sci_csr_bit_t). More...
enum  sci_fifo_bit_t : uint32_t {
  k_sci_frsr_dr = 0x00000001U ,
  k_sci_frsr_rdf = 0x00000040U ,
  k_sci_ftsr_tdfe = 0x00000040U
}
 SCI_B FIFO status bits used by reads of FRSR / FTSR. More...
enum  sci_clr_bit_t : uint32_t {
  k_sci_cfclr_rdrfc = 0x80000000U ,
  k_sci_ffclr_drc = 0x00000001U
}
 CFCLR / FFCLR write-1-to-clear bits this model honours. More...
enum  sci_elc_event_t : uint16_t {
  k_event_sci8_rxi = 0x122U ,
  k_event_sci8_txi = 0x123U ,
  k_event_sci8_tei = 0x124U
}
 SCI8 ELC event numbers the console channel raises (FSP ra8d2 bsp_elc). More...
enum  sci_tune_t : uint32_t {
  k_sci_console_ch = 8U ,
  k_sci_sd_ch = 0U ,
  k_sci_rx_queue_len = 512U ,
  k_sci_data_mask = 0xFFU ,
  k_uart_line_cap = 512U ,
  k_sci_spi_cipo_idle = 0xFFU ,
  k_sci_modem_resp_cap = 96U
}
 SCI_B model sizing and the EK-RA8D2 console channel. More...

Functions

void board_periph_sci_set_tx_sink (void(*sink)(uint8_t channel, uint8_t byte))
 Wire a host sink that receives every byte the firmware transmits.
uint8_t board_periph_sci_console_channel (void)
 The SCI channel the EK-RA8D2 console (J-Link OB VCOM) uses.
void board_periph_sci_feed_rx (uint8_t channel, const uint8_t *data, uint32_t len)
 Queue host->firmware bytes for a channel's receive path.
const char * board_periph_uart_last_line (void)
 The most recent complete line the firmware transmitted over any SCI.
uint32_t board_periph_uart_tx_total (void)
 Total bytes the firmware has transmitted over all SCI channels.
static RA8_INTERNAL bool internal_sci_rx_available (const sci_state_t *s)
 True iff the channel has a queued, unread host RX byte.
static RA8_INTERNAL uint32_t internal_sci_csr_value (const sci_state_t *s)
 Build the CSR value: TX always drained, RDRF reflects the RX queue.
static RA8_INTERNAL uint64_t internal_sci_reg_read (uint32_t ch, uint64_t off)
 Dispatch an SCI read for channel ch at byte offset off.
static RA8_INTERNAL void internal_sci_capture_tx_line (uint8_t byte)
 Accumulate one transmitted byte into the captured last-line buffer.
static RA8_INTERNAL void internal_sci_reg_write (uint32_t ch, uint64_t off, uint32_t value)
 Dispatch an SCI write; TDR is captured, CCR0 shadowed, clears no-op.
static RA8_INTERNAL void internal_sci_tick_channel (uc_engine *uc, uint32_t ch)
 Raise this channel's enabled SCI interrupts through the ICU.
static RA8_INTERNAL uint64_t internal_sci_read (uc_engine *uc, uint64_t addr, unsigned size)
 MMIO read inside the SCI window: route to the addressed channel.
static RA8_INTERNAL void internal_sci_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
 MMIO write inside the SCI window: route to the addressed channel.
static RA8_INTERNAL void internal_sci_tick (uc_engine *uc)
 Service every SCI channel once per emulation chunk.
static RA8_INTERNAL void internal_sci_reset (void)
 Clear all SCI channel state and the captured last-line buffers.
static RA8_INTERNAL void internal_sci_report (void)
 Print one line per SCI channel that moved any bytes.
static RA8_INTERNAL void internal_board_periph_sci_register (void)
 Self-register the SCI block before main runs (decentralized).

Variables

static sci_state_t s_sci [k_sci_count]
static void(* s_sci_tx_sink )(uint8_t channel, uint8_t byte)
 Host sink for transmitted bytes (main.c installs the descriptor-backed output sink).
static char s_uart_last [k_uart_line_cap]
 Last completed TX line.
static char s_uart_pend [k_uart_line_cap]
 Line being accumulated.
static uint32_t s_uart_pend_len
 Chars buffered in s_uart_pend.
static const board_periph_block_t s_k_sci_block
 This block's descriptor (static lifetime; the core keeps the pointer).

Detailed Description

SCI_B UART peripheral-block model for the board emulator.

Models the RA8D2 SCI_B serial channels (ra8_sci_regs.h, the 32-bit-register variant) with enough fidelity for the console examples to run on the emulator (ra8_sci.c semantics):

  • TX is always "drained" – CSR.TDRE / CSR.TEND read as set so the polled transmit-empty / transmit-end waits fall through. Each byte the firmware writes to TDR is counted, captured into a last-line buffer (latched on newline so the board view can show the last console line), and handed to a host sink (main.c prints it as [uart] SCIn: ...).
  • RX is a per-channel ring the host fills via board_periph_sci_feed_rx; CSR.RDRF (and the FIFO RX flags) read set while bytes are queued, RDR reads return them oldest-first.
  • Interrupts: on the console channel an enabled TXI / TEI re-pends each tick (so an interrupt-driven transmitter keeps streaming with TX always drained) and an enabled RXI pends while queued RX bytes remain – all through the core's ICU -> NVIC path.

Self-registers its descriptor (address range + read / write / tick / reset / report) with the board_periph core from a file-scope constructor.

Since
0.1.0

Definition in file board_periph_sci.c.

Enumeration Type Documentation

◆ sci_ccr0_bit_t

enum sci_ccr0_bit_t : uint32_t

SCI_B CCR0 interrupt/enable bits (ra8_sci_ccr0_bit_t).

Enumerator
k_sci_ccr0_re 

RE receive enable (bit 0).

k_sci_ccr0_te 

TE transmit enable (bit 4).

k_sci_ccr0_rie 

RIE receive-interrupt enable (16).

k_sci_ccr0_tie 

TIE transmit-interrupt enable (20).

k_sci_ccr0_teie 

TEIE transmit-end int enable (21).

Definition at line 58 of file board_periph_sci.c.

◆ sci_clr_bit_t

enum sci_clr_bit_t : uint32_t

CFCLR / FFCLR write-1-to-clear bits this model honours.

Enumerator
k_sci_cfclr_rdrfc 

RDRFC clear CSR.RDRF (bit 31).

k_sci_ffclr_drc 

DRC clear FRSR.DR (bit 0).

Definition at line 82 of file board_periph_sci.c.

◆ sci_csr_bit_t

enum sci_csr_bit_t : uint32_t

SCI_B CSR status bits (ra8_sci_csr_bit_t).

Enumerator
k_sci_csr_rxdmon 

RXDMON RXD pin monitor (bit 15).

k_sci_csr_tdre 

TDRE transmit-data-empty (bit 29).

k_sci_csr_tend 

TEND transmit-end (bit 30).

k_sci_csr_rdrf 

RDRF receive-data-full (bit 31).

Definition at line 67 of file board_periph_sci.c.

◆ sci_elc_event_t

enum sci_elc_event_t : uint16_t

SCI8 ELC event numbers the console channel raises (FSP ra8d2 bsp_elc).

RA8D2 ELC event signal table (HUM Ch 19) lays SCI channel events out in RXI / TXI / TEI / ERI / AM order; for the EK-RA8D2 console channel (SCI8, PD02/PD03) these are RXI 0x122, TXI 0x123, TEI 0x124, matching FSP bsp_elc.h for ra8d2 (ELC_EVENT_SCI8_RXI = 0x122, _TXI = 0x123, _TEI = 0x124). A firmware that routes one through ra8_isr_register writes the same number into an IELSR slot, so the ICU model matches the raised event to that slot exactly as it does for the timer events.

Enumerator
k_event_sci8_rxi 

SCI8 RXI receive-data-full event.

k_event_sci8_txi 

SCI8 TXI transmit-data-empty event.

k_event_sci8_tei 

SCI8 TEI transmit-end event.

Definition at line 99 of file board_periph_sci.c.

◆ sci_fifo_bit_t

enum sci_fifo_bit_t : uint32_t

SCI_B FIFO status bits used by reads of FRSR / FTSR.

Enumerator
k_sci_frsr_dr 

FRSR.DR receive-data-ready (bit 0).

k_sci_frsr_rdf 

FRSR.RDF receive-FIFO-data-full (6).

k_sci_ftsr_tdfe 

FTSR.TDFE transmit-FIFO-empty (6).

Definition at line 75 of file board_periph_sci.c.

◆ sci_map_t

enum sci_map_t : uint64_t

SCI_B block geometry (ra8_sci_regs.h, 32-bit-register variant).

Enumerator
k_sci_base 

SCI0 base (Secure alias).

k_sci_stride 

Bytes per SCI channel.

k_sci_count 

SCI0..SCI9.

k_sci_span 

SCI span.

k_sci_off_rdr 

RDR receive data (RDAT[7:0]).

k_sci_off_tdr 

TDR transmit data (TDAT[7:0]).

k_sci_off_ccr0 

CCR0 (TE/RE/RIE/TIE/TEIE).

k_sci_off_csr 

CSR (TDRE/TEND/RDRF + errors).

k_sci_off_frsr 

FRSR FIFO receive status.

k_sci_off_ftsr 

FTSR FIFO transmit status.

k_sci_off_cfclr 

CFCLR common flag clear (W1C).

k_sci_off_ffclr 

FFCLR FIFO flag clear (W1C).

Definition at line 42 of file board_periph_sci.c.

◆ sci_tune_t

enum sci_tune_t : uint32_t

SCI_B model sizing and the EK-RA8D2 console channel.

Enumerator
k_sci_console_ch 

EK-RA8D2 console = SCI8 (PD02/PD03).

k_sci_sd_ch 

EK-RA8D2 Pmod2 microSD = SCI0 Simple-SPI.

k_sci_rx_queue_len 

Per-channel host->firmware RX capacity.

k_sci_data_mask 

RDR/TDR data field is 8 bits.

k_uart_line_cap 

Captured last-TX-line buffer capacity.

k_sci_spi_cipo_idle 

CIPO idles high (0xFF) on an empty SPI bus.

k_sci_modem_resp_cap 

Scratch for one AT-modem reply burst.

Definition at line 106 of file board_periph_sci.c.

Function Documentation

◆ board_periph_sci_console_channel()

uint8_t board_periph_sci_console_channel ( void )

The SCI channel the EK-RA8D2 console (J-Link OB VCOM) uses.

PD02 TXD / PD03 RXD route to SCI8 on the EK-RA8D2 v1, surfaced as the board's debug-console UART (mirrored from libs/ra8_board_ek_ra8d2). main.c feeds --input and --keys to this channel by default.

Returns
The console SCI channel index (8 on the EK-RA8D2).
Since
0.1.0
Return values
valueThe operation-specific board periph SCI console channel value.
Precondition
Arguments satisfy the ranges documented for board periph SCI console channel.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 156 of file board_periph_sci.c.

References k_sci_console_ch.

Referenced by internal_main_feed_inputs(), internal_run_loop_tick_inputs(), and internal_run_print_stop_summary().

◆ board_periph_sci_feed_rx()

void board_periph_sci_feed_rx ( uint8_t channel,
const uint8_t * data,
uint32_t len )

Queue host->firmware bytes for a channel's receive path.

Appends len bytes to the channel's RX queue. The SCI_B model asserts CSR.RDRF (and the FIFO RX data flags) while the queue is non-empty, returns queued bytes from reads of RDR oldest-first, and – if the firmware armed RXI (CCR0.RIE) and routed the channel's RXI event through the ICU – pends the RXI interrupt so interrupt-driven receive also runs. main.c feeds this from --input and --keys so a console example sees real input. Bytes beyond the per-channel queue capacity are dropped (reported on --trace).

Parameters
[in]channelSCI channel index (0..9). Out-of-range is ignored.
[in]dataSource bytes (copied into the queue); ignored if NULL.
[in]lenNumber of bytes to queue.
Returns
Nothing.
Postcondition
Up to the queue's free space of data is readable via RDR and RDRF reflects availability.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for board periph SCI feed rx.
The call executes on the emulator's single owning thread.
Postcondition
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 161 of file board_periph_sci.c.

References board_periph_trace(), k_sci_count, k_sci_rx_queue_len, priv_emu_io_errf(), sci_state_t::rx, sci_state_t::rx_dropped, sci_state_t::rx_head, sci_state_t::rx_tail, and s_sci.

Referenced by internal_main_feed_inputs(), internal_run_loop_tick_inputs(), and internal_sci_reg_write().

◆ board_periph_sci_set_tx_sink()

void board_periph_sci_set_tx_sink ( void(* sink )(uint8_t channel, uint8_t byte))

Wire a host sink that receives every byte the firmware transmits.

The SCI_B model calls sink once per byte written to a channel's TDR (the transmit-data register, used by both the polled and interrupt TX paths and by FIFO mode, which also writes TDR). main.c installs a sink that prints each byte to injected output sink with a clear [uart] prefix so a console example's output is captured and greppable. When no callback is installed, transmitted bytes are still counted for the end-of-run summary but not echoed.

Parameters
[in]sinkCallback invoked as sink(channel, byte) per TX byte, or NULL to detach. The model owns no copy of byte.
Returns
Nothing.
Postcondition
Subsequent TDR writes are delivered to sink.
Since
0.1.0

Definition at line 151 of file board_periph_sci.c.

References s_sci_tx_sink.

Referenced by internal_main_bringup_peripherals().

◆ board_periph_uart_last_line()

const char * board_periph_uart_last_line ( void )

The most recent complete line the firmware transmitted over any SCI.

The SCI_B TX path captures each transmitted byte into a line buffer that is latched on newline (CR is dropped), so the board view can show the last console line a non-display example printed – e.g. "hello, ra8d2!" from uart_hello -- on its "UART:" status line. Returns a pointer to static storage holding the last completed line (empty string before the first newline); the pointer must not be freed and is valid until the next TX byte.

Returns
NUL-terminated last UART line (never NULL; empty until one is sent).
Since
0.1.0

Definition at line 183 of file board_periph_sci.c.

References s_uart_last.

Referenced by internal_fill_status_hw(), and internal_run_stop_banner().

◆ board_periph_uart_tx_total()

uint32_t board_periph_uart_tx_total ( void )

Total bytes the firmware has transmitted over all SCI channels.

Sum of every modelled SCI channel's TX byte counter – a coarse "how chatty is this firmware" figure the board view shows beside the console panel. Counts raw TDR-write bytes (including CR/LF), not completed lines.

Returns
Total SCI TX byte count since reset.
Since
0.1.0
Return values
valueThe operation-specific board periph uart tx total value.
Precondition
Arguments satisfy the ranges documented for board periph uart tx total.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 188 of file board_periph_sci.c.

References k_sci_count, and s_sci.

Referenced by internal_fill_status_console().

◆ internal_board_periph_sci_register()

RA8_INTERNAL void internal_board_periph_sci_register ( void )
static

Self-register the SCI block before main runs (decentralized).

Definition at line 528 of file board_periph_sci.c.

References board_periph_register_block(), RA8_INTERNAL, and s_k_sci_block.

◆ internal_sci_capture_tx_line()

RA8_INTERNAL void internal_sci_capture_tx_line ( uint8_t byte)
static

Accumulate one transmitted byte into the captured last-line buffer.

Mirrors the host console formatter: a newline latches the pending line into s_uart_last (so the board view can show the last complete console line), CR is dropped, and any other byte is appended until the buffer is full. This tracks only the last completed line, independent of the optional TX sink.

Parameters
[in]byteThe transmitted data byte.
Returns
Nothing.
Since
0.1.0
Precondition
Arguments satisfy the ranges documented for SCI capture tx line.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.

Definition at line 292 of file board_periph_sci.c.

References board_console_push(), k_board_console_ch_uart, k_uart_line_cap, RA8_INTERNAL, s_uart_last, s_uart_pend, and s_uart_pend_len.

Referenced by internal_sci_reg_write().

◆ internal_sci_csr_value()

RA8_INTERNAL uint32_t internal_sci_csr_value ( const sci_state_t * s)
static

Build the CSR value: TX always drained, RDRF reflects the RX queue.

Build the csr value: tx always drained, rdrf reflects the rx queue; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Parameters
[in]sModule state instance processed by the operation.
Returns
The SCI csr value result produced by the board periph SCI model.
Return values
valueThe operation-specific SCI csr value value.
Precondition
Arguments satisfy the ranges documented for SCI csr value.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 224 of file board_periph_sci.c.

References internal_sci_rx_available(), k_sci_csr_rdrf, k_sci_csr_rxdmon, k_sci_csr_tdre, k_sci_csr_tend, and RA8_INTERNAL.

Referenced by internal_sci_reg_read().

◆ internal_sci_read()

RA8_INTERNAL uint64_t internal_sci_read ( uc_engine * uc,
uint64_t addr,
unsigned size )
static

MMIO read inside the SCI window: route to the addressed channel.

MMIO read inside the sci window: route to the addressed channel; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
Returns
The SCI read result produced by the board periph SCI model.
Return values
valueThe operation-specific SCI read value.
Precondition
Arguments satisfy the ranges documented for SCI read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 421 of file board_periph_sci.c.

References internal_sci_reg_read(), k_sci_base, k_sci_stride, and RA8_INTERNAL.

◆ internal_sci_reg_read()

RA8_INTERNAL uint64_t internal_sci_reg_read ( uint32_t ch,
uint64_t off )
static

Dispatch an SCI read for channel ch at byte offset off.

Dispatch an sci read for channel ch at byte offset off; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Parameters
[in]chSelected channel identifier.
[in]offRegister or byte offset addressed by the operation.
Returns
The SCI reg read result produced by the board periph SCI model.
Return values
valueThe operation-specific SCI reg read value.
Precondition
Arguments satisfy the ranges documented for SCI reg read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 249 of file board_periph_sci.c.

References sci_state_t::ccr0, internal_sci_csr_value(), internal_sci_rx_available(), k_sci_frsr_dr, k_sci_frsr_rdf, k_sci_ftsr_tdfe, k_sci_off_ccr0, k_sci_off_csr, k_sci_off_frsr, k_sci_off_ftsr, k_sci_off_rdr, k_sci_rx_queue_len, RA8_INTERNAL, sci_state_t::received, sci_state_t::rx, sci_state_t::rx_head, and s_sci.

Referenced by internal_sci_read().

◆ internal_sci_reg_write()

RA8_INTERNAL void internal_sci_reg_write ( uint32_t ch,
uint64_t off,
uint32_t value )
static

Dispatch an SCI write; TDR is captured, CCR0 shadowed, clears no-op.

Dispatch an sci write; tdr is captured, ccr0 shadowed, clears no-op; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Parameters
[in]chSelected channel identifier.
[in]offRegister or byte offset addressed by the operation.
[in]valueRegister or payload value involved in the operation.
Precondition
Arguments satisfy the ranges documented for SCI reg write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 321 of file board_periph_sci.c.

References board_modem_attached(), board_modem_channel(), board_modem_feed_tx(), board_periph_sci_feed_rx(), board_sd_attached(), board_sd_exchange(), sci_state_t::ccr0, internal_sci_capture_tx_line(), k_sci_console_ch, k_sci_data_mask, k_sci_modem_resp_cap, k_sci_off_ccr0, k_sci_off_tdr, k_sci_sd_ch, k_sci_spi_cipo_idle, RA8_INTERNAL, s_sci, s_sci_tx_sink, and sci_state_t::transmitted.

Referenced by internal_sci_write().

◆ internal_sci_report()

RA8_INTERNAL void internal_sci_report ( void )
static

Print one line per SCI channel that moved any bytes.

Print one line per sci channel that moved any bytes; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for SCI report.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 498 of file board_periph_sci.c.

References board_modem_report(), k_sci_count, priv_emu_io_errf(), RA8_INTERNAL, and s_sci.

◆ internal_sci_reset()

RA8_INTERNAL void internal_sci_reset ( void )
static

Clear all SCI channel state and the captured last-line buffers.

Clear all sci channel state and the captured last-line buffers; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for SCI reset.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 476 of file board_periph_sci.c.

References board_modem_reset(), k_sci_count, RA8_INTERNAL, s_sci, s_uart_last, s_uart_pend, and s_uart_pend_len.

◆ internal_sci_rx_available()

RA8_INTERNAL bool internal_sci_rx_available ( const sci_state_t * s)
static

True iff the channel has a queued, unread host RX byte.

True iff the channel has a queued, unread host rx byte; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Parameters
[in]sModule state instance processed by the operation.
Returns
The SCI rx available result produced by the board periph SCI model.
Return values
trueThe SCI rx available condition holds or completed successfully; false otherwise.
Precondition
Arguments satisfy the ranges documented for SCI rx available.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 208 of file board_periph_sci.c.

References RA8_INTERNAL, sci_state_t::rx_head, and sci_state_t::rx_tail.

Referenced by internal_sci_csr_value(), internal_sci_reg_read(), and internal_sci_tick_channel().

◆ internal_sci_tick()

RA8_INTERNAL void internal_sci_tick ( uc_engine * uc)
static

Service every SCI channel once per emulation chunk.

Service every sci channel once per emulation chunk; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
Precondition
Arguments satisfy the ranges documented for SCI tick.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 461 of file board_periph_sci.c.

References internal_sci_tick_channel(), k_sci_count, and RA8_INTERNAL.

◆ internal_sci_tick_channel()

RA8_INTERNAL void internal_sci_tick_channel ( uc_engine * uc,
uint32_t ch )
static

Raise this channel's enabled SCI interrupts through the ICU.

Raise this channel's enabled sci interrupts through the icu; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]chSelected channel identifier.
Precondition
Arguments satisfy the ranges documented for SCI tick channel.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 384 of file board_periph_sci.c.

References board_periph_icu_raise_event(), sci_state_t::ccr0, internal_sci_rx_available(), k_event_sci8_rxi, k_event_sci8_tei, k_event_sci8_txi, k_sci_ccr0_rie, k_sci_ccr0_te, k_sci_ccr0_teie, k_sci_ccr0_tie, k_sci_console_ch, RA8_INTERNAL, and s_sci.

Referenced by internal_sci_tick().

◆ internal_sci_write()

RA8_INTERNAL void internal_sci_write ( uc_engine * uc,
uint64_t addr,
unsigned size,
uint64_t value )
static

MMIO write inside the SCI window: route to the addressed channel.

MMIO write inside the sci window: route to the addressed channel; this step is contained within the board periph SCI model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
[in]valueRegister or payload value involved in the operation.
Precondition
Arguments satisfy the ranges documented for SCI write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SCI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 442 of file board_periph_sci.c.

References internal_sci_reg_write(), k_sci_base, and k_sci_stride.

Variable Documentation

◆ s_k_sci_block

const board_periph_block_t s_k_sci_block
static
Initial value:
= {
.base = (uint64_t)k_sci_base,
.span = (uint64_t)k_sci_span,
.order = (uint32_t)k_block_order_sci,
.name = "SCI_B UART",
}
@ k_block_order_sci
SCI_B UART.
static RA8_INTERNAL void internal_sci_report(void)
Print one line per SCI channel that moved any bytes.
@ k_sci_span
SCI span.
@ k_sci_base
SCI0 base (Secure alias).
static RA8_INTERNAL void internal_sci_reset(void)
Clear all SCI channel state and the captured last-line buffers.
static RA8_INTERNAL uint64_t internal_sci_read(uc_engine *uc, uint64_t addr, unsigned size)
MMIO read inside the SCI window: route to the addressed channel.
static RA8_INTERNAL void internal_sci_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
MMIO write inside the SCI window: route to the addressed channel.
static RA8_INTERNAL void internal_sci_tick(uc_engine *uc)
Service every SCI channel once per emulation chunk.
-proof

This block's descriptor (static lifetime; the core keeps the pointer).

Definition at line 515 of file board_periph_sci.c.

Referenced by internal_board_periph_sci_register().

◆ s_sci

◆ s_sci_tx_sink

void(* s_sci_tx_sink) (uint8_t channel, uint8_t byte) ( uint8_t channel,
uint8_t byte )
static

Host sink for transmitted bytes (main.c installs the descriptor-backed output sink).

Definition at line 139 of file board_periph_sci.c.

Referenced by board_periph_sci_set_tx_sink(), and internal_sci_reg_write().

◆ s_uart_last

char s_uart_last[k_uart_line_cap]
static

Last completed TX line.

Definition at line 147 of file board_periph_sci.c.

Referenced by board_periph_uart_last_line(), internal_sci_capture_tx_line(), and internal_sci_reset().

◆ s_uart_pend

char s_uart_pend[k_uart_line_cap]
static

Line being accumulated.

Definition at line 148 of file board_periph_sci.c.

Referenced by internal_sci_capture_tx_line(), and internal_sci_reset().

◆ s_uart_pend_len

uint32_t s_uart_pend_len
static

Chars buffered in s_uart_pend.

Definition at line 149 of file board_periph_sci.c.

Referenced by internal_sci_capture_tx_line(), and internal_sci_reset().