diff --git a/CHANGELOG.md b/CHANGELOG.md index cbbc9c4b0a..9432cab7bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top! ### Added +- CFG: Support #[cfg] on HW task, cleanup for SW tasks - CFG: Slightly improved support for #[cfg] on Monotonics - CI: Check examples also for thumbv8.{base,main} - Allow custom `link_section` attributes for late resources diff --git a/examples/cfg-whole-task.rs b/examples/cfg-whole-task.rs index b5b978312e..17f31f4ebb 100644 --- a/examples/cfg-whole-task.rs +++ b/examples/cfg-whole-task.rs @@ -82,6 +82,19 @@ mod app { // .. } + // The whole task should disappear, + // currently still present in the Tasks enum + #[cfg(never)] + #[task(binds = UART1, shared = [count])] + fn foo3(mut _cx: foo3::Context) { + #[cfg(debug_assertions)] + { + _cx.shared.count.lock(|count| *count += 10); + + log::spawn(_cx.shared.count.lock(|count| *count)).unwrap(); + } + } + #[cfg(debug_assertions)] #[task(capacity = 2)] fn log(_: log::Context, n: u32) { diff --git a/macros/src/codegen/assertions.rs b/macros/src/codegen/assertions.rs index 66e5409504..3e0ad61c9b 100644 --- a/macros/src/codegen/assertions.rs +++ b/macros/src/codegen/assertions.rs @@ -29,7 +29,9 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec= (#chunks_name * 32) { ::core::panic!("An interrupt out of range is used while in armv6 or armv8m.base"); } diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index 780cc7e3cc..b3f05d2af6 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -93,11 +93,13 @@ pub fn codegen( let user_hardware_task_doc = &format!(" User HW task: {name}"); if !task.is_extern { let attrs = &task.attrs; + let cfgs = &task.cfgs; let context = &task.context; let stmts = &task.stmts; user_tasks.push(quote!( #[doc = #user_hardware_task_doc] #(#attrs)* + #(#cfgs)* #[allow(non_snake_case)] fn #name(#context: #name::Context) { use rtic::Mutex as _; diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 71bcfa8e22..8dcdbcf3e7 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -16,8 +16,6 @@ pub fn codegen( let mut module_items = vec![]; let mut fields = vec![]; let mut values = vec![]; - // Used to copy task cfgs to the whole module - let mut task_cfgs = vec![]; let name = ctxt.ident(app); @@ -208,8 +206,6 @@ pub fn codegen( let priority = spawnee.args.priority; let t = util::spawn_t_ident(priority); let cfgs = &spawnee.cfgs; - // Store a copy of the task cfgs - task_cfgs = cfgs.clone(); let (args, tupled, untupled, ty) = util::regroup_inputs(&spawnee.inputs); let args = &args; let tupled = &tupled; @@ -461,9 +457,8 @@ pub fn codegen( } else { quote!( #(#items)* - #[allow(non_snake_case)] - #(#task_cfgs)* + #(#cfgs)* #[doc = #doc] pub mod #name { #(#module_items)* diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs index 3d541a4749..2362cb7466 100644 --- a/macros/src/codegen/pre_init.rs +++ b/macros/src/codegen/pre_init.rs @@ -16,9 +16,11 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec (TokenStream2, Context::SoftwareTask(name) => &app.software_tasks[name].args.shared_resources, }; + let v = Vec::new(); + let task_cfgs = match ctxt { + Context::HardwareTask(t) => { + &app.hardware_tasks[t].cfgs + // ... + } + Context::SoftwareTask(t) => { + &app.software_tasks[t].cfgs + // ... + } + _ => &v, + }; + let mut fields = vec![]; let mut values = vec![]; let mut has_cfgs = false; @@ -118,6 +131,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, #[allow(non_snake_case)] #[allow(non_camel_case_types)] #[doc = #doc] + #(#task_cfgs)* pub struct #ident<#lt> { #(#fields,)* } @@ -129,6 +143,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, Some(quote!(priority: &#lt rtic::export::Priority)) }; let constructor = quote!( + #(#task_cfgs)* impl<#lt> #ident<#lt> { #[doc(hidden)] #[inline(always)] diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 6bd2a71f11..226121dd8c 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -29,6 +29,7 @@ pub fn codegen( for (name, task) in &app.software_tasks { let inputs = &task.inputs; + let cfgs = &task.cfgs; let (_, _, _, input_ty) = util::regroup_inputs(inputs); let cap = task.args.capacity; @@ -49,6 +50,7 @@ pub fn codegen( mod_app.push(quote!( // /// Queue version of a free-list that keeps track of empty slots in // /// the following buffers + #(#cfgs)* #[allow(non_camel_case_types)] #[allow(non_upper_case_globals)] #[doc(hidden)] @@ -89,6 +91,7 @@ pub fn codegen( #[allow(non_camel_case_types)] #[allow(non_upper_case_globals)] #[doc(hidden)] + #(#cfgs)* static #inputs_ident: rtic::RacyCell<[core::mem::MaybeUninit<#input_ty>; #cap_lit]> = rtic::RacyCell::new([#(#elems,)*]); ));