aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorTyler <[email protected]>2023-09-29 20:02:24 -0600
committerGitHub <[email protected]>2023-09-29 20:02:24 -0600
commit2f9b59c5cf21f1e2761a9ccefdfd86f0edea829c (patch)
tree8964744b4fb753cf98f6f413464106c4d2a72976 /embassy-executor/src
parentce91fb2bfc846570ef543a09396c428d70675245 (diff)
parent95b3d9eb3b3657de3d7bc9c04f8fb83eae901640 (diff)
Merge branch 'main' into issue-1974-add-sai-driver
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/arch/cortex_m.rs5
-rw-r--r--embassy-executor/src/arch/wasm.rs5
-rw-r--r--embassy-executor/src/fmt.rs45
-rw-r--r--embassy-executor/src/raw/mod.rs2
-rw-r--r--embassy-executor/src/raw/util.rs5
5 files changed, 48 insertions, 14 deletions
diff --git a/embassy-executor/src/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs
index 0806a22ab..fde862f3c 100644
--- a/embassy-executor/src/arch/cortex_m.rs
+++ b/embassy-executor/src/arch/cortex_m.rs
@@ -1,5 +1,3 @@
1const THREAD_PENDER: usize = usize::MAX;
2
3#[export_name = "__pender"] 1#[export_name = "__pender"]
4#[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))] 2#[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))]
5fn __pender(context: *mut ()) { 3fn __pender(context: *mut ()) {
@@ -48,13 +46,14 @@ fn __pender(context: *mut ()) {
48pub use thread::*; 46pub use thread::*;
49#[cfg(feature = "executor-thread")] 47#[cfg(feature = "executor-thread")]
50mod thread { 48mod thread {
49 pub(super) const THREAD_PENDER: usize = usize::MAX;
50
51 use core::arch::asm; 51 use core::arch::asm;
52 use core::marker::PhantomData; 52 use core::marker::PhantomData;
53 53
54 #[cfg(feature = "nightly")] 54 #[cfg(feature = "nightly")]
55 pub use embassy_macros::main_cortex_m as main; 55 pub use embassy_macros::main_cortex_m as main;
56 56
57 use crate::arch::THREAD_PENDER;
58 use crate::{raw, Spawner}; 57 use crate::{raw, Spawner};
59 58
60 /// Thread mode executor, using WFE/SEV. 59 /// Thread mode executor, using WFE/SEV.
diff --git a/embassy-executor/src/arch/wasm.rs b/embassy-executor/src/arch/wasm.rs
index 934fd69e5..15aed867a 100644
--- a/embassy-executor/src/arch/wasm.rs
+++ b/embassy-executor/src/arch/wasm.rs
@@ -73,9 +73,10 @@ mod thread {
73 pub fn start(&'static mut self, init: impl FnOnce(Spawner)) { 73 pub fn start(&'static mut self, init: impl FnOnce(Spawner)) {
74 unsafe { 74 unsafe {
75 let executor = &self.inner; 75 let executor = &self.inner;
76 self.ctx.closure.write(Closure::new(move |_| { 76 let future = Closure::new(move |_| {
77 executor.poll(); 77 executor.poll();
78 })); 78 });
79 self.ctx.closure.write_in_place(|| future);
79 init(self.inner.spawner()); 80 init(self.inner.spawner());
80 } 81 }
81 } 82 }
diff --git a/embassy-executor/src/fmt.rs b/embassy-executor/src/fmt.rs
index 066970813..78e583c1c 100644
--- a/embassy-executor/src/fmt.rs
+++ b/embassy-executor/src/fmt.rs
@@ -1,6 +1,8 @@
1#![macro_use] 1#![macro_use]
2#![allow(unused_macros)] 2#![allow(unused_macros)]
3 3
4use core::fmt::{Debug, Display, LowerHex};
5
4#[cfg(all(feature = "defmt", feature = "log"))] 6#[cfg(all(feature = "defmt", feature = "log"))]
5compile_error!("You may not enable both `defmt` and `log` features."); 7compile_error!("You may not enable both `defmt` and `log` features.");
6 8
@@ -81,14 +83,17 @@ macro_rules! todo {
81 }; 83 };
82} 84}
83 85
86#[cfg(not(feature = "defmt"))]
84macro_rules! unreachable { 87macro_rules! unreachable {
85 ($($x:tt)*) => { 88 ($($x:tt)*) => {
86 { 89 ::core::unreachable!($($x)*)
87 #[cfg(not(feature = "defmt"))] 90 };
88 ::core::unreachable!($($x)*); 91}
89 #[cfg(feature = "defmt")] 92
90 ::defmt::unreachable!($($x)*); 93#[cfg(feature = "defmt")]
91 } 94macro_rules! unreachable {
95 ($($x:tt)*) => {
96 ::defmt::unreachable!($($x)*)
92 }; 97 };
93} 98}
94 99
@@ -223,3 +228,31 @@ impl<T, E> Try for Result<T, E> {
223 self 228 self
224 } 229 }
225} 230}
231
232#[allow(unused)]
233pub(crate) struct Bytes<'a>(pub &'a [u8]);
234
235impl<'a> Debug for Bytes<'a> {
236 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
237 write!(f, "{:#02x?}", self.0)
238 }
239}
240
241impl<'a> Display for Bytes<'a> {
242 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
243 write!(f, "{:#02x?}", self.0)
244 }
245}
246
247impl<'a> LowerHex for Bytes<'a> {
248 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
249 write!(f, "{:#02x?}", self.0)
250 }
251}
252
253#[cfg(feature = "defmt")]
254impl<'a> defmt::Format for Bytes<'a> {
255 fn format(&self, fmt: defmt::Formatter) {
256 defmt::write!(fmt, "{:02x}", self.0)
257 }
258}
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index c1d82e18a..6d2c1c18a 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -203,7 +203,7 @@ impl<F: Future + 'static> AvailableTask<F> {
203 fn initialize_impl<S>(self, future: impl FnOnce() -> F) -> SpawnToken<S> { 203 fn initialize_impl<S>(self, future: impl FnOnce() -> F) -> SpawnToken<S> {
204 unsafe { 204 unsafe {
205 self.task.raw.poll_fn.set(Some(TaskStorage::<F>::poll)); 205 self.task.raw.poll_fn.set(Some(TaskStorage::<F>::poll));
206 self.task.future.write(future()); 206 self.task.future.write_in_place(future);
207 207
208 let task = TaskRef::new(self.task); 208 let task = TaskRef::new(self.task);
209 209
diff --git a/embassy-executor/src/raw/util.rs b/embassy-executor/src/raw/util.rs
index e2e8f4df8..c46085e45 100644
--- a/embassy-executor/src/raw/util.rs
+++ b/embassy-executor/src/raw/util.rs
@@ -17,8 +17,9 @@ impl<T> UninitCell<T> {
17 &mut *self.as_mut_ptr() 17 &mut *self.as_mut_ptr()
18 } 18 }
19 19
20 pub unsafe fn write(&self, val: T) { 20 #[inline(never)]
21 ptr::write(self.as_mut_ptr(), val) 21 pub unsafe fn write_in_place(&self, func: impl FnOnce() -> T) {
22 ptr::write(self.as_mut_ptr(), func())
22 } 23 }
23 24
24 pub unsafe fn drop_in_place(&self) { 25 pub unsafe fn drop_in_place(&self) {