|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Octal-SPI (xSPI) manual-command + NOR-flash peripheral model for ra8_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 | xspi_state_t |
| xSPI model state: register-window shadow + op counters. More... | |
Enumerations | |
| enum | xspi_console_t : uint32_t { k_xspi_console_line_cap = 48U } |
| Console-tap line buffer capacity for an xSPI command summary. More... | |
| enum | xspi_map_t : uint64_t { k_xspi_base = 0x40268000UL , k_xspi_span = 0x200UL , k_xspi_off_cdctl0 = 0x070UL , k_xspi_off_cdbuf = 0x080UL , k_xspi_off_ints = 0x190UL , k_xspi_off_intc = 0x194UL } |
| XSPI0 register-window geometry (ra8_ospi_regs.h). More... | |
| enum | xspi_cdt_field_t : uint32_t { k_xspi_cdt_pos_cmdsize = 0U , k_xspi_cdt_pos_datasize = 5U , k_xspi_cdt_pos_cmd = 16U , k_xspi_cdt_mask_cmdsize = 0x3U , k_xspi_cdt_mask_datasize = 0xFU , k_xspi_cdt_mask_cmd = 0xFFFFU , k_xspi_cdt_byte = 0xFFU } |
| Command-descriptor (CDT) field positions / masks (ra8_ospi_regs.h). More... | |
| enum | xspi_ctl_field_t : uint32_t { k_xspi_cdctl0_trreq = 1UL << 0U , k_xspi_ints_cmdcmp = 1UL << 0U , k_xspi_cdbuf_cdt = 0U , k_xspi_cdbuf_addr = 1U , k_xspi_cdbuf_data0 = 2U , k_xspi_cdbuf_data1 = 3U } |
| CDCTL0 / INTS bits + CDBUF slot-0 word indices. More... | |
| enum | xspi_op_t : uint32_t { k_xspi_op_wren = 0x06U , k_xspi_op_pp = 0x02U , k_xspi_op_rdsr = 0x05U , k_xspi_op_rdid = 0x9FU , k_xspi_op_read = 0x03U , k_xspi_op_erase = 0x20U } |
| JEDEC opcodes the engine decodes (ra8_xspi.c). More... | |
| enum | xspi_lit_t : uint32_t { k_xspi_flash_size = 0x4000000UL , k_xspi_sector_len = 0x1000UL , k_xspi_words = 128U , k_xspi_erased = 0xFFU , k_xspi_status_wel = 0x02U , k_xspi_jedec_cdd0 = 0x001A5A9DUL , k_xspi_byte_bits = 8U } |
| Backing-flash + register-window sizing and constants. More... | |
| enum | xspi_order_t : uint32_t { k_xspi_block_order = 95U } |
| Per-tick / report order slot (after the SD block, before SPI). More... | |
Functions | |
| static RA8_INTERNAL uint8_t | internal_xspi_flash_byte (uint32_t addr) |
Current flash content byte at addr (0xFF beyond the part). | |
| static RA8_INTERNAL void | internal_xspi_mark_dirty (uint32_t end_excl) |
Raise the dirty high-water mark to cover [0, end_excl). | |
| static RA8_INTERNAL uint32_t | internal_xspi_cdbuf_word (uint32_t w) |
Word index of CDBUF slot-0 entry w inside the window shadow. | |
| static RA8_INTERNAL uint32_t | internal_xspi_opcode (uint32_t cdt) |
| Extract the 1/2-byte opcode from a CDT descriptor word. | |
| static RA8_INTERNAL void | internal_xspi_do_read (uint32_t addr, uint32_t n) |
Read n bytes (<= 8) from flash@addr into CDD0/CDD1. | |
| static RA8_INTERNAL void | internal_xspi_do_program (uint32_t addr, uint32_t n) |
Page-program n bytes (<= 8) of CDD0/CDD1 into flash@addr (NOR AND). | |
| static RA8_INTERNAL void | internal_xspi_do_erase (uint32_t addr) |
Erase the 4 KiB sector containing addr (restore 0xFF). | |
| static RA8_INTERNAL void | internal_xspi_exec_command (void) |
| Execute the slot-0 manual command, then raise INTS.CMDCMP. | |
| static RA8_INTERNAL void | internal_xspi_reset (void) |
| Reset the xSPI model: zero the window, erase the touched flash prefix. | |
| static RA8_INTERNAL uint64_t | internal_xspi_read (uc_engine *uc, uint64_t addr, unsigned size) |
| MMIO read inside the xSPI window. | |
| static RA8_INTERNAL void | internal_xspi_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value) |
| MMIO write inside the xSPI window (TRREQ kicks; INTC is W1C). | |
| static RA8_INTERNAL void | internal_xspi_report (void) |
| End-of-run xSPI section: op counts (only if the bus was used). | |
| static RA8_INTERNAL void | internal_xspi_block_register (void) |
| Register the xSPI block before main (host constructor). | |
Variables | |
| static xspi_state_t | s_xspi |
| static uint8_t | s_xspi_flash_neg [k_xspi_flash_size] |
| Backing NOR array for the full 64 MiB part, stored INVERTED. | |
| static uint32_t | s_xspi_dirty_hi |
| Exclusive high-water mark of bytes ever programmed/erased this run. | |
| static const board_periph_block_t | s_k_xspi_block |
| xSPI block descriptor (self-registered with the core). | |
Octal-SPI (xSPI) manual-command + NOR-flash peripheral model for ra8_emulator.
Models the RA8D2 XSPI0 manual-command engine (ra8_ospi_regs.h, ra8_xspi.c) at 0x40268000 plus a backing NOR-flash array, so the firmware's real "fill CDBUF, set CDCTL0.TRREQ, poll INTS.CMDCMP, read CDBUF" sequence actually round-trips data. Without this block the xSPI MMIO was unmodeled: flash_journal reached its run budget only because it tolerates the failed ops, while threadx_levelx_demo / threadx_fs_levelx_demo panic-halted inside lx_nor_flash_format (LevelX needs the flash to truly read back what it wrote).
The model decodes the slot-0 command descriptor (CDBUF[0] = CDT, [1] = CDA, [2] = CDD0, [3] = CDD1) on every TRREQ kick:
Definition in file board_periph_xspi.c.
| enum xspi_cdt_field_t : uint32_t |
Command-descriptor (CDT) field positions / masks (ra8_ospi_regs.h).
Definition at line 57 of file board_periph_xspi.c.
| enum xspi_console_t : uint32_t |
Console-tap line buffer capacity for an xSPI command summary.
| Enumerator | |
|---|---|
| k_xspi_console_line_cap | Max chars in an "OSPI .. @0x.." line. |
Definition at line 42 of file board_periph_xspi.c.
| enum xspi_ctl_field_t : uint32_t |
CDCTL0 / INTS bits + CDBUF slot-0 word indices.
Definition at line 68 of file board_periph_xspi.c.
| enum xspi_lit_t : uint32_t |
Backing-flash + register-window sizing and constants.
Definition at line 88 of file board_periph_xspi.c.
| enum xspi_map_t : uint64_t |
XSPI0 register-window geometry (ra8_ospi_regs.h).
Definition at line 47 of file board_periph_xspi.c.
| enum xspi_op_t : uint32_t |
JEDEC opcodes the engine decodes (ra8_xspi.c).
| Enumerator | |
|---|---|
| k_xspi_op_wren | Write enable. |
| k_xspi_op_pp | Page program. |
| k_xspi_op_rdsr | Read status. |
| k_xspi_op_rdid | Read JEDEC ID. |
| k_xspi_op_read | Normal read. |
| k_xspi_op_erase | 4 KiB sector erase. |
Definition at line 78 of file board_periph_xspi.c.
| enum xspi_order_t : uint32_t |
Per-tick / report order slot (after the SD block, before SPI).
| Enumerator | |
|---|---|
| k_xspi_block_order | Report ordering only. |
Definition at line 101 of file board_periph_xspi.c.
|
static |
Register the xSPI block before main (host constructor).
Definition at line 457 of file board_periph_xspi.c.
References board_periph_register_block(), RA8_INTERNAL, and s_k_xspi_block.
|
static |
Word index of CDBUF slot-0 entry w inside the window shadow.
Word index of cdbuf slot-0 entry w inside the window shadow; this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
| [in] | w | W input used by the operation. |
| value | The operation-specific xSPI cdbuf word value. |
Definition at line 193 of file board_periph_xspi.c.
References k_xspi_off_cdbuf, and RA8_INTERNAL.
Referenced by internal_xspi_do_program(), internal_xspi_do_read(), and internal_xspi_exec_command().
|
static |
Erase the 4 KiB sector containing addr (restore 0xFF).
Erase the 4 kib sector containing addr (restore 0xff); this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
| [in] | addr | Guest address involved in the operation. |
Definition at line 295 of file board_periph_xspi.c.
References internal_xspi_mark_dirty(), k_xspi_flash_size, k_xspi_sector_len, memset(), RA8_INTERNAL, s_xspi, and s_xspi_flash_neg.
Referenced by internal_xspi_exec_command().
|
static |
Page-program n bytes (<= 8) of CDD0/CDD1 into flash@addr (NOR AND).
Page-program n bytes (<= 8) of cdd0/cdd1 into flash@addr (nor and); this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
| [in] | addr | Guest address involved in the operation. |
| [in] | n | Number of elements or bytes participating in the operation. |
Definition at line 262 of file board_periph_xspi.c.
References board_console_push(), internal_xspi_cdbuf_word(), internal_xspi_mark_dirty(), k_board_console_ch_ospi, k_xspi_byte_bits, k_xspi_cdbuf_data0, k_xspi_cdbuf_data1, k_xspi_cdt_byte, k_xspi_console_line_cap, k_xspi_flash_size, RA8_INTERNAL, s_xspi, and s_xspi_flash_neg.
Referenced by internal_xspi_exec_command().
|
static |
Read n bytes (<= 8) from flash@addr into CDD0/CDD1.
Read n bytes (<= 8) from flash@addr into cdd0/cdd1; this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
| [in] | addr | Guest address involved in the operation. |
| [in] | n | Number of elements or bytes participating in the operation. |
Definition at line 231 of file board_periph_xspi.c.
References board_console_push(), internal_xspi_cdbuf_word(), internal_xspi_flash_byte(), k_board_console_ch_ospi, k_xspi_byte_bits, k_xspi_cdbuf_data0, k_xspi_cdbuf_data1, k_xspi_console_line_cap, RA8_INTERNAL, and s_xspi.
Referenced by internal_xspi_exec_command().
|
static |
Execute the slot-0 manual command, then raise INTS.CMDCMP.
Execute the slot-0 manual command, then raise ints.cmdcmp; this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
Definition at line 315 of file board_periph_xspi.c.
References internal_xspi_cdbuf_word(), internal_xspi_do_erase(), internal_xspi_do_program(), internal_xspi_do_read(), internal_xspi_opcode(), k_xspi_cdbuf_addr, k_xspi_cdbuf_cdt, k_xspi_cdbuf_data0, k_xspi_cdt_mask_datasize, k_xspi_cdt_pos_datasize, k_xspi_ints_cmdcmp, k_xspi_jedec_cdd0, k_xspi_off_ints, k_xspi_op_erase, k_xspi_op_pp, k_xspi_op_rdid, k_xspi_op_rdsr, k_xspi_op_read, k_xspi_status_wel, RA8_INTERNAL, and s_xspi.
Referenced by internal_xspi_write().
|
static |
Current flash content byte at addr (0xFF beyond the part).
Current flash content byte at addr (0xff beyond the part); this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
| [in] | addr | Guest address involved in the operation. |
| value | The operation-specific xSPI flash byte value. |
Definition at line 158 of file board_periph_xspi.c.
References k_xspi_erased, k_xspi_flash_size, RA8_INTERNAL, and s_xspi_flash_neg.
Referenced by internal_xspi_do_read().
|
static |
Raise the dirty high-water mark to cover [0, end_excl).
Raise the dirty high-water mark to cover [0, end_excl); this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
| [in] | end_excl | End excl input used by the operation. |
Definition at line 175 of file board_periph_xspi.c.
References RA8_INTERNAL, and s_xspi_dirty_hi.
Referenced by internal_xspi_do_erase(), and internal_xspi_do_program().
|
static |
Extract the 1/2-byte opcode from a CDT descriptor word.
Extract the 1/2-byte opcode from a cdt descriptor word; this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
| [in] | cdt | Cdt input used by the operation. |
| value | The operation-specific xSPI opcode value. |
Definition at line 209 of file board_periph_xspi.c.
References k_xspi_byte_bits, k_xspi_cdt_byte, k_xspi_cdt_mask_cmd, k_xspi_cdt_mask_cmdsize, k_xspi_cdt_pos_cmd, k_xspi_cdt_pos_cmdsize, and RA8_INTERNAL.
Referenced by internal_xspi_exec_command().
|
static |
MMIO read inside the xSPI window.
MMIO read inside the xspi window; this step is contained within the board periph xSPI 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 xSPI read value. |
Definition at line 378 of file board_periph_xspi.c.
References k_xspi_base, k_xspi_words, RA8_INTERNAL, and s_xspi.
|
static |
End-of-run xSPI section: op counts (only if the bus was used).
End-of-run xspi section: op counts (only if the bus was used); this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
Definition at line 432 of file board_periph_xspi.c.
References priv_emu_io_errf(), RA8_INTERNAL, and s_xspi.
|
static |
Reset the xSPI model: zero the window, erase the touched flash prefix.
Reset the xspi model: zero the window, erase the touched flash prefix; this step is contained within the board periph xSPI model and uses bounded caller or module-owned storage.
Definition at line 353 of file board_periph_xspi.c.
References memset(), RA8_INTERNAL, s_xspi, s_xspi_dirty_hi, and s_xspi_flash_neg.
|
static |
MMIO write inside the xSPI window (TRREQ kicks; INTC is W1C).
MMIO write inside the xspi window (trreq kicks; intc is w1c); this step is contained within the board periph xSPI 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 402 of file board_periph_xspi.c.
References internal_xspi_exec_command(), k_xspi_base, k_xspi_cdctl0_trreq, k_xspi_off_cdctl0, k_xspi_off_intc, k_xspi_off_ints, k_xspi_words, and s_xspi.
|
static |
xSPI block descriptor (self-registered with the core).
Definition at line 444 of file board_periph_xspi.c.
Referenced by internal_xspi_block_register().
|
static |
Definition at line 113 of file board_periph_xspi.c.
Referenced by internal_xspi_do_erase(), internal_xspi_do_program(), internal_xspi_do_read(), internal_xspi_exec_command(), internal_xspi_read(), internal_xspi_report(), internal_xspi_reset(), and internal_xspi_write().
|
static |
Exclusive high-water mark of bytes ever programmed/erased this run.
Lets internal_xspi_reset restore only the touched prefix of the 64 MiB array instead of sweeping (and thereby committing) all of it on every warm reboot of the emulator.
Definition at line 145 of file board_periph_xspi.c.
Referenced by internal_xspi_mark_dirty(), and internal_xspi_reset().
|
static |
Backing NOR array for the full 64 MiB part, stored INVERTED.
Each byte holds the bitwise complement of the flash content, so the all-zero BSS image IS the erased (0xFF) part: a fresh ra8_emulator process pays no resident memory for the 64 MiB until a sector is actually programmed or erased (the zero page is never dirtied by reads). NOR semantics translate directly: page-program clears flash bits = SETS stored bits (OR), sector erase restores 0xFF = clears stored bytes to 0.
Definition at line 132 of file board_periph_xspi.c.
Referenced by internal_xspi_do_erase(), internal_xspi_do_program(), internal_xspi_flash_byte(), and internal_xspi_reset().