Skip to content

Commit 800904a

Browse files
committed
Handle more cfgs, support cfg on HW/SW tasks
1 parent 259be7b commit 800904a

File tree

8 files changed

+39
-6
lines changed

8 files changed

+39
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
99

1010
### Added
1111

12+
- CFG: Support #[cfg] on HW task, cleanup for SW tasks
1213
- CFG: Slightly improved support for #[cfg] on Monotonics
1314
- CI: Check examples also for thumbv8.{base,main}
1415
- Allow custom `link_section` attributes for late resources

examples/cfg-whole-task.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ mod app {
8282
// ..
8383
}
8484

85+
// The whole task should disappear,
86+
// currently still present in the Tasks enum
87+
#[cfg(never)]
88+
#[task(binds = UART1, shared = [count])]
89+
fn foo3(mut _cx: foo3::Context) {
90+
#[cfg(debug_assertions)]
91+
{
92+
_cx.shared.count.lock(|count| *count += 10);
93+
94+
log::spawn(_cx.shared.count.lock(|count| *count)).unwrap();
95+
}
96+
}
97+
8598
#[cfg(debug_assertions)]
8699
#[task(capacity = 2)]
87100
fn log(_: log::Context, n: u32) {

macros/src/codegen/assertions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
2929
.filter_map(|(_, task)| {
3030
if !util::is_exception(&task.args.binds) {
3131
let interrupt_name = &task.args.binds;
32+
let cfgs = &task.cfgs;
3233
Some(quote!(
34+
#(#cfgs)*
3335
if (#device::Interrupt::#interrupt_name as usize) >= (#chunks_name * 32) {
3436
::core::panic!("An interrupt out of range is used while in armv6 or armv8m.base");
3537
}

macros/src/codegen/hardware_tasks.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ pub fn codegen(
9393
let user_hardware_task_doc = &format!(" User HW task: {name}");
9494
if !task.is_extern {
9595
let attrs = &task.attrs;
96+
let cfgs = &task.cfgs;
9697
let context = &task.context;
9798
let stmts = &task.stmts;
9899
user_tasks.push(quote!(
99100
#[doc = #user_hardware_task_doc]
100101
#(#attrs)*
102+
#(#cfgs)*
101103
#[allow(non_snake_case)]
102104
fn #name(#context: #name::Context) {
103105
use rtic::Mutex as _;

macros/src/codegen/module.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ pub fn codegen(
1616
let mut module_items = vec![];
1717
let mut fields = vec![];
1818
let mut values = vec![];
19-
// Used to copy task cfgs to the whole module
20-
let mut task_cfgs = vec![];
2119

2220
let name = ctxt.ident(app);
2321

@@ -208,8 +206,6 @@ pub fn codegen(
208206
let priority = spawnee.args.priority;
209207
let t = util::spawn_t_ident(priority);
210208
let cfgs = &spawnee.cfgs;
211-
// Store a copy of the task cfgs
212-
task_cfgs = cfgs.clone();
213209
let (args, tupled, untupled, ty) = util::regroup_inputs(&spawnee.inputs);
214210
let args = &args;
215211
let tupled = &tupled;
@@ -461,9 +457,8 @@ pub fn codegen(
461457
} else {
462458
quote!(
463459
#(#items)*
464-
465460
#[allow(non_snake_case)]
466-
#(#task_cfgs)*
461+
#(#cfgs)*
467462
#[doc = #doc]
468463
pub mod #name {
469464
#(#module_items)*

macros/src/codegen/pre_init.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
1616
// Populate the FreeQueue
1717
for (name, task) in &app.software_tasks {
1818
let cap = task.args.capacity;
19+
let cfgs = &task.cfgs;
1920
let fq_ident = util::fq_ident(name);
2021

2122
stmts.push(quote!(
23+
#(#cfgs)*
2224
(0..#cap).for_each(|i| (&mut *#fq_ident.get_mut()).enqueue_unchecked(i));
2325
));
2426
}

macros/src/codegen/shared_resources_struct.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
1515
Context::SoftwareTask(name) => &app.software_tasks[name].args.shared_resources,
1616
};
1717

18+
let v = Vec::new();
19+
let task_cfgs = match ctxt {
20+
Context::HardwareTask(t) => {
21+
&app.hardware_tasks[t].cfgs
22+
// ...
23+
}
24+
Context::SoftwareTask(t) => {
25+
&app.software_tasks[t].cfgs
26+
// ...
27+
}
28+
_ => &v,
29+
};
30+
1831
let mut fields = vec![];
1932
let mut values = vec![];
2033
let mut has_cfgs = false;
@@ -118,6 +131,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
118131
#[allow(non_snake_case)]
119132
#[allow(non_camel_case_types)]
120133
#[doc = #doc]
134+
#(#task_cfgs)*
121135
pub struct #ident<#lt> {
122136
#(#fields,)*
123137
}
@@ -129,6 +143,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
129143
Some(quote!(priority: &#lt rtic::export::Priority))
130144
};
131145
let constructor = quote!(
146+
#(#task_cfgs)*
132147
impl<#lt> #ident<#lt> {
133148
#[doc(hidden)]
134149
#[inline(always)]

macros/src/codegen/software_tasks.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn codegen(
2929

3030
for (name, task) in &app.software_tasks {
3131
let inputs = &task.inputs;
32+
let cfgs = &task.cfgs;
3233
let (_, _, _, input_ty) = util::regroup_inputs(inputs);
3334

3435
let cap = task.args.capacity;
@@ -49,6 +50,7 @@ pub fn codegen(
4950
mod_app.push(quote!(
5051
// /// Queue version of a free-list that keeps track of empty slots in
5152
// /// the following buffers
53+
#(#cfgs)*
5254
#[allow(non_camel_case_types)]
5355
#[allow(non_upper_case_globals)]
5456
#[doc(hidden)]
@@ -89,6 +91,7 @@ pub fn codegen(
8991
#[allow(non_camel_case_types)]
9092
#[allow(non_upper_case_globals)]
9193
#[doc(hidden)]
94+
#(#cfgs)*
9295
static #inputs_ident: rtic::RacyCell<[core::mem::MaybeUninit<#input_ty>; #cap_lit]> =
9396
rtic::RacyCell::new([#(#elems,)*]);
9497
));

0 commit comments

Comments
 (0)