aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/pre_init.rs
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2021-03-04 19:12:35 +0000
committerGravatar GitHub <noreply@github.com> 2021-03-04 19:12:35 +0000
commit89a5c8004efaa8f42c86a1aedb609f49ec511333 (patch)
tree6db5b553e24a540284edc3f3fbf87043c638defc /macros/src/codegen/pre_init.rs
parent81a8a591353b1ea0208c68b28ee81286629039cc (diff)
parent2e4a4ffd87c8a031f27635c060042019511523dc (diff)
downloadrtic-89a5c8004efaa8f42c86a1aedb609f49ec511333.tar.gz
rtic-89a5c8004efaa8f42c86a1aedb609f49ec511333.tar.zst
rtic-89a5c8004efaa8f42c86a1aedb609f49ec511333.zip
Merge #436v0.6.0-alpha.1
436: New monotonic r=AfoHT a=korken89 Design document: https://hackmd.io/vWa9GvssR8qBfUYgMZm0CQ Closes #433 Closes #432 Closes #427 Closes #426 Closes #403 Closes #332 Closes #312 Closes #309 Closes #299 Closes #292 Closes #247 Closes #219 Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'macros/src/codegen/pre_init.rs')
-rw-r--r--macros/src/codegen/pre_init.rs58
1 files changed, 43 insertions, 15 deletions
diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs
index 969de84a..d5105445 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<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();));
@@ -15,6 +17,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
for (name, task) in &app.software_tasks {
let cap = task.args.capacity;
let fq_ident = util::fq_ident(name);
+ let fq_ident = util::mark_internal_ident(&fq_ident);
stmts.push(quote!(
(0..#cap).for_each(|i| #fq_ident.enqueue_unchecked(i));
@@ -47,14 +50,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
let interrupt = util::interrupt_ident();
stmts.push(quote!(
core.NVIC.set_priority(
- you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml::#interrupt::#name,
+ #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(you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml::#interrupt::#name);));
+ stmts.push(quote!(rtic::export::NVIC::unmask(#rt_err::#interrupt::#name);));
}
// Set exception priorities
@@ -74,23 +77,48 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
);));
}
- // Initialize the SysTick if there exist a TimerQueue
- if extra.monotonic.is_some() {
- let priority = analysis.channels.keys().max().unwrap();
+ // Initialize monotonic's interrupts
+ for (_, monotonic) in app.monotonics.iter()
+ //.map(|(ident, monotonic)| (ident, &monotonic.args.priority, &monotonic.args.binds))
+ {
+ let priority = &monotonic.args.priority;
+ let binds = &monotonic.args.binds;
// Compile time assert that this priority is supported by the device
stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
- stmts.push(quote!(core.SCB.set_priority(
- rtic::export::SystemHandler::SysTick,
- rtic::export::logical2hw(#priority, #nvic_prio_bits),
- );));
-
- stmts.push(quote!(
- core.SYST.set_clock_source(rtic::export::SystClkSource::Core);
- core.SYST.enable_counter();
- core.DCB.enable_trace();
- ));
+ let app_name = &app.name;
+ let app_path = quote! {crate::#app_name};
+ let mono_type = &monotonic.ty;
+
+ if &*binds.to_string() == "SysTick" {
+ stmts.push(quote!(
+ core.SCB.set_priority(
+ rtic::export::SystemHandler::SysTick,
+ rtic::export::logical2hw(#priority, #nvic_prio_bits),
+ );
+
+ // Always enable monotonic interrupts if they should never be off
+ if !<#mono_type as rtic::Monotonic>::DISABLE_INTERRUPT_ON_EMPTY_QUEUE {
+ core::mem::transmute::<_, cortex_m::peripheral::SYST>(())
+ .enable_interrupt();
+ }
+ ));
+ } else {
+ // NOTE this also checks that the interrupt exists in the `Interrupt` enumeration
+ let interrupt = util::interrupt_ident();
+ stmts.push(quote!(
+ core.NVIC.set_priority(
+ #rt_err::#interrupt::#binds,
+ rtic::export::logical2hw(#priority, #nvic_prio_bits),
+ );
+
+ // Always enable monotonic interrupts if they should never be off
+ if !<#mono_type as rtic::Monotonic>::DISABLE_INTERRUPT_ON_EMPTY_QUEUE {
+ rtic::export::NVIC::unmask(#app_path::#rt_err::#interrupt::#binds);
+ }
+ ));
+ }
}
// If there's no user `#[idle]` then optimize returning from interrupt handlers