ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_periph_prcr.c
Go to the documentation of this file.
1
37
38#include <stdint.h>
39#include <stdio.h>
40
41#include "board_periph_block.h"
44#include "ra8_attributes.h"
45
47typedef enum : uint64_t {
48 k_prcr_base = 0x4001E3FAUL,
49 k_prcr_span = 0x2UL,
51
53typedef enum : uint16_t {
54 k_prcr_key_mask = 0xFF00U,
55 k_prcr_key_value = 0xA500U,
58
60typedef enum : uint32_t {
63
67typedef struct {
68 uint16_t groups;
69 uint32_t unlocks;
70 uint32_t bad_key;
72
74
86{
87 s_prcr = (prcr_state_t){};
88}
89
91{
92 return (uint16_t)(s_prcr.groups & group_mask) == group_mask;
93}
94
111RA8_INTERNAL static uint64_t internal_prcr_read(uc_engine* uc, uint64_t addr, unsigned size)
112{
113 (void)uc;
114 (void)addr;
115 (void)size;
116 return 0U;
117}
118
136RA8_INTERNAL static void
137internal_prcr_write(uc_engine* uc, uint64_t addr, unsigned size, uint64_t value)
138{
139 (void)uc;
140 (void)addr;
141 (void)size;
142 const uint16_t word = (uint16_t)value;
143 if ((uint16_t)(word & (uint16_t)k_prcr_key_mask) != (uint16_t)k_prcr_key_value) {
144 s_prcr.bad_key++;
145 return;
146 }
147 s_prcr.groups = (uint16_t)(word & (uint16_t)k_prcr_group_mask);
148 if (s_prcr.groups != 0U) {
149 s_prcr.unlocks++;
150 }
151}
152
162{
163 if (s_prcr.bad_key != 0U) {
164 /* Loud: a PRCR write without the 0xA5 key unlocks nothing on silicon. */
165 (void)priv_emu_io_errf(
166 " SYSC-PRCR : unlocks=%u REJECTED=%u (missing 0xA5 key in PRKEY[7:0])\n",
167 s_prcr.unlocks,
168 s_prcr.bad_key);
169 return;
170 }
171 if (s_prcr.unlocks == 0U) {
172 return; /* Untouched: stay quiet. */
173 }
174 (void)priv_emu_io_errf(" SYSC-PRCR : unlocks=%u\n", s_prcr.unlocks);
175}
176
179 .base = (uint64_t)k_prcr_base,
180 .span = (uint64_t)k_prcr_span,
181 .order = (uint32_t)k_prcr_block_order,
182 .read = internal_prcr_read,
184 .tick = nullptr,
185 .reset = internal_prcr_reset,
186 .report = internal_prcr_report,
187 .name = "SYSC-PRCR",
188 .observe = true,
189};
190
192[[gnu::constructor]] RA8_INTERNAL static void internal_prcr_block_register(void)
193{
195}
Decentralized peripheral-block registry for the board emulator core.
void board_periph_register_block(const board_periph_block_t *block)
Register a peripheral block's descriptor with the core registry.
static uint64_t internal_prcr_read(uc_engine *uc, uint64_t addr, unsigned size)
MMIO read stub – never called for an observe-only block.
prcr_order_t
Per-tick order slot for the PRCR block (relative order).
@ k_prcr_block_order
Just before the VBATT-backup block.
static void internal_prcr_reset(void)
Return PRCR to its power-on state: every group locked.
prcr_mask_t
PRCR field masks (HUM Ch 13.2.1 p 522).
@ k_prcr_group_mask
PRC0/1/3/4/5; bit 2 + 7:6 reserved.
@ k_prcr_key_mask
PRKEY[7:0] lives in bits 15:8.
@ k_prcr_key_value
Mandatory 0xA5 write key.
static void internal_prcr_block_register(void)
Register the PRCR block before main (host constructor).
static prcr_state_t s_prcr
static void internal_prcr_report(void)
End-of-run PRCR section: unlock traffic and any key mistakes.
static const board_periph_block_t s_k_prcr_block
PRCR block descriptor (observe-only: snoops, does not own).
bool priv_board_prcr_group_unlocked(uint16_t group_mask)
Report whether every bit in group_mask is currently unlocked.
prcr_geom_t
PRCR window geometry (HUM Ch 13.2.1 p 522).
@ k_prcr_span
One 16-bit register.
@ k_prcr_base
PRCR_S: SYSC base 0x4001_E000 + 0x3FA.
static void internal_prcr_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
Snoop a PRCR write and update the retained group mask.
Module-private PRCR unlock state shared with the protected blocks.
Bounded raw-descriptor I/O seam for the RA8 emulator.
emu_io_result_t priv_emu_io_errf(const char *format,...)
Format bounded text and write it to the injected error descriptor.
-proof
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
A modelled peripheral block's self-description for the core registry.
Live PRCR group-unlock mask, and the counters behind the report.
uint32_t bad_key
Writes discarded for carrying a wrong key.
uint32_t unlocks
Keyed writes that enabled >= 1 group.
uint16_t groups
Currently write-enabled group bits.