|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
RA8 <-> Eclipse ThreadX glue: SysTick kernel-tick retuning. More...
Go to the source code of this file.
Enumerations | |
| enum | ra8_threadx_tick_t : uint32_t { k_ra8_threadx_tick_hz = 1000UL } |
| ThreadX kernel tick rate used to derive the SysTick reload. More... | |
| enum | ra8_systick_reload_limit_t : uint32_t { k_ra8_systick_reload_max = 0x00FFFFFFUL } |
| Architectural range limit of the Cortex-M SysTick reload register. More... | |
Functions | |
| ra8_err_t | ra8_threadx_systick_reload_for (uint32_t cpuclk_hz, uint32_t tick_hz, uint32_t *out_reload) |
| Compute the SysTick reload for a given core clock + tick rate. | |
| ra8_err_t | ra8_threadx_systick_retune (void) |
| Reprogram SysTick.LOAD from the live CPUCLK0 rate. | |
RA8 <-> Eclipse ThreadX glue: SysTick kernel-tick retuning.
The project-tuned tx_initialize_low_level.S programs SysTick from a compile-time clock assumption (RA8_BOOT_CLOCK_HZ, 1 GHz – the post-CGC CPUCLK0 target). That is correct only if the app raised CPUCLK0 to exactly that rate before tx_kernel_enter(). An app that enters the kernel on a different clock – the boot-default MOCO (~8 MHz), or any other CGC target – would run the ThreadX kernel tick at the wrong rate: a nominal 1 ms tick scaled by the ratio of the compile-time assumption to the live clock (~119x too slow on MOCO).
ra8_threadx_systick_retune closes that gap. Called from tx_application_define – which ThreadX runs AFTER _tx_initialize_low_level but BEFORE the first scheduling decision – it re-derives SysTick.LOAD from the live CPUCLK0 rate reported by ra8_cgc_get_clock_hz, so the kernel tick is accurate regardless of which clock the app brought up. If the live clock is so high that the per-tick reload cannot fit the 24-bit SYST_RVR register, the function returns an error rather than silently truncating the reload – the caller can then halt instead of drifting.
ra8_threadx_systick_reload_for is the pure arithmetic core, split out so the range/validity logic is host-unit-testable without touching the Cortex-M System Control Space.
Definition in file ra8_threadx.h.
| enum ra8_systick_reload_limit_t : uint32_t |
Architectural range limit of the Cortex-M SysTick reload register.
SYST_RVR (0xE000E014) has a 24-bit RELOAD field (bits [23:0]); the top byte reads as zero. A reload larger than this cannot be represented, so ra8_threadx_systick_reload_for rejects it instead of truncating.
| Enumerator | |
|---|---|
| k_ra8_systick_reload_max | Max SYST_RVR reload (24-bit). |
Definition at line 75 of file ra8_threadx.h.
| enum ra8_threadx_tick_t : uint32_t |
ThreadX kernel tick rate used to derive the SysTick reload.
Mirrors TX_TIMER_TICKS_PER_SECOND in port/threadx/inc/tx_user.h. The two MUST agree: tx_user.h declares the rate ThreadX assumes for tx_thread_sleep / timer math, and this value is what ra8_threadx_systick_retune programs SysTick to fire at.
| Enumerator | |
|---|---|
| k_ra8_threadx_tick_hz | 1 kHz -> 1 ms kernel tick. |
Definition at line 60 of file ra8_threadx.h.
|
nodiscard |
Compute the SysTick reload for a given core clock + tick rate.
Derives the SYST_RVR reload value as cpuclk_hz / tick_hz - 1, the count that makes SysTick underflow once per tick period. Validates that the inputs are non-zero, that the clock is fast enough for at least one tick period (cpuclk_hz >= tick_hz), and that the resulting reload fits the 24-bit SYST_RVR field. Pure arithmetic – touches no hardware – so it is exercised directly by the host MC/DC unit tests.
| [in] | cpuclk_hz | Live core (CPUCLK0) frequency in Hz. Must be > 0. |
| [in] | tick_hz | Kernel tick rate in Hz (see k_ra8_threadx_tick_hz). Must be > 0. |
| [out] | out_reload | On success, the SYST_RVR reload value to program. |
| k_ra8_ok | Reload computed and written to out_reload. |
| k_ra8_err_null_ptr | out_reload is NULL. |
| k_ra8_err_invalid_arg | cpuclk_hz or tick_hz is 0, or the clock is slower than one tick period. |
| k_ra8_err_out_of_range | Reload would exceed the 24-bit SYST_RVR range (cpuclk_hz far too high for tick_hz). |
out_reload is a valid, writable uint32_t. out_reload is left unmodified.Definition at line 34 of file tx_systick_retune.c.
References k_ra8_err_invalid_arg, k_ra8_err_out_of_range, k_ra8_ok, k_ra8_systick_reload_max, RA8_CHECK_NULL_PTR, ra8_log_error, and s_tag.
Referenced by ra8_threadx_systick_retune(), and tx_application_define().
|
nodiscard |
Reprogram SysTick.LOAD from the live CPUCLK0 rate.
Queries the live CPUCLK0 frequency via ra8_cgc_get_clock_hz, derives the reload with ra8_threadx_systick_reload_for for the ThreadX tick rate (k_ra8_threadx_tick_hz), then writes SYST_RVR and clears SYST_CVR so the new period takes effect on the next reload. The SysTick enable / clock-source / interrupt bits programmed by _tx_initialize_low_level.S are left untouched.
Call this from tx_application_define (which ThreadX invokes after _tx_initialize_low_level but before the first scheduling decision) so that whatever clock the app raised via ra8_cgc_init() – or did not – the kernel tick is accurate. Calling it earlier (from main before tx_kernel_enter) has no effect: _tx_initialize_low_level reprograms SYST_RVR afterwards and would overwrite it.
| k_ra8_ok | SysTick reprogrammed for the live clock. |
| k_ra8_err_invalid_arg | CPUCLK0 query returned a nonsensical rate (0, or too slow for one tick period). |
| k_ra8_err_out_of_range | Live clock too high for a 24-bit reload. |
Definition at line 64 of file tx_systick_retune.c.
References k_ra8_clock_id_cpuclk0, k_ra8_ok, k_ra8_threadx_tick_hz, ra8_cgc_get_clock_hz(), ra8_log_info_val, RA8_RETURN_ON_ERROR, ra8_systick_set_reload(), ra8_threadx_systick_reload_for(), and s_tag.
Referenced by tx_application_define().