diff options
author | 2017-11-20 05:11:25 +0100 | |
---|---|---|
committer | 2017-12-09 12:45:57 +0100 | |
commit | e97afa71ce7bf3d78e257de1aab329135e98c721 (patch) | |
tree | 8335f9d8327a9863ec64b79934f8241b350f7fe3 /macros/src | |
parent | e620b1e57a39f342cf73ad6ac8ab0e179b97bfd5 (diff) | |
download | rtic-e97afa71ce7bf3d78e257de1aab329135e98c721.tar.gz rtic-e97afa71ce7bf3d78e257de1aab329135e98c721.tar.zst rtic-e97afa71ce7bf3d78e257de1aab329135e98c721.zip |
peripherals as scoped singletons
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/check.rs | 18 | ||||
-rw-r--r-- | macros/src/trans.rs | 18 |
2 files changed, 27 insertions, 9 deletions
diff --git a/macros/src/check.rs b/macros/src/check.rs index 3cd112ac..63cac1fa 100644 --- a/macros/src/check.rs +++ b/macros/src/check.rs @@ -63,16 +63,15 @@ pub fn app(app: check::App) -> Result<App> { tasks: app.tasks .into_iter() .map(|(k, v)| { - let v = ::check::task(k.as_ref(), v) - .chain_err(|| format!("checking task `{}`", k))?; + let v = + ::check::task(k.as_ref(), v).chain_err(|| format!("checking task `{}`", k))?; Ok((k, v)) }) .collect::<Result<_>>()?, }; - ::check::resources(&app) - .chain_err(|| "checking `resources`")?; + ::check::resources(&app).chain_err(|| "checking `resources`")?; Ok(app) } @@ -93,6 +92,17 @@ fn resources(app: &App) -> Result<()> { bail!("resource `{}` is unused", resource); } + for (name, task) in &app.tasks { + for resource in &task.resources { + ensure!( + app.resources.contains_key(&resource), + "task {} contains an undeclared resource with name {}", + name, + resource + ); + } + } + Ok(()) } diff --git a/macros/src/trans.rs b/macros/src/trans.rs index 96ff770b..b97ff408 100644 --- a/macros/src/trans.rs +++ b/macros/src/trans.rs @@ -161,8 +161,13 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) { let device = &app.device; let krate = krate(); - let mut tys = vec![quote!(#device::Peripherals)]; - let mut exprs = vec![quote!(#device::Peripherals::all())]; + let mut tys = vec![quote!(init::Peripherals)]; + let mut exprs = vec![quote!{ + init::Peripherals { + core: ::#device::CorePeripherals::steal(), + device: ::#device::Peripherals::steal(), + } + }]; let mut ret = None; let mut mod_items = vec![]; @@ -255,7 +260,10 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) { root.push(quote! { #[allow(unsafe_code)] mod init { - pub use ::#device::Peripherals; + pub struct Peripherals { + pub core: ::#device::CorePeripherals, + pub device: ::#device::Peripherals, + } #(#mod_items)* } @@ -268,7 +276,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) { Kind::Exception(ref e) => { if exceptions.is_empty() { exceptions.push(quote! { - let scb = &*#device::SCB.get(); + let scb = &*#device::SCB::ptr(); }); } @@ -284,7 +292,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) { // Interrupt. These can be enabled / disabled through the NVIC if interrupts.is_empty() { interrupts.push(quote! { - let nvic = &*#device::NVIC.get(); + let nvic = &*#device::NVIC::ptr(); }); } |