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

Fix mono timer #254

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//! ```

use core::ops;
use cortex_m::peripheral::DWT;
use cortex_m::peripheral::{DCB, DWT};

use crate::rcc::Clocks;

Expand Down Expand Up @@ -227,14 +227,20 @@ impl_arithmetic!(MegaHertz, u32);
impl_arithmetic!(Bps, u32);

/// A monotonic non-decreasing timer
///
/// This uses the timer in the debug watch trace peripheral. This means, that if the
/// core is stopped, the timer does not count up. This may be relevant if you are using
/// cortex_m_semihosting::hprintln for debugging in which case the timer will be stopped
/// while printing
#[derive(Clone, Copy)]
pub struct MonoTimer {
frequency: Hertz,
}

impl MonoTimer {
/// Creates a new `Monotonic` timer
pub fn new(mut dwt: DWT, clocks: Clocks) -> Self {
pub fn new(mut dwt: DWT, mut dcb: DCB, clocks: Clocks) -> Self {
dcb.enable_trace();
dwt.enable_cycle_counter();

// now the CYCCNT counter can't be stopped or reset
Expand Down