diff options
Diffstat (limited to 'embassy-executor')
| -rw-r--r-- | embassy-executor/CHANGELOG.md | 3 | ||||
| -rw-r--r-- | embassy-executor/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-executor/src/arch/cortex_m.rs | 5 | ||||
| -rw-r--r-- | embassy-executor/src/arch/wasm.rs | 5 | ||||
| -rw-r--r-- | embassy-executor/src/fmt.rs | 45 | ||||
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-executor/src/raw/util.rs | 5 |
7 files changed, 52 insertions, 17 deletions
diff --git a/embassy-executor/CHANGELOG.md b/embassy-executor/CHANGELOG.md index 4853ba29b..ccbca1eb3 100644 --- a/embassy-executor/CHANGELOG.md +++ b/embassy-executor/CHANGELOG.md | |||
| @@ -5,11 +5,12 @@ All notable changes to this project will be documented in this file. | |||
| 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
| 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
| 7 | 7 | ||
| 8 | ## 0.3.0 - TBD | 8 | ## 0.3.0 - 2023-08-25 |
| 9 | 9 | ||
| 10 | - Replaced Pender. Implementations now must define an extern function called `__pender`. | 10 | - Replaced Pender. Implementations now must define an extern function called `__pender`. |
| 11 | - Made `raw::AvailableTask` public | 11 | - Made `raw::AvailableTask` public |
| 12 | - Made `SpawnToken::new_failed` public | 12 | - Made `SpawnToken::new_failed` public |
| 13 | - You can now use arbitrary expressions to specify `#[task(pool_size = X)]` | ||
| 13 | 14 | ||
| 14 | ## 0.2.1 - 2023-08-10 | 15 | ## 0.2.1 - 2023-08-10 |
| 15 | 16 | ||
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 2a67f70da..35944625f 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -58,8 +58,8 @@ log = { version = "0.4.14", optional = true } | |||
| 58 | rtos-trace = { version = "0.1.2", optional = true } | 58 | rtos-trace = { version = "0.1.2", optional = true } |
| 59 | 59 | ||
| 60 | futures-util = { version = "0.3.17", default-features = false } | 60 | futures-util = { version = "0.3.17", default-features = false } |
| 61 | embassy-macros = { version = "0.2.0", path = "../embassy-macros" } | 61 | embassy-macros = { version = "0.2.1", path = "../embassy-macros" } |
| 62 | embassy-time = { version = "0.1.2", path = "../embassy-time", optional = true} | 62 | embassy-time = { version = "0.1.3", path = "../embassy-time", optional = true} |
| 63 | atomic-polyfill = "1.0.1" | 63 | atomic-polyfill = "1.0.1" |
| 64 | critical-section = "1.1" | 64 | critical-section = "1.1" |
| 65 | static_cell = "1.1" | 65 | static_cell = "1.1" |
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 @@ | |||
| 1 | const 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"))] |
| 5 | fn __pender(context: *mut ()) { | 3 | fn __pender(context: *mut ()) { |
| @@ -48,13 +46,14 @@ fn __pender(context: *mut ()) { | |||
| 48 | pub use thread::*; | 46 | pub use thread::*; |
| 49 | #[cfg(feature = "executor-thread")] | 47 | #[cfg(feature = "executor-thread")] |
| 50 | mod thread { | 48 | mod 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 | ||
| 4 | use core::fmt::{Debug, Display, LowerHex}; | ||
| 5 | |||
| 4 | #[cfg(all(feature = "defmt", feature = "log"))] | 6 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 5 | compile_error!("You may not enable both `defmt` and `log` features."); | 7 | compile_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"))] | ||
| 84 | macro_rules! unreachable { | 87 | macro_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 | } | 94 | macro_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)] | ||
| 233 | pub(crate) struct Bytes<'a>(pub &'a [u8]); | ||
| 234 | |||
| 235 | impl<'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 | |||
| 241 | impl<'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 | |||
| 247 | impl<'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")] | ||
| 254 | impl<'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) { |
