aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2023-08-12 22:42:50 +0200
committerDániel Buga <[email protected]>2023-08-12 22:42:50 +0200
commit6ab0d71d9246cdc65f392212d03d639a51d21098 (patch)
tree8fbb717373b07d916c2e28d81f37ef9f556d6b13 /embassy-executor/src
parentd5e66f6f87222de65ac575c4b923b2fee5487388 (diff)
Tweak identifiers and comments
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/arch/cortex_m.rs13
-rw-r--r--embassy-executor/src/arch/riscv32.rs13
-rw-r--r--embassy-executor/src/arch/std.rs12
-rw-r--r--embassy-executor/src/arch/xtensa.rs13
-rw-r--r--embassy-executor/src/interrupt.rs16
-rw-r--r--embassy-executor/src/thread.rs30
6 files changed, 50 insertions, 47 deletions
diff --git a/embassy-executor/src/arch/cortex_m.rs b/embassy-executor/src/arch/cortex_m.rs
index 355a0f086..6c1300ae5 100644
--- a/embassy-executor/src/arch/cortex_m.rs
+++ b/embassy-executor/src/arch/cortex_m.rs
@@ -11,27 +11,22 @@ mod thread {
11 use crate::thread::ThreadContext; 11 use crate::thread::ThreadContext;
12 12
13 #[export_name = "__thread_mode_pender"] 13 #[export_name = "__thread_mode_pender"]
14 fn __thread_mode_pender(_core_id: OpaqueThreadContext) { 14 fn __thread_mode_pender(_context: OpaqueThreadContext) {
15 unsafe { core::arch::asm!("sev") } 15 unsafe { core::arch::asm!("sev") }
16 } 16 }
17 17
18 /// TODO 18 /// TODO
19 // Name pending 19 // Name pending
20 #[derive(Default)] // Default enables Executor::new 20 #[derive(Default)] // Default enables Executor::new
21 pub struct CortexMThreadContext; 21 pub struct Context;
22 22
23 impl ThreadContext for CortexMThreadContext { 23 impl ThreadContext for Context {
24 #[cfg(feature = "thread-context")] 24 #[cfg(feature = "thread-context")]
25 fn context(&self) -> OpaqueThreadContext { 25 fn context(&self) -> OpaqueThreadContext {
26 // Enabling thread-context is not incorrect, just wasteful. 26 // Enabling thread-context is not incorrect, just wasteful.
27 OpaqueThreadContext(0) 27 OpaqueThreadContext(0)
28 } 28 }
29 29
30 #[cfg(not(feature = "thread-context"))]
31 fn context(&self) -> OpaqueThreadContext {
32 OpaqueThreadContext(())
33 }
34
35 fn wait(&mut self) { 30 fn wait(&mut self) {
36 unsafe { core::arch::asm!("wfe") } 31 unsafe { core::arch::asm!("wfe") }
37 } 32 }
@@ -39,7 +34,7 @@ mod thread {
39 34
40 /// TODO 35 /// TODO
41 // Type alias for backwards compatibility 36 // Type alias for backwards compatibility
42 pub type Executor = crate::thread::ThreadModeExecutor<CortexMThreadContext>; 37 pub type Executor = crate::thread::ThreadModeExecutor<Context>;
43} 38}
44 39
45// None of this has to be public, I guess? 40// None of this has to be public, I guess?
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs
index c4e772e34..087204006 100644
--- a/embassy-executor/src/arch/riscv32.rs
+++ b/embassy-executor/src/arch/riscv32.rs
@@ -17,27 +17,22 @@ mod thread {
17 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); 17 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false);
18 18
19 #[export_name = "__thread_mode_pender"] 19 #[export_name = "__thread_mode_pender"]
20 fn __thread_mode_pender(_core_id: OpaqueThreadContext) { 20 fn __thread_mode_pender(_context: OpaqueThreadContext) {
21 SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); 21 SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst);
22 } 22 }
23 23
24 /// TODO 24 /// TODO
25 // Name pending 25 // Name pending
26 #[derive(Default)] // Default enables Executor::new 26 #[derive(Default)] // Default enables Executor::new
27 pub struct RiscVThreadContext; 27 pub struct Context;
28 28
29 impl ThreadContext for RiscVThreadContext { 29 impl ThreadContext for Context {
30 #[cfg(feature = "thread-context")] 30 #[cfg(feature = "thread-context")]
31 fn context(&self) -> OpaqueThreadContext { 31 fn context(&self) -> OpaqueThreadContext {
32 // Enabling thread-context is not incorrect, just wasteful. 32 // Enabling thread-context is not incorrect, just wasteful.
33 OpaqueThreadContext(0) 33 OpaqueThreadContext(0)
34 } 34 }
35 35
36 #[cfg(not(feature = "thread-context"))]
37 fn context(&self) -> OpaqueThreadContext {
38 OpaqueThreadContext(())
39 }
40
41 fn wait(&mut self) { 36 fn wait(&mut self) {
42 // We do not care about race conditions between the load and store operations, 37 // We do not care about race conditions between the load and store operations,
43 // interrupts will only set this value to true. 38 // interrupts will only set this value to true.
@@ -60,5 +55,5 @@ mod thread {
60 55
61 /// TODO 56 /// TODO
62 // Type alias for backwards compatibility 57 // Type alias for backwards compatibility
63 pub type Executor = crate::thread::ThreadModeExecutor<RiscVThreadContext>; 58 pub type Executor = crate::thread::ThreadModeExecutor<Context>;
64} 59}
diff --git a/embassy-executor/src/arch/std.rs b/embassy-executor/src/arch/std.rs
index b08974a02..2731e275e 100644
--- a/embassy-executor/src/arch/std.rs
+++ b/embassy-executor/src/arch/std.rs
@@ -18,11 +18,11 @@ mod thread {
18 18
19 /// TODO 19 /// TODO
20 // Name pending 20 // Name pending
21 pub struct StdThreadCtx { 21 pub struct Context {
22 signaler: &'static Signaler, 22 signaler: &'static Signaler,
23 } 23 }
24 24
25 impl Default for StdThreadCtx { 25 impl Default for Context {
26 fn default() -> Self { 26 fn default() -> Self {
27 Self { 27 Self {
28 signaler: &*Box::leak(Box::new(Signaler::new())), 28 signaler: &*Box::leak(Box::new(Signaler::new())),
@@ -30,7 +30,7 @@ mod thread {
30 } 30 }
31 } 31 }
32 32
33 impl ThreadContext for StdThreadCtx { 33 impl ThreadContext for Context {
34 fn context(&self) -> OpaqueThreadContext { 34 fn context(&self) -> OpaqueThreadContext {
35 OpaqueThreadContext(self.signaler as *const _ as usize) 35 OpaqueThreadContext(self.signaler as *const _ as usize)
36 } 36 }
@@ -41,8 +41,8 @@ mod thread {
41 } 41 }
42 42
43 #[export_name = "__thread_mode_pender"] 43 #[export_name = "__thread_mode_pender"]
44 fn __thread_mode_pender(core_id: OpaqueThreadContext) { 44 fn __thread_mode_pender(context: OpaqueThreadContext) {
45 let signaler: &'static Signaler = unsafe { std::mem::transmute(core_id) }; 45 let signaler: &'static Signaler = unsafe { std::mem::transmute(context) };
46 signaler.signal() 46 signaler.signal()
47 } 47 }
48 48
@@ -76,5 +76,5 @@ mod thread {
76 76
77 /// TODO 77 /// TODO
78 // Type alias for backwards compatibility 78 // Type alias for backwards compatibility
79 pub type Executor = crate::thread::ThreadModeExecutor<StdThreadCtx>; 79 pub type Executor = crate::thread::ThreadModeExecutor<Context>;
80} 80}
diff --git a/embassy-executor/src/arch/xtensa.rs b/embassy-executor/src/arch/xtensa.rs
index 1097bff83..54c842025 100644
--- a/embassy-executor/src/arch/xtensa.rs
+++ b/embassy-executor/src/arch/xtensa.rs
@@ -15,27 +15,22 @@ mod thread {
15 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false); 15 static SIGNAL_WORK_THREAD_MODE: AtomicBool = AtomicBool::new(false);
16 16
17 #[export_name = "__thread_mode_pender"] 17 #[export_name = "__thread_mode_pender"]
18 fn __thread_mode_pender(_core_id: OpaqueThreadContext) { 18 fn __thread_mode_pender(_context: OpaqueThreadContext) {
19 SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst); 19 SIGNAL_WORK_THREAD_MODE.store(true, Ordering::SeqCst);
20 } 20 }
21 21
22 /// TODO 22 /// TODO
23 // Name pending 23 // Name pending
24 #[derive(Default)] // Default enables Executor::new 24 #[derive(Default)] // Default enables Executor::new
25 pub struct XtensaThreadContext; 25 pub struct Context;
26 26
27 impl ThreadContext for XtensaThreadContext { 27 impl ThreadContext for Context {
28 #[cfg(feature = "thread-context")] 28 #[cfg(feature = "thread-context")]
29 fn context(&self) -> OpaqueThreadContext { 29 fn context(&self) -> OpaqueThreadContext {
30 // Enabling thread-context is not incorrect, just wasteful. 30 // Enabling thread-context is not incorrect, just wasteful.
31 OpaqueThreadContext(0) 31 OpaqueThreadContext(0)
32 } 32 }
33 33
34 #[cfg(not(feature = "thread-context"))]
35 fn context(&self) -> OpaqueThreadContext {
36 OpaqueThreadContext(())
37 }
38
39 fn wait(&mut self) { 34 fn wait(&mut self) {
40 unsafe { 35 unsafe {
41 // Manual critical section implementation that only masks interrupts handlers. 36 // Manual critical section implementation that only masks interrupts handlers.
@@ -66,5 +61,5 @@ mod thread {
66 61
67 /// TODO 62 /// TODO
68 // Type alias for backwards compatibility 63 // Type alias for backwards compatibility
69 pub type Executor = crate::thread::ThreadModeExecutor<XtensaThreadContext>; 64 pub type Executor = crate::thread::ThreadModeExecutor<Context>;
70} 65}
diff --git a/embassy-executor/src/interrupt.rs b/embassy-executor/src/interrupt.rs
index c1084ea7b..6f310651b 100644
--- a/embassy-executor/src/interrupt.rs
+++ b/embassy-executor/src/interrupt.rs
@@ -7,13 +7,17 @@ use atomic_polyfill::{AtomicBool, Ordering};
7 7
8use crate::raw::{self, OpaqueInterruptContext, Pender}; 8use crate::raw::{self, OpaqueInterruptContext, Pender};
9 9
10/// An interrupt source that can be used to drive an [`InterruptExecutor`]. 10/// Architecture-specific interface for an interrupt-mode executor. This trait describes what data
11// Name pending 11/// should be passed to the [`InterruptExecutor`]'s pender, and how to enable the interrupt that
12/// triggers polling the executor.
13// TODO: Name pending
12pub trait InterruptContext { 14pub trait InterruptContext {
13 /// Creates an opaque identifier for this interrupt. 15 /// A pointer-sized piece of data that is passed to the pender function.
16 ///
17 /// Usually, the context contains the interrupt that should be used to wake the executor.
14 fn context(&self) -> OpaqueInterruptContext; 18 fn context(&self) -> OpaqueInterruptContext;
15 19
16 /// Sets up the interrupt request. 20 /// Enabled the interrupt request.
17 fn enable(&self); 21 fn enable(&self);
18} 22}
19 23
@@ -36,8 +40,8 @@ pub trait InterruptContext {
36/// Some chips reserve some interrupts for this purpose, sometimes named "software interrupts" (SWI). 40/// Some chips reserve some interrupts for this purpose, sometimes named "software interrupts" (SWI).
37/// If this is not the case, you may use an interrupt from any unused peripheral. 41/// If this is not the case, you may use an interrupt from any unused peripheral.
38/// 42///
39/// It is somewhat more complex to use, it's recommended to use the thread-mode 43/// It is somewhat more complex to use, it's recommended to use the
40/// [`Executor`] instead, if it works for your use case. 44/// [`crate::thread::ThreadModeExecutor`] instead, if it works for your use case.
41pub struct InterruptModeExecutor { 45pub struct InterruptModeExecutor {
42 started: AtomicBool, 46 started: AtomicBool,
43 executor: UnsafeCell<MaybeUninit<raw::Executor>>, 47 executor: UnsafeCell<MaybeUninit<raw::Executor>>,
diff --git a/embassy-executor/src/thread.rs b/embassy-executor/src/thread.rs
index 2d2c6daa5..f977d41e7 100644
--- a/embassy-executor/src/thread.rs
+++ b/embassy-executor/src/thread.rs
@@ -5,13 +5,21 @@ use core::marker::PhantomData;
5use crate::raw::{OpaqueThreadContext, Pender}; 5use crate::raw::{OpaqueThreadContext, Pender};
6use crate::{raw, Spawner}; 6use crate::{raw, Spawner};
7 7
8/// TODO 8/// Architecture-specific interface for a thread-mode executor. This trait describes what the
9// Name pending 9/// executor should do when idle, and what data should be passed to its pender.
10// TODO: Name pending
10pub trait ThreadContext: Sized { 11pub trait ThreadContext: Sized {
11 /// TODO 12 /// A pointer-sized piece of data that is passed to the pender function.
13 ///
14 /// For example, on multi-core systems, this can be used to store the ID of the core that
15 /// should be woken up.
16 #[cfg(feature = "thread-context")]
12 fn context(&self) -> OpaqueThreadContext; 17 fn context(&self) -> OpaqueThreadContext;
13 18
14 /// TODO 19 /// Waits for the executor to be waken.
20 ///
21 /// While it is valid for this function can be empty, it is recommended to use a WFE instruction
22 /// or equivalent to let the CPU sleep.
15 fn wait(&mut self); 23 fn wait(&mut self);
16} 24}
17 25
@@ -40,11 +48,17 @@ impl<C: ThreadContext> ThreadModeExecutor<C> {
40 Self::with_context(C::default()) 48 Self::with_context(C::default())
41 } 49 }
42 50
43 /// Create a new Executor. 51 /// Create a new Executor using the given thread context.
44 pub fn with_context(context: C) -> Self { 52 pub fn with_context(thread_context: C) -> Self {
53 #[cfg(not(feature = "thread-context"))]
54 let context = OpaqueThreadContext(());
55
56 #[cfg(feature = "thread-context")]
57 let context = thread_context.context();
58
45 Self { 59 Self {
46 inner: raw::Executor::new(Pender::Thread(context.context())), 60 inner: raw::Executor::new(Pender::Thread(context)),
47 context, 61 context: thread_context,
48 not_send: PhantomData, 62 not_send: PhantomData,
49 } 63 }
50 } 64 }