diff options
author | 2021-02-18 19:30:59 +0100 | |
---|---|---|
committer | 2021-02-18 19:30:59 +0100 | |
commit | ebf2f058a4d2a1fcf118144b9893dc3038939bad (patch) | |
tree | 11c7b828cc380737de36e6ab77edbd63bf42a72e /macros/src/codegen/post_init.rs | |
parent | b57ef0bf9d836ad031e4a4f7930162003128dc74 (diff) | |
download | rtic-ebf2f058a4d2a1fcf118144b9893dc3038939bad.tar.gz rtic-ebf2f058a4d2a1fcf118144b9893dc3038939bad.tar.zst rtic-ebf2f058a4d2a1fcf118144b9893dc3038939bad.zip |
Now with new monotonic trait and crate
Diffstat (limited to 'macros/src/codegen/post_init.rs')
-rw-r--r-- | macros/src/codegen/post_init.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 9268e040..b6cf47c3 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -1,6 +1,7 @@ -use proc_macro2::TokenStream as TokenStream2; +use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; use rtic_syntax::ast::App; +use syn::Index; use crate::{analyze::Analysis, codegen::util}; @@ -25,12 +26,17 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { } } - for (monotonic, _) in app.monotonics.iter() { - stmts.push(quote!(#monotonic::reset();)); - } + for (i, (monotonic, _)) in app.monotonics.iter().enumerate() { + let idx = Index { + index: i as u32, + span: Span::call_site(), + }; + stmts.push(quote!(monotonics.#idx.reset();)); - // Forget the monotonics so they won't be dropped. - stmts.push(quote!(core::mem::forget(monotonics);)); + // Store the monotonic + let name = util::monotonic_ident(&monotonic.to_string()); + stmts.push(quote!(#name.as_mut_ptr().write(monotonics.#idx);)); + } // Enable the interrupts -- this completes the `init`-ialization phase stmts.push(quote!(rtic::export::interrupt::enable();)); |