aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/util.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-10-28 21:11:13 -0500
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-10-28 21:11:13 -0500
commita3783a6d3d90ab549766b13651ec8ff8013762c5 (patch)
tree29fc5a2ed50c73ebfeca65fd52ad241d9995677d /macros/src/codegen/util.rs
parentf9b30a1ff87acd5f3c29a32369f0537e8e3d2bf1 (diff)
downloadrtic-a3783a6d3d90ab549766b13651ec8ff8013762c5.tar.gz
rtic-a3783a6d3d90ab549766b13651ec8ff8013762c5.tar.zst
rtic-a3783a6d3d90ab549766b13651ec8ff8013762c5.zip
WIP generators tasksgenerator-tasks
Diffstat (limited to 'macros/src/codegen/util.rs')
-rw-r--r--macros/src/codegen/util.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs
index 207272dc..3ee55bfa 100644
--- a/macros/src/codegen/util.rs
+++ b/macros/src/codegen/util.rs
@@ -91,6 +91,43 @@ pub fn impl_mutex(
)
}
+/// Generates a `Mutex` implementation for a resource seen from a generator task
+pub fn impl_gmutex(
+ extra: &Extra,
+ cfgs: &[Attribute],
+ cfg_core: Option<&TokenStream2>,
+ name: &Ident,
+ ty: TokenStream2,
+ ceiling: u8,
+ ptr: TokenStream2,
+) -> TokenStream2 {
+ let path = quote!(gresources::#name);
+
+ let device = extra.device;
+ quote!(
+ #(#cfgs)*
+ #cfg_core
+ impl rtfm::Mutex for #path {
+ type T = #ty;
+
+ #[inline(always)]
+ fn lock<R>(&mut self, f: impl FnOnce(&mut #ty) -> R) -> R {
+ /// Priority ceiling
+ const CEILING: u8 = #ceiling;
+
+ unsafe {
+ rtfm::export::glock(
+ #ptr,
+ CEILING,
+ #device::NVIC_PRIO_BITS,
+ f,
+ )
+ }
+ }
+ }
+ )
+}
+
/// Generates an identifier for a cross-initialization barrier
pub fn init_barrier(initializer: Core) -> Ident {
Ident::new(&format!("IB{}", initializer), Span::call_site())
@@ -323,3 +360,11 @@ pub fn suffixed(name: &str, core: u8) -> Ident {
pub fn tq_ident(core: Core) -> Ident {
Ident::new(&format!("TQ{}", core), Span::call_site())
}
+
+pub fn generator_ident(task: &str) -> Ident {
+ Ident::new(&format!("{}S", task), Span::call_site())
+}
+
+pub fn generator_type(task: &str) -> Ident {
+ Ident::new(&format!("{}T", task), Span::call_site())
+}