|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Module-private module-stop (MSTP) gate state shared with the core. More...
Go to the source code of this file.
Enumerations | |
| enum | board_mstp_geom_t : uint64_t { k_board_mstp_win_base = 0x40203000UL , k_board_mstp_win_span = 0x14UL } |
| R_MSTP register-window geometry (HUM Ch 11.2.6..11.2.10 p 443-450). More... | |
Functions | |
| void | priv_board_mstp_reset (void) |
Restore MSTPCRA..MSTPCRE to their all-stopped reset values. | |
| void | priv_board_mstp_apply_write (uint64_t off, unsigned size, uint32_t value) |
Apply a firmware write to the MSTPCRA..MSTPCRE shadow. | |
| uint32_t | priv_board_mstp_read_reg (uint64_t off, unsigned size) |
Read the tracked MSTPCRA..MSTPCRE shadow (the read-back path). | |
| bool | priv_board_mstp_addr_stopped (uint64_t addr) |
Report whether the peripheral instance owning addr is module-stopped. | |
| void | priv_board_mstp_note_gated_access (uint64_t addr, bool is_write) |
| Record that an MMIO access to a module-stopped peripheral was dropped. | |
| uint32_t | priv_board_mstp_gated_read_count (void) |
| Number of reads zeroed because their peripheral was module-stopped. | |
| uint32_t | priv_board_mstp_gated_write_count (void) |
| Number of writes dropped because their peripheral was module-stopped. | |
| const char * | priv_board_mstp_last_gated_name (void) |
| Label of the peripheral whose access was most recently gated off. | |
Module-private module-stop (MSTP) gate state shared with the core.
On the RA8D2 every peripheral has a Module Stop bit in one of MSTPCRA..MSTPCRE (R_MSTP at 0x4020_3000 – HUM Ch 11.2.6..11.2.10 p 443-450). When that bit is set the peripheral is clock-gated OFF: it does not respond to bus accesses, so its registers read 0 and writes are dropped. At reset every peripheral bit is 1 (stopped); firmware clears the bit – via ra8_mstp_enable – before it may touch the peripheral.
ra8_emulator modelled no module-stop state at all, so a peripheral answered its registers whether or not firmware had released it. A driver that forgot to cancel module-stop therefore worked perfectly in the emulator and did nothing on hardware (#405, the same masked-pass shape as #247's power domain and #131's protected writes).
This seam closes that gap. board_periph_mstp_model.c owns the five MSTPCRx words and the address->bit gate table; the board_periph core (board_periph.c) consults priv_board_mstp_addr_stopped before dispatching an MMIO access to an owning block, and drops it – read 0 / write ignored – exactly as the silicon does when the block is stopped. The model half is kept free of any Unicorn dependency so the gate table is unit-testable on the host (tests/misc/src/test_ra8_emulator_mstp_gate.c); the block glue that needs the engine lives in board_periph_mstp.c.
Definition in file board_periph_mstp_internal.h.
| enum board_mstp_geom_t : uint64_t |
R_MSTP register-window geometry (HUM Ch 11.2.6..11.2.10 p 443-450).
The Secure alias of the block is at 0x4020_3000; ra8_emulator's MMIO callbacks rebuild every access – Secure and the IDAU bit[28] Non-secure alias 0x5020_3000 alike – onto this Secure base, so a single window covers both views. MSTPCRA..MSTPCRE occupy the first five 32-bit words.
k_board_mstp_win_span == 5 * 4 bytes. | Enumerator | |
|---|---|
| k_board_mstp_win_base | R_MSTP base (Secure alias). |
| k_board_mstp_win_span | MSTPCRA..E = 5 x uint32 = 20 B. |
Definition at line 56 of file board_periph_mstp_internal.h.
| bool priv_board_mstp_addr_stopped | ( | uint64_t | addr | ) |
Report whether the peripheral instance owning addr is module-stopped.
Maps addr through the address->module-stop-bit gate table (each entry cites the governing MSTPCRx bit from HUM Ch 11.2.6..11.2.10) and returns whether that bit is currently set. An address covered by no gate entry – a peripheral with no module-stop control (GPIO, ICU, SYSC), or one ra8_emulator does not gate – is never stopped, so unmodelled and un-gated blocks answer exactly as before.
| [in] | addr | Absolute peripheral register address being accessed. |
true when addr belongs to a gated instance whose module-stop bit is set (unclocked); false otherwise. | true | The owning instance is stopped: reads 0, writes dropped. |
| false | Not gated, or the owning instance is running. |
Definition at line 452 of file board_periph_mstp_model.c.
References mstp_family_t::ids, internal_mstp_bit_set(), internal_mstp_family_for_addr(), and RA8_PRIV.
Referenced by board_periph_read(), and board_periph_write().
| void priv_board_mstp_apply_write | ( | uint64_t | off, |
| unsigned | size, | ||
| uint32_t | value ) |
Apply a firmware write to the MSTPCRA..MSTPCRE shadow.
Merges value into the tracked register bytes at off (a 0-based offset into the 20-byte block), so any 8/16/32-bit access width lands correctly. Clearing a bit ungates that peripheral; setting it re-gates it. HUM Ch 11.2.6 p 443: "bit clear == ungate the peripheral". The model accepts every bit (PSAR Non-secure attribution is not re-modelled here) because firmware never relies on a Secure write to a delegated bit sticking.
| [in] | off | Byte offset within the R_MSTP window (0..19). |
| [in] | size | Access width in bytes (1/2/4). |
| [in] | value | Little-endian value being written. |
value inside the window replace the tracked bytes. Definition at line 421 of file board_periph_mstp_model.c.
References k_board_mstp_win_span, k_mstp_byte_bits, k_mstp_byte_mask, k_mstp_bytes_per_reg, RA8_PRIV, and s_mstpcr.
Referenced by internal_mstp_write().
| uint32_t priv_board_mstp_gated_read_count | ( | void | ) |
Number of reads zeroed because their peripheral was module-stopped.
Number of reads zeroed because their peripheral was module-stopped; this step is contained within the board periph module-stop model and uses bounded caller or module-owned storage.
| value | The operation-specific board module-stop gated read count value. |
Definition at line 476 of file board_periph_mstp_model.c.
References RA8_PRIV, and s_gated_reads.
Referenced by internal_mstp_report().
| uint32_t priv_board_mstp_gated_write_count | ( | void | ) |
Number of writes dropped because their peripheral was module-stopped.
Number of writes dropped because their peripheral was module-stopped; this step is contained within the board periph module-stop model and uses bounded caller or module-owned storage.
| value | The operation-specific board module-stop gated write count value. |
Definition at line 481 of file board_periph_mstp_model.c.
References RA8_PRIV, and s_gated_writes.
Referenced by internal_mstp_report().
| const char * priv_board_mstp_last_gated_name | ( | void | ) |
Label of the peripheral whose access was most recently gated off.
Definition at line 486 of file board_periph_mstp_model.c.
References RA8_PRIV, and s_last_gated.
Referenced by internal_mstp_report().
| void priv_board_mstp_note_gated_access | ( | uint64_t | addr, |
| bool | is_write ) |
Record that an MMIO access to a module-stopped peripheral was dropped.
Called by the core dispatch when priv_board_mstp_addr_stopped forced a read to 0 or a write to be discarded. Bumps the dropped-access counter and remembers the offending peripheral's label so the end-of-run report can make the masked bug LOUD instead of silent.
| [in] | addr | Absolute address that was gated off. |
| [in] | is_write | true for a dropped write, false for a zeroed read. |
Definition at line 462 of file board_periph_mstp_model.c.
References internal_mstp_family_for_addr(), mstp_family_t::name, RA8_PRIV, s_gated_reads, s_gated_writes, and s_last_gated.
Referenced by board_periph_read(), and board_periph_write().
| uint32_t priv_board_mstp_read_reg | ( | uint64_t | off, |
| unsigned | size ) |
Read the tracked MSTPCRA..MSTPCRE shadow (the read-back path).
Returns the bytes of the shadow at off, so the firmware's mandated module-stop read-back (HUM Ch 11.2.6 Note 2 p 443) sees the value it just wrote and settles immediately – deterministic, unlike the sparse fallback's spin-settle toggle.
| [in] | off | Byte offset within the R_MSTP window (0..19). |
| [in] | size | Access width in bytes (1/2/4). |
off, or 0 for bytes outside the window. off addresses the R_MSTP window. | value | The operation-specific board module-stop read reg value. |
Definition at line 436 of file board_periph_mstp_model.c.
References k_board_mstp_win_span, k_mstp_byte_bits, k_mstp_byte_mask, k_mstp_bytes_per_reg, RA8_PRIV, and s_mstpcr.
Referenced by internal_mstp_read().
| void priv_board_mstp_reset | ( | void | ) |
Restore MSTPCRA..MSTPCRE to their all-stopped reset values.
Every peripheral bit returns to 1 (module stopped), matching the silicon power-on state, so a gated block reads 0 until firmware ungates it. The MSTPCRA SRAM bits (0..3) are left running (0), mirroring the safe pattern ra8_mstp_init writes (HUM Ch 11.2.6 p 443).
Definition at line 410 of file board_periph_mstp_model.c.
References k_mstp_reg_count, k_mstp_reset_a, k_mstp_reset_rest, RA8_PRIV, s_gated_reads, s_gated_writes, s_last_gated, and s_mstpcr.
Referenced by internal_mstp_block_register().