diff options
| author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-03 16:31:11 +0000 |
|---|---|---|
| committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-03 16:31:11 +0000 |
| commit | 777765e522949ebf84d05d4db075132172d81494 (patch) | |
| tree | 41bc00739da8f832eb5ba68ef99ec8b9d06111a4 /src/export.rs | |
| parent | 653338e7997a0cdc5deaed98b1bb5f60006717ed (diff) | |
| parent | 3a867e70c3b1afc4943ec597e4f188432fba5a8b (diff) | |
Merge #97
97: v0.4.0 r=japaric a=japaric
closes #32
closes #33
Co-authored-by: Jorge Aparicio <jorge@japaric.io>
Diffstat (limited to 'src/export.rs')
| -rw-r--r-- | src/export.rs | 84 |
1 files changed, 84 insertions, 0 deletions
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<N> = Queue<u8, N>; +pub type ReadyQueue<T, N> = Queue<(T, u8), N>; + +#[cfg(armv7m)] +#[inline(always)] +pub fn run<F>(f: F) +where + F: FnOnce(), +{ + let initial = basepri::read(); + f(); + unsafe { basepri::write(initial) } +} + +#[cfg(not(armv7m))] +#[inline(always)] +pub fn run<F>(f: F) +where + F: FnOnce(), +{ + f(); +} + +// TODO(MaybeUninit) Until core::mem::MaybeUninit is stabilized we use our own (inefficient) +// implementation +pub struct MaybeUninit<T> { + value: Option<T>, +} + +impl<T> MaybeUninit<T> { + 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<T>() +where + T: Send, +{ +} + +#[inline(always)] +pub fn assert_sync<T>() +where + T: Sync, +{ +} |
