From 62771839061aaa7dd518d40969bee609d7d2bda8 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 13 Dec 2020 14:52:16 +0100 Subject: [PATCH] Now handling SysTick as well --- examples/test_new_monotonic.rs | 2 +- macros/src/codegen.rs | 4 +++- macros/src/codegen/module.rs | 17 ++++++++++++++-- macros/src/codegen/pre_init.rs | 32 +++++++++++++++++++++---------- macros/src/codegen/timer_queue.rs | 12 ++++++++++-- macros/src/codegen/util.rs | 11 ++++++++++- 6 files changed, 61 insertions(+), 17 deletions(-) diff --git a/examples/test_new_monotonic.rs b/examples/test_new_monotonic.rs index 3323c09b3b..67883465b6 100644 --- a/examples/test_new_monotonic.rs +++ b/examples/test_new_monotonic.rs @@ -8,7 +8,7 @@ use rtic::app; #[app(device = lm3s6965, dispatchers = [UART])] mod app { - #[monotonic(binds = SomeISR1)] + #[monotonic(binds = SysTick)] type MyMono1 = hal::Mono1; #[monotonic(binds = SomeISR2, default = true)] diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 1219e14f97..bb8aa4e751 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -114,11 +114,13 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { }) .collect(); + let rt_err = util::rt_err_ident(); + quote!( /// Implementation details pub mod #name { /// Always include the device crate which contains the vector table - use #device as you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml; + use #device as #rt_err; #(#monotonic_imports)* diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 2b6042c8c8..bf77c4d9fb 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -246,6 +246,19 @@ pub fn codegen( items.push(quote!(pub use #m::spawn_at;)); } + let (unmask, pend) = if &*m_isr.to_string() == "SysTick" { + ( + quote!(core::mem::transmute::<_, cortex_m::peripheral::SYST>(()).disable_interrupt()), + quote!(cortex_m::peripheral::SCB::set_pendst()), + ) + } else { + let rt_err = util::rt_err_ident(); + ( + quote!(rtic::export::NVIC::unmask(#app_path::#rt_err::#enum_::#m_isr)), + quote!(rtic::pend(#app_path::#rt_err::#enum_::#m_isr)), + ) + }; + items.push(quote!( pub mod #m { #(#cfgs)* @@ -287,8 +300,8 @@ pub fn codegen( rtic::export::interrupt::free(|_| #app_path::#tq.enqueue_unchecked( nr, - || rtic::export::NVIC::unmask(#app_path::you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml::#enum_::#m_isr), - || rtic::pend(#app_path::you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml::#enum_::#m_isr), + || #unmask, + || #pend, )); Ok(()) diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs index 26ba558c8f..e7b1b03bc6 100644 --- a/macros/src/codegen/pre_init.rs +++ b/macros/src/codegen/pre_init.rs @@ -8,6 +8,8 @@ use crate::{analyze::Analysis, check::Extra, codegen::util}; pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec { 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();)); @@ -47,14 +49,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec Vec Vec Vec Vec>(); let bound_interrupt = &monotonic.args.binds; + let enable_isr = if &*bound_interrupt.to_string() == "SysTick" { + quote!(core::mem::transmute::<_, cortex_m::peripheral::SYST>(()).enable_interrupt()) + } else { + quote!(rtic::export::NVIC::mask(#rt_err::#enum_::#bound_interrupt)) + }; items.push(quote!( #[no_mangle] @@ -106,7 +114,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec Ident { /// Generates an identifier for the `enum` of `schedule`-able tasks pub fn schedule_t_ident() -> Ident { - Ident::new(&"SCHED_T".to_string(), Span::call_site()) + Ident::new(&"SCHED_T", Span::call_site()) } /// Generates an identifier for the `enum` of `spawn`-able tasks @@ -228,6 +228,7 @@ pub fn spawn_t_ident(priority: u8) -> Ident { Ident::new(&format!("P{}_T", priority), Span::call_site()) } +/// Suffixed identifier pub fn suffixed(name: &str) -> Ident { let span = Span::call_site(); Ident::new(name, span) @@ -237,3 +238,11 @@ pub fn suffixed(name: &str) -> Ident { pub fn tq_ident(name: &str) -> Ident { Ident::new(&format!("TQ_{}", name), Span::call_site()) } + +/// The name to get better RT flag errors +pub fn rt_err_ident() -> Ident { + Ident::new( + &"you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml", + Span::call_site(), + ) +}