|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Implementation of the ThreadX SysTick kernel-tick retune. More...
#include <stdint.h>#include "ra8_cgc.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_log.h"#include "ra8_systick.h"#include "ra8_threadx.h"Go to the source code of this file.
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. | |
Variables | |
| static const char * | s_tag = "TX_SYST" |
Implementation of the ThreadX SysTick kernel-tick retune.
See port/threadx/inc/ra8_threadx.h for the public contract. ra8_threadx_systick_reload_for derives the SYST_RVR reload from the live core clock and the kernel tick rate; ra8_threadx_systick_retune then programs it through the shared ra8_core SysTick timebase primitive (ra8_systick_set_reload), which owns the SYST_RVR / SYST_CVR access. That primitive replaced this file's private address-cast accessors, so the SysTick registers are now programmed from exactly one place in the tree. The SysTick registers are architectural (Arm), not Renesas peripherals, so they carry an Arm v8-M reference rather than a HUM citation. On the host unit-test build the primitive writes to the fake MMIO map, so the retune runs end-to-end and the clock query + reload arithmetic remain testable.
Definition in file tx_systick_retune.c.
|
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().
|
static |
Definition at line 32 of file tx_systick_retune.c.