mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
move some interrupt configuration to pre_init
This commit is contained in:
parent
f7ac71ab22
commit
d14e25d72d
1 changed files with 26 additions and 22 deletions
|
@ -142,7 +142,7 @@ pub fn app(app: &App, analysis: &Analysis) -> TokenStream {
|
|||
|
||||
let timer_queue = timer_queue(&ctxt, app, analysis);
|
||||
|
||||
let pre_init = pre_init(&ctxt, analysis);
|
||||
let pre_init = pre_init(&ctxt, &app, analysis);
|
||||
|
||||
let assertions = assertions(app, analysis);
|
||||
|
||||
|
@ -385,16 +385,6 @@ fn post_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok
|
|||
// the device into compile errors
|
||||
let device = &app.args.device;
|
||||
let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS);
|
||||
for (name, interrupt) in &app.interrupts {
|
||||
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!(p.NVIC.set_priority(
|
||||
#device::Interrupt::#name,
|
||||
((1 << #nvic_prio_bits) - #priority) << (8 - #nvic_prio_bits),
|
||||
)));
|
||||
}
|
||||
|
||||
for (name, exception) in &app.exceptions {
|
||||
let priority = exception.args.priority;
|
||||
exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits))));
|
||||
|
@ -413,16 +403,6 @@ fn post_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok
|
|||
)));
|
||||
}
|
||||
|
||||
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!(p.NVIC.set_priority(
|
||||
#device::Interrupt::#name,
|
||||
((1 << #nvic_prio_bits) - #priority) << (8 - #nvic_prio_bits),
|
||||
)));
|
||||
}
|
||||
|
||||
if app.idle.is_none() {
|
||||
// Set SLEEPONEXIT bit to enter sleep mode when returning from ISR
|
||||
exprs.push(quote!(p.SCB.scr.modify(|r| r | 1 << 1)));
|
||||
|
@ -1592,7 +1572,7 @@ fn timer_queue(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::T
|
|||
quote!(#(#items)*)
|
||||
}
|
||||
|
||||
fn pre_init(ctxt: &Context, analysis: &Analysis) -> proc_macro2::TokenStream {
|
||||
fn pre_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::TokenStream {
|
||||
let mut exprs = vec![];
|
||||
|
||||
// FIXME(MaybeUninit) Because we are using a fake MaybeUninit we need to set the Option tag to
|
||||
|
@ -1642,6 +1622,30 @@ fn pre_init(ctxt: &Context, analysis: &Analysis) -> proc_macro2::TokenStream {
|
|||
))
|
||||
}
|
||||
|
||||
// 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 (name, interrupt) in &app.interrupts {
|
||||
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!(p.NVIC.set_priority(
|
||||
#device::Interrupt::#name,
|
||||
((1 << #nvic_prio_bits) - #priority) << (8 - #nvic_prio_bits),
|
||||
);));
|
||||
}
|
||||
|
||||
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!(p.NVIC.set_priority(
|
||||
#device::Interrupt::#name,
|
||||
((1 << #nvic_prio_bits) - #priority) << (8 - #nvic_prio_bits),
|
||||
);));
|
||||
}
|
||||
|
||||
// Set the cycle count to 0 and disable it while `init` executes
|
||||
if cfg!(feature = "timer-queue") {
|
||||
exprs.push(quote!(p.DWT.ctrl.modify(|r| r & !1);));
|
||||
|
|
Loading…
Reference in a new issue