From c631049efcadca8b07940c794cce2be58fa48444 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 3 Nov 2018 17:02:41 +0100 Subject: v0.4.0 closes #32 closes #33 --- src/export.rs | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/export.rs (limited to 'src/export.rs') diff --git a/src/export.rs b/src/export.rs new file mode 100644 index 0000000..cb63e0c --- /dev/null +++ b/src/export.rs @@ -0,0 +1,84 @@ +/// IMPLEMENTATION DETAILS. DO NOT USE ANYTHING IN THIS MODULE +use core::{hint, ptr}; + +#[cfg(armv7m)] +use cortex_m::register::basepri; +pub use cortex_m::{ + asm::wfi, interrupt, peripheral::scb::SystemHandler, peripheral::syst::SystClkSource, + peripheral::Peripherals, +}; +pub use cortex_m_rt::{entry, exception}; +pub use heapless::consts; +use heapless::spsc::Queue; + +#[cfg(feature = "timer-queue")] +pub use crate::tq::{isr as sys_tick, NotReady, TimerQueue}; + +pub type FreeQueue = Queue; +pub type ReadyQueue = Queue<(T, u8), N>; + +#[cfg(armv7m)] +#[inline(always)] +pub fn run(f: F) +where + F: FnOnce(), +{ + let initial = basepri::read(); + f(); + unsafe { basepri::write(initial) } +} + +#[cfg(not(armv7m))] +#[inline(always)] +pub fn run(f: F) +where + F: FnOnce(), +{ + f(); +} + +// TODO(MaybeUninit) Until core::mem::MaybeUninit is stabilized we use our own (inefficient) +// implementation +pub struct MaybeUninit { + value: Option, +} + +impl MaybeUninit { + pub const fn uninitialized() -> Self { + MaybeUninit { value: None } + } + + pub unsafe fn get_ref(&self) -> &T { + if let Some(x) = self.value.as_ref() { + x + } else { + hint::unreachable_unchecked() + } + } + + pub unsafe fn get_mut(&mut self) -> &mut T { + if let Some(x) = self.value.as_mut() { + x + } else { + hint::unreachable_unchecked() + } + } + + pub fn set(&mut self, val: T) { + unsafe { ptr::write(&mut self.value, Some(val)) } + } +} + +#[inline(always)] +pub fn assert_send() +where + T: Send, +{ +} + +#[inline(always)] +pub fn assert_sync() +where + T: Sync, +{ +} -- cgit v1.2.3