Skip to content

Commit

Permalink
systick: added set_hertz()
Browse files Browse the repository at this point in the history
Added a setter for the hertz field of systick and used Cell::set instead
of overwriting the old Cell.
  • Loading branch information
GabrielPavaloiu committed Dec 11, 2024
1 parent 010c408 commit 14b5440
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions arch/cortex-m/src/systick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
Expand All @@ -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 {
Expand Down

0 comments on commit 14b5440

Please sign in to comment.