Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OneShotTimer / PeriodicTimer should take the Timer via PeripheralRef pattern #1741

Closed
bjoernQ opened this issue Jul 2, 2024 · 1 comment · Fixed by #1855
Closed

OneShotTimer / PeriodicTimer should take the Timer via PeripheralRef pattern #1741

bjoernQ opened this issue Jul 2, 2024 · 1 comment · Fixed by #1855
Assignees
Labels
peripheral:timer Timer peripheral
Milestone

Comments

@bjoernQ
Copy link
Contributor

bjoernQ commented Jul 2, 2024

When a timer is passed into one of the constructors it's currently impossible to drop the backing hardware driver and re-create it

i.e. this is possible currently

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = SystemControl::new(peripherals.SYSTEM);
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

    let mut syst = peripherals.SYSTIMER;

    let mut systimer = SystemTimer::new(&mut syst);
    println!("SYSTIMER Current value = {}", SystemTimer::now());

    let mut alarm0 = &mut systimer.alarm0;

   

    let delay = Delay::new(&clocks);

    for _ in 0..10 {
        if alarm0.is_running() {
            alarm0.stop();
        }

        alarm0.clear_interrupt();
        alarm0.reset();

        alarm0.enable_auto_reload(false);
        alarm0.load_value(500u64.millis()).unwrap();
        alarm0.start();

        while !alarm0.is_interrupt_set() {
            // Wait
        }

        alarm0.stop();
        alarm0.clear_interrupt();


        println!("hello");
    }

    core::mem::drop(systimer);

    let mut systimer = SystemTimer::new(&mut syst);
    println!("SYSTIMER Current value = {}", SystemTimer::now());

    loop {}
}

But not when using a OneShotDriver instead of using the raw alarm

@jessebraham jessebraham added the peripheral:timer Timer peripheral label Jul 8, 2024
@jessebraham jessebraham added this to the 0.20.0 milestone Jul 17, 2024
@jessebraham jessebraham self-assigned this Jul 17, 2024
@jessebraham jessebraham added the status:in-progress This task is currently being worked on label Jul 23, 2024
@Dominaezzz
Copy link
Collaborator

Might be a little late for this suggestion but couldn't OneShotTimer/PeriodicTimer just return ownership of it's timer? Like a into_inner() type thing (similar to FlashSafeDma).

@tom-borcin tom-borcin removed the status:in-progress This task is currently being worked on label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
peripheral:timer Timer peripheral
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants