|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Ultra-Low-Power Timer (ULPT) driver header. More...
Go to the source code of this file.
Typedefs | |
| typedef void(* | ra8_ulpt_event_fn_t) (void *ctx, uint8_t channel) |
| ULPT event callback. | |
Functions | |
| ra8_err_t | ra8_ulpt_init (void) |
| Reset both ULPT channels to their power-on state. | |
| ra8_err_t | ra8_ulpt_start (uint8_t channel, uint32_t period) |
| Start a ULPT channel counting down from period. | |
| ra8_err_t | ra8_ulpt_stop (uint8_t channel) |
| Stop a ULPT channel and confirm the counter has halted. | |
| ra8_err_t | ra8_ulpt_deinit (uint8_t channel) |
| Tear down a ULPT channel. | |
| ra8_err_t | ra8_ulpt_set_period (uint8_t channel, uint32_t period) |
| Change the ULPT period at runtime. | |
| ra8_err_t | ra8_ulpt_get_status (uint8_t channel, uint8_t *out_mask) |
| Read ULPTCR status bits. | |
| ra8_err_t | ra8_ulpt_attach_handler (ra8_ulpt_event_fn_t fn, void *ctx) |
| Attach a ULPT event callback (shared across channels). | |
| void | ra8_ulpt_dispatch (uint8_t channel) |
| Dispatch a ULPT event – fire callback. | |
| ra8_err_t | ra8_ulpt_enter_stop (uint8_t channel) |
| Put one channel into MSTP-gated stop. | |
| ra8_err_t | ra8_ulpt_exit_stop (uint8_t channel) |
| Exit MSTP-gated stop. | |
Ultra-Low-Power Timer (ULPT) driver header.
Declares reset, configuration, start, stop, and counter access for the two ultra-low-power timer channels.
Definition in file ra8_ulpt.h.
| typedef void(* ra8_ulpt_event_fn_t) (void *ctx, uint8_t channel) |
ULPT event callback.
Definition at line 75 of file ra8_ulpt.h.
|
nodiscard |
Attach a ULPT event callback (shared across channels).
Attach a ULPT event callback (shared across channels).
Stores (fn, ctx) in the shared slot consulted by every ra8_ulpt_dispatch call, regardless of channel index. Passing fn == NULL detaches.
| [in] | fn | Callback function or NULL to detach. |
| [in] | ctx | Opaque value forwarded verbatim to fn. |
| k_ra8_ok | Slot updated. |
Definition at line 282 of file ra8_ulpt.c.
References k_ra8_ok, s_ulpt_ctx, and s_ulpt_fn.
|
nodiscard |
Tear down a ULPT channel.
Tear down a ULPT channel.
Clears ULPTCR (HUM Ch 25.2.1 "ULPTCR : ULPT Control Register", p 1190) so the counter stops, then releases the matching MSTP gate.
| [in] | channel | ULPT channel index (0 or 1). |
| k_ra8_ok | Channel stopped, MSTP released. |
| k_ra8_err_invalid_arg | channel >= 2. |
| k_ra8_err_invalid_state | ra8_mstp_disable underflow. |
Definition at line 177 of file ra8_ulpt.c.
References k_ra8_err_invalid_arg, k_ra8_ulpt_channel_count, RA8_CHECK_NULL_PTR, ra8_mstp_disable(), ra8_ulpt(), s_tag, s_ulpt_mstp_table, and r_ulpt_regs_t::ULPTCR.
| void ra8_ulpt_dispatch | ( | uint8_t | channel | ) |
Dispatch a ULPT event – fire callback.
Called from the ULPT compare-match / underflow ISR (HUM Ch 26 "Ultra-Low Power Timer (ULPT)", p 1273) to invoke the registered handler. Out-of-range channel and unattached slots are silently ignored so spurious IRQs are harmless.
| [in] | channel | ULPT channel index (0 or 1). |
Dispatch a ULPT event – fire callback.
Out-of-range channel values and detached slots are silently dropped so spurious IRQs are harmless.
| [in] | channel | ULPT channel index (0 or 1). |
Definition at line 308 of file ra8_ulpt.c.
References k_ra8_ulpt_channel_count, s_ulpt_ctx, and s_ulpt_fn.
|
nodiscard |
Put one channel into MSTP-gated stop.
Put one channel into MSTP-gated stop.
Releases the per-channel MSTP gate so the channel stops consuming clock during sleep / standby. Counter state is preserved by the always-on ULPT clock domain.
| [in] | channel | ULPT channel index (0 or 1). |
| k_ra8_ok | MSTP reference dropped. |
| k_ra8_err_invalid_arg | channel >= 2. |
| k_ra8_err_invalid_state | ra8_mstp_disable underflow. |
Definition at line 344 of file ra8_ulpt.c.
References k_ra8_err_invalid_arg, k_ra8_ulpt_channel_count, ra8_mstp_disable(), and s_ulpt_mstp_table.
|
nodiscard |
Exit MSTP-gated stop.
Exit MSTP-gated stop.
Re-takes the per-channel MSTP gate so the channel resumes clocking with its prior counter / control state intact.
| [in] | channel | ULPT channel index (0 or 1). |
| k_ra8_ok | MSTP reference taken. |
| k_ra8_err_invalid_arg | channel >= 2. |
| k_ra8_err_invalid_state | ra8_mstp_enable over-took limit. |
Definition at line 375 of file ra8_ulpt.c.
References k_ra8_err_invalid_arg, k_ra8_ulpt_channel_count, ra8_mstp_enable(), and s_ulpt_mstp_table.
|
nodiscard |
Read ULPTCR status bits.
Read ULPTCR status bits.
Returns the raw 8-bit ULPTCR value (HUM Ch 25.2.1, p 1190) so callers can inspect TSTART / TCSTF / TUNDF / TEDGF without leaking the register layout.
| [in] | channel | ULPT channel index (0 or 1). |
| [out] | out_mask | Receives the ULPTCR snapshot. |
| k_ra8_ok | Status read into *out_mask. |
| k_ra8_err_null_ptr | out_mask was NULL. |
| k_ra8_err_invalid_arg | channel >= 2. |
Definition at line 249 of file ra8_ulpt.c.
References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ulpt_channel_count, RA8_CHECK_NULL_PTR, ra8_ulpt(), s_tag, and r_ulpt_regs_t::ULPTCR.
Referenced by internal_lus_wait_count_started(), lpi_wait_count_started(), and main().
|
nodiscard |
Reset both ULPT channels to their power-on state.
Definition at line 64 of file ra8_ulpt.c.
References k_ra8_err_hw_init_failed, k_ra8_ok, k_ra8_ulpt_channel_count, ra8_log_info, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, ra8_ulpt(), s_tag, s_ulpt_mstp_table, r_ulpt_regs_t::ULPTCNT, r_ulpt_regs_t::ULPTCR, r_ulpt_regs_t::ULPTIOC, r_ulpt_regs_t::ULPTMR1, r_ulpt_regs_t::ULPTMR2, and r_ulpt_regs_t::ULPTMR3.
Referenced by internal_lus_setup_or_halt(), internal_setup_or_halt(), and lpi_setup_or_halt().
|
nodiscard |
Change the ULPT period at runtime.
Change the ULPT period at runtime.
Writes period into ULPTCNT (HUM Ch 25.2.4 "ULPTCNT : ULPT Counter", p 1192). Use on a stopped channel or immediately after a counter refresh.
| [in] | channel | ULPT channel index (0 or 1). |
| [in] | period | 32-bit reload value. |
| k_ra8_ok | Counter rewritten. |
| k_ra8_err_invalid_arg | channel >= 2. |
Definition at line 213 of file ra8_ulpt.c.
References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ulpt_channel_count, RA8_CHECK_NULL_PTR, ra8_ulpt(), s_tag, and r_ulpt_regs_t::ULPTCNT.
|
nodiscard |
Start a ULPT channel counting down from period.
| [in] | channel | Channel index (0..1). |
| [in] | period | 32-bit reload value loaded into ULPT before start. |
Definition at line 93 of file ra8_ulpt.c.
References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_ulpt_channel_count, k_ra8_ulpt_mask_tstart, RA8_CHECK_NULL_PTR, ra8_log_info_val, ra8_ulpt(), s_tag, r_ulpt_regs_t::ULPTCNT, r_ulpt_regs_t::ULPTCR, r_ulpt_regs_t::ULPTMR1, r_ulpt_regs_t::ULPTMR2, and r_ulpt_regs_t::ULPTMR3.
Referenced by internal_arm(), lpi_idle_one_period(), and main().
|
nodiscard |
Stop a ULPT channel and confirm the counter has halted.
Toggles ULPTCR.TSTOP (HUM Ch 25.2.1 "ULPTCR", p 1190) to force the down-counter to stop, clears ULPTCR, then polls the count-status flag ULPTCR.TCSTF until it reads 0. TCSTF lags the stop request by a few ULPTLCLK (32.768 kHz) cycles, so the confirm poll is bounded by k_ra8_ulpt_stop_poll_max (NASA Power of 10 Rule 2). Confirming the halt matters before a caller re-arms the channel for Software Standby: re-arming while TCSTF is still set hangs on the second wake.
| [in] | channel | Channel index (0..1). |
| k_ra8_ok | Counter stopped and TCSTF confirmed low. |
| k_ra8_err_invalid_arg | channel >= 2. |
| k_ra8_err_hw_timeout | TCSTF stayed set past the poll bound. |
Definition at line 121 of file ra8_ulpt.c.
References k_ra8_err_invalid_arg, k_ra8_ulpt_channel_count, k_ra8_ulpt_mask_tcstf, k_ra8_ulpt_mask_tstop, k_ra8_ulpt_stop_poll_max, RA8_CHECK_NULL_PTR, ra8_hw_wait_flag_clear8(), ra8_ulpt(), s_tag, and r_ulpt_regs_t::ULPTCR.
Referenced by lpi_idle_one_period(), and main().