diff options
author | 2019-06-24 14:09:12 +0200 | |
---|---|---|
committer | 2019-06-24 14:09:12 +0200 | |
commit | 596cf585ea8dc278d88e0652dffbacbc75de04c6 (patch) | |
tree | 147bad178f15a7e7a91d847f39d501ecc1051821 /src | |
parent | 4e51bb68b976c6bb6a9a989dc560d2a8123a84ca (diff) | |
download | rtic-596cf585ea8dc278d88e0652dffbacbc75de04c6.tar.gz rtic-596cf585ea8dc278d88e0652dffbacbc75de04c6.tar.zst rtic-596cf585ea8dc278d88e0652dffbacbc75de04c6.zip |
Monotonic trait is safe; add MultiCore trait
Diffstat (limited to '')
-rw-r--r-- | src/cyccnt.rs | 7 | ||||
-rw-r--r-- | src/export.rs | 7 | ||||
-rw-r--r-- | src/lib.rs | 5 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/cyccnt.rs b/src/cyccnt.rs index a2b216c1..468aa712 100644 --- a/src/cyccnt.rs +++ b/src/cyccnt.rs @@ -116,6 +116,11 @@ pub struct Duration { } impl Duration { + /// Creates a new `Duration` from the specified number of clock cycles + pub fn from_cycles(cycles: u32) -> Self { + Duration { inner: cycles } + } + /// Returns the total number of clock cycles contained by this `Duration` pub fn as_cycles(&self) -> u32 { self.inner @@ -181,7 +186,7 @@ impl U32Ext for u32 { pub struct CYCCNT; #[cfg(not(feature = "heterogeneous"))] -unsafe impl crate::Monotonic for CYCCNT { +impl crate::Monotonic for CYCCNT { type Instant = Instant; fn ratio() -> u32 { diff --git a/src/export.rs b/src/export.rs index 7646e3c5..572068ce 100644 --- a/src/export.rs +++ b/src/export.rs @@ -108,6 +108,13 @@ where { } +#[inline(always)] +pub fn assert_multicore<T>() +where + T: super::MultiCore, +{ +} + #[cfg(armv7m)] #[inline(always)] pub unsafe fn lock<T, R>( @@ -117,7 +117,7 @@ impl From<cortex_m::Peripherals> for Peripherals { } /// A monotonic clock / counter -pub unsafe trait Monotonic { +pub trait Monotonic { /// A measurement of this clock type Instant: Copy + Ord + Sub; @@ -134,6 +134,9 @@ pub unsafe trait Monotonic { fn zero() -> Self::Instant; } +/// A marker trait that indicates that it is correct to use this type in multi-core context +pub trait MultiCore {} + /// Sets the given `interrupt` as pending /// /// This is a convenience function around |