ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_periph_lvd.c File Reference

LVD / PVD voltage-monitor status model for ra8_emulator. More...

#include <stdint.h>
#include <stdio.h>
#include "board_periph_block.h"
#include "emu_host_io_internal.h"
Include dependency graph for board_periph_lvd.c:

Go to the source code of this file.

Data Structures

struct  lvd_state_t
 PVD control-byte shadows (status bytes are synthesised). More...

Enumerations

enum  lvd_geom_t : uint64_t {
  k_lvd_base = 0x4001E0E0UL ,
  k_lvd_span = 0x04UL ,
  k_lvd_off_pvd1cr1 = 0x00UL ,
  k_lvd_off_pvd1sr = 0x01UL ,
  k_lvd_off_pvd2cr1 = 0x02UL ,
  k_lvd_off_pvd2sr = 0x03UL
}
 PVD status-window geometry (ra8_lvd_regs.h). More...
enum  lvd_field_t : uint8_t {
  k_lvd_sr_det = 0x01U ,
  k_lvd_sr_mon = 0x02U ,
  k_lvd_sr_healthy = 0x02U
}
 PVDmSR field masks + the healthy-rail status value (ra8_lvd.c). More...
enum  lvd_order_t : uint32_t { k_lvd_block_order = 170U }
 Per-tick order slot for the LVD block (relative order only). More...

Functions

static RA8_INTERNAL void internal_lvd_reset (void)
 Reset the LVD model to power-on state.
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_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
 MMIO write inside the PVD status window.
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).

Variables

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).

Detailed Description

LVD / PVD voltage-monitor status model for ra8_emulator.

Models the RA8D2 low-voltage detection status registers (ra8_lvd_regs.h, ra8_lvd.c) so a VCC monitor reports a healthy rail, instead of the status reading back zero. Against the sparse fallback lvd_monitor_demo configured PVD1 (threshold 2.80 V) but PVD1SR.MON read back 0, so the banner reported mon=below ok=N – the opposite of a healthy 3.3 V board. This block makes PVD1SR.MON (and PVD2SR.MON) read "above threshold" with the latched-crossing flag DET clear, so the banner reports mon=above ok=Y – the reading a correctly-powered EK-RA8D2 gives.

The PVD status registers live inside the R_SYSTEM block; this model claims only the four-byte window holding PVD1CR1 / PVD1SR / PVD2CR1 / PVD2SR (0x4001E0E0..0x4001E0E3), leaving the rest of R_SYSTEM (clock-generator bring-up, etc.) to the sparse fallback. The control bytes (PVD1CR1 / PVD2CR1) shadow their writes so the driver's read-back succeeds; the status bytes (PVD1SR / PVD2SR) always report MON = above, DET = 0. A write to a status byte with DET = 0 is honoured (the driver clears DET write-0-to-clear); MON is read-only live state and stays asserted.

The emulator has no analog rail to compare, so reporting "above" is the faithful steady state for a powered board – the genuine driver path (ra8_lvd_get_status reading PVD1SR.MON / .DET) sees exactly what a healthy 3.3 V supply yields on silicon.

Since
0.1.0

Definition in file board_periph_lvd.c.

Enumeration Type Documentation

◆ lvd_field_t

enum lvd_field_t : uint8_t

PVDmSR field masks + the healthy-rail status value (ra8_lvd.c).

Enumerator
k_lvd_sr_det 

DET latched threshold-crossing (bit 0).

k_lvd_sr_mon 

MON live "VCC above Vdetm" flag (bit 1).

k_lvd_sr_healthy 

MON = above, DET = 0: a healthy rail.

Definition at line 51 of file board_periph_lvd.c.

◆ lvd_geom_t

enum lvd_geom_t : uint64_t

PVD status-window geometry (ra8_lvd_regs.h).

Enumerator
k_lvd_base 

PVD1CR1 .

. PVD2SR window base.

k_lvd_span 

PVD1CR1/PVD1SR/PVD2CR1/PVD2SR.

k_lvd_off_pvd1cr1 

PVD1CR1 control (8b).

k_lvd_off_pvd1sr 

PVD1SR status (8b).

k_lvd_off_pvd2cr1 

PVD2CR1 control (8b).

k_lvd_off_pvd2sr 

PVD2SR status (8b).

Definition at line 41 of file board_periph_lvd.c.

◆ lvd_order_t

enum lvd_order_t : uint32_t

Per-tick order slot for the LVD block (relative order only).

Enumerator
k_lvd_block_order 

After the CAC block; report order.

Definition at line 58 of file board_periph_lvd.c.

Function Documentation

◆ internal_lvd_block_register()

RA8_INTERNAL void internal_lvd_block_register ( void )
static

Register the LVD status window before main (host constructor).

Definition at line 171 of file board_periph_lvd.c.

References board_periph_register_block(), RA8_INTERNAL, and s_k_lvd_block.

◆ internal_lvd_read()

RA8_INTERNAL uint64_t internal_lvd_read ( uc_engine * uc,
uint64_t addr,
unsigned size )
static

MMIO read inside the PVD status window.

MMIO read inside the pvd status window; this step is contained within the board periph lvd model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
Returns
The lvd read result produced by the board periph lvd model.
Return values
valueThe operation-specific lvd read value.
Precondition
Arguments satisfy the ranges documented for lvd read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph lvd model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 97 of file board_periph_lvd.c.

References k_lvd_base, k_lvd_off_pvd1cr1, k_lvd_off_pvd1sr, k_lvd_off_pvd2cr1, k_lvd_off_pvd2sr, k_lvd_sr_healthy, RA8_INTERNAL, and s_lvd.

◆ internal_lvd_report()

RA8_INTERNAL void internal_lvd_report ( void )
static

End-of-run LVD section: status reads served.

End-of-run lvd section: status reads served; this step is contained within the board periph lvd model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for lvd report.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph lvd model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 149 of file board_periph_lvd.c.

References priv_emu_io_errf(), RA8_INTERNAL, and s_lvd.

◆ internal_lvd_reset()

RA8_INTERNAL void internal_lvd_reset ( void )
static

Reset the LVD model to power-on state.

Reset the lvd model to power-on state; this step is contained within the board periph lvd model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for lvd reset.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph lvd model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 79 of file board_periph_lvd.c.

References RA8_INTERNAL, and s_lvd.

◆ internal_lvd_write()

RA8_INTERNAL void internal_lvd_write ( uc_engine * uc,
uint64_t addr,
unsigned size,
uint64_t value )
static

MMIO write inside the PVD status window.

MMIO write inside the pvd status window; this step is contained within the board periph lvd model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
[in]valueRegister or payload value involved in the operation.
Precondition
Arguments satisfy the ranges documented for lvd write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph lvd model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 128 of file board_periph_lvd.c.

References k_lvd_base, k_lvd_off_pvd1cr1, k_lvd_off_pvd2cr1, and s_lvd.

Variable Documentation

◆ s_k_lvd_block

const board_periph_block_t s_k_lvd_block
static
Initial value:
= {
.base = (uint64_t)k_lvd_base,
.span = (uint64_t)k_lvd_span,
.order = (uint32_t)k_lvd_block_order,
.tick = nullptr,
.name = "LVD/PVD",
}
@ k_lvd_span
PVD1CR1/PVD1SR/PVD2CR1/PVD2SR.
@ 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.
@ 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_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
MMIO write inside the PVD status window.
-proof

LVD status-window descriptor (self-registered with the core).

Definition at line 158 of file board_periph_lvd.c.

Referenced by internal_lvd_block_register().

◆ s_lvd