|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
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"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). | |
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):
[uart] SCIn: ...).Self-registers its descriptor (address range + read / write / tick / reset / report) with the board_periph core from a file-scope constructor.
Definition in file board_periph_sci.c.
| enum sci_ccr0_bit_t : uint32_t |
SCI_B CCR0 interrupt/enable bits (ra8_sci_ccr0_bit_t).
Definition at line 58 of file board_periph_sci.c.
| 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.
| enum sci_csr_bit_t : uint32_t |
SCI_B CSR status bits (ra8_sci_csr_bit_t).
Definition at line 67 of file board_periph_sci.c.
| 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.
| 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.
| enum sci_map_t : uint64_t |
SCI_B block geometry (ra8_sci_regs.h, 32-bit-register variant).
Definition at line 42 of file board_periph_sci.c.
| enum sci_tune_t : uint32_t |
SCI_B model sizing and the EK-RA8D2 console channel.
Definition at line 106 of file board_periph_sci.c.
| 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.
| value | The operation-specific board periph SCI console channel value. |
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().
| 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).
| [in] | channel | SCI channel index (0..9). Out-of-range is ignored. |
| [in] | data | Source bytes (copied into the queue); ignored if NULL. |
| [in] | len | Number of bytes to queue. |
data is readable via RDR and RDRF reflects availability. 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().
| 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.
| [in] | sink | Callback invoked as sink(channel, byte) per TX byte, or NULL to detach. The model owns no copy of byte. |
sink. Definition at line 151 of file board_periph_sci.c.
References s_sci_tx_sink.
Referenced by internal_main_bringup_peripherals().
| 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.
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().
| 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.
| value | The operation-specific board periph uart tx total value. |
Definition at line 188 of file board_periph_sci.c.
References k_sci_count, and s_sci.
Referenced by internal_fill_status_console().
|
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.
|
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.
| [in] | byte | The transmitted data byte. |
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().
|
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.
| [in] | s | Module state instance processed by the operation. |
| value | The operation-specific SCI csr value value. |
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().
|
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.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | addr | Guest address involved in the operation. |
| [in] | size | Size of the requested region or access in bytes. |
| value | The operation-specific SCI read value. |
Definition at line 421 of file board_periph_sci.c.
References internal_sci_reg_read(), k_sci_base, k_sci_stride, and RA8_INTERNAL.
|
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.
| [in] | ch | Selected channel identifier. |
| [in] | off | Register or byte offset addressed by the operation. |
| value | The operation-specific SCI reg read value. |
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().
|
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.
| [in] | ch | Selected channel identifier. |
| [in] | off | Register or byte offset addressed by the operation. |
| [in] | value | Register or payload value involved in the operation. |
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().
|
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.
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.
|
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.
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.
|
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.
| [in] | s | Module state instance processed by the operation. |
| true | The SCI rx available condition holds or completed successfully; false otherwise. |
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().
|
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.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
Definition at line 461 of file board_periph_sci.c.
References internal_sci_tick_channel(), k_sci_count, and RA8_INTERNAL.
|
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.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | ch | Selected channel identifier. |
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().
|
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.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | addr | Guest address involved in the operation. |
| [in] | size | Size of the requested region or access in bytes. |
| [in] | value | Register or payload value involved in the operation. |
Definition at line 442 of file board_periph_sci.c.
References internal_sci_reg_write(), k_sci_base, and k_sci_stride.
|
static |
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().
|
static |
Definition at line 136 of file board_periph_sci.c.
Referenced by board_periph_sci_feed_rx(), board_periph_uart_tx_total(), internal_sci_reg_read(), internal_sci_reg_write(), internal_sci_report(), internal_sci_reset(), and internal_sci_tick_channel().
|
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().
|
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().
|
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().
|
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().