aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/shared_resources_struct.rs
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2023-01-23 20:05:47 +0100
committerGravatar Henrik Tjäder <henrik@tjaders.com> 2023-03-01 00:33:31 +0100
commit306aa47170fd59369b7a184924e287dc3706d64d (patch)
tree75a331a63a4021f078e330bf2ce4edb1228e2ecf /macros/src/codegen/shared_resources_struct.rs
parentb8b881f446a226d6f3c4a7db7c9174590b47dbf6 (diff)
downloadrtic-306aa47170fd59369b7a184924e287dc3706d64d.tar.gz
rtic-306aa47170fd59369b7a184924e287dc3706d64d.tar.zst
rtic-306aa47170fd59369b7a184924e287dc3706d64d.zip
Add rtic-timer (timerqueue + monotonic) and rtic-monotonics (systick-monotonic)
Diffstat (limited to 'macros/src/codegen/shared_resources_struct.rs')
-rw-r--r--macros/src/codegen/shared_resources_struct.rs119
1 files changed, 0 insertions, 119 deletions
diff --git a/macros/src/codegen/shared_resources_struct.rs b/macros/src/codegen/shared_resources_struct.rs
deleted file mode 100644
index fa6f0fcb..00000000
--- a/macros/src/codegen/shared_resources_struct.rs
+++ /dev/null
@@ -1,119 +0,0 @@
-use crate::syntax::{ast::App, Context};
-use proc_macro2::TokenStream as TokenStream2;
-use quote::quote;
-
-use crate::codegen::util;
-
-/// Generate shared resources structs
-pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
- let resources = match ctxt {
- Context::Init => unreachable!("Tried to generate shared resources struct for init"),
- Context::Idle => {
- &app.idle
- .as_ref()
- .expect("RTIC-ICE: unable to get idle name")
- .args
- .shared_resources
- }
- Context::HardwareTask(name) => &app.hardware_tasks[name].args.shared_resources,
- Context::SoftwareTask(name) => &app.software_tasks[name].args.shared_resources,
- };
-
- let mut fields = vec![];
- let mut values = vec![];
-
- for (name, access) in resources {
- let res = app.shared_resources.get(name).expect("UNREACHABLE");
-
- let cfgs = &res.cfgs;
-
- // access hold if the resource is [x] (exclusive) or [&x] (shared)
- let mut_ = if access.is_exclusive() {
- Some(quote!(mut))
- } else {
- None
- };
- let ty = &res.ty;
- let mangled_name = util::static_shared_resource_ident(name);
- let shared_name = util::need_to_lock_ident(name);
-
- if res.properties.lock_free {
- // Lock free resources of `idle` and `init` get 'static lifetime
- let lt = if ctxt.runs_once() {
- quote!('static)
- } else {
- quote!('a)
- };
-
- fields.push(quote!(
- #(#cfgs)*
- #[allow(missing_docs)]
- pub #name: &#lt #mut_ #ty
- ));
- } else if access.is_shared() {
- fields.push(quote!(
- #(#cfgs)*
- #[allow(missing_docs)]
- pub #name: &'a #ty
- ));
- } else {
- fields.push(quote!(
- #(#cfgs)*
- #[allow(missing_docs)]
- pub #name: shared_resources::#shared_name<'a>
- ));
-
- values.push(quote!(
- #(#cfgs)*
- #name: shared_resources::#shared_name::new()
-
- ));
-
- // continue as the value has been filled,
- continue;
- }
-
- let expr = if access.is_exclusive() {
- quote!(&mut *(&mut *#mangled_name.get_mut()).as_mut_ptr())
- } else {
- quote!(&*(&*#mangled_name.get()).as_ptr())
- };
-
- values.push(quote!(
- #(#cfgs)*
- #name: #expr
- ));
- }
-
- fields.push(quote!(
- #[doc(hidden)]
- pub __rtic_internal_marker: core::marker::PhantomData<&'a ()>
- ));
-
- values.push(quote!(__rtic_internal_marker: core::marker::PhantomData));
-
- let doc = format!("Shared resources `{}` has access to", ctxt.ident(app));
- let ident = util::shared_resources_ident(ctxt, app);
- let item = quote!(
- #[allow(non_snake_case)]
- #[allow(non_camel_case_types)]
- #[doc = #doc]
- pub struct #ident<'a> {
- #(#fields,)*
- }
- );
-
- let constructor = quote!(
- impl<'a> #ident<'a> {
- #[inline(always)]
- #[allow(missing_docs)]
- pub unsafe fn new() -> Self {
- #ident {
- #(#values,)*
- }
- }
- }
- );
-
- (item, constructor)
-}