From 14b54401e5dbddf2dc613760722f4b5bd47826f1 Mon Sep 17 00:00:00 2001 From: GabrielPavaloiu Date: Wed, 11 Dec 2024 18:15:11 +0200 Subject: [PATCH] systick: added set_hertz() Added a setter for the hertz field of systick and used Cell::set instead of overwriting the old Cell. --- arch/cortex-m/src/systick.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/cortex-m/src/systick.rs b/arch/cortex-m/src/systick.rs index 9120e195d4..9a152b0572 100644 --- a/arch/cortex-m/src/systick.rs +++ b/arch/cortex-m/src/systick.rs @@ -87,8 +87,8 @@ impl SysTick { /// * `clock_speed` - the frequency of SysTick tics in Hertz. For example, /// if the SysTick is driven by the CPU clock, it is simply the CPU speed. pub unsafe fn new_with_calibration(clock_speed: u32) -> SysTick { - let mut res = SysTick::new(); - res.hertz = Cell::new(clock_speed); + let res = SysTick::new(); + res.hertz.set(clock_speed); res } @@ -102,7 +102,7 @@ impl SysTick { /// if the SysTick is driven by the CPU clock, it is simply the CPU speed. pub unsafe fn new_with_calibration_and_external_clock(clock_speed: u32) -> SysTick { let mut res = SysTick::new(); - res.hertz = Cell::new(clock_speed); + res.hertz.set(clock_speed); res.external_clock = true; res } @@ -122,6 +122,19 @@ impl SysTick { tenms * 100 } } + + /// Modifies the locally stored frequncy + /// + /// # Important + /// + /// This function does not change the actual systick frequency. + /// This function must be called only while the clock is not armed. + /// When changing the hardware systick frequency, the reload value register + /// should be updated and the current value register should be reset, in + /// order for the tick count to match the current frequency. + pub unsafe fn set_hertz(&self, clock_speed: u32) { + self.hertz.set(clock_speed); + } } impl kernel::platform::scheduler_timer::SchedulerTimer for SysTick {