|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
CAC (Clock Frequency Accuracy Measurement) edge-counter model. More...
#include <stdint.h>#include <stdio.h>#include "board_periph_block.h"#include "emu_host_io_internal.h"Go to the source code of this file.
Data Structures | |
| struct | cac_state_t |
| CAC register state. More... | |
Enumerations | |
| enum | cac_geom_t : uint64_t { k_cac_base = 0x40202400UL , k_cac_span = 0x10UL , k_cac_off_cacr0 = 0x00UL , k_cac_off_caicr = 0x03UL , k_cac_off_castr = 0x04UL , k_cac_off_caulvr = 0x06UL , k_cac_off_callvr = 0x08UL , k_cac_off_cacntbr = 0x0AUL } |
| CAC block geometry (ra8_cac_regs.h, r_cac_regs_t). More... | |
| enum | cac_field_t : uint8_t { k_cac_cacr0_cfme = 0x01U , k_cac_castr_ferrf = 0x01U , k_cac_castr_mendf = 0x02U , k_cac_castr_ovff = 0x04U , k_cac_caicr_ferrfcl = 0x10U , k_cac_caicr_mendfcl = 0x20U , k_cac_caicr_ovffcl = 0x40U } |
| CACR0 / CASTR / CAICR field masks (ra8_cac.c). More... | |
| enum | cac_order_t : uint32_t { k_cac_block_order = 165U } |
| Per-tick order slot for the CAC block (relative order only). More... | |
Functions | |
| static RA8_INTERNAL void | internal_cac_measure (void) |
| Complete one measurement: latch an in-window count and set MENDF. | |
| static RA8_INTERNAL void | internal_cac_reset (void) |
| Reset the CAC model to power-on state. | |
| static RA8_INTERNAL uint64_t | internal_cac_read (uc_engine *uc, uint64_t addr, unsigned size) |
| MMIO read inside the CAC window. | |
| static RA8_INTERNAL void | internal_cac_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value) |
| MMIO write inside the CAC window. | |
| static RA8_INTERNAL void | internal_cac_report (void) |
| End-of-run CAC section: measurements + last count and window. | |
| static RA8_INTERNAL void | internal_cac_block_register (void) |
| Register the CAC block before main (host constructor). | |
Variables | |
| static cac_state_t | s_cac |
| static const board_periph_block_t | s_k_cac_block |
| CAC block descriptor (self-registered with the core). | |
CAC (Clock Frequency Accuracy Measurement) edge-counter model.
Models the RA8D2 CAC (ra8_cac_regs.h, ra8_cac.c) at 0x40202400 so a frequency-accuracy measurement actually completes with an in-window edge count, instead of the status flag never asserting. Against the sparse fallback cac_accuracy_demo started a measurement (CACR0.CFME = 1) but CASTR.MENDF never set, so ra8_cac_measure timed out and the banner reported meas=TIMEOUT. This block latches MENDF on the start write and returns a count inside the programmed [CALLVR, CAULVR] window, so the measurement completes with FERRF / OVFF clear and the banner reports ok=Y.
The CAC counts edges of a measurement-target clock during one reference period and sets CASTR.FERRF when the count falls outside the upper / lower limit registers. The board emulator has no real clocks to count, so rather than invent an edge rate it reports the midpoint of the firmware's own programmed window: that is in-band by construction, so the genuine driver path (start -> poll MENDF -> read CACNTBR -> check FERRF) sees a healthy measurement exactly as a correctly-tuned crystal would on silicon.
Sequence modelled (HUM Ch 10.2):
CACR0 (+0x00) CFME bit starts a measurement. On a CFME=1 write the model loads CACNTBR with the [CALLVR, CAULVR] midpoint and sets CASTR.MENDF (FERRF / OVFF stay clear). A CFME=0 write stops it.CASTR (+0x04) exposes MENDF / FERRF / OVFF; the driver's CAICR clear bits (FERRFCL / MENDFCL / OVFFCL, +4 in CAICR) clear the matching flags.CAULVR (+0x06) / CALLVR (+0x08) are the window limits the driver programmes; CACNTBR (+0x0A) is the latched count it reads back.Definition in file board_periph_cac.c.
| enum cac_field_t : uint8_t |
CACR0 / CASTR / CAICR field masks (ra8_cac.c).
Definition at line 57 of file board_periph_cac.c.
| enum cac_geom_t : uint64_t |
CAC block geometry (ra8_cac_regs.h, r_cac_regs_t).
Definition at line 45 of file board_periph_cac.c.
| enum cac_order_t : uint32_t |
Per-tick order slot for the CAC block (relative order only).
| Enumerator | |
|---|---|
| k_cac_block_order | After the DRW block; report order. |
Definition at line 68 of file board_periph_cac.c.
|
static |
Register the CAC block before main (host constructor).
Definition at line 225 of file board_periph_cac.c.
References board_periph_register_block(), RA8_INTERNAL, and s_k_cac_block.
|
static |
Complete one measurement: latch an in-window count and set MENDF.
Complete one measurement: latch an in-window count and set mendf; this step is contained within the board periph cac model and uses bounded caller or module-owned storage.
Definition at line 92 of file board_periph_cac.c.
References k_cac_castr_mendf, RA8_INTERNAL, and s_cac.
Referenced by internal_cac_write().
|
static |
MMIO read inside the CAC window.
MMIO read inside the cac window; this step is contained within the board periph cac 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 cac read value. |
Definition at line 127 of file board_periph_cac.c.
References k_cac_base, k_cac_off_cacntbr, k_cac_off_cacr0, k_cac_off_callvr, k_cac_off_castr, k_cac_off_caulvr, RA8_INTERNAL, and s_cac.
|
static |
End-of-run CAC section: measurements + last count and window.
End-of-run cac section: measurements + last count and window; this step is contained within the board periph cac model and uses bounded caller or module-owned storage.
Definition at line 199 of file board_periph_cac.c.
References priv_emu_io_errf(), RA8_INTERNAL, and s_cac.
|
static |
Reset the CAC model to power-on state.
Reset the cac model to power-on state; this step is contained within the board periph cac model and uses bounded caller or module-owned storage.
Definition at line 109 of file board_periph_cac.c.
References RA8_INTERNAL, and s_cac.
|
static |
MMIO write inside the CAC window.
MMIO write inside the cac window; this step is contained within the board periph cac 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 163 of file board_periph_cac.c.
References internal_cac_measure(), k_cac_base, k_cac_cacr0_cfme, k_cac_caicr_ferrfcl, k_cac_caicr_mendfcl, k_cac_caicr_ovffcl, k_cac_castr_ferrf, k_cac_castr_mendf, k_cac_castr_ovff, k_cac_off_cacr0, k_cac_off_caicr, k_cac_off_callvr, k_cac_off_caulvr, and s_cac.
|
static |
Definition at line 82 of file board_periph_cac.c.
Referenced by internal_cac_measure(), internal_cac_read(), internal_cac_report(), internal_cac_reset(), and internal_cac_write().
|
static |
CAC block descriptor (self-registered with the core).
Definition at line 212 of file board_periph_cac.c.
Referenced by internal_cac_block_register().