522: validate unused dispatchers r=AfoHT a=japaric

closes #521

Co-authored-by: Jorge Aparicio <jorge@japaric.io>
This commit is contained in:
bors[bot] 2021-08-31 18:08:33 +00:00 committed by GitHub
commit f46b22f797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 4 deletions

View file

@ -31,6 +31,13 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
let device = &extra.device; let device = &extra.device;
let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS); 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.extern_interrupts.keys() {
stmts.push(quote!(let _ = #rt_err::#interrupt::#name;));
}
let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id)); let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id));
// Unmask interrupts and set their priorities // Unmask interrupts and set their priorities
@ -45,8 +52,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
// Compile time assert that this priority is supported by the device // 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!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));
// NOTE this also checks that the interrupt exists in the `Interrupt` enumeration
let interrupt = util::interrupt_ident();
stmts.push(quote!( stmts.push(quote!(
core.NVIC.set_priority( core.NVIC.set_priority(
#rt_err::#interrupt::#name, #rt_err::#interrupt::#name,
@ -100,8 +105,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
} }
)); ));
} else { } else {
// NOTE this also checks that the interrupt exists in the `Interrupt` enumeration
let interrupt = util::interrupt_ident();
stmts.push(quote!( stmts.push(quote!(
core.NVIC.set_priority( core.NVIC.set_priority(
#rt_err::#interrupt::#binds, #rt_err::#interrupt::#binds,

15
ui/unknown-interrupt.rs Normal file
View file

@ -0,0 +1,15 @@
#![no_main]
#[rtic::app(device = lm3s6965, dispatchers = [UnknownInterrupt])]
mod app {
#[shared]
struct Shared {}
#[local]
struct Local {}
#[init]
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
(Shared {}, Local {}, init::Monotonics())
}
}

View file

@ -0,0 +1,5 @@
error[E0599]: no variant or associated item named `UnknownInterrupt` found for enum `Interrupt` in the current scope
--> $DIR/unknown-interrupt.rs:3:47
|
3 | #[rtic::app(device = lm3s6965, dispatchers = [UnknownInterrupt])]
| ^^^^^^^^^^^^^^^^ variant or associated item not found in `Interrupt`