aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-executor/Cargo.toml1
-rw-r--r--embassy-executor/src/arch/riscv32.rs18
-rw-r--r--embassy-macros/Cargo.toml1
-rw-r--r--embassy-macros/src/macros/main.rs15
4 files changed, 20 insertions, 15 deletions
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml
index 910d6fa37..45b0955bf 100644
--- a/embassy-executor/Cargo.toml
+++ b/embassy-executor/Cargo.toml
@@ -31,6 +31,7 @@ flavors = [
31default = [] 31default = []
32std = ["embassy-macros/std", "critical-section/std"] 32std = ["embassy-macros/std", "critical-section/std"]
33wasm = ["dep:wasm-bindgen", "dep:js-sys", "embassy-macros/wasm"] 33wasm = ["dep:wasm-bindgen", "dep:js-sys", "embassy-macros/wasm"]
34riscv = ["embassy-macros/riscv"]
34 35
35# Enable nightly-only features 36# Enable nightly-only features
36nightly = [] 37nightly = []
diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs
index 2a4b006da..76eb8b114 100644
--- a/embassy-executor/src/arch/riscv32.rs
+++ b/embassy-executor/src/arch/riscv32.rs
@@ -55,19 +55,11 @@ impl Executor {
55 unsafe { 55 unsafe {
56 self.inner.poll(); 56 self.inner.poll();
57 // we do not care about race conditions between the load and store operations, interrupts 57 // we do not care about race conditions between the load and store operations, interrupts
58 //will only set this value to true. 58 // will only set this value to true.
59 critical_section::with(|_| { 59 // if there is work to do, loop back to polling
60 // if there is work to do, loop back to polling 60 if !SIGNAL_WORK_THREAD_MODE.fetch_and(false, Ordering::SeqCst) {
61 // TODO can we relax this? 61 core::arch::asm!("wfi");
62 if SIGNAL_WORK_THREAD_MODE.load(Ordering::SeqCst) { 62 }
63 SIGNAL_WORK_THREAD_MODE.store(false, Ordering::SeqCst);
64 }
65 // if not, wait for interrupt
66 else {
67 core::arch::asm!("wfi");
68 }
69 });
70 // if an interrupt occurred while waiting, it will be serviced here
71 } 63 }
72 } 64 }
73 } 65 }
diff --git a/embassy-macros/Cargo.toml b/embassy-macros/Cargo.toml
index 98e4d1c70..9b83771c8 100644
--- a/embassy-macros/Cargo.toml
+++ b/embassy-macros/Cargo.toml
@@ -23,6 +23,7 @@ proc-macro = true
23[features] 23[features]
24std = [] 24std = []
25wasm = [] 25wasm = []
26riscv = []
26 27
27# Enabling this cause interrupt::take! to require embassy-executor 28# Enabling this cause interrupt::take! to require embassy-executor
28rtos-trace-interrupt = [] 29rtos-trace-interrupt = []
diff --git a/embassy-macros/src/macros/main.rs b/embassy-macros/src/macros/main.rs
index afe9bd3e2..54806847c 100644
--- a/embassy-macros/src/macros/main.rs
+++ b/embassy-macros/src/macros/main.rs
@@ -45,7 +45,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
45 } 45 }
46 }; 46 };
47 47
48 #[cfg(all(feature = "std", not(feature = "wasm")))] 48 #[cfg(all(feature = "std", not(feature = "wasm"), not(feature = "riscv")))]
49 let main = quote! { 49 let main = quote! {
50 fn main() -> ! { 50 fn main() -> ! {
51 let mut executor = ::embassy_executor::Executor::new(); 51 let mut executor = ::embassy_executor::Executor::new();
@@ -57,13 +57,24 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
57 } 57 }
58 }; 58 };
59 59
60 #[cfg(all(not(feature = "std"), not(feature = "wasm")))] 60 #[cfg(all(not(feature = "std"), not(feature = "wasm"), not(feature = "riscv")))]
61 let main = quote! { 61 let main = quote! {
62 #[cortex_m_rt::entry] 62 #[cortex_m_rt::entry]
63 fn main() -> ! { 63 fn main() -> ! {
64 let mut executor = ::embassy_executor::Executor::new(); 64 let mut executor = ::embassy_executor::Executor::new();
65 let executor = unsafe { __make_static(&mut executor) }; 65 let executor = unsafe { __make_static(&mut executor) };
66 executor.run(|spawner| {
67 spawner.must_spawn(__embassy_main(spawner));
68 })
69 }
70 };
66 71
72 #[cfg(all(not(feature = "std"), not(feature = "wasm"), feature = "riscv"))]
73 let main = quote! {
74 #[riscv_rt::entry]
75 fn main() -> ! {
76 let mut executor = ::embassy_executor::Executor::new();
77 let executor = unsafe { __make_static(&mut executor) };
67 executor.run(|spawner| { 78 executor.run(|spawner| {
68 spawner.must_spawn(__embassy_main(spawner)); 79 spawner.must_spawn(__embassy_main(spawner));
69 }) 80 })