|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
VBATT backup-register (VBTBKRn) reset-retained domain model. More...
#include <stdint.h>#include <stdio.h>#include "board_periph_block.h"#include "board_periph_prcr_internal.h"#include "emu_host_io_internal.h"Go to the source code of this file.
Data Structures | |
| struct | bkup_ctrl_t |
| VBATT control state (cleared by a reset; data is not). More... | |
Enumerations | |
| enum | bkup_geom_t : uint64_t { k_bkup_base = 0x4001EC40UL , k_bkup_span = 0x180UL , k_bkup_off_vbtber = 0x000UL , k_bkup_off_vbtbkr0 = 0x0C0UL , k_bkup_reg_count = 128UL } |
| VBATT backup window geometry (ra8_bkup_regs.h). More... | |
| enum | bkup_vbtber_mask_t : uint8_t { k_bkup_vbtber_mask_vbae = 0x08U , k_bkup_vbtber_reset = 0x08U } |
| VBTBER field masks (HUM Ch 12.2.6 p 504). More... | |
| enum | bkup_order_t : uint32_t { k_bkup_block_order = 175U } |
| Per-tick order slot for the VBATT-backup block (relative order). More... | |
Functions | |
| static void | internal_bkup_reset (void) |
| Reset only the VBATT control state; the backup bytes are retained. | |
| static uint64_t | internal_bkup_read (uc_engine *uc, uint64_t addr, unsigned size) |
| MMIO read inside the VBATT backup window (width-aware). | |
| static void | internal_bkup_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value) |
| MMIO write inside the VBATT backup window (width-aware). | |
| static void | internal_bkup_report (void) |
| End-of-run VBATT-backup section: writes accepted / dropped this run. | |
| static void | internal_bkup_block_register (void) |
| Register the VBATT-backup block before main (host constructor). | |
Variables | |
| static uint8_t | s_bkup_vbtbkr [k_bkup_reg_count] |
| Retained VBTBKRn bytes – the battery-backed domain. | |
| static bkup_ctrl_t | s_bkup |
| static const board_periph_block_t | s_k_bkup_block |
| VBATT-backup block descriptor (self-registered with the core). | |
VBATT backup-register (VBTBKRn) reset-retained domain model.
Models the RA8D2 VBATT backup registers (ra8_bkup_regs.h, ra8_bkup.c) as a reset-retained power domain, so bkup_survival_demo can prove that backup state survives a CPU reset. The 128 VBTBKRn bytes (32 x 32-bit words) live in the R_SYSTEM block at 0x4001ED00; on silicon they keep their contents across a reset (and, with a battery on VBATT, across a power cycle). The sparse fallback treated them as ordinary peripheral memory that cleared on every run, so the demo's sentinel was never found and it reported survived=N.
This block claims the VBTBKRn window plus the access-enable byte (VBTBER, 0xC40) and holds the 128 backup bytes in a host-static buffer that the block's reset hook deliberately does NOT clear. The ra8_emulator run loop's --reboot path re-runs the firmware from its reset vector after resetting the peripheral blocks; because this block preserves the backup bytes across that reset, the second boot finds the sentinel intact – exactly the reset-survival contract. The bytes clear only at process start (static zero-initialisation), modelling the first-ever boot with a dead battery.
Two silicon preconditions gate a VBTBKRn write, and both are modelled here:
0x00000000; after PRCR = 0xA502 the identical write sticks.VBTBER resets to 0x08 (VBAE = 1) per its "Value after reset" row in HUM Ch 12.2.6 p 504, matching a J-Link read of a live board, so VBAE alone never blocks a first write – which is precisely why modelling only VBAE left the emulator green while the bench was red. Writes to VBTBER itself are PRC1-gated too, so firmware that clears VBAE without unlocking does not change it, exactly as on silicon.
A write dropped for either reason is counted in dropped and named in the end-of-run report, so the cause is visible rather than inferred from a failing banner. Reads always return the retained byte (PRCR gates writes only, HUM Ch 13.1 p 520).
The earlier revision of this file blamed the OFS1.PVDAS option byte for the #131 divergence and declared it unmodelable. That was wrong: PVDAS governs the battery power-supply switch (HUM Ch 12.3.2 p 514), not register access, and on the EK-RA8D2 – where VBATT is tied to VCC and the switch is stopped – the backup registers read and write correctly with the default OFS1 once PRC1 is unlocked. Bench-proven: rw=ok survived=Y.
Definition in file board_periph_bkup.c.
| enum bkup_geom_t : uint64_t |
VBATT backup window geometry (ra8_bkup_regs.h).
Definition at line 69 of file board_periph_bkup.c.
| enum bkup_order_t : uint32_t |
Per-tick order slot for the VBATT-backup block (relative order).
| Enumerator | |
|---|---|
| k_bkup_block_order | After the LVD block; report order. |
Definition at line 84 of file board_periph_bkup.c.
| enum bkup_vbtber_mask_t : uint8_t |
VBTBER field masks (HUM Ch 12.2.6 p 504).
| Enumerator | |
|---|---|
| k_bkup_vbtber_mask_vbae | VBAE @ bit 3: 1 = enable VBTBKRn access. |
| k_bkup_vbtber_reset | "Value after reset" row: VBAE = 1. |
Definition at line 78 of file board_periph_bkup.c.
|
static |
Register the VBATT-backup block before main (host constructor).
Definition at line 251 of file board_periph_bkup.c.
References board_periph_register_block(), RA8_INTERNAL, and s_k_bkup_block.
|
static |
MMIO read inside the VBATT backup window (width-aware).
MMIO read inside the vbatt backup window (width-aware); this step is contained within the board periph bkup 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 bkup read value. |
Definition at line 140 of file board_periph_bkup.c.
References k_bkup_base, k_bkup_off_vbtber, k_bkup_off_vbtbkr0, k_bkup_reg_count, RA8_INTERNAL, s_bkup, and s_bkup_vbtbkr.
|
static |
End-of-run VBATT-backup section: writes accepted / dropped this run.
End-of-run vbatt-backup section: writes accepted / dropped this run; this step is contained within the board periph bkup model and uses bounded caller or module-owned storage.
Definition at line 213 of file board_periph_bkup.c.
References priv_emu_io_errf(), RA8_INTERNAL, and s_bkup.
|
static |
Reset only the VBATT control state; the backup bytes are retained.
Reset only the vbatt control state; the backup bytes are retained; this step is contained within the board periph bkup model and uses bounded caller or module-owned storage.
Definition at line 115 of file board_periph_bkup.c.
References k_bkup_vbtber_reset, RA8_INTERNAL, and s_bkup.
|
static |
MMIO write inside the VBATT backup window (width-aware).
MMIO write inside the vbatt backup window (width-aware); this step is contained within the board periph bkup 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 171 of file board_periph_bkup.c.
References k_bkup_base, k_bkup_off_vbtber, k_bkup_off_vbtbkr0, k_bkup_reg_count, k_bkup_vbtber_mask_vbae, k_board_prcr_grp1_lpm, priv_board_prcr_group_unlocked(), s_bkup, and s_bkup_vbtbkr.
|
static |
Definition at line 105 of file board_periph_bkup.c.
Referenced by internal_bkup_read(), internal_bkup_report(), internal_bkup_reset(), and internal_bkup_write().
|
static |
Retained VBTBKRn bytes – the battery-backed domain.
Survives a peripheral reset (the block's reset hook leaves it untouched), so a --reboot re-run finds the prior boot's contents intact. Clears only at process start (static zero-init): the first-ever boot.
Definition at line 95 of file board_periph_bkup.c.
Referenced by internal_bkup_read(), and internal_bkup_write().
|
static |
VBATT-backup block descriptor (self-registered with the core).
Definition at line 238 of file board_periph_bkup.c.
Referenced by internal_bkup_block_register().