|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Low Power Mode + clock-domain wrapper implementation. More...
#include "ra8_pwr.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_cgc.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_hw_intrinsics.h"#include "ra8_log.h"#include "ra8_lpm_regs.h"#include "ra8_mstp.h"#include "ra8_mstp_regs.h"#include "ra8_system_regs.h"Go to the source code of this file.
Enumerations | |
| enum | pwr_mask_t : uint16_t { k_pwr_byte_mask = 0xFFU } |
| Low-byte mask for register/bit decomposition. More... | |
| enum | ra8_pwr_dim_t : uint8_t { k_ra8_pwr_wupen_count = 2U , k_ra8_pwr_wupen_bits = 32U } |
| WUPEN address-decode bounds. More... | |
Functions | |
| static volatile uint32_t * | internal_wupen_ptr (uint8_t reg) |
| Pointer to one of the 32-bit WUPEN registers. | |
| static bool | internal_decode_wake (ra8_pwr_wake_t source, uint8_t *out_reg, uint8_t *out_bit) |
| Decode and validate a packed wake source. | |
| static void | internal_wfi (void) |
| WFI wrapper. | |
| 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. | |
Variables | |
| static const char * | s_tag = "PWR" |
Low Power Mode + clock-domain wrapper implementation.
Ring 3 / HAL substrate. See ra8_pwr.h for the API contract. Implementation depth is intentionally minimal:
Definition in file ra8_pwr.c.
| enum pwr_mask_t : uint16_t |
| enum ra8_pwr_dim_t : uint8_t |
|
static |
Decode and validate a packed wake source.
| [in] | source | Packed identifier. |
| [out] | out_reg | Register index 0 or 1. |
| [out] | out_bit | Bit position 0..31. |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 101 of file ra8_pwr.c.
References k_pwr_byte_mask, k_ra8_pwr_wupen_bits, and k_ra8_pwr_wupen_count.
Referenced by ra8_pwr_clear_wake_source(), ra8_pwr_set_wake_source(), and ra8_pwr_wake_source_is_enabled().
|
inlinestatic |
WFI wrapper.
No-op on the host build.
Routes through the ra8_hw_intrinsics seam: on the Cortex-M85 target it expands to wfi; on the host the stub returns at once so unit tests can call ra8_pwr_enter_sleep() without stalling.
Definition at line 131 of file ra8_pwr.c.
References ra8_hw_wfi(), and RA8_INTERNAL.
Referenced by ra8_pwr_enter_sleep(), and ra8_pwr_enter_software_standby().
|
static |
Pointer to one of the 32-bit WUPEN registers.
The WUPEN registers live inside the SYSC block at the offsets defined in ra8_lpm_regs.h.
Definition at line 74 of file ra8_pwr.c.
References k_ra8_lpm_wupen0_off, k_ra8_lpm_wupen1_off, k_ra8_system_base_addr, and RA8_INTERNAL.
Referenced by ra8_pwr_clear_wake_source(), ra8_pwr_enter_software_standby(), ra8_pwr_init(), ra8_pwr_set_wake_source(), and ra8_pwr_wake_source_is_enabled().
|
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.