|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
CAN-FD controller peripheral-block model for the board emulator. More...
#include <stdint.h>#include <stdio.h>#include <string.h>#include "board_console.h"#include "board_periph_block.h"#include "emu_host_io_internal.h"Go to the source code of this file.
Data Structures | |
| struct | canfd_inst_t |
| One CANFD instance: flat register backing store. More... | |
Enumerations | |
| enum | canfd_map_t : uint64_t { k_canfd0_base = 0x40380000UL , k_canfd1_base = 0x40382000UL , k_canfd_span = 0x1920UL , k_canfd_count = 2UL , k_canfd_words = 0x1920UL / 4UL , k_canfd_off_cnctr = 0x004UL , k_canfd_off_cnsts = 0x008UL , k_canfd_off_gctr = 0x018UL , k_canfd_off_gsts = 0x01CUL , k_canfd_off_rfsts0 = 0x044UL , k_canfd_off_rfpctr0 = 0x04CUL , k_canfd_off_tmc0 = 0x070UL , k_canfd_off_tmsts0 = 0x074UL , k_canfd_off_rf0 = 0x520UL , k_canfd_off_tm0 = 0x604UL , k_canfd_frame_words = 0x4CUL / 4UL , k_canfd_off_afl = 0x120UL , k_canfd_afl_stride = 0x10UL , k_canfd_afl_count = 16UL } |
| CANFD block geometry (ra8_canfd_regs.h, FSP R_CANFD_Type). More... | |
| enum | canfd_gsts_t : uint32_t { k_gsts_grststs = 1UL << 0U , k_gsts_ghltsts = 1UL << 1U , k_gsts_graminit = 1UL << 3U } |
| Global status (CFDGSTS) bit masks the model drives. More... | |
| enum | canfd_cnsts_t : uint32_t { k_cnsts_crstst = 1UL << 0U , k_cnsts_chltst = 1UL << 1U } |
| Channel status (CFDC[0].STS) bit masks the model drives. More... | |
| enum | canfd_id_mask_t : uint32_t { k_canfd_id_std = 0x000007FFUL , k_canfd_id_ext = 0x1FFFFFFFUL } |
| Message-ID field masks (CFDRF.ID / CFDTM.ID), for trace + report. More... | |
| enum | canfd_ptr_t : uint32_t { k_canfd_ptr_word = 1UL , k_canfd_ptr_dlc_shift = 28UL , k_canfd_ptr_dlc_mask = 0xFUL } |
| CFDTM/CFDRF.PTR frame fields (PTR layout: [15:0] timestamp, [31:28] DLC). More... | |
| enum | canfd_mode_t : uint32_t { k_mode_mask = 0x3UL , k_mode_operation = 0x0UL , k_mode_reset = 0x1UL , k_mode_halt = 0x2UL } |
| Global / channel mode-control field (GMDC / CHMDC, bits [1:0]). More... | |
| enum | canfd_rfsts_t : uint32_t { k_rfsts_empty = 1UL << 0U , k_rfsts_if = 1UL << 3U } |
| RX FIFO status (CFDRFSTS[0]) bit masks. More... | |
| enum | canfd_tmc_t : uint8_t { k_tmc_txreq = 1U << 0U , k_tmsts_done = 0x04U } |
| TX MB control / status byte bits. More... | |
| enum | canfd_elc_event_t : uint16_t { k_event_can0_rxf = 0x33DU } |
| CANFD0 RX-FIFO (RXF) ELC event the model pends on loopback delivery. More... | |
Functions | |
| static RA8_INTERNAL uint32_t | internal_canfd_instance (uint64_t addr) |
| Resolve an absolute address to its instance index (0/1) or count. | |
| static RA8_INTERNAL uint64_t | internal_canfd_offset (uint32_t inst, uint64_t addr) |
In-window byte offset of addr for instance inst. | |
| static RA8_INTERNAL uint32_t | internal_canfd_word (uint64_t off) |
| Word index into the backing store for an in-window offset. | |
| static RA8_INTERNAL void | internal_canfd_apply_global_mode (canfd_inst_t *c, uint32_t gctr) |
| Apply a mode-control write to its matching status register bits. | |
| static RA8_INTERNAL void | internal_canfd_apply_channel_mode (canfd_inst_t *c, uint32_t ctr) |
| Apply a channel mode-control write to its matching status bits. | |
| static RA8_INTERNAL bool | internal_canfd_frame_accepted (const canfd_inst_t *c, uint32_t tx_id) |
Decide whether tx_id passes the programmed acceptance filter. | |
| static RA8_INTERNAL void | internal_canfd_console_frame (uint32_t inst, uint32_t tx_id, uint32_t dlc, const char *outcome) |
| Push a one-line CAN-FD frame summary to the board console CAN lane. | |
| static RA8_INTERNAL void | internal_canfd_loopback_deliver (uc_engine *uc, uint32_t inst) |
| Copy TX MB 0 into RX FIFO 0 and flag the frame available. | |
| static RA8_INTERNAL uint64_t | internal_canfd_read (uc_engine *uc, uint64_t addr, unsigned size) |
| MMIO read inside a CANFD window: read back the latched register. | |
| static RA8_INTERNAL void | internal_canfd_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value) |
| Handle a write to a CANFD register with side effects, else latch it. | |
| static RA8_INTERNAL void | internal_canfd_reset (void) |
| Reset both CANFD instances to a coherent power-on state. | |
| static RA8_INTERNAL void | internal_canfd_report (void) |
| Print one line per CANFD instance that looped a frame back. | |
| static RA8_INTERNAL void | internal_board_periph_canfd_register (void) |
| Self-register both CANFD windows before main runs (decentralized). | |
Variables | |
| static canfd_inst_t | s_canfd [k_canfd_count] |
| static const board_periph_block_t | s_k_canfd0_block |
| CANFD0 register window + the shared loopback reset / report. | |
| static const board_periph_block_t | s_k_canfd1_block |
| CANFD1 register window (reset / report handled by the CANFD0 block). | |
CAN-FD controller peripheral-block model for the board emulator.
Models the two RA8D2 CANFD instances (ra8_canfd_regs.h / ra8_canfd.c) at 0x40380000 (CANFD0) and 0x40382000 (CANFD1), each a 0x1920-byte channel window, so the internal-loopback demo round-trips a frame instead of timing out in the sparse fallback. Two behaviours are modelled on top of a flat read-back register store:
Self-registers its descriptor with the board_periph core from a file-scope constructor; the core keeps no central block list – see board_periph_block.h.
Definition in file board_periph_canfd.c.
| enum canfd_cnsts_t : uint32_t |
Channel status (CFDC[0].STS) bit masks the model drives.
| Enumerator | |
|---|---|
| k_cnsts_crstst | Channel reset status. |
| k_cnsts_chltst | Channel halt status. |
Definition at line 76 of file board_periph_canfd.c.
| enum canfd_elc_event_t : uint16_t |
CANFD0 RX-FIFO (RXF) ELC event the model pends on loopback delivery.
RA8D2 ELC event signal table (HUM Ch 19 Table 19.3) groups the CANFD0 interrupts together; the global RX-FIFO event (CAN0_RXF) is the RX-available interrupt source. The canfd_loopback demo is purely POLLED – it registers no CAN ISR and links no IELSR slot to this event – so pending it is a no-op for that demo and is done only so an interrupt-driven receiver would also be exercised. The numeric value is not verified against a local FSP bsp_elc.h (FSP is not installed here); it is unused on the demo's success path, which rests entirely on the RFEMP / RFIF status modelling above.
| Enumerator | |
|---|---|
| k_event_can0_rxf | CANFD0 RXF RX-FIFO event (best-effort). |
Definition at line 127 of file board_periph_canfd.c.
| enum canfd_gsts_t : uint32_t |
Global status (CFDGSTS) bit masks the model drives.
| Enumerator | |
|---|---|
| k_gsts_grststs | Global reset status. |
| k_gsts_ghltsts | Global halt status. |
| k_gsts_graminit | Global RAM-init in progress. |
Definition at line 69 of file board_periph_canfd.c.
| enum canfd_id_mask_t : uint32_t |
Message-ID field masks (CFDRF.ID / CFDTM.ID), for trace + report.
| Enumerator | |
|---|---|
| k_canfd_id_std | 11-bit standard ID. |
| k_canfd_id_ext | 29-bit extended ID. |
Definition at line 82 of file board_periph_canfd.c.
| enum canfd_map_t : uint64_t |
CANFD block geometry (ra8_canfd_regs.h, FSP R_CANFD_Type).
Definition at line 46 of file board_periph_canfd.c.
| enum canfd_mode_t : uint32_t |
Global / channel mode-control field (GMDC / CHMDC, bits [1:0]).
| Enumerator | |
|---|---|
| k_mode_mask | 2-bit mode field. |
| k_mode_operation | Operation mode. |
| k_mode_reset | Reset mode. |
| k_mode_halt | Halt mode. |
Definition at line 95 of file board_periph_canfd.c.
| enum canfd_ptr_t : uint32_t |
CFDTM/CFDRF.PTR frame fields (PTR layout: [15:0] timestamp, [31:28] DLC).
| Enumerator | |
|---|---|
| k_canfd_ptr_word | PTR is the 2nd word of a frame window. |
| k_canfd_ptr_dlc_shift | DLC occupies PTR bits [31:28]. |
| k_canfd_ptr_dlc_mask | 4-bit DLC code mask (0..15). |
Definition at line 88 of file board_periph_canfd.c.
| enum canfd_rfsts_t : uint32_t |
RX FIFO status (CFDRFSTS[0]) bit masks.
| Enumerator | |
|---|---|
| k_rfsts_empty | RFEMP: FIFO empty flag. |
| k_rfsts_if | RFIF: RX interrupt flag. |
Definition at line 103 of file board_periph_canfd.c.
| enum canfd_tmc_t : uint8_t |
TX MB control / status byte bits.
| Enumerator | |
|---|---|
| k_tmc_txreq | CFDTMC.TMTR transmit request. |
| k_tmsts_done | CFDTMSTS.TMTRF = 10b complete. |
Definition at line 109 of file board_periph_canfd.c.
|
static |
Self-register both CANFD windows before main runs (decentralized).
Definition at line 513 of file board_periph_canfd.c.
References board_periph_register_block(), RA8_INTERNAL, s_k_canfd0_block, and s_k_canfd1_block.
|
static |
Apply a channel mode-control write to its matching status bits.
Apply a channel mode-control write to its matching status bits; this step is contained within the board periph canfd model and uses bounded caller or module-owned storage.
| [in,out] | c | Active controller, card, or command state processed by the operation. |
| [in] | ctr | Ctr input used by the operation. |
Definition at line 230 of file board_periph_canfd.c.
References internal_canfd_word(), k_canfd_off_cnsts, k_cnsts_chltst, k_cnsts_crstst, k_mode_halt, k_mode_mask, k_mode_reset, RA8_INTERNAL, and canfd_inst_t::reg.
Referenced by internal_canfd_write().
|
static |
Apply a mode-control write to its matching status register bits.
Apply a mode-control write to its matching status register bits; this step is contained within the board periph canfd model and uses bounded caller or module-owned storage.
| [in,out] | c | Active controller, card, or command state processed by the operation. |
| [in] | gctr | Gctr input used by the operation. |
Definition at line 207 of file board_periph_canfd.c.
References internal_canfd_word(), k_canfd_off_gsts, k_gsts_ghltsts, k_gsts_graminit, k_gsts_grststs, k_mode_halt, k_mode_mask, k_mode_reset, RA8_INTERNAL, and canfd_inst_t::reg.
Referenced by internal_canfd_write().
|
static |
Push a one-line CAN-FD frame summary to the board console CAN lane.
Formats a short, human-readable record of a single transmitted CAN-FD frame – the originating controller instance, the identifier in hex, the 4-bit DLC code, and the outcome note – into a bounded stack buffer and appends it to k_board_console_ch_can via board_console_push. This is the console-tab tap only: it performs no register access and writes nothing to injected output sink/injected error sink, so the smoke/golden output stays byte-identical. It is invoked once per transmit request (one logical CAN frame), never per byte, so the ring does not flood.
| [in] | inst | CANFD instance index (0 = CANFD0, 1 = CANFD1). |
| [in] | tx_id | Transmitted identifier, already masked to 29 bits. |
| [in] | dlc | 4-bit data-length code from CFDTM.PTR[31:28] (0..15). |
| [in] | outcome | Borrowed NUL-terminated delivery note (e.g. "-> RXF0"). |
outcome is a valid NUL-terminated string. inst is a valid CANFD instance index (< k_canfd_count). < Max chars in a "CANFD<n> TX id=.." line.
Definition at line 308 of file board_periph_canfd.c.
References board_console_push(), and k_board_console_ch_can.
Referenced by internal_canfd_loopback_deliver().
|
static |
Decide whether tx_id passes the programmed acceptance filter.
Scans the CFDGAFL page-0 entry window (the demos use filter ids < one page, so paging does not apply). An entry is active when its mask (CFDGAFL.M) is non-zero; a frame is accepted if it matches any active entry, (tx_id & mask) == (accept_id & mask). With no active entry the filter is open – internal loopback that programs no filters (canfd_loopback) keeps delivering every frame, while canfd_filter_demo's programmed slots drop the non-matching id.
| [in] | c | Channel instance whose CFDGAFL window to read. |
| [in] | tx_id | Transmitted frame id (29-bit field, IDE/RTR masked off). |
| true | The canfd frame accepted condition holds or completed successfully; false otherwise. |
Definition at line 264 of file board_periph_canfd.c.
References internal_canfd_word(), k_canfd_afl_count, k_canfd_afl_stride, k_canfd_id_ext, k_canfd_off_afl, RA8_INTERNAL, and canfd_inst_t::reg.
Referenced by internal_canfd_loopback_deliver().
|
static |
Resolve an absolute address to its instance index (0/1) or count.
Resolve an absolute address to its instance index (0/1) or count; this step is contained within the board periph canfd model and uses bounded caller or module-owned storage.
| [in] | addr | Guest address involved in the operation. |
| value | The operation-specific canfd instance value. |
Definition at line 150 of file board_periph_canfd.c.
References k_canfd0_base, k_canfd1_base, k_canfd_count, k_canfd_span, and RA8_INTERNAL.
Referenced by internal_canfd_read(), and internal_canfd_write().
|
static |
Copy TX MB 0 into RX FIFO 0 and flag the frame available.
Copy tx mb 0 into rx fifo 0 and flag the frame available; this step is contained within the board periph canfd model and uses bounded caller or module-owned storage.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | inst | Inst input used by the operation. |
Definition at line 328 of file board_periph_canfd.c.
References board_periph_icu_raise_event(), board_periph_trace(), internal_canfd_console_frame(), internal_canfd_frame_accepted(), internal_canfd_word(), k_canfd_frame_words, k_canfd_id_ext, k_canfd_off_rf0, k_canfd_off_rfsts0, k_canfd_off_tm0, k_canfd_off_tmsts0, k_canfd_ptr_dlc_mask, k_canfd_ptr_dlc_shift, k_canfd_ptr_word, k_event_can0_rxf, k_rfsts_empty, k_rfsts_if, k_tmsts_done, canfd_inst_t::loopbacks, priv_emu_io_errf(), RA8_INTERNAL, canfd_inst_t::reg, and s_canfd.
Referenced by internal_canfd_write().
|
static |
In-window byte offset of addr for instance inst.
In-window byte offset of addr for instance inst; this step is contained within the board periph canfd model and uses bounded caller or module-owned storage.
| [in] | inst | Inst input used by the operation. |
| [in] | addr | Guest address involved in the operation. |
| value | The operation-specific canfd offset value. |
Definition at line 175 of file board_periph_canfd.c.
References k_canfd0_base, k_canfd1_base, and RA8_INTERNAL.
Referenced by internal_canfd_read(), and internal_canfd_write().
|
static |
MMIO read inside a CANFD window: read back the latched register.
MMIO read inside a canfd window: read back the latched register; this step is contained within the board periph canfd 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 canfd read value. |
Definition at line 382 of file board_periph_canfd.c.
References internal_canfd_instance(), internal_canfd_offset(), internal_canfd_word(), k_canfd_count, k_canfd_span, RA8_INTERNAL, and s_canfd.
|
static |
Print one line per CANFD instance that looped a frame back.
Print one line per canfd instance that looped a frame back; this step is contained within the board periph canfd model and uses bounded caller or module-owned storage.
Definition at line 472 of file board_periph_canfd.c.
References internal_canfd_word(), k_canfd_count, k_canfd_id_std, k_canfd_off_rf0, priv_emu_io_errf(), RA8_INTERNAL, and s_canfd.
|
static |
Reset both CANFD instances to a coherent power-on state.
Reset both canfd instances to a coherent power-on state; this step is contained within the board periph canfd model and uses bounded caller or module-owned storage.
Definition at line 455 of file board_periph_canfd.c.
References internal_canfd_word(), k_canfd_count, k_canfd_off_rfsts0, k_rfsts_empty, memset(), RA8_INTERNAL, and s_canfd.
|
static |
Word index into the backing store for an in-window offset.
Word index into the backing store for an in-window offset; this step is contained within the board periph canfd model and uses bounded caller or module-owned storage.
| [in] | off | Register or byte offset addressed by the operation. |
| value | The operation-specific canfd word value. |
Definition at line 192 of file board_periph_canfd.c.
References RA8_INTERNAL.
Referenced by internal_canfd_apply_channel_mode(), internal_canfd_apply_global_mode(), internal_canfd_frame_accepted(), internal_canfd_loopback_deliver(), internal_canfd_read(), internal_canfd_report(), internal_canfd_reset(), and internal_canfd_write().
|
static |
Handle a write to a CANFD register with side effects, else latch it.
Handle a write to a canfd register with side effects, else latch it; this step is contained within the board periph canfd 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 410 of file board_periph_canfd.c.
References internal_canfd_apply_channel_mode(), internal_canfd_apply_global_mode(), internal_canfd_instance(), internal_canfd_loopback_deliver(), internal_canfd_offset(), internal_canfd_word(), k_canfd_count, k_canfd_off_cnctr, k_canfd_off_gctr, k_canfd_off_rfpctr0, k_canfd_off_rfsts0, k_canfd_off_tmc0, k_canfd_span, k_rfsts_empty, k_rfsts_if, k_tmc_txreq, canfd_inst_t::reg, and s_canfd.
|
static |
Definition at line 137 of file board_periph_canfd.c.
Referenced by internal_canfd_loopback_deliver(), internal_canfd_read(), internal_canfd_report(), internal_canfd_reset(), and internal_canfd_write().
|
static |
CANFD0 register window + the shared loopback reset / report.
Definition at line 487 of file board_periph_canfd.c.
Referenced by internal_board_periph_canfd_register().
|
static |
CANFD1 register window (reset / report handled by the CANFD0 block).
Definition at line 500 of file board_periph_canfd.c.
Referenced by internal_board_periph_canfd_register().