-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
time: Add time module from stm32h7xx-hal
- Loading branch information
1 parent
35d3a65
commit fd6a42f
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! Time units | ||
pub use fugit::{ | ||
HertzU32 as Hertz, KilohertzU32 as KiloHertz, MegahertzU32 as MegaHertz, | ||
MicrosDurationU32 as MicroSeconds, MillisDurationU32 as MilliSeconds, | ||
NanosDurationU32 as NanoSeconds, | ||
}; | ||
|
||
//use core::time::Duration; | ||
use cortex_m::peripheral::DWT; | ||
|
||
/// Bits per second | ||
pub type Bps = Hertz; | ||
|
||
/// Extension trait that adds convenience methods to the `u32` type | ||
pub trait U32Ext { | ||
/// Wrap in `Bps` | ||
fn bps(self) -> Bps; | ||
} | ||
|
||
impl U32Ext for u32 { | ||
fn bps(self) -> Bps { | ||
Bps::from_raw(self) | ||
} | ||
} | ||
|
||
/// A measurement of a monotonically nondecreasing clock | ||
#[derive(Clone, Copy)] | ||
pub struct Instant { | ||
now: u32, | ||
} | ||
|
||
impl Instant { | ||
/// Ticks elapsed since the `Instant` was created | ||
pub fn elapsed(&self) -> u32 { | ||
DWT::cycle_count().wrapping_sub(self.now) | ||
} | ||
} |