|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Realtime Clock (RTC) calendar peripheral-block model for ra8_emulator. 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 | rtc_state_t |
| The modelled RTC: a control-register shadow + a binary time mirror. More... | |
Enumerations | |
| enum | rtc_lit_t : uint32_t { k_bcd_base = 10U , k_bcd_shift = 4U , k_nibble_mask = 0x0FU , k_year_mod = 100U , k_year_base = 2000U } |
| BCD packing + calendar constants for the RTC model. More... | |
| enum | rtc_order_t : uint32_t { k_rtc_block_order = 60U } |
| Per-tick order slot for the RTC block. More... | |
| enum | rtc_geom_t : uint64_t { k_rtc_base = 0x40202000UL , k_rtc_span = 0x80UL } |
| RTC register window geometry (ra8_rtc_regs.h). More... | |
| enum | rtc_off_t : uint64_t { k_rtc_off_r64cnt = 0x00UL , k_rtc_off_rseccnt = 0x02UL , k_rtc_off_rmincnt = 0x04UL , k_rtc_off_rhrcnt = 0x06UL , k_rtc_off_rwkcnt = 0x08UL , k_rtc_off_rdaycnt = 0x0AUL , k_rtc_off_rmoncnt = 0x0CUL , k_rtc_off_ryrcnt = 0x0EUL , k_rtc_off_rsecar = 0x10UL , k_rtc_off_rminar = 0x12UL , k_rtc_off_rhrar = 0x14UL , k_rtc_off_rwkar = 0x16UL , k_rtc_off_rdayar = 0x18UL , k_rtc_off_rmonar = 0x1AUL , k_rtc_off_ryrar = 0x1CUL , k_rtc_off_ryraren = 0x1EUL , k_rtc_off_rcr1 = 0x22UL , k_rtc_off_rcr2 = 0x24UL , k_rtc_off_rcr4 = 0x28UL } |
| RTC register byte offsets (subset the driver touches). More... | |
| enum | rtc_bit_t : uint8_t { k_rtc_rcr1_aie = 0x01U , k_rtc_rcr1_pie = 0x04U , k_rtc_rcr2_start = 0x01U , k_rtc_alarm_enb = 0x80U , k_rtc_alarm_val = 0x7FU } |
| RCR1 / RCR2 bit masks (ra8_rtc_regs.h, ra8_rtc.h). More... | |
| enum | rtc_calendar_t : uint32_t { k_rtc_secs_per_min = 60U , k_rtc_mins_per_hour = 60U , k_rtc_hours_per_day = 24U , k_rtc_days_per_mon = 28U , k_rtc_mons_per_year = 12U , k_rtc_ticks_per_sec = 8U } |
| Calendar moduli + the modelled time:tick ratio. More... | |
| enum | rtc_r64_t : uint8_t { k_rtc_r64_mask = 0x3FU } |
| 64 Hz counter range (R64CNT is 6 bits). More... | |
| enum | rtc_event_t : uint16_t { k_rtc_event_alarm = 0x0BBU , k_rtc_event_periodic = 0x0BCU } |
| RTC alarm / periodic ELC events the model emits (FSP ra8d2 bsp_elc). More... | |
Functions | |
| static RA8_INTERNAL uint8_t | internal_rtc_bin_to_bcd (uint8_t bin) |
| Binary 0..99 -> packed BCD. | |
| static RA8_INTERNAL uint8_t | internal_rtc_bcd_to_bin (uint8_t bcd) |
| Packed BCD -> binary 0..99. | |
| static RA8_INTERNAL void | internal_rtc_publish_calendar (void) |
| Refresh the BCD calendar shadow registers from the binary mirror. | |
| static RA8_INTERNAL void | internal_rtc_latch_calendar (void) |
| Load the binary time mirror from a freshly written BCD calendar. | |
| static RA8_INTERNAL uint64_t | internal_rtc_read (uc_engine *uc, uint64_t addr, unsigned size) |
Read size bytes little-endian from the RTC shadow at off. | |
| static RA8_INTERNAL bool | internal_rtc_is_calendar_off (uint64_t off) |
True iff offset off is a calendar-count register (BCD value). | |
| static RA8_INTERNAL void | internal_rtc_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value) |
Write size bytes little-endian into the RTC shadow at off. | |
| static RA8_INTERNAL void | internal_rtc_advance_one_second (void) |
| Advance the binary time mirror by one modelled second. | |
| static RA8_INTERNAL bool | internal_rtc_alarm_matches (void) |
| True iff the running time matches the armed (ENB) alarm fields. | |
| static RA8_INTERNAL void | internal_rtc_raise_events (uc_engine *uc) |
| Raise alarm / periodic ELC events for one elapsed modelled second. | |
| static RA8_INTERNAL void | internal_rtc_tick (uc_engine *uc) |
| Advance the RTC each chunk while running; raise its events. | |
| static RA8_INTERNAL void | internal_rtc_reset (void) |
| Clear the RTC register shadow and the time mirror. | |
| static RA8_INTERNAL void | internal_rtc_report (void) |
| Print the RTC's final time and its alarm / periodic event totals. | |
| static RA8_INTERNAL void | internal_board_periph_rtc_register (void) |
| Self-register the RTC window before main runs (decentralized). | |
Variables | |
| static rtc_state_t | s_rtc |
| static const board_periph_block_t | s_k_rtc_block |
| RTC register window + the calendar tick / reset / report. | |
Realtime Clock (RTC) calendar peripheral-block model for ra8_emulator.
Models the RA8D2 RTC (ra8_rtc_regs.h, ra8_rtc.c) in 24-hour BCD calendar mode with a real, advancing time base plus the alarm and periodic interrupt sources, so an example such as rtc_alarm (waits for the alarm flag) and rtc_periodic_demo (waits for the alarm-or-periodic flag) run to their log line and the alarm / periodic ELC events actually fire.
Control registers are a faithful shadow so the driver's bring-up poll loops complete deterministically: ra8_rtc_init clears RCR2 then waits for CNTMD to read 0, sets RCR2.HR24 and waits for it to read back, then sets RCR2.START and waits for it; it also clears RCR1 and waits for 0. The model honours every such readback. The driver's status surface is unusual – ra8_rtc_get_status returns RCR1 & (AIE|CIE|PIE), i.e. the enable bits double as the polled "fired" flags – so reflecting RCR1 exactly is what lets the demos' poll loops make progress.
On top of that faithful shadow the model adds genuine RTC behaviour:
ra8_rtc_get reports a clock that moves – the time register advances, exactly as the verification asks.The RTC is a single register window (0x40202000, 0x80 bytes); the block carries a tick that advances the calendar and raises the two events.
Definition in file board_periph_rtc.c.
| enum rtc_bit_t : uint8_t |
RCR1 / RCR2 bit masks (ra8_rtc_regs.h, ra8_rtc.h).
Definition at line 105 of file board_periph_rtc.c.
| enum rtc_calendar_t : uint32_t |
Calendar moduli + the modelled time:tick ratio.
Definition at line 114 of file board_periph_rtc.c.
| enum rtc_event_t : uint16_t |
RTC alarm / periodic ELC events the model emits (FSP ra8d2 bsp_elc).
The RA8D2 ELC signal table (HUM Ch 19) places the RTC alarm interrupt (RTC_ALM) at 0x0BB and the RTC periodic interrupt (RTC_PRD) at 0x0BC, matching FSP bsp_elc.h. A firmware that routes either through ra8_isr_register writes the same number into an IELSR slot, so the ICU model links the raised event to that slot.
| Enumerator | |
|---|---|
| k_rtc_event_alarm | RTC_ALM alarm-match event. |
| k_rtc_event_periodic | RTC_PRD periodic event. |
Definition at line 138 of file board_periph_rtc.c.
| enum rtc_geom_t : uint64_t |
RTC register window geometry (ra8_rtc_regs.h).
| Enumerator | |
|---|---|
| k_rtc_base | RTC block base. |
| k_rtc_span | FSP R_RTC_Type size. |
Definition at line 76 of file board_periph_rtc.c.
| enum rtc_lit_t : uint32_t |
BCD packing + calendar constants for the RTC model.
| Enumerator | |
|---|---|
| k_bcd_base | Decimal radix for BCD packing. |
| k_bcd_shift | Tens nibble shift. |
| k_nibble_mask | Low BCD nibble. |
| k_year_mod | Two-digit year wrap. |
| k_year_base | Calendar epoch base year. |
Definition at line 52 of file board_periph_rtc.c.
| enum rtc_off_t : uint64_t |
RTC register byte offsets (subset the driver touches).
Definition at line 82 of file board_periph_rtc.c.
| enum rtc_order_t : uint32_t |
Per-tick order slot for the RTC block.
Placed above the existing board_periph_block_order_t slots (gpio 10, timer 20, sci 30, i2c 40) and above the DMAC block, so the RTC ticks and reports after them. Spacing is deliberate; only the relative order matters and the RTC shares no state with another block, so the absolute value is free. A local enum keeps the value typed without editing the shared header the conflict-free rule forbids touching.
| Enumerator | |
|---|---|
| k_rtc_block_order | RTC tick / reset / report order slot. |
Definition at line 71 of file board_periph_rtc.c.
| enum rtc_r64_t : uint8_t |
64 Hz counter range (R64CNT is 6 bits).
| Enumerator | |
|---|---|
| k_rtc_r64_mask | R64CNT counts 0..63. |
Definition at line 124 of file board_periph_rtc.c.
|
static |
Self-register the RTC window before main runs (decentralized).
Definition at line 509 of file board_periph_rtc.c.
References board_periph_register_block(), RA8_INTERNAL, and s_k_rtc_block.
|
static |
Advance the binary time mirror by one modelled second.
Advance the binary time mirror by one modelled second; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
Definition at line 336 of file board_periph_rtc.c.
References k_rtc_days_per_mon, k_rtc_hours_per_day, k_rtc_mins_per_hour, k_rtc_mons_per_year, k_rtc_secs_per_min, RA8_INTERNAL, and s_rtc.
Referenced by internal_rtc_tick().
|
static |
True iff the running time matches the armed (ENB) alarm fields.
True iff the running time matches the armed (enb) alarm fields; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
| true | The RTC alarm matches condition holds or completed successfully; false otherwise. |
Definition at line 376 of file board_periph_rtc.c.
References internal_rtc_bcd_to_bin(), k_rtc_alarm_enb, k_rtc_alarm_val, k_rtc_off_rhrar, k_rtc_off_rminar, k_rtc_off_rsecar, RA8_INTERNAL, and s_rtc.
Referenced by internal_rtc_raise_events().
|
static |
Packed BCD -> binary 0..99.
Packed bcd -> binary 0..99; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
| [in] | bcd | Bcd input used by the operation. |
| value | The operation-specific RTC bcd to bin value. |
Definition at line 193 of file board_periph_rtc.c.
References k_bcd_base, k_bcd_shift, k_nibble_mask, and RA8_INTERNAL.
Referenced by internal_rtc_alarm_matches(), and internal_rtc_latch_calendar().
|
static |
Binary 0..99 -> packed BCD.
Binary 0..99 -> packed bcd; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
| [in] | bin | Bin input used by the operation. |
| value | The operation-specific RTC bin to bcd value. |
Definition at line 176 of file board_periph_rtc.c.
References k_bcd_base, k_bcd_shift, and RA8_INTERNAL.
Referenced by internal_rtc_publish_calendar().
|
static |
True iff offset off is a calendar-count register (BCD value).
True iff offset off is a calendar-count register (bcd value); this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
| [in] | off | Register or byte offset addressed by the operation. |
| true | The RTC is calendar off condition holds or completed successfully; false otherwise. |
Definition at line 281 of file board_periph_rtc.c.
References k_rtc_off_rdaycnt, k_rtc_off_rhrcnt, k_rtc_off_rmincnt, k_rtc_off_rmoncnt, k_rtc_off_rseccnt, k_rtc_off_ryrcnt, and RA8_INTERNAL.
Referenced by internal_rtc_write().
|
static |
Load the binary time mirror from a freshly written BCD calendar.
Load the binary time mirror from a freshly written bcd calendar; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
Definition at line 228 of file board_periph_rtc.c.
References internal_rtc_bcd_to_bin(), k_rtc_off_rdaycnt, k_rtc_off_rhrcnt, k_rtc_off_rmincnt, k_rtc_off_rmoncnt, k_rtc_off_rseccnt, k_rtc_off_ryrcnt, RA8_INTERNAL, and s_rtc.
Referenced by internal_rtc_write().
|
static |
Refresh the BCD calendar shadow registers from the binary mirror.
Refresh the bcd calendar shadow registers from the binary mirror; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
Definition at line 208 of file board_periph_rtc.c.
References internal_rtc_bin_to_bcd(), k_rtc_off_r64cnt, k_rtc_off_rdaycnt, k_rtc_off_rhrcnt, k_rtc_off_rmincnt, k_rtc_off_rmoncnt, k_rtc_off_rseccnt, k_rtc_off_ryrcnt, k_rtc_r64_mask, k_year_mod, RA8_INTERNAL, and s_rtc.
Referenced by internal_rtc_tick().
|
static |
Raise alarm / periodic ELC events for one elapsed modelled second.
Raise alarm / periodic elc events for one elapsed modelled second; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
Definition at line 406 of file board_periph_rtc.c.
References board_periph_icu_raise_event(), board_periph_trace(), internal_rtc_alarm_matches(), k_rtc_event_alarm, k_rtc_event_periodic, k_rtc_off_rcr1, k_rtc_rcr1_aie, k_rtc_rcr1_pie, priv_emu_io_errf(), RA8_INTERNAL, and s_rtc.
Referenced by internal_rtc_tick().
|
static |
Read size bytes little-endian from the RTC shadow at off.
Read size bytes little-endian from the rtc shadow at off; this step is contained within the board periph RTC 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 RTC read value. |
Definition at line 256 of file board_periph_rtc.c.
References k_rtc_base, k_rtc_span, RA8_INTERNAL, and s_rtc.
|
static |
Print the RTC's final time and its alarm / periodic event totals.
Print the rtc's final time and its alarm / periodic event totals; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
Definition at line 479 of file board_periph_rtc.c.
References k_year_base, priv_emu_io_errf(), RA8_INTERNAL, and s_rtc.
|
static |
Clear the RTC register shadow and the time mirror.
Clear the rtc register shadow and the time mirror; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
Definition at line 466 of file board_periph_rtc.c.
References RA8_INTERNAL, and s_rtc.
|
static |
Advance the RTC each chunk while running; raise its events.
Advance the rtc each chunk while running; raise its events; this step is contained within the board periph RTC model and uses bounded caller or module-owned storage.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
Definition at line 436 of file board_periph_rtc.c.
References internal_rtc_advance_one_second(), internal_rtc_publish_calendar(), internal_rtc_raise_events(), k_rtc_off_rcr2, k_rtc_rcr2_start, k_rtc_ticks_per_sec, RA8_INTERNAL, and s_rtc.
|
static |
Write size bytes little-endian into the RTC shadow at off.
Write size bytes little-endian into the rtc shadow at off; this step is contained within the board periph RTC 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 301 of file board_periph_rtc.c.
References internal_rtc_is_calendar_off(), internal_rtc_latch_calendar(), k_rtc_base, k_rtc_span, and s_rtc.
|
static |
RTC register window + the calendar tick / reset / report.
Definition at line 496 of file board_periph_rtc.c.
Referenced by internal_board_periph_rtc_register().
|
static |
Definition at line 158 of file board_periph_rtc.c.
Referenced by internal_rtc_advance_one_second(), internal_rtc_alarm_matches(), internal_rtc_latch_calendar(), internal_rtc_publish_calendar(), internal_rtc_raise_events(), internal_rtc_read(), internal_rtc_report(), internal_rtc_reset(), internal_rtc_tick(), and internal_rtc_write().