diff options
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/codegen.rs | 7 | ||||
-rw-r--r-- | macros/src/codegen/module.rs | 20 | ||||
-rw-r--r-- | macros/src/codegen/post_init.rs | 15 | ||||
-rw-r--r-- | macros/src/codegen/software_tasks.rs | 2 | ||||
-rw-r--r-- | macros/src/codegen/timer_queue.rs | 6 |
5 files changed, 40 insertions, 10 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 9c444fed..89173d45 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -108,6 +108,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { .map(|(_, monotonic)| { let name = &monotonic.ident; let name_str = &name.to_string(); + let cfgs = &monotonic.cfgs; let ident = util::monotonic_ident(name_str); let doc = &format!( "This module holds the static implementation for `{}::now()`", @@ -115,7 +116,10 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { ); let default_monotonic = if monotonic.args.default { - quote!(pub use #name::now;) + quote!( + #(#cfgs)* + pub use #name::now; + ) } else { quote!() }; @@ -125,6 +129,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #[doc = #doc] #[allow(non_snake_case)] + #(#cfgs)* pub mod #name { /// Read the current time from this monotonic diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index d05784d1..71bcfa8e 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -116,8 +116,12 @@ pub fn codegen( .monotonics .iter() .map(|(_, monotonic)| { + let cfgs = &monotonic.cfgs; let mono = &monotonic.ty; - quote! {#mono} + quote! { + #(#cfgs)* + pub #mono + } }) .collect(); @@ -128,7 +132,7 @@ pub fn codegen( #[allow(non_snake_case)] #[allow(non_camel_case_types)] pub struct #internal_monotonics_ident( - #(pub #monotonic_types),* + #(#monotonic_types),* ); )); @@ -226,8 +230,8 @@ pub fn codegen( // Spawn caller items.push(quote!( - #(#cfgs)* /// Spawns the task directly + #(#cfgs)* pub fn #internal_spawn_ident(#(#args,)*) -> Result<(), #ty> { let input = #tupled; @@ -267,6 +271,7 @@ pub fn codegen( let tq = util::tq_ident(&monotonic.ident.to_string()); let t = util::schedule_t_ident(); let m = &monotonic.ident; + let cfgs = &monotonic.cfgs; let m_ident = util::monotonic_ident(&monotonic_name); let m_isr = &monotonic.args.binds; let enum_ = util::interrupt_ident(); @@ -298,13 +303,17 @@ pub fn codegen( if monotonic.args.default { module_items.push(quote!( + #(#cfgs)* pub use #m::spawn_after; + #(#cfgs)* pub use #m::spawn_at; + #(#cfgs)* pub use #m::SpawnHandle; )); } module_items.push(quote!( #[doc(hidden)] + #(#cfgs)* pub mod #m { pub use super::super::#internal_spawn_after_ident as spawn_after; pub use super::super::#internal_spawn_at_ident as spawn_at; @@ -322,6 +331,7 @@ pub fn codegen( marker: u32, } + #(#cfgs)* impl core::fmt::Debug for #internal_spawn_handle_ident { #[doc(hidden)] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -353,6 +363,7 @@ pub fn codegen( /// Reschedule after #[inline] + #(#cfgs)* pub fn reschedule_after( self, duration: <#m as rtic::Monotonic>::Duration @@ -361,6 +372,7 @@ pub fn codegen( } /// Reschedule at + #(#cfgs)* pub fn reschedule_at( self, instant: <#m as rtic::Monotonic>::Instant @@ -376,11 +388,11 @@ pub fn codegen( } } - #(#cfgs)* /// Spawns the task after a set duration relative to the current time /// /// This will use the time `Instant::new(0)` as baseline if called in `#[init]`, /// so if you use a non-resetable timer use `spawn_at` when in `#[init]` + #(#cfgs)* #[allow(non_snake_case)] pub fn #internal_spawn_after_ident( duration: <#m as rtic::Monotonic>::Duration diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 9531254c..460b4e21 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -43,21 +43,28 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { } } - for (i, (monotonic, _)) in app.monotonics.iter().enumerate() { + for (i, (monotonic_ident, monotonic)) in app.monotonics.iter().enumerate() { // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); // stmts.push(quote!(#[doc = #doc])); + let cfgs = &monotonic.cfgs; #[allow(clippy::cast_possible_truncation)] let idx = Index { index: i as u32, span: Span::call_site(), }; - stmts.push(quote!(monotonics.#idx.reset();)); + stmts.push(quote!( + #(#cfgs)* + monotonics.#idx.reset(); + )); // Store the monotonic - let name = util::monotonic_ident(&monotonic.to_string()); - stmts.push(quote!(#name.get_mut().write(Some(monotonics.#idx));)); + let name = util::monotonic_ident(&monotonic_ident.to_string()); + stmts.push(quote!( + #(#cfgs)* + #name.get_mut().write(Some(monotonics.#idx)); + )); } // Enable the interrupts -- this completes the `init`-ialization phase diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 7c3f70fb..6bd2a71f 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -62,6 +62,7 @@ pub fn codegen( for (_, monotonic) in &app.monotonics { let instants = util::monotonic_instants_ident(name, &monotonic.ident); let mono_type = &monotonic.ty; + let cfgs = &monotonic.cfgs; let uninit = mk_uninit(); // For future use @@ -73,6 +74,7 @@ pub fn codegen( #[allow(non_camel_case_types)] #[allow(non_upper_case_globals)] #[doc(hidden)] + #(#cfgs)* static #instants: rtic::RacyCell<[core::mem::MaybeUninit<<#mono_type as rtic::Monotonic>::Instant>; #cap_lit]> = rtic::RacyCell::new([#(#elems,)*]); diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs index 32e288c5..f5867dc4 100644 --- a/macros/src/codegen/timer_queue.rs +++ b/macros/src/codegen/timer_queue.rs @@ -13,7 +13,6 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea // Generate the marker counter used to track for `cancel` and `reschedule` let tq_marker = util::timer_queue_marker_ident(); items.push(quote!( - // #[doc = #doc] #[doc(hidden)] #[allow(non_camel_case_types)] #[allow(non_upper_case_globals)] @@ -56,6 +55,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea let tq = util::tq_ident(&monotonic_name); let t = util::schedule_t_ident(); let mono_type = &monotonic.ty; + let cfgs = &monotonic.cfgs; let m_ident = util::monotonic_ident(&monotonic_name); // Static variables and resource proxy @@ -76,6 +76,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea #[doc(hidden)] #[allow(non_camel_case_types)] #[allow(non_upper_case_globals)] + #(#cfgs)* static #tq: rtic::RacyCell<#tq_ty> = rtic::RacyCell::new(rtic::export::TimerQueue(rtic::export::SortedLinkedList::new_u16())); )); @@ -88,6 +89,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea #[doc(hidden)] #[allow(non_camel_case_types)] #[allow(non_upper_case_globals)] + #(#cfgs)* static #mono: rtic::RacyCell<Option<#mono_type>> = rtic::RacyCell::new(None); )); } @@ -126,6 +128,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea }) .collect::<Vec<_>>(); + let cfgs = &monotonic.cfgs; let bound_interrupt = &monotonic.args.binds; let disable_isr = if &*bound_interrupt.to_string() == "SysTick" { quote!(core::mem::transmute::<_, rtic::export::SYST>(()).disable_interrupt()) @@ -136,6 +139,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea items.push(quote!( #[no_mangle] #[allow(non_snake_case)] + #(#cfgs)* unsafe fn #bound_interrupt() { while let Some((task, index)) = rtic::export::interrupt::free(|_| if let Some(mono) = (&mut *#m_ident.get_mut()).as_mut() { |