|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Low Power Mode (LPM) HAL driver implementation. More...
#include "ra8_lpm.h"#include <stdint.h>#include "ra8_attributes.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_register_protection.h"Go to the source code of this file.
Enumerations | |
| enum | lpm_byte_mask_t : uint16_t { k_lpm_byte_mask = 0xFFU } |
| Low-byte mask for the PRCR protect register. More... | |
| enum | ra8_lpm_status_shift_t : uint8_t { k_ra8_lpm_status_shift_sbycr = 0U , k_ra8_lpm_status_shift_dpsbycr = 8U , k_ra8_lpm_status_shift_lpscr = 16U , k_ra8_lpm_status_shift_sscr1 = 24U } |
| Bit shifts used to pack SBYCR / DPSBYCR / LPSCR / SSCR1. More... | |
| enum | ra8_lpm_cause_shift_t : uint8_t { k_ra8_lpm_cause_shift_wupen0 = 0U , k_ra8_lpm_cause_shift_wupen1 = 32U } |
| Bit shifts used to pack WUPEN0 / WUPEN1 into a 64-bit cause word. More... | |
| enum | ra8_lpm_dpsi_count_t : uint8_t { k_ra8_lpm_dpsier_count = 4U , k_ra8_lpm_dpsifr_count = 4U , k_ra8_lpm_dpsieg_count = 3U } |
| Buffer counts for ra8_lpm_get_dpsi_state. More... | |
Functions | |
| static void | internal_wait_for_interrupt (void) |
| Issue a Data Synchronization Barrier followed by WFI. | |
| static void | internal_set_sleepdeep (bool enable) |
| Toggle SCB.SCR.SLEEPDEEP for non-Sleep mode entry. | |
| static ra8_err_t | internal_validate_mode (ra8_sleep_mode_t mode) |
| Validate mode against the LPSCR.LPMD encoding table. | |
| static ra8_lpm_off_t | internal_clock_offset (ra8_lpm_clock_t clock) |
| Resolve ra8_lpm_clock_t to its OCR offset. | |
| static ra8_lpm_off_t | internal_dpsier_offset (ra8_lpm_dpsier_idx_t idx) |
| Resolve a DPSIER index to its register offset. | |
| static ra8_lpm_off_t | internal_dpsifr_offset (ra8_lpm_dpsier_idx_t idx) |
| Resolve a DPSIFR index to its register offset. | |
| static ra8_lpm_off_t | internal_dpsiegr_offset (ra8_lpm_dpsier_idx_t idx) |
| Resolve a DPSIEGR index to its register offset. | |
| ra8_err_t | ra8_lpm_init (const ra8_lpm_config_t *cfg) |
| Initialise the LPM block from a config descriptor. | |
| ra8_err_t | ra8_lpm_deinit (void) |
| Restore SBYCR / DPSBYCR / LPSCR / SSCR1 to cold-reset defaults. | |
| ra8_err_t | ra8_lpm_prcr_unlock (void) |
| Unlock PRCR.PRC1 to permit writes to LPM control registers. | |
| ra8_err_t | ra8_lpm_prcr_relock (void) |
| Re-lock PRCR.PRC1 after protected writes. | |
| ra8_err_t | ra8_lpm_set_wakeup_sources (uint32_t wupen0, uint32_t wupen1) |
| Programme the raw WUPEN0 / WUPEN1 masks. | |
| ra8_err_t | ra8_lpm_arm_wupen0_bits (uint32_t bits) |
| OR-in additional WUPEN0 bits without disturbing other sources. | |
| ra8_err_t | ra8_lpm_clear_wupen0_bits (uint32_t bits) |
| AND-out WUPEN0 bits to disarm specific wake-up sources. | |
| ra8_err_t | ra8_lpm_arm_wupen1_bits (uint32_t bits) |
| OR-in additional WUPEN1 bits without disturbing other sources. | |
| ra8_err_t | ra8_lpm_clear_wupen1_bits (uint32_t bits) |
| AND-out WUPEN1 bits to disarm specific wake-up sources. | |
| ra8_err_t | ra8_lpm_arm_dpsier (ra8_lpm_dpsier_idx_t idx, uint8_t value) |
| Programme the per-byte DPSIER0..3 enable byte directly. | |
| ra8_err_t | ra8_lpm_clear_dpsifr (ra8_lpm_dpsier_idx_t idx) |
| Clear DPSIFR0..3 so a stale flag does not cancel deep standby. | |
| ra8_err_t | ra8_lpm_set_dpsiegr (ra8_lpm_dpsier_idx_t idx, uint8_t value) |
| Programme DPSIEGR0..2 (deep-standby IRQ edge polarity). | |
| ra8_err_t | ra8_lpm_snooze_set_request_sources (bool ulpt0_underflow, bool ulpt1_underflow, bool acmphs0) |
| Configure ULPT-driven snooze request sources. | |
| ra8_err_t | ra8_lpm_snooze_set_end_sources (bool ulpt0, bool ulpt1, bool usbfs, bool usbhs) |
| Configure end-of-snooze sources via DPSIER3 (ULPT/USB hooks). | |
| ra8_err_t | ra8_lpm_set_ram_retention (const ra8_lpm_ram_retention_t *cfg) |
| Programme PDRAMSCR0 / PDRAMSCR1 from a retention descriptor. | |
| ra8_err_t | ra8_lpm_set_ldo_standby (const ra8_lpm_ldo_cfg_t *cfg) |
| Programme PLL1LDOCR / PLL2LDOCR / HOCOLDOCR SKEEP bits. | |
| ra8_err_t | ra8_lpm_set_clock_stop (ra8_lpm_clock_t clock, bool stop) |
| Set or clear the per-oscillator stop bit before sleep entry. | |
| ra8_err_t | ra8_lpm_get_clock_stop (ra8_lpm_clock_t clock, bool *stop) |
| Read the per-oscillator stop bit. | |
| ra8_err_t | ra8_lpm_get_opccr (uint8_t *opccr) |
| Read OPCCR raw byte (OPCM[1:0] + OPCMTSF). | |
| ra8_err_t | ra8_lpm_wait_for_opccr (uint32_t poll_limit) |
| Wait for OPCCR.OPCMTSF to clear (mode-transition complete). | |
| ra8_err_t | ra8_lpm_enter_sleep (ra8_sleep_mode_t mode) |
| Programme LPSCR for mode and enter the requested sleep. | |
| ra8_err_t | ra8_lpm_enter_deep_standby (void) |
| Convenience wrapper – enter Deep Software Standby mode 1. | |
| ra8_err_t | ra8_lpm_get_status (uint32_t *out) |
| Read LPM status (SBYCR | DPSBYCR | LPSCR | SSCR1) packed. | |
| ra8_err_t | ra8_lpm_get_exit_cause (uint64_t *out) |
| Snapshot WUPEN0 / WUPEN1 into a single 64-bit word. | |
| ra8_err_t | ra8_lpm_get_dpsi_state (uint8_t enables[4], uint8_t flags[4], uint8_t edges[3]) |
| Read DPSIER0..3 + DPSIFR0..3 + DPSIEGR0..2 into a buffer. | |
Variables | |
| static const char * | s_tag = "LPM" |
| Component tag used in every log line emitted by this driver. | |
Low Power Mode (LPM) HAL driver implementation.
Implements the public API declared in ra8_lpm.h. Every register access carries a HUM Ch 11 (LPM) or HUM Ch 14 (ICU for WUPEN0/1) citation. The driver covers the full set of registers described in HUM Ch 11 (pages 429..497):
The driver does NOT manipulate SYSTEM.PRCR by side-effect during sleep entry; instead it exposes ra8_lpm_prcr_unlock and ra8_lpm_prcr_relock so the caller can scope the unlock to the exact critical section. The legacy contract (caller has unlocked PRC1 before the protected writes) is preserved.
On host builds the WFI routes through the ra8_hw_intrinsics seam, whose host stub returns at once, so unit tests can drive ra8_lpm_enter_sleep and observe the LPSCR write through the fake mmap without the test binary actually halting. The SCR.SLEEPDEEP read-modify-write runs unchanged on every build: the fake mmap backs the Cortex-M System Control Space window (core region at 0xE0000000), so host tests stage and assert the real toggle sequence.
Definition in file ra8_lpm.c.
| enum lpm_byte_mask_t : uint16_t |
| enum ra8_lpm_cause_shift_t : uint8_t |
| enum ra8_lpm_dpsi_count_t : uint8_t |
Buffer counts for ra8_lpm_get_dpsi_state.
| Enumerator | |
|---|---|
| k_ra8_lpm_dpsier_count | DPSIER0..3 count. |
| k_ra8_lpm_dpsifr_count | DPSIFR0..3 count. |
| k_ra8_lpm_dpsieg_count | DPSIEGR0..2 count. |
| enum ra8_lpm_status_shift_t : uint8_t |
|
static |
Resolve ra8_lpm_clock_t to its OCR offset.
Returns 0 on invalid input – callers must validate first.
| [in] | clock | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 200 of file ra8_lpm.c.
References k_ra8_lpm_clock_count, k_ra8_lpm_clock_hoco, k_ra8_lpm_clock_loco, k_ra8_lpm_clock_main, k_ra8_lpm_clock_moco, k_ra8_lpm_clock_sub, k_ra8_lpm_hococr_off, k_ra8_lpm_lococr_off, k_ra8_lpm_mococr_off, k_ra8_lpm_mosccr_off, k_ra8_lpm_sosccr_off, and RA8_INTERNAL.
Referenced by ra8_lpm_get_clock_stop(), and ra8_lpm_set_clock_stop().
|
static |
Resolve a DPSIEGR index to its register offset.
DPSIEGR3 does not exist on RA8D2 (HUM Ch 11.2 stops at DPSIEGR2); passing index 3 returns DPSIEGR2 so the caller observes a harmless re-read.
| [in] | idx | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 330 of file ra8_lpm.c.
References k_ra8_lpm_dpsiegr0_off, k_ra8_lpm_dpsiegr1_off, k_ra8_lpm_dpsiegr2_off, k_ra8_lpm_dpsier_idx_0, k_ra8_lpm_dpsier_idx_1, k_ra8_lpm_dpsier_idx_2, k_ra8_lpm_dpsier_idx_3, k_ra8_lpm_dpsier_idx_count, and RA8_INTERNAL.
Referenced by ra8_lpm_set_dpsiegr().
|
static |
Resolve a DPSIER index to its register offset.
See implementation.
| [in] | idx | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 246 of file ra8_lpm.c.
References k_ra8_lpm_dpsier0_off, k_ra8_lpm_dpsier1_off, k_ra8_lpm_dpsier2_off, k_ra8_lpm_dpsier3_off, k_ra8_lpm_dpsier_idx_0, k_ra8_lpm_dpsier_idx_1, k_ra8_lpm_dpsier_idx_2, k_ra8_lpm_dpsier_idx_3, k_ra8_lpm_dpsier_idx_count, and RA8_INTERNAL.
Referenced by ra8_lpm_arm_dpsier().
|
static |
Resolve a DPSIFR index to its register offset.
See implementation.
| [in] | idx | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 286 of file ra8_lpm.c.
References k_ra8_lpm_dpsier_idx_0, k_ra8_lpm_dpsier_idx_1, k_ra8_lpm_dpsier_idx_2, k_ra8_lpm_dpsier_idx_3, k_ra8_lpm_dpsier_idx_count, k_ra8_lpm_dpsifr0_off, k_ra8_lpm_dpsifr1_off, k_ra8_lpm_dpsifr2_off, k_ra8_lpm_dpsifr3_off, and RA8_INTERNAL.
Referenced by ra8_lpm_arm_dpsier(), and ra8_lpm_clear_dpsifr().
|
inlinestatic |
Toggle SCB.SCR.SLEEPDEEP for non-Sleep mode entry.
Reads-modify-writes SCR so sibling SCR bits (e.g. SLEEPONEXIT, SEVONPEND) are preserved. SCR is an Arm core register (Armv8-M SCS, not in the HUM); the same sequence runs on every build – the host unit-test fake mmap backs the SCS window with RAM, so tests stage and assert the toggle directly.
| [in] | enable | true – set SLEEPDEEP; false – clear. |
Definition at line 139 of file ra8_lpm.c.
References k_ra8_lpm_scb_scr_sleepdeep, RA8_INTERNAL, and ra8_lpm_scb_scr().
Referenced by ra8_lpm_enter_sleep().
|
static |
Validate mode against the LPSCR.LPMD encoding table.
See implementation.
| [in] | mode | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 165 of file ra8_lpm.c.
References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_sleep_mode_deep_sleep, k_ra8_sleep_mode_deep_standby_1, k_ra8_sleep_mode_deep_standby_2, k_ra8_sleep_mode_deep_standby_3, k_ra8_sleep_mode_sleep, k_ra8_sleep_mode_software_std, and RA8_INTERNAL.
Referenced by ra8_lpm_enter_sleep().
|
inlinestatic |
Issue a Data Synchronization Barrier followed by WFI.
A DSB retires every prior register write before the core sleeps, per the HUM Ch 11 "Low Power Mode" entry sequence, then WFI parks the core. Both primitives route through the ra8_hw_intrinsics seam, so the host build substitutes no-ops (defined in tests/mocks/src/ra8_host_asm_stub.c) and a unit test can drive ra8_lpm_enter_sleep without blocking.
Definition at line 112 of file ra8_lpm.c.
References ra8_hw_dsb(), ra8_hw_wfi(), and RA8_INTERNAL.
Referenced by ra8_lpm_enter_sleep().
|
nodiscard |
Programme the per-byte DPSIER0..3 enable byte directly.
| [in] | idx | DPSIER selector (k_ra8_lpm_dpsier_idx_*). |
| [in] | value | 8-bit enable mask to write. |
| k_ra8_ok | Register updated. |
| k_ra8_err_invalid_arg | idx out of range. |
Definition at line 502 of file ra8_lpm.c.
References internal_dpsier_offset(), internal_dpsifr_offset(), k_ra8_err_invalid_arg, k_ra8_lpm_dpsier_idx_count, k_ra8_ok, ra8_log_error, ra8_lpm_sysc_reg8(), and s_tag.
Referenced by internal_lpm_dpsby1_arm_wake(), internal_lpm_dpsby2_arm_wake(), and internal_lpm_dpsby3_arm_wake().
|
nodiscard |
OR-in additional WUPEN0 bits without disturbing other sources.
| [in] | bits | k_ra8_lpm_wupen0_* mask to set. |
| k_ra8_ok | WUPEN0 updated. |
Definition at line 465 of file ra8_lpm.c.
References k_ra8_lpm_wupen0_off, k_ra8_ok, and ra8_lpm_icu_reg32().
Referenced by internal_lpm_dpsby1_arm_wake(), internal_lpm_dpsby2_arm_wake(), internal_lpm_dpsby3_arm_wake(), internal_lpm_swstd_arm_wake(), and internal_lpm_wake_arm0().
|
nodiscard |
OR-in additional WUPEN1 bits without disturbing other sources.
| [in] | bits | k_ra8_lpm_wupen1_* mask to set. |
| k_ra8_ok | WUPEN1 updated. |
Definition at line 481 of file ra8_lpm.c.
References k_ra8_lpm_wupen1_off, k_ra8_ok, and ra8_lpm_icu_reg32().
Referenced by internal_lpm_wake_arm1(), internal_lus_arm_wake(), and lpi_arm_wake().
|
nodiscard |
Clear DPSIFR0..3 so a stale flag does not cancel deep standby.
| [in] | idx | DPSIER selector (k_ra8_lpm_dpsier_idx_*). |
| k_ra8_ok | Flag cleared. |
| k_ra8_err_invalid_arg | idx out of range. |
Definition at line 522 of file ra8_lpm.c.
References internal_dpsifr_offset(), k_ra8_err_invalid_arg, k_ra8_lpm_dpsier_idx_count, k_ra8_ok, ra8_log_error, ra8_lpm_sysc_reg8(), and s_tag.
|
nodiscard |
AND-out WUPEN0 bits to disarm specific wake-up sources.
| [in] | bits | k_ra8_lpm_wupen0_* mask to clear. |
| k_ra8_ok | WUPEN0 updated. |
Definition at line 473 of file ra8_lpm.c.
References k_ra8_lpm_wupen0_off, k_ra8_ok, and ra8_lpm_icu_reg32().
Referenced by internal_lpm_wake_disarm_all().
|
nodiscard |
AND-out WUPEN1 bits to disarm specific wake-up sources.
| [in] | bits | k_ra8_lpm_wupen1_* mask to clear. |
| k_ra8_ok | WUPEN1 updated. |
Definition at line 489 of file ra8_lpm.c.
References k_ra8_lpm_wupen1_off, k_ra8_ok, and ra8_lpm_icu_reg32().
Referenced by internal_lpm_wake_disarm_all().
|
nodiscard |
Restore SBYCR / DPSBYCR / LPSCR / SSCR1 to cold-reset defaults.
Rewrites SBYCR with its reset value (OPE=1, all other bits 0), DPSBYCR with its reset value (DCSSMODE=01b), LPSCR with its reset value (System Active), SSCR1=0, all WUPEN bits=0, all DPSIER bits=0. Used during clean teardown so a stray IRQ does not bring us out of a subsequent sleep with stale wake-up arming.
| k_ra8_ok | Registers reset. |
Definition at line 394 of file ra8_lpm.c.
References k_ra8_lpm_dpsbycr_off, k_ra8_lpm_dpsbycr_reset_val, k_ra8_lpm_dpsier0_off, k_ra8_lpm_dpsier1_off, k_ra8_lpm_dpsier2_off, k_ra8_lpm_dpsier3_off, k_ra8_lpm_lpscr_off, k_ra8_lpm_sbycr_off, k_ra8_lpm_sbycr_reset_val, k_ra8_lpm_sscr1_off, k_ra8_lpm_wupen0_off, k_ra8_lpm_wupen1_off, k_ra8_ok, ra8_log_info, ra8_lpm_icu_reg32(), ra8_lpm_sysc_reg8(), and s_tag.
|
nodiscard |
Convenience wrapper – enter Deep Software Standby mode 1.
| k_ra8_ok | WFI returned (cold path: never returns on hardware). |
Definition at line 786 of file ra8_lpm.c.
References k_ra8_sleep_mode_deep_standby_1, and ra8_lpm_enter_sleep().
|
nodiscard |
Programme LPSCR for mode and enter the requested sleep.
Maps mode to the LPSCR.LPMD encoding from HUM 11.2.20 p 457, writes the new LPSCR value, configures SCR.SLEEPDEEP for non-Sleep modes, then executes WFI. For k_ra8_sleep_mode_sleep the LPMD field is left at 0 (System Active) and a plain WFI puts only the CPU to sleep – peripherals stay clocked.
| [in] | mode | Target sleep mode (sleep / deep-sleep / software-standby / deep-standby 1..3). |
| k_ra8_ok | Mode programmed and WFI returned. |
| k_ra8_err_invalid_arg | mode was not a valid encoding. |
Definition at line 735 of file ra8_lpm.c.
References internal_set_sleepdeep(), internal_validate_mode(), internal_wait_for_interrupt(), k_ra8_lpm_lpscr_lpmd_mask, k_ra8_lpm_lpscr_off, k_ra8_ok, k_ra8_sleep_mode_deep_sleep, k_ra8_sleep_mode_deep_standby_1, k_ra8_sleep_mode_deep_standby_2, k_ra8_sleep_mode_deep_standby_3, k_ra8_sleep_mode_sleep, k_ra8_sleep_mode_software_std, ra8_log_info_val, ra8_lpm_sysc_reg8(), RA8_RETURN_ON_ERROR, and s_tag.
Referenced by internal_lpm_demo_one_wake(), lpi_idle_one_period(), main(), pp_demo_cycle_modes(), and ra8_lpm_enter_deep_standby().
|
nodiscard |
Read the per-oscillator stop bit.
| [in] | clock | Oscillator selector (k_ra8_lpm_clock_*). |
| [out] | stop | Receives the current stop bit (1 = stopped). |
| k_ra8_ok | *stop populated. |
| k_ra8_err_invalid_arg | clock out of range. |
| k_ra8_err_null_ptr | stop was nullptr. |
Definition at line 688 of file ra8_lpm.c.
References internal_clock_offset(), k_ra8_err_invalid_arg, k_ra8_lpm_clock_count, k_ra8_lpm_clock_stop_mask, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_error, ra8_lpm_sysc_reg8(), and s_tag.
|
nodiscard |
Read DPSIER0..3 + DPSIFR0..3 + DPSIEGR0..2 into a buffer.
| [out] | enables | Receives DPSIER0..3 (must be 4 bytes). |
| [out] | flags | Receives DPSIFR0..3 (must be 4 bytes). |
| [out] | edges | Receives DPSIEGR0..2 (must be 3 bytes). |
| k_ra8_ok | All buffers populated. |
| k_ra8_err_null_ptr | Any of enables / flags / edges was nullptr. |
Definition at line 828 of file ra8_lpm.c.
References k_ra8_lpm_dpsiegr0_off, k_ra8_lpm_dpsiegr1_off, k_ra8_lpm_dpsiegr2_off, k_ra8_lpm_dpsier0_off, k_ra8_lpm_dpsier1_off, k_ra8_lpm_dpsier2_off, k_ra8_lpm_dpsier3_off, k_ra8_lpm_dpsifr0_off, k_ra8_lpm_dpsifr1_off, k_ra8_lpm_dpsifr2_off, k_ra8_lpm_dpsifr3_off, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_lpm_sysc_reg8(), and s_tag.
|
nodiscard |
Snapshot WUPEN0 / WUPEN1 into a single 64-bit word.
Returns (WUPEN1 << 32) | WUPEN0 – which sources were armed at the moment of the call. Combined with the post-wake NVIC pending mask the application can decide what woke it.
| [out] | out | Receives the packed wake-up enable snapshot. |
| k_ra8_ok | *out populated. |
| k_ra8_err_null_ptr | out was nullptr. |
Definition at line 814 of file ra8_lpm.c.
References k_ra8_lpm_cause_shift_wupen0, k_ra8_lpm_cause_shift_wupen1, k_ra8_lpm_wupen0_off, k_ra8_lpm_wupen1_off, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_lpm_icu_reg32(), and s_tag.
Referenced by internal_lpm_wake_arm0(), internal_lpm_wake_arm1(), and internal_lpm_wake_disarm_all().
|
nodiscard |
Read OPCCR raw byte (OPCM[1:0] + OPCMTSF).
| [out] | opccr | Receives the live OPCCR byte. |
| k_ra8_ok | *opccr populated. |
| k_ra8_err_null_ptr | opccr was nullptr. |
Definition at line 706 of file ra8_lpm.c.
References k_ra8_lpm_opccr_off, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_lpm_sysc_reg8(), and s_tag.
|
nodiscard |
Read LPM status (SBYCR | DPSBYCR | LPSCR | SSCR1) packed.
Packs four single-byte registers into a uint32:
| Byte | Source |
|---|---|
| [0] | SBYCR |
| [1] | DPSBYCR |
| [2] | LPSCR |
| [3] | SSCR1 |
Useful for telemetry: "what mode are we in, did IOKEEP latch, is fast-return enabled?".
| [out] | out | Receives the packed status word. |
| k_ra8_ok | *out populated. |
| k_ra8_err_null_ptr | out was nullptr. |
Definition at line 796 of file ra8_lpm.c.
References k_ra8_lpm_dpsbycr_off, k_ra8_lpm_lpscr_off, k_ra8_lpm_sbycr_off, k_ra8_lpm_sscr1_off, k_ra8_lpm_status_shift_dpsbycr, k_ra8_lpm_status_shift_lpscr, k_ra8_lpm_status_shift_sbycr, k_ra8_lpm_status_shift_sscr1, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_lpm_sysc_reg8(), and s_tag.
|
nodiscard |
Initialise the LPM block from a config descriptor.
Writes SBYCR.OPE, DPSBYCR (IOKEEP + DCSSMODE), and SSCR1 (SS2FR + SS2LP) from cfg. Clears LPSCR.LPMD to System Active so the next plain WFI does an ordinary CPU sleep until the application explicitly arms a deeper mode via ra8_lpm_enter_sleep.
| [in] | cfg | Non-NULL configuration descriptor. |
| k_ra8_ok | All four registers programmed. |
| k_ra8_err_null_ptr | cfg was nullptr. |
Definition at line 358 of file ra8_lpm.c.
References ra8_lpm_config_t::dcdc_softstart, ra8_lpm_config_t::io_port_keep, k_ra8_lpm_dpsbycr_dcssmode_shift, k_ra8_lpm_dpsbycr_iokeep_mask, k_ra8_lpm_dpsbycr_off, k_ra8_lpm_lpscr_off, k_ra8_lpm_sbycr_off, k_ra8_lpm_sbycr_ope_mask, k_ra8_lpm_sscr1_off, k_ra8_lpm_sscr1_ss2fr_mask, k_ra8_lpm_sscr1_ss2lp_shift, k_ra8_ok, ra8_lpm_config_t::opa_bus_keep, RA8_CHECK_NULL_PTR, ra8_log_info, ra8_lpm_sysc_reg8(), s_tag, ra8_lpm_config_t::sscr_fast_return, and ra8_lpm_config_t::sscr_low_power.
Referenced by internal_lpm_deep_setup_or_halt(), internal_lpm_demo_setup_or_halt(), internal_lpm_dpsby1_setup_or_halt(), internal_lpm_dpsby2_setup_or_halt(), internal_lpm_dpsby3_setup_or_halt(), internal_lpm_swstd_setup_or_halt(), internal_lpm_wake_setup_or_halt(), internal_lus_setup_or_halt(), lpi_setup_or_halt(), m85_lpm_configure(), and pp_demo_modules_or_halt().
|
nodiscard |
Re-lock PRCR.PRC1 after protected writes.
| k_ra8_ok | PRC1 locked. |
Definition at line 441 of file ra8_lpm.c.
References k_lpm_byte_mask, k_ra8_lpm_prcr_key, k_ra8_lpm_prcr_off, k_ra8_lpm_prcr_prc1_msk, k_ra8_ok, and ra8_lpm_sysc_reg16().
Referenced by m85_gate_hoco(), and m85_lpm_configure().
|
nodiscard |
Unlock PRCR.PRC1 to permit writes to LPM control registers.
Writes 0xA502 to SYSTEM.PRCR (key 0xA5 + PRC1=1). The companion ra8_lpm_prcr_relock writes 0xA500 to lock the region again. Pairs with the standby/wake critical section.
| k_ra8_ok | PRC1 unlocked. |
Definition at line 430 of file ra8_lpm.c.
References k_lpm_byte_mask, k_ra8_lpm_prcr_key, k_ra8_lpm_prcr_off, k_ra8_lpm_prcr_prc1_msk, k_ra8_ok, and ra8_lpm_sysc_reg16().
Referenced by m85_gate_hoco(), and m85_lpm_configure().
|
nodiscard |
Set or clear the per-oscillator stop bit before sleep entry.
Toggles the STOP bit (bit 0) of the oscillator control register selected by clock – MOSCCR, HOCOCR, MOCOCR, LOCOCR or SOSCCR. Those registers belong to the clock-generation circuit and are PRC0-protected (HUM Ch 13.1 Table 13.1); a write issued while PRC0 is locked is discarded silently by the hardware. The read-modify-write is therefore performed inside a self-contained PRCR CGC unlock window: the caller does not unlock PRCR beforehand, and PRCR is returned to its fully-locked state before return.
| [in] | clock | Oscillator selector (k_ra8_lpm_clock_*). |
| [in] | stop | true – request stop; false – request run. |
| k_ra8_ok | Stop bit toggled. |
| k_ra8_err_invalid_arg | clock out of range. |
Definition at line 661 of file ra8_lpm.c.
References internal_clock_offset(), k_ra8_err_invalid_arg, k_ra8_lpm_clock_count, k_ra8_lpm_clock_stop_mask, k_ra8_ok, k_ra8_prcr_unlock_cgc, ra8_log_error, ra8_lpm_sysc_reg8(), RA8_PROTECTED_WRITE, and s_tag.
Referenced by internal_lus_setup_or_halt(), lpi_setup_or_halt(), and m85_gate_hoco().
|
nodiscard |
Programme DPSIEGR0..2 (deep-standby IRQ edge polarity).
| [in] | idx | DPSIEGR selector (0..2 only – DPSIEGR3 not used). |
| [in] | value | 8-bit edge mask: bit=1 selects rising edge. |
| k_ra8_ok | Register updated. |
| k_ra8_err_invalid_arg | idx out of range. |
Definition at line 535 of file ra8_lpm.c.
References internal_dpsiegr_offset(), k_ra8_err_invalid_arg, k_ra8_lpm_dpsier_idx_count, k_ra8_ok, ra8_log_error, ra8_lpm_sysc_reg8(), and s_tag.
|
nodiscard |
Programme PLL1LDOCR / PLL2LDOCR / HOCOLDOCR SKEEP bits.
| [in] | cfg | Non-NULL LDO retention configuration. |
| k_ra8_ok | All three LDOCR bytes updated. |
| k_ra8_err_null_ptr | cfg was nullptr. |
| k_ra8_err_invalid_state | OPCCR.OPCM != 0 (writes prohibited). |
Definition at line 626 of file ra8_lpm.c.
References ra8_lpm_ldo_cfg_t::hoco, k_ra8_err_invalid_state, k_ra8_lpm_hocoldocr_off, k_ra8_lpm_ldocr_skeep_mask, k_ra8_lpm_ldocr_skeep_shift, k_ra8_lpm_opccr_off, k_ra8_lpm_opccr_opcm_mask, k_ra8_lpm_pll1ldocr_off, k_ra8_lpm_pll2ldocr_off, k_ra8_ok, ra8_lpm_ldo_cfg_t::pll1, ra8_lpm_ldo_cfg_t::pll2, RA8_CHECK_NULL_PTR, ra8_log_error, ra8_lpm_sysc_reg8(), and s_tag.
|
nodiscard |
Programme PDRAMSCR0 / PDRAMSCR1 from a retention descriptor.
| [in] | cfg | Non-NULL retention configuration. |
| k_ra8_ok | Both registers programmed. |
| k_ra8_err_null_ptr | cfg was nullptr. |
Definition at line 606 of file ra8_lpm.c.
References ra8_lpm_ram_retention_t::cpu0_tcm_keep, ra8_lpm_ram_retention_t::cpu1_tcm_keep, k_ra8_lpm_pdramscr0_off, k_ra8_lpm_pdramscr0_writable, k_ra8_lpm_pdramscr1_off, k_ra8_lpm_pdramscr1_rkeep0_mask, k_ra8_lpm_pdramscr1_rkeep1_mask, k_ra8_ok, ra8_lpm_ram_retention_t::pdramscr0_bits, RA8_CHECK_NULL_PTR, ra8_lpm_sysc_reg16(), ra8_lpm_sysc_reg8(), and s_tag.
|
nodiscard |
Programme the raw WUPEN0 / WUPEN1 masks.
Writes wupen0 to ICU.WUPEN0 and wupen1 to ICU.WUPEN1 verbatim. Use the k_ra8_lpm_wupen0_* / k_ra8_lpm_wupen1_* helper enums to assemble bit patterns.
| [in] | wupen0 | Mask for WUPEN0 (IRQ0..15 + IWDT/PVD/RTC/USB...). |
| [in] | wupen1 | Mask for WUPEN1 (ULPT/I3C/SOSC/CMP). |
| k_ra8_ok | Masks written. |
Definition at line 456 of file ra8_lpm.c.
References k_ra8_lpm_wupen0_off, k_ra8_lpm_wupen1_off, k_ra8_ok, and ra8_lpm_icu_reg32().
|
nodiscard |
Configure end-of-snooze sources via DPSIER3 (ULPT/USB hooks).
Mirrors the FSP "snooze end" concept by writing the relevant DPSIER3 bits (DULPT0IE / DULPT1IE / DUSBFSIE / DUSBHSIE) so a subsequent deep-standby entry can be cancelled by the same peripheral that woke it from snooze.
| [in] | ulpt0 | Set DPSIER3.DULPT0IE. |
| [in] | ulpt1 | Set DPSIER3.DULPT1IE. |
| [in] | usbfs | Set DPSIER3.DUSBFSIE. |
| [in] | usbhs | Set DPSIER3.DUSBHSIE. |
| k_ra8_ok | DPSIER3 updated. |
Definition at line 575 of file ra8_lpm.c.
References k_ra8_lpm_dpsier3_dulpt0ie_mask, k_ra8_lpm_dpsier3_dulpt1ie_mask, k_ra8_lpm_dpsier3_dusbfsie_mask, k_ra8_lpm_dpsier3_dusbhsie_mask, k_ra8_lpm_dpsier3_off, k_ra8_lpm_dpsifr3_off, k_ra8_ok, and ra8_lpm_sysc_reg8().
|
nodiscard |
Configure ULPT-driven snooze request sources.
RA8D2 does not implement the dedicated SNZCR/SNZEDCR/SNZREQCR register block found on older RA Gen-1 parts. Instead, the chip supports a "Software Standby + ULPT wake" pattern where ULPT0 (or ULPT1) periodically wakes the MCU from Software Standby to sample an ADC channel or service an I2C transaction. This helper writes the ULPT-related bits in WUPEN1 to enable that pattern.
| [in] | ulpt0_underflow | Set to enable ULPT0 underflow wake. |
| [in] | ulpt1_underflow | Set to enable ULPT1 underflow wake. |
| [in] | acmphs0 | Set to enable ACMPHS0 comparator wake. |
| k_ra8_ok | WUPEN1 updated. |
Definition at line 553 of file ra8_lpm.c.
References k_ra8_lpm_wupen0_acmphs0, k_ra8_lpm_wupen0_off, k_ra8_lpm_wupen1_off, k_ra8_lpm_wupen1_ulpt0u, k_ra8_lpm_wupen1_ulpt1u, k_ra8_ok, and ra8_lpm_icu_reg32().
|
nodiscard |
Wait for OPCCR.OPCMTSF to clear (mode-transition complete).
| [in] | poll_limit | Maximum number of polling iterations. |
| k_ra8_ok | OPCMTSF cleared within budget. |
| k_ra8_err_hw_timeout | poll_limit exhausted with OPCMTSF=1. |
Definition at line 714 of file ra8_lpm.c.
References k_ra8_err_hw_timeout, k_ra8_err_invalid_arg, k_ra8_lpm_opccr_off, k_ra8_lpm_opccr_opcmtsf_msk, k_ra8_ok, ra8_log_error, ra8_lpm_sysc_reg8(), and s_tag.