ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_periph_lvd.c
Go to the documentation of this file.
1
33
34#include <stdint.h>
35#include <stdio.h>
36
37#include "board_periph_block.h"
39
41typedef enum : uint64_t {
42 k_lvd_base = 0x4001E0E0UL,
43 k_lvd_span = 0x04UL,
49
51typedef enum : uint8_t {
52 k_lvd_sr_det = 0x01U,
53 k_lvd_sr_mon = 0x02U,
56
58typedef enum : uint32_t {
61
63typedef struct {
64 uint8_t pvd1cr1;
65 uint8_t pvd2cr1;
66 uint32_t reads;
68
70
80{
81 s_lvd = (lvd_state_t){};
82}
83
97RA8_INTERNAL static uint64_t internal_lvd_read(uc_engine* uc, uint64_t addr, unsigned size)
98{
99 (void)uc;
100 (void)size;
101 const uint64_t off = addr - (uint64_t)k_lvd_base;
102 if (off == (uint64_t)k_lvd_off_pvd1cr1) {
103 return s_lvd.pvd1cr1;
104 }
105 if (off == (uint64_t)k_lvd_off_pvd2cr1) {
106 return s_lvd.pvd2cr1;
107 }
108 if ((off == (uint64_t)k_lvd_off_pvd1sr) || (off == (uint64_t)k_lvd_off_pvd2sr)) {
109 s_lvd.reads++;
110 return (uint64_t)k_lvd_sr_healthy; /* MON = above, DET = 0. */
111 }
112 return 0U;
113}
114
127RA8_INTERNAL static void
128internal_lvd_write(uc_engine* uc, uint64_t addr, unsigned size, uint64_t value)
129{
130 (void)uc;
131 (void)size;
132 const uint64_t off = addr - (uint64_t)k_lvd_base;
133 if (off == (uint64_t)k_lvd_off_pvd1cr1) {
134 s_lvd.pvd1cr1 = (uint8_t)value;
135 } else if (off == (uint64_t)k_lvd_off_pvd2cr1) {
136 s_lvd.pvd2cr1 = (uint8_t)value;
137 }
138 /* PVDmSR writes (DET write-0-to-clear) are absorbed: MON stays "above". */
139}
140
150{
151 if (s_lvd.reads == 0U) {
152 return; /* Untouched: stay quiet. */
153 }
154 (void)priv_emu_io_errf(" LVD/PVD : status reads=%u (MON=above, DET=0)\n", s_lvd.reads);
155}
156
159 .base = (uint64_t)k_lvd_base,
160 .span = (uint64_t)k_lvd_span,
161 .order = (uint32_t)k_lvd_block_order,
162 .read = internal_lvd_read,
164 .tick = nullptr,
165 .reset = internal_lvd_reset,
166 .report = internal_lvd_report,
167 .name = "LVD/PVD",
168};
169
171[[gnu::constructor]] RA8_INTERNAL static void internal_lvd_block_register(void)
172{
174}
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.
lvd_geom_t
PVD status-window geometry (ra8_lvd_regs.h).
@ k_lvd_off_pvd1sr
PVD1SR status (8b).
@ k_lvd_off_pvd2sr
PVD2SR status (8b).
@ k_lvd_off_pvd2cr1
PVD2CR1 control (8b).
@ k_lvd_span
PVD1CR1/PVD1SR/PVD2CR1/PVD2SR.
@ k_lvd_off_pvd1cr1
PVD1CR1 control (8b).
@ k_lvd_base
PVD1CR1 .
static RA8_INTERNAL uint64_t internal_lvd_read(uc_engine *uc, uint64_t addr, unsigned size)
MMIO read inside the PVD status window.
static RA8_INTERNAL void internal_lvd_reset(void)
Reset the LVD model to power-on state.
lvd_field_t
PVDmSR field masks + the healthy-rail status value (ra8_lvd.c).
@ k_lvd_sr_mon
MON live "VCC above Vdetm" flag (bit 1).
@ k_lvd_sr_healthy
MON = above, DET = 0: a healthy rail.
@ k_lvd_sr_det
DET latched threshold-crossing (bit 0).
lvd_order_t
Per-tick order slot for the LVD block (relative order only).
@ k_lvd_block_order
After the CAC block; report order.
static RA8_INTERNAL void internal_lvd_report(void)
End-of-run LVD section: status reads served.
static RA8_INTERNAL void internal_lvd_block_register(void)
Register the LVD status window before main (host constructor).
static RA8_INTERNAL void internal_lvd_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
MMIO write inside the PVD status window.
static lvd_state_t s_lvd
static const board_periph_block_t s_k_lvd_block
LVD status-window descriptor (self-registered with the core).
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
#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.
PVD control-byte shadows (status bytes are synthesised).
uint8_t pvd2cr1
PVD2CR1 control shadow.
uint8_t pvd1cr1
PVD1CR1 control shadow.
uint32_t reads
Status reads served (report).