aboutsummaryrefslogtreecommitdiff
path: root/src/interrupt.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-04 22:14:13 -0500
committerGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-04 22:14:42 -0500
commitd383d40459d1b6cba7ec2fd9f45b10439a6dbac4 (patch)
tree36ecbde73ee3d0173c793d3e921010a93519d922 /src/interrupt.rs
parent9828d7c4f3eddde66526df183acfb9360ee2bece (diff)
downloadcortex-m-d383d40459d1b6cba7ec2fd9f45b10439a6dbac4.tar.gz
cortex-m-d383d40459d1b6cba7ec2fd9f45b10439a6dbac4.tar.zst
cortex-m-d383d40459d1b6cba7ec2fd9f45b10439a6dbac4.zip
move non Cortex-M specific bits into a crate
closes #50
Diffstat (limited to 'src/interrupt.rs')
-rw-r--r--src/interrupt.rs45
1 files changed, 2 insertions, 43 deletions
diff --git a/src/interrupt.rs b/src/interrupt.rs
index 2e43e85..6d7e6ce 100644
--- a/src/interrupt.rs
+++ b/src/interrupt.rs
@@ -1,40 +1,6 @@
//! Interrupts
-use core::cell::UnsafeCell;
-
-/// A "mutex" based on critical sections
-pub struct Mutex<T> {
- inner: UnsafeCell<T>,
-}
-
-impl<T> Mutex<T> {
- /// Creates a new mutex
- pub const fn new(value: T) -> Self {
- Mutex { inner: UnsafeCell::new(value) }
- }
-}
-
-impl<T> Mutex<T> {
- /// Borrows the data for the duration of the critical section
- pub fn borrow<'cs>(&self, _ctxt: &'cs CriticalSection) -> &'cs T {
- unsafe { &*self.inner.get() }
- }
-}
-
-/// Interrupt number
-pub unsafe trait Nr {
- /// Returns the number associated with this interrupt
- fn nr(&self) -> u8;
-}
-
-// NOTE `Mutex` can be used as a channel so, the protected data must be `Send`
-// to prevent sending non-Sendable stuff (e.g. interrupt tokens) across
-// different execution contexts (e.g. interrupts)
-unsafe impl<T> Sync for Mutex<T>
-where
- T: Send,
-{
-}
+pub use mcu::{CriticalSection, Mutex, Nr};
/// Disables all interrupts
#[inline(always)]
@@ -74,13 +40,6 @@ pub unsafe fn enable() {
}
}
-/// Critical section context
-///
-/// Indicates that you are executing code within a critical section
-pub struct CriticalSection {
- _0: (),
-}
-
/// Execute closure `f` in an interrupt-free context.
///
/// This as also known as a "critical section".
@@ -93,7 +52,7 @@ where
// disable interrupts
disable();
- let r = f(&CriticalSection { _0: () });
+ let r = f(unsafe { &CriticalSection::new() });
// If the interrupts were active before our `disable` call, then re-enable
// them. Otherwise, keep them disabled