diff options
author | 2017-07-27 11:37:58 -0500 | |
---|---|---|
committer | 2017-07-27 11:37:58 -0500 | |
commit | 0b5afce771cb9e5cc42c4fd4c5e18f020bf1ecad (patch) | |
tree | affdb231beeb7c823a36197c780c3cd740a7e0c2 /macros/src | |
parent | dee2fcde716a2dbb1404caa4e0f8f4ce11c472c8 (diff) | |
download | rtic-0b5afce771cb9e5cc42c4fd4c5e18f020bf1ecad.tar.gz rtic-0b5afce771cb9e5cc42c4fd4c5e18f020bf1ecad.tar.zst rtic-0b5afce771cb9e5cc42c4fd4c5e18f020bf1ecad.zip |
refactor Resource / Threshold into its own crate, drop task!, tweak rtfm::atomic
task! can be re-added in a backward compatible fashion and I'd like to not have
two ways to assign a task handler to an interrupt / exception in the first
release.
rtfm::atomic now uses the `Threshold` token instead of the `CriticalSection`
token. This reduces overhead by dropping the "are interrupts enabled?" check.
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/trans.rs | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/macros/src/trans.rs b/macros/src/trans.rs index a137e0ec..4f389d30 100644 --- a/macros/src/trans.rs +++ b/macros/src/trans.rs @@ -238,7 +238,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.borrow(_cs); + let nvic = &*#device::NVIC.get(); }); } @@ -262,7 +262,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) { // Exception if exceptions.is_empty() { exceptions.push(quote! { - let scb = #device::SCB.borrow(_cs); + let scb = &*#device::SCB.get(); }); } @@ -280,7 +280,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) { // type check let init: fn(#(#tys,)*) = #init; - #krate::atomic(|_cs| unsafe { + #krate::atomic(unsafe { &mut #krate::Threshold::new(0) }, |_t| unsafe { init(#(#exprs,)*); #(#exceptions)* @@ -328,15 +328,19 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) { fn borrow<'cs>( &'cs self, - _cs: &'cs #krate::CriticalSection, + t: &'cs #krate::Threshold, ) -> &'cs #krate::Static<#ty> { + assert!(t.value() >= #ceiling); + unsafe { #krate::Static::ref_(&#_name) } } fn borrow_mut<'cs>( &'cs mut self, - _cs: &'cs #krate::CriticalSection, + t: &'cs #krate::Threshold, ) -> &'cs mut #krate::Static<#ty> { + assert!(t.value() >= #ceiling); + unsafe { #krate::Static::ref_mut(&mut #_name) } @@ -390,8 +394,10 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) { fn borrow<'cs>( &'cs self, - _cs: &'cs #krate::CriticalSection, + t: &'cs #krate::Threshold, ) -> &'cs #krate::Static<#device::#name> { + assert!(t.value() >= #ceiling); + unsafe { #krate::Static::ref_(&*#device::#name.get()) } @@ -399,8 +405,10 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) { fn borrow_mut<'cs>( &'cs mut self, - _cs: &'cs #krate::CriticalSection, + t: &'cs #krate::Threshold, ) -> &'cs mut #krate::Static<#device::#name> { + assert!(t.value() >= #ceiling); + unsafe { #krate::Static::ref_mut( &mut *#device::#name.get(), @@ -458,7 +466,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) { impls.push(quote! { #[allow(unsafe_code)] - impl #krate::Resource for _resource::#name { + unsafe impl #krate::Resource for _resource::#name { #(#impl_items)* } }); @@ -594,7 +602,13 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) { let priority = task.priority; if needs_threshold { tys.push(quote!(&mut #krate::Threshold)); - exprs.push(quote!(&mut #krate::Threshold::new(#priority))); + exprs.push(quote! { + &mut if #priority == 1 << #device::NVIC_PRIO_BITS { + #krate::Threshold::new(::core::u8::MAX) + } else { + #krate::Threshold::new(#priority) + } + }); } if has_resources { |