aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/codegen')
-rw-r--r--macros/src/codegen/init.rs28
-rw-r--r--macros/src/codegen/module.rs6
-rw-r--r--macros/src/codegen/post_init.rs3
-rw-r--r--macros/src/codegen/util.rs8
4 files changed, 43 insertions, 2 deletions
diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs
index 6376ce31..6b57add1 100644
--- a/macros/src/codegen/init.rs
+++ b/macros/src/codegen/init.rs
@@ -58,6 +58,24 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
}
));
+ let monotonic_types: Vec<_> = app
+ .monotonics
+ .iter()
+ .map(|(_, monotonic)| {
+ let mono = &monotonic.ty;
+ quote! {#mono}
+ })
+ .collect();
+ let monotonics = util::monotonics_ident(&name);
+
+ root_init.push(quote!(
+ /// Monotonics used by the system
+ #[allow(non_snake_case)]
+ pub struct #monotonics(
+ #(#monotonic_types),*
+ );
+ ));
+
let mut locals_pat = None;
let mut locals_new = None;
if !init.locals.is_empty() {
@@ -72,10 +90,16 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
let attrs = &init.attrs;
let stmts = &init.stmts;
let locals_pat = locals_pat.iter();
+
+ let mut user_init_return = vec![quote! {#name::LateResources}];
+ if !app.monotonics.is_empty() {
+ user_init_return.push(quote! {#name::Monotonics});
+ }
+
let user_init = Some(quote!(
#(#attrs)*
#[allow(non_snake_case)]
- fn #name(#(#locals_pat,)* #context: #name::Context) -> #name::LateResources {
+ fn #name(#(#locals_pat,)* #context: #name::Context) -> (#(#user_init_return,)*) {
#(#stmts)*
}
));
@@ -92,7 +116,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
let app_path = quote! {crate::#app_name};
let locals_new = locals_new.iter();
let call_init = Some(
- quote!(let late = #app_path::#name(#(#locals_new,)* #name::Context::new(core.into()));),
+ quote!(let (late, monotonics) = #app_path::#name(#(#locals_new,)* #name::Context::new(core.into()));),
);
root_init.push(module::codegen(
diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs
index 2ff4801e..d398a1a8 100644
--- a/macros/src/codegen/module.rs
+++ b/macros/src/codegen/module.rs
@@ -131,11 +131,17 @@ pub fn codegen(
if let Context::Init = ctxt {
let init = &app.inits.first().unwrap();
let late_resources = util::late_resources_ident(&init.name);
+ let monotonics = util::monotonics_ident(&init.name);
items.push(quote!(
#[doc(inline)]
pub use super::#late_resources as LateResources;
));
+
+ items.push(quote!(
+ #[doc(inline)]
+ pub use super::#monotonics as Monotonics;
+ ));
}
let doc = match ctxt {
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs
index 5545944d..9174daeb 100644
--- a/macros/src/codegen/post_init.rs
+++ b/macros/src/codegen/post_init.rs
@@ -25,6 +25,9 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
}
}
+ // Forget the monotonics so they won't be dropped.
+ stmts.push(quote!(core::mem::forget(monotonics);));
+
// Enable the interrupts -- this completes the `init`-ialization phase
stmts.push(quote!(rtic::export::interrupt::enable();));
diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs
index fb8f1a84..4273ee2c 100644
--- a/macros/src/codegen/util.rs
+++ b/macros/src/codegen/util.rs
@@ -111,6 +111,14 @@ pub fn late_resources_ident(init: &Ident) -> Ident {
)
}
+/// Generates a pre-reexport identifier for the "monotonics" struct
+pub fn monotonics_ident(init: &Ident) -> Ident {
+ Ident::new(
+ &format!("{}Monotonics", init.to_string()),
+ Span::call_site(),
+ )
+}
+
/// Mangle an ident
pub fn mangle_ident(ident: &Ident) -> Ident {
Ident::new(