More ergonomic error from static asserts messages

This commit is contained in:
Emil Fresk 2022-05-17 20:12:36 +02:00
parent 6896749f7b
commit cd445165c5
2 changed files with 33 additions and 6 deletions

View file

@ -49,8 +49,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
Some((&task.args.priority, &task.args.binds))
}
})) {
let es = format!(
"Maximum priority used by interrupt vector '{}' is more than supported by hardware",
name
);
// Compile time assert that this priority is supported by the device
stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
stmts.push(quote!(
const _: () = assert!((1 << #nvic_prio_bits) >= #priority as usize, #es);
));
stmts.push(quote!(
core.NVIC.set_priority(
@ -72,8 +78,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
None
}
}) {
let es = format!(
"Maximum priority used by interrupt vector '{}' is more than supported by hardware",
name
);
// Compile time assert that this priority is supported by the device
stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
stmts.push(quote!(
const _: () = assert!((1 << #nvic_prio_bits) >= #priority as usize, #es);
));
stmts.push(quote!(core.SCB.set_priority(
rtic::export::SystemHandler::#name,
@ -90,8 +102,15 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
};
let binds = &monotonic.args.binds;
let name = &monotonic.ident;
let es = format!(
"Maximum priority used by monotonic '{}' is more than supported by hardware",
name
);
// Compile time assert that this priority is supported by the device
stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
stmts.push(quote!(
const _: () = assert!((1 << #nvic_prio_bits) >= #priority as usize, #es);
));
let mono_type = &monotonic.ty;