mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
refactor: make binds
harder to misuse
This commit is contained in:
parent
2fd6ae69d1
commit
8eccef7d9c
3 changed files with 16 additions and 21 deletions
|
@ -106,12 +106,8 @@ pub fn app(app: &App) -> parse::Result<()> {
|
|||
}
|
||||
|
||||
// Check that free interrupts are not being used
|
||||
for (name, interrupt) in &app.interrupts {
|
||||
let name = if let Some(ref binds) = interrupt.args.binds {
|
||||
binds
|
||||
} else {
|
||||
name
|
||||
};
|
||||
for (handler, interrupt) in &app.interrupts {
|
||||
let name = interrupt.args.binds(handler);
|
||||
|
||||
if app.free_interrupts.contains_key(name) {
|
||||
return Err(parse::Error::new(
|
||||
|
|
|
@ -468,12 +468,8 @@ fn post_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok
|
|||
// the device into compile errors
|
||||
let device = &app.args.device;
|
||||
let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS);
|
||||
for (name, exception) in &app.exceptions {
|
||||
let name = if let Some(ref binds) = exception.args.binds {
|
||||
binds
|
||||
} else {
|
||||
name
|
||||
};
|
||||
for (handler, exception) in &app.exceptions {
|
||||
let name = exception.args.binds(handler);
|
||||
let priority = exception.args.priority;
|
||||
exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits))));
|
||||
exprs.push(quote!(p.SCB.set_priority(
|
||||
|
@ -1128,7 +1124,7 @@ fn exceptions(ctxt: &mut Context, app: &App, analysis: &Analysis) -> Vec<proc_ma
|
|||
};
|
||||
|
||||
let locals = mk_locals(&exception.statics, false);
|
||||
let symbol = exception.args.binds.as_ref().unwrap_or(ident).to_string();
|
||||
let symbol = exception.args.binds(ident).to_string();
|
||||
let alias = ctxt.ident_gen.mk_ident(None, false);
|
||||
let unsafety = &exception.unsafety;
|
||||
quote!(
|
||||
|
@ -1214,7 +1210,7 @@ fn interrupts(
|
|||
|
||||
let locals = mk_locals(&interrupt.statics, false);
|
||||
let alias = ctxt.ident_gen.mk_ident(None, false);
|
||||
let symbol = interrupt.args.binds.as_ref().unwrap_or(ident).to_string();
|
||||
let symbol = interrupt.args.binds(ident).to_string();
|
||||
let unsafety = &interrupt.unsafety;
|
||||
scoped.push(quote!(
|
||||
// unsafe trampoline to deter end-users from calling this non-reentrant function
|
||||
|
@ -1997,12 +1993,8 @@ fn pre_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Toke
|
|||
// the device into compile errors
|
||||
let device = &app.args.device;
|
||||
let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS);
|
||||
for (name, interrupt) in &app.interrupts {
|
||||
let name = if let Some(ref binds) = interrupt.args.binds {
|
||||
binds
|
||||
} else {
|
||||
name
|
||||
};
|
||||
for (handler, interrupt) in &app.interrupts {
|
||||
let name = interrupt.args.binds(handler);
|
||||
let priority = interrupt.args.priority;
|
||||
exprs.push(quote!(p.NVIC.enable(#device::Interrupt::#name);));
|
||||
exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits));));
|
||||
|
|
|
@ -731,13 +731,20 @@ pub struct Exception {
|
|||
}
|
||||
|
||||
pub struct ExceptionArgs {
|
||||
pub binds: Option<Ident>,
|
||||
binds: Option<Ident>,
|
||||
pub priority: u8,
|
||||
pub resources: Idents,
|
||||
pub schedule: Idents,
|
||||
pub spawn: Idents,
|
||||
}
|
||||
|
||||
impl ExceptionArgs {
|
||||
/// Returns the name of the exception / interrupt this handler binds to
|
||||
pub fn binds<'a>(&'a self, handler: &'a Ident) -> &'a Ident {
|
||||
self.binds.as_ref().unwrap_or(handler)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for ExceptionArgs {
|
||||
fn parse(input: ParseStream<'_>) -> parse::Result<Self> {
|
||||
parse_args(input, /* binds */ true, /* capacity */ false).map(
|
||||
|
|
Loading…
Reference in a new issue