From d383d40459d1b6cba7ec2fd9f45b10439a6dbac4 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 4 Jul 2017 22:14:13 -0500 Subject: move non Cortex-M specific bits into a crate closes #50 --- src/interrupt.rs | 45 ++------------------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) (limited to 'src/interrupt.rs') 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 { - inner: UnsafeCell, -} - -impl Mutex { - /// Creates a new mutex - pub const fn new(value: T) -> Self { - Mutex { inner: UnsafeCell::new(value) } - } -} - -impl Mutex { - /// 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 Sync for Mutex -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 -- cgit v1.2.3