From 11f795aaf69dbd7d185bbf0136ae555b53768538 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 23 Feb 2019 22:20:30 +0100 Subject: [PATCH] add `binds` example and make it work --- ci/expected/binds.run | 4 ++++ ci/script.sh | 1 + examples/binds.rs | 48 +++++++++++++++++++++++++++++++++++++++++++ macros/src/codegen.rs | 4 ++-- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 ci/expected/binds.run create mode 100644 examples/binds.rs diff --git a/ci/expected/binds.run b/ci/expected/binds.run new file mode 100644 index 0000000000..f84cff0157 --- /dev/null +++ b/ci/expected/binds.run @@ -0,0 +1,4 @@ +init +foo called 1 time +idle +foo called 2 times diff --git a/ci/script.sh b/ci/script.sh index 5cc79fbbce..7cda1e5e66 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -93,6 +93,7 @@ main() { idle init interrupt + binds resource lock diff --git a/examples/binds.rs b/examples/binds.rs new file mode 100644 index 0000000000..a8b386fb7e --- /dev/null +++ b/examples/binds.rs @@ -0,0 +1,48 @@ +//! examples/binds.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +extern crate panic_semihosting; + +use cortex_m_semihosting::{debug, hprintln}; +use lm3s6965::Interrupt; +use rtfm::app; + +// `examples/interrupt.rs` rewritten to use `binds` +#[app(device = lm3s6965)] +const APP: () = { + #[init] + fn init() { + rtfm::pend(Interrupt::UART0); + + hprintln!("init").unwrap(); + } + + #[idle] + fn idle() -> ! { + hprintln!("idle").unwrap(); + + rtfm::pend(Interrupt::UART0); + + debug::exit(debug::EXIT_SUCCESS); + + loop {} + } + + #[interrupt(binds = UART0)] + fn foo() { + static mut TIMES: u32 = 0; + + *TIMES += 1; + + hprintln!( + "foo called {} time{}", + *TIMES, + if *TIMES > 1 { "s" } else { "" } + ) + .unwrap(); + } +}; diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 117bce8cf6..0e25e8a7a6 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