diff options
author | 2023-03-04 21:10:24 +0000 | |
---|---|---|
committer | 2023-03-04 21:10:24 +0000 | |
commit | 7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b (patch) | |
tree | 80a47f0dc40059014e9448c4c2eb34c54dff45fe /rtic-macros/src/codegen/pre_init.rs | |
parent | 1c5db277e4161470136dbd2a11e914ff1d383581 (diff) | |
parent | 98c5490d94950608d31cd5ad9dd260f2f853735c (diff) | |
download | rtic-7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b.tar.gz rtic-7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b.tar.zst rtic-7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b.zip |
Merge #694
694: RTIC 2 r=AfoHT a=korken89
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Co-authored-by: Per Lindgren <per.lindgren@ltu.se>
Diffstat (limited to 'rtic-macros/src/codegen/pre_init.rs')
-rw-r--r-- | rtic-macros/src/codegen/pre_init.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/rtic-macros/src/codegen/pre_init.rs b/rtic-macros/src/codegen/pre_init.rs new file mode 100644 index 00000000..a2d0e8c1 --- /dev/null +++ b/rtic-macros/src/codegen/pre_init.rs @@ -0,0 +1,24 @@ +use super::bindings::{pre_init_checks, pre_init_enable_interrupts}; +use crate::analyze::Analysis; +use crate::syntax::ast::App; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +/// Generates code that runs before `#[init]` +pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { + let mut stmts = vec![]; + + // Disable interrupts -- `init` must run with interrupts disabled + stmts.push(quote!(rtic::export::interrupt::disable();)); + + stmts.push(quote!( + // To set the variable in cortex_m so the peripherals cannot be taken multiple times + let mut core: rtic::export::Peripherals = rtic::export::Peripherals::steal().into(); + )); + + stmts.append(&mut pre_init_checks(app, analysis)); + + stmts.append(&mut pre_init_enable_interrupts(app, analysis)); + + stmts +} |