diff options
author | 2019-04-21 16:21:57 +0000 | |
---|---|---|
committer | 2019-04-21 16:21:57 +0000 | |
commit | 852337e03b4e84ef920c36c811b0676242e062ce (patch) | |
tree | 79e7bfbd392d3c58be4d481a801447a95e36e2ed /macros/src/codegen.rs | |
parent | b5a756bd7d394226e505f0cb4f91a5de01d9b950 (diff) | |
parent | a562fb32329f3dedb1a2b3a0bfa6061271559788 (diff) | |
download | rtic-852337e03b4e84ef920c36c811b0676242e062ce.tar.gz rtic-852337e03b4e84ef920c36c811b0676242e062ce.tar.zst rtic-852337e03b4e84ef920c36c811b0676242e062ce.zip |
Merge #174v0.4.3
174: v0.4.3 r=japaric a=japaric
prepares a new release
Co-authored-by: Jorge Aparicio <jorge@japaric.io>
Diffstat (limited to 'macros/src/codegen.rs')
-rw-r--r-- | macros/src/codegen.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 1b3f67b8..4468216f 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -464,14 +464,15 @@ fn init(ctxt: &mut Context, app: &App, analysis: &Analysis) -> (proc_macro2::Tok fn post_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::TokenStream { let mut exprs = vec![]; - // 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, exception) in &app.exceptions { let name = exception.args.binds(handler); let priority = exception.args.priority; - exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits)))); + + // compile time assert that the priority is supported by the device + exprs.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];)); + exprs.push(quote!(p.SCB.set_priority( rtfm::export::SystemHandler::#name, ((1 << #nvic_prio_bits) - #priority) << (8 - #nvic_prio_bits), @@ -480,7 +481,10 @@ fn post_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok if !analysis.timer_queue.tasks.is_empty() { let priority = analysis.timer_queue.priority; - exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits)))); + + // compile time assert that the priority is supported by the device + exprs.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];)); + exprs.push(quote!(p.SCB.set_priority( rtfm::export::SystemHandler::SysTick, ((1 << #nvic_prio_bits) - #priority) << (8 - #nvic_prio_bits), @@ -1995,7 +1999,10 @@ fn pre_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Toke let name = interrupt.args.binds(handler); let priority = interrupt.args.priority; exprs.push(quote!(p.NVIC.enable(#device::Interrupt::#name);)); + + // compile time assert that the priority is supported by the device 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), @@ -2005,7 +2012,10 @@ 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);)); + + // compile time assert that the priority is supported by the device 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), |