aboutsummaryrefslogtreecommitdiff
path: root/rtic-macros/src/codegen/pre_init.rs
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2023-02-11 08:55:19 +0100
committerGravatar Henrik Tjäder <henrik@tjaders.com> 2023-03-01 00:35:20 +0100
commit60f0342b697cdddbab9c0e8c6d772bc7aab9de38 (patch)
tree5bbb73e299f416f4c10adf329704b734379caa41 /rtic-macros/src/codegen/pre_init.rs
parent1cda61fbda205920517f7b63af90c97c38ff9af6 (diff)
downloadrtic-60f0342b697cdddbab9c0e8c6d772bc7aab9de38.tar.gz
rtic-60f0342b697cdddbab9c0e8c6d772bc7aab9de38.tar.zst
rtic-60f0342b697cdddbab9c0e8c6d772bc7aab9de38.zip
Break out core specific codegen to bindings
Diffstat (limited to 'rtic-macros/src/codegen/pre_init.rs')
-rw-r--r--rtic-macros/src/codegen/pre_init.rs69
1 files changed, 4 insertions, 65 deletions
diff --git a/rtic-macros/src/codegen/pre_init.rs b/rtic-macros/src/codegen/pre_init.rs
index 28ba29c0..a2d0e8c1 100644
--- a/rtic-macros/src/codegen/pre_init.rs
+++ b/rtic-macros/src/codegen/pre_init.rs
@@ -1,15 +1,13 @@
+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;
-use crate::{analyze::Analysis, codegen::util};
-
/// Generates code that runs before `#[init]`
pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
let mut stmts = vec![];
- let rt_err = util::rt_err_ident();
-
// Disable interrupts -- `init` must run with interrupts disabled
stmts.push(quote!(rtic::export::interrupt::disable();));
@@ -18,68 +16,9 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
let mut core: rtic::export::Peripherals = rtic::export::Peripherals::steal().into();
));
- let device = &app.args.device;
- let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS);
-
- // check that all dispatchers exists in the `Interrupt` enumeration regardless of whether
- // they are used or not
- let interrupt = util::interrupt_ident();
- for name in app.args.dispatchers.keys() {
- stmts.push(quote!(let _ = #rt_err::#interrupt::#name;));
- }
-
- let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id));
-
- // Unmask interrupts and set their priorities
- for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().filter_map(|task| {
- if util::is_exception(&task.args.binds) {
- // We do exceptions in another pass
- None
- } else {
- Some((&task.args.priority, &task.args.binds))
- }
- })) {
- let es = format!(
- "Maximum priority used by interrupt vector '{name}' is more than supported by hardware"
- );
- // Compile time assert that this priority is supported by the device
- stmts.push(quote!(
- const _: () = if (1 << #nvic_prio_bits) < #priority as usize { ::core::panic!(#es); };
- ));
-
- stmts.push(quote!(
- core.NVIC.set_priority(
- #rt_err::#interrupt::#name,
- rtic::export::logical2hw(#priority, #nvic_prio_bits),
- );
- ));
-
- // NOTE unmask the interrupt *after* setting its priority: changing the priority of a pended
- // interrupt is implementation defined
- stmts.push(quote!(rtic::export::NVIC::unmask(#rt_err::#interrupt::#name);));
- }
-
- // Set exception priorities
- for (name, priority) in app.hardware_tasks.values().filter_map(|task| {
- if util::is_exception(&task.args.binds) {
- Some((&task.args.binds, task.args.priority))
- } else {
- None
- }
- }) {
- let es = format!(
- "Maximum priority used by interrupt vector '{name}' is more than supported by hardware"
- );
- // Compile time assert that this priority is supported by the device
- stmts.push(quote!(
- const _: () = if (1 << #nvic_prio_bits) < #priority as usize { ::core::panic!(#es); };
- ));
+ stmts.append(&mut pre_init_checks(app, analysis));
- stmts.push(quote!(core.SCB.set_priority(
- rtic::export::SystemHandler::#name,
- rtic::export::logical2hw(#priority, #nvic_prio_bits),
- );));
- }
+ stmts.append(&mut pre_init_enable_interrupts(app, analysis));
stmts
}