|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Reset cause introspection + software reset trigger. More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_reset_raw_t |
| Raw register snapshot returned by ra8_reset_get_raw. More... | |
Functions | |
| ra8_err_t | ra8_reset_init (void) |
| Snapshot the reset cause at boot. | |
| void | ra8_reset_test_only_reset_state (void) |
| Reset the cached reset-cause snapshot for host tests. | |
| ra8_err_t | ra8_reset_get_cause (ra8_reset_cause_t *out) |
| Decode the latched RSTSRn flags into a single primary cause. | |
| ra8_err_t | ra8_reset_get_raw (ra8_reset_raw_t *out) |
| Read the raw RSTSR0 / RSTSR1 / RSTSR2 / RSTSR3 register words. | |
| ra8_err_t | ra8_reset_clear_cause (uint32_t mask) |
| Clear (write 0 to) the requested set of latched RSTSRn flags. | |
| ra8_err_t | ra8_reset_get_attribution (uint32_t *out) |
| Read the RSTSAR (Reset Security Attribution) register. | |
| void | ra8_reset_software_reset (void) |
| Trigger a software-initiated system reset. | |
| ra8_err_t | ra8_reset_set_source_mask (ra8_reset_source_t source, bool disable) |
| Enable or disable the occurrence of a specific reset source. | |
| ra8_err_t | ra8_reset_get_source_mask (ra8_reset_source_t source, bool *disabled) |
| Read whether a specific reset source is currently masked (disabled). | |
Reset cause introspection + software reset trigger.
RA8D2 reset HAL driver. The chip exposes 21 distinct reset causes (HUM Ch 6.1 p 244 Table 6.1) and three "Reset Status Registers" (RSTSR0, RSTSR1, RSTSR2) plus an extended RSTSR3 for the core-voltage / overcurrent / temperature monitor flags. This driver collapses every cause into a small set of tagged enums that the application can switch on without having to know which physical register or bit owns which cause.
| API | Purpose |
|---|---|
| ra8_reset_init | Snapshot reset cause at boot |
| ra8_reset_get_cause | Decode RSTSR0/1/2/3 -> typed cause |
| ra8_reset_get_raw | Return the raw 8/32-bit register words |
| ra8_reset_clear_cause | Software-clear (write 0 after read 1) |
| ra8_reset_get_attribution | Read RSTSAR security attribution |
| ra8_reset_software_reset | Trigger AIRCR.SYSRESETREQ (no return) |
| ra8_reset_set_source_mask | Disable/enable a reset source (SYRSTMSK0/1/2) |
| ra8_reset_get_source_mask | Read a reset source's mask state |
Per HUM Ch 6.2.2 / 6.2.3 / 6.2.4 / 6.2.5 register descriptions, the RSTSRn registers are R/W with the Note: "Only 0 can be written. To clear a flag, read 1 from it and then write 0." They do not sit behind PRCR. RSTSAR sits behind PRCR.PRC1 (CGC + LVD group); the driver does not touch RSTSAR write-side – only read-side – so no PRCR unlock is required for ra8_reset_get_attribution.
Definition in file ra8_reset.h.
| enum ra8_reset_cause_t : uint8_t |
Decoded reset-cause taxonomy.
Values are non-overlapping so the driver can return exactly one primary cause; callers that want to inspect all latched flags (multiple resets can stack between two software reads) should use ra8_reset_get_raw.
Ordering follows HUM Ch 6.1 Table 6.1 p 244. The first matching flag (in register-index order RSTSR2 -> RSTSR0 -> RSTSR3 -> RSTSR1) wins; k_ra8_reset_cause_unknown is returned when no flag is set (e.g. the firmware itself cleared every cause earlier in boot).
Definition at line 93 of file ra8_reset.h.
| enum ra8_reset_source_t : uint8_t |
Reset sources whose occurrence can be individually disabled.
Each value maps to one mask bit across SYRSTMSK0/1/2 (HUM Ch 6.2.6-6.2.8 p 262-264). Setting a source's mask disables the corresponding reset; clearing it re-enables the reset (the reset-value of every mask is 0 = enabled). k_ra8_reset_source_count is a non-source sentinel used for range validation, never a maskable bit.
Definition at line 391 of file ra8_reset.h.
|
nodiscard |
Clear (write 0 to) the requested set of latched RSTSRn flags.
Per HUM Ch 6.2.2 / 6.2.3 / 6.2.4 register descriptions, every RSTSRn flag uses the "read 1 then write 0" idiom: software clears a bit by writing 0 after observing it as 1. This function performs the write step for every bit selected by mask across all three RSTSR registers.
The mask argument is encoded as follows so a single call can clear flags from RSTSR0 (bits 0..7), RSTSR1 (bits 8..30) and RSTSR2/RSTSR3 (bits 31..) without forcing the caller to issue three separate calls:
RSTSR3 has no software-clear path – its flags are owned by the core-voltage / temperature monitor secure code; this function leaves RSTSR3 alone.
| [in] | mask | Encoded clear mask (see above). |
| k_ra8_ok | Mask applied. |
Definition at line 350 of file ra8_reset.c.
References internal_decode(), internal_read_raw(), k_ra8_ok, k_ra8_reset_mask_rstsr0_msk, k_ra8_reset_mask_rstsr1_shift, k_ra8_reset_mask_rstsr1_window, k_ra8_reset_mask_rstsr2_cwsf, k_ra8_reset_rstsr2_cwsf_msk, ra8_reset_rstsr0(), ra8_reset_rstsr1(), ra8_reset_rstsr2(), and s_state.
Referenced by main().
|
nodiscard |
Read the RSTSAR (Reset Security Attribution) register.
RSTSAR at SYSC offset 0x3C4 holds five NONSECn bits that select whether each of the five reset-status group registers (RSTSR0..RSTSR3 + future) is reachable from the non-secure side. The driver returns the raw 32-bit value; callers can mask against k_ra8_reset_rstsar_field_msk to drop reserved upper bits.
| [out] | out | Receives the RSTSAR value (non-NULL). |
| k_ra8_ok | Value written. |
| k_ra8_err_null_ptr | out was nullptr. |
Definition at line 386 of file ra8_reset.c.
References k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_reset_rstsar(), and s_tag.
|
nodiscard |
Decode the latched RSTSRn flags into a single primary cause.
If ra8_reset_init was called this returns the cached snapshot; otherwise it reads the registers fresh. The returned value is the highest-priority cause currently latched. Priority order matches HUM Ch 6.1 Table 6.1 p 244 (POR -> LVD -> Deep SW Standby -> core/temp/overcurrent -> IWDT/WDT/SW/Lockup/LM/BUS/CM -> Cold/Warm).
To examine every latched flag at once (multiple causes can stack between two reads), use ra8_reset_get_raw instead.
| [out] | out | Decoded cause (non-NULL). |
| k_ra8_ok | Cause written to *out. |
| k_ra8_err_null_ptr | out was nullptr. |
Definition at line 326 of file ra8_reset.c.
References internal_decode(), internal_read_raw(), k_ra8_ok, RA8_CHECK_NULL_PTR, s_state, and s_tag.
Referenced by internal_wakeup_reason(), and main().
|
nodiscard |
Read the raw RSTSR0 / RSTSR1 / RSTSR2 / RSTSR3 register words.
If ra8_reset_init has run this returns the cached snapshot; otherwise the registers are read fresh.
| [out] | out | Destination struct (non-NULL). |
| k_ra8_ok | Raw values written. |
| k_ra8_err_null_ptr | out was nullptr. |
Definition at line 339 of file ra8_reset.c.
References internal_read_raw(), k_ra8_ok, RA8_CHECK_NULL_PTR, s_state, and s_tag.
|
nodiscard |
Read whether a specific reset source is currently masked (disabled).
Reads the relevant SYRSTMSK0/1/2 byte and returns the mask state for source. Reads do not require a PRCR unlock.
| [in] | source | Reset source to query (< k_ra8_reset_source_count). |
| [out] | disabled | Receives true if the reset is masked/disabled. |
| k_ra8_ok | Result written to *disabled. |
| k_ra8_err_null_ptr | disabled was nullptr. |
| k_ra8_err_invalid_arg | source >= k_ra8_reset_source_count. |
source is a valid ra8_reset_source_t (< count). Definition at line 537 of file ra8_reset.c.
References internal_source_loc(), k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_error, and s_tag.
|
nodiscard |
Snapshot the reset cause at boot.
Reads RSTSR0/1/2/3 once and caches the decoded cause + raw words in a file-scope static. Subsequent calls to ra8_reset_get_cause / ra8_reset_get_raw return the snapshot rather than re-reading the registers. This is the only safe way to share the cause across the firmware – any other code path that calls ra8_reset_clear_cause would otherwise destroy the information before later modules could see it.
Idempotent: calling ra8_reset_init more than once re-reads the registers and overwrites the snapshot, which is what you want during unit tests but you should avoid in production code.
| k_ra8_ok | Snapshot captured. |
Definition at line 310 of file ra8_reset.c.
References internal_decode(), internal_read_raw(), k_ra8_ok, ra8_log_info_val, s_state, and s_tag.
Referenced by internal_wdt_demo_setup_or_halt(), main(), and wdt_rr_setup_or_halt().
|
nodiscard |
Enable or disable the occurrence of a specific reset source.
Sets (disable == true) or clears (disable == false) the mask bit for source in SYRSTMSK0/1/2. The register group is write-protected by PRCR.PRC5 (HUM Ch 6.2.6 Note p 262): this function unlocks PRC5, performs the read-modify-write of the relevant SYRSTMSKn byte, then relocks PRC5 – leaving the other PRC bits untouched.
| [in] | source | Reset source to mask/unmask (< k_ra8_reset_source_count). |
| [in] | disable | true disables the reset; false re-enables it. |
| k_ra8_ok | Mask bit updated. |
| k_ra8_err_invalid_arg | source >= k_ra8_reset_source_count. |
source is a valid ra8_reset_source_t (< count). source reads disable. Definition at line 505 of file ra8_reset.c.
References internal_source_loc(), k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_reset_prcr_key, k_ra8_reset_prcr_pr_bits_msk, k_ra8_reset_prcr_prc5_msk, ra8_log_error, ra8_reset_prcr(), and s_tag.
| void ra8_reset_software_reset | ( | void | ) |
Trigger a software-initiated system reset.
Writes the Cortex-M85 SCB->AIRCR register with the mandatory 0x05FA write-key in the upper half-word and the SYSRESETREQ bit set, exactly as CMSIS NVIC_SystemReset does. The reset does not return – on real hardware control is given to the reset exception handler within a few cycles. The function ends with a __DSB (or its off-target equivalent) so the AIRCR write is observable before the CPU stalls waiting for reset.
After the reset completes RSTSR1.SWRF will read 1 and ra8_reset_get_cause will return k_ra8_reset_cause_software.
Definition at line 394 of file ra8_reset.c.
References k_ra8_reset_aircr_sysresetreq_msk, k_ra8_reset_aircr_vectkey_pos, k_ra8_reset_aircr_vectkey_value, ra8_hw_wait_for_reset(), ra8_log_info, ra8_reset_aircr(), and s_tag.
Referenced by main().
| void ra8_reset_test_only_reset_state | ( | void | ) |
Reset the cached reset-cause snapshot for host tests.
Zeroes the cached boot-cause snapshot so each host test case starts from the driver's just-loaded state. Compiled unconditionally (like the other *_test_* helpers) but only ever called from tests/; on the target it is an unreferenced symbol dropped by --gc-sections.
Definition at line 319 of file ra8_reset.c.
References k_ra8_reset_cause_unknown, and s_state.