diff options
author | 2020-12-03 21:04:06 +0100 | |
---|---|---|
committer | 2020-12-03 21:04:06 +0100 | |
commit | ef50aeb2e8245b69843280fabb62589c0716ffdd (patch) | |
tree | a159de70654135eb87c52629c6026766eac3bff0 /macros/src | |
parent | 3b4c10e790e63ac328a7bdb98451ac11d5935731 (diff) | |
download | rtic-ef50aeb2e8245b69843280fabb62589c0716ffdd.tar.gz rtic-ef50aeb2e8245b69843280fabb62589c0716ffdd.tar.zst rtic-ef50aeb2e8245b69843280fabb62589c0716ffdd.zip |
Save, init generation fixed
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/check.rs | 14 | ||||
-rw-r--r-- | macros/src/codegen.rs | 2 | ||||
-rw-r--r-- | macros/src/codegen/init.rs | 28 | ||||
-rw-r--r-- | macros/src/codegen/module.rs | 6 | ||||
-rw-r--r-- | macros/src/codegen/post_init.rs | 3 | ||||
-rw-r--r-- | macros/src/codegen/util.rs | 8 | ||||
-rw-r--r-- | macros/src/lib.rs | 2 |
7 files changed, 45 insertions, 18 deletions
diff --git a/macros/src/check.rs b/macros/src/check.rs index e3161cb9..42bd90db 100644 --- a/macros/src/check.rs +++ b/macros/src/check.rs @@ -62,18 +62,6 @@ pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<Extra> { for (name, task) in &app.hardware_tasks { let name_s = task.args.binds.to_string(); match &*name_s { - "SysTick" => { - // If the timer queue is used, then SysTick is unavailable - if app.args.monotonic.is_some() { - return Err(parse::Error::new( - name.span(), - "this exception can't be used because it's being used by the runtime", - )); - } else { - // OK - } - } - "NonMaskableInt" | "HardFault" => { return Err(parse::Error::new( name.span(), @@ -88,7 +76,7 @@ pub fn app(app: &App, _analysis: &Analysis) -> parse::Result<Extra> { if let Some(device) = app.args.device.clone() { Ok(Extra { device, - monotonic: app.args.monotonic.clone(), + monotonic: None, peripherals: app.args.peripherals, }) } else { diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 3cddf570..52940bc3 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -61,8 +61,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { use super::*; #[no_mangle] unsafe extern "C" fn #main() -> ! { - let _TODO: () = (); - #(#assertion_stmts)* #(#pre_init_stmts)* 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( diff --git a/macros/src/lib.rs b/macros/src/lib.rs index dc37eaea..c9136e55 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,4 +1,4 @@ -#![deny(warnings)] +// #![deny(warnings)] extern crate proc_macro; |