aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor-macros/src/macros/main.rs
diff options
context:
space:
mode:
authorDummyc0m <[email protected]>2024-10-06 23:23:33 -0700
committerDummyc0m <[email protected]>2024-10-06 23:33:34 -0700
commit9e6e09a8d747ec90aae215df8471dfe349993487 (patch)
tree0cd116be26fea69f9b770b3f36c87fc1273ae20b /embassy-executor-macros/src/macros/main.rs
parent8f273497453d3ca3f297465b67820d4d36705d11 (diff)
executor/spin: introduce an architecture agnostic executor
Spin polls the raw executor and never sleeps. It is useful for disabling any power features associated with wfi/wfe-like instructions. When implementing support for the CH32V30x MCU, the wfi instruction had issues interacting with the USB OTG peripheral and appeared to be non-spec-compliant. 1. When sending a USB Data-in packet, the USB peripheral appears to be unable to read the system main memory while in WFI. This manifests in the USB peripheral sending all or partially zeroed DATA packets. Disabling WFI works around this issue. 2. The WFI instruction does not wake up the processor when MIE is disabled. The MCU provides a WFITOWFE bit to emulate the WFE instruction on arm, which, when enabled, ignores the MIE and allows the processor to wake up. This works around the non-compliant WFI implementation. Co-authored-by: Codetector <[email protected]> Co-authored-by: Dummyc0m <[email protected]>
Diffstat (limited to 'embassy-executor-macros/src/macros/main.rs')
-rw-r--r--embassy-executor-macros/src/macros/main.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/embassy-executor-macros/src/macros/main.rs b/embassy-executor-macros/src/macros/main.rs
index 26dfa2397..66a3965d0 100644
--- a/embassy-executor-macros/src/macros/main.rs
+++ b/embassy-executor-macros/src/macros/main.rs
@@ -1,5 +1,5 @@
1use darling::export::NestedMeta; 1use darling::export::NestedMeta;
2use darling::FromMeta; 2use darling::{Error, FromMeta};
3use proc_macro2::TokenStream; 3use proc_macro2::TokenStream;
4use quote::quote; 4use quote::quote;
5use syn::{Expr, ReturnType, Type}; 5use syn::{Expr, ReturnType, Type};
@@ -50,6 +50,33 @@ pub fn riscv(args: &[NestedMeta]) -> TokenStream {
50 } 50 }
51} 51}
52 52
53pub fn spin(args: &[NestedMeta]) -> TokenStream {
54 let maybe_entry = match Args::from_list(args) {
55 Ok(args) => args.entry,
56 Err(e) => return e.write_errors(),
57 };
58
59 let entry = match maybe_entry {
60 Some(str) => str,
61 None => return Error::missing_field("entry").write_errors(),
62 };
63 let entry = match Expr::from_string(&entry) {
64 Ok(expr) => expr,
65 Err(e) => return e.write_errors(),
66 };
67
68 quote! {
69 #[#entry]
70 fn main() -> ! {
71 let mut executor = ::embassy_executor::Executor::new();
72 let executor = unsafe { __make_static(&mut executor) };
73 executor.run(|spawner| {
74 spawner.must_spawn(__embassy_main(spawner));
75 })
76 }
77 }
78}
79
53pub fn cortex_m() -> TokenStream { 80pub fn cortex_m() -> TokenStream {
54 quote! { 81 quote! {
55 #[cortex_m_rt::entry] 82 #[cortex_m_rt::entry]