Skip to content

Commit

Permalink
timer: Take &ReferenceClock rather than &ClocksManager
Browse files Browse the repository at this point in the history
ClocksManager may have been de-structured by the time a timer is created.
The source of the Timer is the ref-clock (shared with the watchdog).
  • Loading branch information
ithinuel committed Aug 16, 2023
1 parent 76efb36 commit 5763a2e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rp2040-hal/examples/adc_fifo_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn main() -> ! {
adc_fifo.resume();

// initialize a timer, to measure the total sampling time (printed below)
let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks.reference_clock);

// NOTE: in a real-world program, instead of calling `wait` now, you would probably:
// 1. Enable one of the DMA interrupts for the channel (e.g. `dma.ch0.enable_irq0()`)
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/adc_fifo_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn main() -> ! {
let mut i = 0;

// initialize a timer, to measure the total sampling time (printed below)
let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks.reference_clock);

loop {
// busy-wait until the FIFO contains at least two samples:
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn main() -> ! {
.ok()
.unwrap();

let mut timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let mut timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks.reference_clock);

// The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO);
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/examples/vector_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn main() -> ! {
// Configure GPIO25 as an output
let led_pin = pins.gpio25.into_push_pull_output();

let mut timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let mut timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks.reference_clock);
critical_section::with(|cs| {
let mut alarm = timer.alarm_0().unwrap();
// Schedule an alarm in 1 second
Expand Down
4 changes: 2 additions & 2 deletions rp2040-hal/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use fugit::{MicrosDurationU32, MicrosDurationU64, TimerInstantU64};

use crate::{
atomic_register_access::{write_bitmask_clear, write_bitmask_set},
clocks::ClocksManager,
clocks::ReferenceClock,
pac::{self, RESETS, TIMER},
resets::SubsystemReset,
typelevel::Sealed,
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Timer {
/// Make sure that clocks and watchdog are configured, so
/// that timer ticks happen at a frequency of 1MHz.
/// Otherwise, `Timer` won't work as expected.
pub fn new(timer: TIMER, resets: &mut RESETS, _clocks: &ClocksManager) -> Self {
pub fn new(timer: TIMER, resets: &mut RESETS, _clocks: &ReferenceClock) -> Self {
timer.reset_bring_down(resets);
timer.reset_bring_up(resets);
Self { _private: () }
Expand Down

0 comments on commit 5763a2e

Please sign in to comment.