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 --- examples/binds.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 examples/binds.rs (limited to 'examples') diff --git a/examples/binds.rs b/examples/binds.rs new file mode 100644 index 0000000..a8b386f --- /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(); + } +}; -- cgit v1.2.3