|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Low Power Mode + clock-domain wrapper. More...
Go to the source code of this file.
Enumerations | |
| enum | ra8_pwr_wupen_reg_t : uint8_t { k_ra8_pwr_wupen_reg_0 = 0U , k_ra8_pwr_wupen_reg_1 = 1U } |
| Which of the two WUPEN registers a wake source lives in. More... | |
| enum | ra8_pwr_wake_t : uint16_t { k_ra8_pwr_wake_irq0 = (uint16_t)(k_ra8_pwr_wupen_reg_0 << 8) , k_ra8_pwr_wake_irq1 = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 1U) , k_ra8_pwr_wake_irq2 = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 2U) , k_ra8_pwr_wake_irq3 = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 3U) , k_ra8_pwr_wake_irq4 = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 4U) , k_ra8_pwr_wake_irq5 = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 5U) , k_ra8_pwr_wake_irq6 = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 6U) , k_ra8_pwr_wake_irq7 = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 7U) , k_ra8_pwr_wake_iwdt = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 16U) , k_ra8_pwr_wake_lvd1 = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 18U) , k_ra8_pwr_wake_lvd2 = (uint16_t)((k_ra8_pwr_wupen_reg_0 << 8) | 19U) , k_ra8_pwr_wake_rtc_alarm , k_ra8_pwr_wake_rtc_period , k_ra8_pwr_wake_usbhs_resume , k_ra8_pwr_wake_usbfs_resume , k_ra8_pwr_wake_agt0 = (uint16_t)(k_ra8_pwr_wupen_reg_1 << 8) , k_ra8_pwr_wake_agt1 = (uint16_t)((k_ra8_pwr_wupen_reg_1 << 8) | 1U) , k_ra8_pwr_wake_ulpt0 = (uint16_t)((k_ra8_pwr_wupen_reg_1 << 8) | 2U) , k_ra8_pwr_wake_ulpt1 = (uint16_t)((k_ra8_pwr_wupen_reg_1 << 8) | 3U) } |
| Packed (WUPEN register, bit) wake-source identifier. More... | |
Functions | |
| ra8_err_t | ra8_pwr_init (void) |
| Initialise the LPM substrate. | |
| ra8_err_t | ra8_pwr_module_request (ra8_mstp_t id) |
| Ask for a peripheral's clock to be enabled. | |
| ra8_err_t | ra8_pwr_module_release (ra8_mstp_t id) |
| Release a previously-requested peripheral. | |
| ra8_err_t | ra8_pwr_set_wake_source (ra8_pwr_wake_t source) |
| Enable an LPM wake source. | |
| ra8_err_t | ra8_pwr_clear_wake_source (ra8_pwr_wake_t source) |
| Disable an LPM wake source. | |
| ra8_err_t | ra8_pwr_wake_source_is_enabled (ra8_pwr_wake_t source, bool *out_enabled) |
| Read the current WUPEN bit value for a source. | |
| void | ra8_pwr_enter_sleep (void) |
| Enter CPU sleep mode (peripherals continue running). | |
| ra8_err_t | ra8_pwr_enter_software_standby (void) |
| Enter Software Standby mode. | |
| ra8_err_t | ra8_pwr_get_clock_hz (ra8_clock_id_t id, uint32_t *out_hz) |
| Forward to ra8_cgc_get_clock_hz() for naming consistency. | |
Low Power Mode + clock-domain wrapper.
Ring 3 / HAL substrate. Sits on top of ra8_mstp and ra8_cgc and exposes the small set of helpers every driver checklist needs:
The 14-checkbox per-driver feature template (see docs/ROADMAP.md) lists "Power transition" as "ra8_pwr_module_enter_stop + restore, wake event register". The naming in this file is the canonical version: request / release for ungate / gate so that "stop" only ever means "STBY-style stopped" rather than "MSTP bit set".
The RA8D2 has 64 distinct wake-up sources spread across two 32-bit WUPEN registers (HUM 11.2.x). Sources include the IRQ pins, AGT/ULPT timers, RTC alarm, USB suspend/resume, LVD detectors, and the temperature monitor. ra8_pwr_set_wake_source() takes a packed identifier (register index + bit) and toggles the corresponding bit.
Single-threaded init context only.
Definition in file ra8_pwr.h.
| enum ra8_pwr_wake_t : uint16_t |
Packed (WUPEN register, bit) wake-source identifier.
Encoding mirrors ra8_mstp_t: (reg << 8) | bit. Only a handful of well-known sources are listed here; full coverage of all 64 sources is added as the relevant drivers come online.
Source list comes from HUM Ch 14 "Interrupt Controller Unit (ICU)" (the WUPEN0 and WUPEN1 register description tables).
| enum ra8_pwr_wupen_reg_t : uint8_t |
|
nodiscard |
Disable an LPM wake source.
Clears the corresponding bit in WUPEN0 or WUPEN1.
| [in] | source | Packed ra8_pwr_wake_t identifier. |
| k_ra8_ok | The bit is clear. |
| k_ra8_err_invalid_arg | source decodes to an out-of-range register or bit. |
Definition at line 183 of file ra8_pwr.c.
References internal_decode_wake(), internal_wupen_ptr(), k_ra8_err_invalid_arg, k_ra8_ok, ra8_log_error_val, and s_tag.
| void ra8_pwr_enter_sleep | ( | void | ) |
Enter CPU sleep mode (peripherals continue running).
Issues a single WFI instruction. The Cortex-M85 enters Sleep mode and the CPU clock is gated until any enabled interrupt fires. Peripherals run normally because LPMD bits are not touched.
On the host (RA8_OFF_TARGET) this is a no-op so unit tests do not stall.
Definition at line 212 of file ra8_pwr.c.
References internal_wfi().
|
nodiscard |
Enter Software Standby mode.
Sets LPSCR.LPMD = 0x5 and the Cortex-M85 SCR.SLEEPDEEP bit, then issues WFI (HUM 11.6.2.1 p 482). Most oscillators stop, the CPU stops, peripherals freeze. Wakes from any source armed via ra8_pwr_set_wake_source().
On the host this is a no-op.
| k_ra8_ok | Returned cleanly after wake. |
| k_ra8_err_invalid_state | Caller failed to arm any wake source first. |
Definition at line 217 of file ra8_pwr.c.
References internal_wfi(), internal_wupen_ptr(), k_ra8_err_invalid_state, k_ra8_ok, ra8_log_error, and s_tag.
|
nodiscard |
Forward to ra8_cgc_get_clock_hz() for naming consistency.
Plain forwarding helper. Drivers that already include ra8_pwr.h for module gating do not need to also include ra8_cgc.h just to look up a baud-rate divider.
| [in] | id | Clock identifier. |
| [out] | out_hz | On success, current frequency in Hz. |
Definition at line 240 of file ra8_pwr.c.
References ra8_cgc_get_clock_hz().
|
nodiscard |
Initialise the LPM substrate.
Validates the post-reset state and clears every WUPEN bit so that subsequent ra8_pwr_set_wake_source() calls are the only source of wake events. Also calls ra8_mstp_init() so the MSTP ref-count table starts in lockstep with hardware.
| k_ra8_ok | Substrate ready. |
| k_ra8_err_hw_timeout | ra8_mstp_init() did not see its read-back within budget. |
Definition at line 141 of file ra8_pwr.c.
References internal_wupen_ptr(), k_ra8_ok, ra8_log_error_val, ra8_log_info, ra8_mstp_init(), and s_tag.
Referenced by ra8_nsc_periph_init().
|
nodiscard |
Release a previously-requested peripheral.
Forwards to ra8_mstp_disable(id).
| [in] | id | Peripheral identifier from ra8_mstp_t. |
Definition at line 163 of file ra8_pwr.c.
References ra8_mstp_disable().
|
nodiscard |
Ask for a peripheral's clock to be enabled.
Forwards to ra8_mstp_enable(id) after logging. Future versions will validate the requested module against the current LPM state and route the request through an NSC veneer.
| [in] | id | Peripheral identifier from ra8_mstp_t. |
Definition at line 158 of file ra8_pwr.c.
References ra8_mstp_enable().
|
nodiscard |
Enable an LPM wake source.
Sets the corresponding bit in WUPEN0 or WUPEN1 (HUM 11.2.x register descriptions). Wake sources are addressed by the packed ra8_pwr_wake_t enum.
| [in] | source | Packed ra8_pwr_wake_t identifier. |
| k_ra8_ok | The bit is set. |
| k_ra8_err_invalid_arg | source decodes to an out-of-range register or bit. |
Definition at line 168 of file ra8_pwr.c.
References internal_decode_wake(), internal_wupen_ptr(), k_ra8_err_invalid_arg, k_ra8_ok, ra8_log_error_val, and s_tag.
|
nodiscard |
Read the current WUPEN bit value for a source.
Diagnostic accessor used by tests. Returns true if the source is currently armed.
| [in] | source | Packed ra8_pwr_wake_t identifier. |
| [out] | out_enabled | true on success if the bit is set. |
| k_ra8_ok | Bit value returned. |
| k_ra8_err_null_ptr | out_enabled was NULL. |
| k_ra8_err_invalid_arg | source decoded out of range. |
Definition at line 198 of file ra8_pwr.c.
References internal_decode_wake(), internal_wupen_ptr(), k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, and s_tag.