diff options
author | 2017-07-27 17:08:42 -0500 | |
---|---|---|
committer | 2017-07-27 17:08:42 -0500 | |
commit | d396da59502ef67f624bb4d8927ff8697232f66c (patch) | |
tree | 264e29e59cf4fe119fb82481b9c6949c579e8399 /macros/src/trans.rs | |
parent | ad2a523cf9d39191d54f4dda3c99f22b5bade7de (diff) | |
download | rtic-d396da59502ef67f624bb4d8927ff8697232f66c.tar.gz rtic-d396da59502ef67f624bb4d8927ff8697232f66c.tar.zst rtic-d396da59502ef67f624bb4d8927ff8697232f66c.zip |
make task.$T.enabled optional
and move the logic that differentiates interrupts from exceptions from the crate
to the procedural macro logic
Diffstat (limited to 'macros/src/trans.rs')
-rw-r--r-- | macros/src/trans.rs | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/macros/src/trans.rs b/macros/src/trans.rs index 468d9675..02b5e8cd 100644 --- a/macros/src/trans.rs +++ b/macros/src/trans.rs @@ -2,7 +2,7 @@ use quote::{Ident, Tokens}; use syn::{Lit, StrStyle}; use analyze::{Ownership, Ownerships}; -use check::App; +use check::{App, Kind}; fn krate() -> Ident { Ident::from("rtfm") @@ -236,44 +236,47 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) { let mut exceptions = vec![]; let mut interrupts = vec![]; for (name, task) in &app.tasks { - if let Some(enabled) = task.enabled { - // Interrupt. These can be enabled / disabled through the NVIC - if interrupts.is_empty() { - interrupts.push(quote! { - let nvic = &*#device::NVIC.get(); + match task.kind { + Kind::Exception(ref e) => { + if exceptions.is_empty() { + exceptions.push(quote! { + let scb = &*#device::SCB.get(); + }); + } + + let nr = e.nr(); + let priority = task.priority; + exceptions.push(quote! { + let prio_bits = #device::NVIC_PRIO_BITS; + let hw = ((1 << prio_bits) - #priority) << (8 - prio_bits); + scb.shpr[#nr - 4].write(hw); }); } + Kind::Interrupt { enabled } => { + // Interrupt. These can be enabled / disabled through the NVIC + if interrupts.is_empty() { + interrupts.push(quote! { + let nvic = &*#device::NVIC.get(); + }); + } - let priority = task.priority; - interrupts.push(quote! { - let prio_bits = #device::NVIC_PRIO_BITS; - let hw = ((1 << prio_bits) - #priority) << (8 - prio_bits); - nvic.set_priority(#device::Interrupt::#name, hw); - }); - - if enabled { - interrupts.push(quote! { - nvic.enable(#device::Interrupt::#name); - }); - } else { + let priority = task.priority; interrupts.push(quote! { - nvic.disable(#device::Interrupt::#name); + let prio_bits = #device::NVIC_PRIO_BITS; + let hw = ((1 << prio_bits) - #priority) << (8 - prio_bits); + nvic.set_priority(#device::Interrupt::#name, hw); }); - } - } else { - // Exception - if exceptions.is_empty() { - exceptions.push(quote! { - let scb = &*#device::SCB.get(); - }); - } - let priority = task.priority; - exceptions.push(quote! { - let prio_bits = #device::NVIC_PRIO_BITS; - let hw = ((1 << prio_bits) - #priority) << (8 - prio_bits); - scb.shpr[#krate::Exception::#name.nr() - 4].write(hw); - }); + if enabled { + interrupts.push(quote! { + nvic.enable(#device::Interrupt::#name); + }); + } else { + interrupts.push(quote! { + nvic.disable(#device::Interrupt::#name); + }); + } + } } } |