|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
ULPT0-underflow wake from Software Standby (LPSCR.LPMD = 0x5). More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_elc_regs.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_lpm.h"#include "ra8_lpm_regs.h"#include "ra8_time.h"#include "ra8_ulpt.h"Go to the source code of this file.
Enumerations | |
| enum | lus_const_t : uint32_t { k_lus_baud = 115200U , k_lus_period_ticks = 0x4000U , k_lus_tcstf_poll_limit = 0x100000U } |
| Demo tunables. More... | |
| enum | lus_chan_t : uint8_t { k_lus_channel = 0U } |
| ULPT channel selector. More... | |
Functions | |
| static void | internal_lus_panic_halt (void) |
| Park the processor after an unrecoverable setup or arm failure. | |
| static void | internal_lus_ulpt_isr (void *ctx) |
| ULPT0 underflow interrupt service routine. | |
| static ra8_err_t | internal_lus_wait_count_started (uint8_t channel) |
| Spin until the ULPT count operation has actually started. | |
| static void | internal_lus_setup_or_halt (void) |
| Bring CGC + SysTick + SCI8 + ULPT + LPM block up. | |
| static ra8_err_t | internal_lus_arm_wake (void) |
| Wire the ULPT0 underflow as a Software-Standby wake source. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| static const uint8_t | s_lus_boot_msg [] = "lpm_ulpt: boot\r\n" |
| Boot banner emitted once before the first standby entry. | |
| static const uint8_t | s_lus_wake_msg [] = "lpm_ulpt: wake\r\n" |
| Wake banner and per-underflow HIL gate string. | |
| volatile uint32_t | g_lpm_ulpt_wake_count = 0U |
| Liveness counter – bumped in the ULPT0 underflow ISR. | |
ULPT0-underflow wake from Software Standby (LPSCR.LPMD = 0x5).
Deep-idle foundation demo: the CPU spends almost all of its time in Software Standby (every clock domain gated except LOCO and the always-on wake detectors) and is woken purely by the on-chip Ultra-Low-Power Timer, with no off-chip crystal in the loop.
Why ULPT and not the RTC: with ULPTMR1.TCK1 = 0 the ULPT counts from ULPTLCLK – the LOCO-derived 32.768 kHz clock (HUM Table 9.2 p 320) – which keeps running through Software Standby while LOCOCR.LCSTP = 0 (HUM Table 11.3 footnote *2 p 433). LOCO is internal, so unlike the RTC alarm (which depends on the bare-board sub-clock crystal) this wake source does not rely on the intermittent SOSC.
The wake path that the earlier ULPT standby attempt was missing: on the RA8D2 a Software-Standby wake needs BOTH halves of the ICU wired, not just the WUPEN bit.
Boot flow:
Unlike lpm_software_standby_demo (RTC / SOSC), the wake here runs off LOCO, so the periodic "lpm_ulpt: wake" banner is a real, bench-gatable wake signal (see hil.conf).
Definition in file main.c.
| enum lus_chan_t : uint8_t |
| enum lus_const_t : uint32_t |
|
staticnodiscard |
Wire the ULPT0 underflow as a Software-Standby wake source.
Both halves of the RA8D2 wake path are required (see file header): the IELSRn/NVIC link via ra8_isr_register AND the async WUPEN1.ULP0U detector via ra8_lpm_arm_wupen1_bits.
| k_ra8_ok | Both NVIC event routing and asynchronous wake detection are armed. |
Definition at line 285 of file main.c.
References internal_lus_ulpt_isr(), k_ra8_elc_event_ulpt0_ulpti, k_ra8_isr_prio_default, k_ra8_lpm_wupen1_ulpt0u, k_ra8_ok, RA8_INTERNAL, ra8_isr_init(), ra8_isr_register(), and ra8_lpm_arm_wupen1_bits().
Referenced by main().
|
static |
Park the processor after an unrecoverable setup or arm failure.
Enters a permanent wait loop so register and counter state remains available to a debugger without continuing into standby.
Definition at line 127 of file main.c.
References RA8_INTERNAL.
Referenced by internal_lus_setup_or_halt(), and main().
|
static |
Bring CGC + SysTick + SCI8 + ULPT + LPM block up.
Same shape as lpm_software_standby_demo but swaps the RTC for the ULPT. The SCI8 J-Link console (PD02 TXD / PD03 RXD) is brought up via the EK-RA8D2 board-support console API.
Definition at line 222 of file main.c.
References internal_lus_panic_halt(), k_lus_baud, k_ra8_clock_id_cpuclk0, k_ra8_lpm_clock_loco, k_ra8_lpm_dcssmode_128us, k_ra8_lpm_ss2lp_default, k_ra8_ok, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, ra8_lpm_init(), ra8_lpm_set_clock_stop(), ra8_time_init(), and ra8_ulpt_init().
Referenced by main().
|
static |
ULPT0 underflow interrupt service routine.
Real path: ULPT0 counter underflow -> ULPT0_ULPTI ELC event -> IELSRn link -> NVIC pend -> vector 16 + IRQ -> ra8_isr_dispatch -> here. Cancelling Software Standby is handled by the WUPEN1.ULP0U detector + the NVIC pend; this handler only records liveness. The underflow source flag (ULPTCR.TUNF) is cleared by the ra8_ulpt_stop in the main loop's re-arm step, so the ISR stays minimal and allocation-free.
| [in] | ctx | Unused registration context. |
ctx is the unused context registered by this application. Definition at line 156 of file main.c.
References g_lpm_ulpt_wake_count, and RA8_INTERNAL.
Referenced by internal_lus_arm_wake().
|
staticnodiscard |
Spin until the ULPT count operation has actually started.
HUM Section 25.4.7 (p 1214) requires confirming ULPTCR.TCSTF = 1 (count operation started) before entering a standby mode – otherwise the standby transition can gate the sync clock before the counter has begun, leaving it stalled and unable to underflow. ra8_ulpt_start only sets TSTART; this closes the gap from the application side.
| [in] | channel | ULPT channel index (0 or 1). |
| k_ra8_ok | The hardware confirms the count operation started. |
| k_ra8_err_hw_timeout | The bounded poll expired before TCSTF asserted. |
channel. channel identifies an initialized ULPT instance. Definition at line 187 of file main.c.
References k_lus_tcstf_poll_limit, k_ra8_err_hw_timeout, k_ra8_ok, k_ra8_ulpt_bit_tcstf, RA8_INTERNAL, and ra8_ulpt_get_status().
Referenced by main().
| void main | ( | void | ) |
The application entry point Reset_Handler hands control to.
Returns void, not int. This is a freestanding image: there is no hosted C environment, no process and nothing to report an exit status to. ISO C fixes main at int only for a hosted implementation; for a freestanding one (C23 5.1.2.1) the startup function's name and type are implementation-defined, and this is that definition. Reset_Handler discards no value because there is none to discard, and if main ever does return, startup halts the CPU rather than resuming anything.
The firmware lane is compiled -ffreestanding (see cmake/ra8_add_app.cmake) and the flag and this signature travel together: without it both GCC and clang reject a non-int main (-Wmain / -Wmain-return-type). Do not remove one without the other.
That coupling is why the declaration sits behind __STDC_HOSTED__ == 0, which -ffreestanding sets and a hosted build does not. The guard is not defensive dressing: this header is reachable from host builds (the unit tests compile ra8_core natively), and an unguarded void main(void); makes every hosted translation unit that includes it fail with conflicting types for 'main' against its own ISO int main. The declaration therefore exists exactly where its contract does.
Hosted first-party code – everything under tests/ and tools/ – uses the ISO int main(...) contract instead, because it genuinely does run under an OS that reads the exit status. scripts/checks/check_entry_points.py holds each domain to its own contract (#707).
Declared here, once, for the same reason SystemInit is: every vector_table.c used to restate it as a local extern int32_t main(void);, sixteen copies that no compiler ever compared against the definition – and roughly thirty of them had silently drifted out of agreement with the main they called.
The application entry point Reset_Handler hands control to.
Brings up CGC + BSP audio then plays blocks.
The application entry point Reset_Handler hands control to.
Brings up CGC + GPT triple, runs sweep.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART, then enters ThreadX.
The application entry point Reset_Handler hands control to.
Brings up LED, console, SDHI pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up CGC + USB-FS + UAC1, then enters the iso-IN feed loop forever.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
See file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Definition at line 302 of file main.c.
References internal_lus_arm_wake(), internal_lus_panic_halt(), internal_lus_setup_or_halt(), internal_lus_wait_count_started(), k_lus_channel, k_lus_period_ticks, k_ra8_ok, k_ra8_sleep_mode_software_std, ra8_board_uart_console_write(), ra8_isr_globals_enable(), ra8_lpm_enter_sleep(), ra8_ulpt_start(), ra8_ulpt_stop(), s_lus_boot_msg, and s_lus_wake_msg.
| volatile uint32_t g_lpm_ulpt_wake_count = 0U |
Liveness counter – bumped in the ULPT0 underflow ISR.
Incremented from internal_lus_ulpt_isr each time a ULPT0 underflow cancels Software Standby. Exposed (non-static, volatile) so a J-Link session can watch the wake cadence without the UART.
Definition at line 114 of file main.c.
Referenced by internal_lus_ulpt_isr().
|
static |
|
static |