diff --git a/ci/expected/cfg-monotonic.run b/ci/expected/cfg-monotonic.run new file mode 100644 index 0000000000..e69de29bb2 diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 9c444fed36..89173d450e 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 d05784d18b..71bcfa8e22 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 9531254caf..460b4e2160 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 { } } - 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 7c3f70fb30..6bd2a71f11 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 32e288c56d..f5867dc40e 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 Vec Vec = 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> = rtic::RacyCell::new(None); )); } @@ -126,6 +128,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> 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