From d0f33add0a354da612a1543bdcd74418feedbaf2 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 23 Feb 2019 21:48:47 +0100 Subject: add `binds` argument to the `interrupt` and `exception` attributes --- macros/src/codegen.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'macros/src/codegen.rs') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 83e5026..117bce8 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -469,6 +469,11 @@ fn post_init(ctxt: &Context, app: &App, analysis: &Analysis) -> proc_macro2::Tok 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 + }; let priority = exception.args.priority; exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits)))); exprs.push(quote!(p.SCB.set_priority( @@ -1082,9 +1087,10 @@ fn exceptions(ctxt: &mut Context, app: &App, analysis: &Analysis) -> Vec Vec proc_macro2::Toke 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 + }; let priority = interrupt.args.priority; exprs.push(quote!(p.NVIC.enable(#device::Interrupt::#name);)); exprs.push(quote!(assert!(#priority <= (1 << #nvic_prio_bits));)); -- cgit v1.2.3 From 11f795aaf69dbd7d185bbf0136ae555b53768538 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 23 Feb 2019 22:20:30 +0100 Subject: add `binds` example and make it work --- macros/src/codegen.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'macros/src/codegen.rs') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 117bce8..0e25e8a 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -1128,7 +1128,7 @@ fn exceptions(ctxt: &mut Context, app: &App, analysis: &Analysis) -> Vec Date: Tue, 26 Feb 2019 23:25:16 +0100 Subject: refactor: make `binds` harder to misuse --- macros/src/codegen.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'macros/src/codegen.rs') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 0e25e8a..1d201c0 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -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_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));)); -- cgit v1.2.3