1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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,
{
}
|