diff options
author | 2019-04-16 22:54:18 +0000 | |
---|---|---|
committer | 2019-04-16 22:54:18 +0000 | |
commit | 77def324548e204d3a36a4e89eb528904c381158 (patch) | |
tree | 98d6835a2048d96bbe4df0173731df82feee7c21 /macros/src | |
parent | e1e4c98cb900a1425b583edeb12cd3df7ff34ea1 (diff) | |
parent | aa7eec02996aca9304187f36d674d5fe898aece6 (diff) | |
download | rtic-77def324548e204d3a36a4e89eb528904c381158.tar.gz rtic-77def324548e204d3a36a4e89eb528904c381158.tar.zst rtic-77def324548e204d3a36a4e89eb528904c381158.zip |
Merge #170
170: check task priority at compile time r=TeXitoi a=japaric
before we were checking the priority at runtime. The compile time error message
when the priority is too high is kind of awful though.
Co-authored-by: Jorge Aparicio <jorge@japaric.io>
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/codegen.rs | 6 | ||||
-rw-r--r-- | macros/src/syntax.rs | 4 |
2 files changed, 4 insertions, 6 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 94e8cd8c..1b3f67b8 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), diff --git a/macros/src/syntax.rs b/macros/src/syntax.rs index 7f87f633..228d9588 100644 --- a/macros/src/syntax.rs +++ b/macros/src/syntax.rs @@ -1039,10 +1039,10 @@ fn parse_args( } let value = lit.value(); - if value > u64::from(u8::MAX) { + if value > u64::from(u8::MAX) || value == 0 { return Err(parse::Error::new( lit.span(), - "this literal must be in the range 0...255", + "this literal must be in the range 1...255", )); } |