aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen.rs
diff options
context:
space:
mode:
authorJorge Aparicio <jorge@japaric.io>2019-04-16 23:04:24 +0200
committerJorge Aparicio <jorge@japaric.io>2019-04-16 23:04:24 +0200
commitaa7eec02996aca9304187f36d674d5fe898aece6 (patch)
treea6b0769f5b7b92c3d79f1b8b5b788bba0fe46fc3 /macros/src/codegen.rs
parent8da925647ea1ce47e876526d0bd3d918e782d578 (diff)
check task priority at compile time
before we were checking the priority at runtime. The compile time error message when the priority is too high is kind of awful though.
Diffstat (limited to 'macros/src/codegen.rs')
-rw-r--r--macros/src/codegen.rs6
1 files changed, 2 insertions, 4 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index 1d201c0..8b054ab 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -1989,15 +1989,13 @@ fn pre_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Toke
))
}
- // TODO turn the assertions that check that the priority is not larger than what's supported by
- // the device into compile errors
let device = &app.args.device;
let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS);
for (handler, interrupt) in &app.interrupts {
let name = interrupt.args.binds(handler);
let priority = interrupt.args.priority;
exprs.push(quote!(p.NVIC.enable(#device::Interrupt::#name);));
- exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits));));
+ exprs.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
exprs.push(quote!(p.NVIC.set_priority(
#device::Interrupt::#name,
((1 << #nvic_prio_bits) - #priority) << (8 - #nvic_prio_bits),
@@ -2007,7 +2005,7 @@ fn pre_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Toke
for (priority, dispatcher) in &analysis.dispatchers {
let name = &dispatcher.interrupt;
exprs.push(quote!(p.NVIC.enable(#device::Interrupt::#name);));
- exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits));));
+ exprs.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
exprs.push(quote!(p.NVIC.set_priority(
#device::Interrupt::#name,
((1 << #nvic_prio_bits) - #priority) << (8 - #nvic_prio_bits),