aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJorge Aparicio <jorge@japaric.io>2019-02-23 22:20:30 +0100
committerJorge Aparicio <jorge@japaric.io>2019-02-26 23:22:34 +0100
commit11f795aaf69dbd7d185bbf0136ae555b53768538 (patch)
treeeb14ba79d3c6a195836b627bc10702d6b573b60f /examples
parenta23380828071af69ec0362aae1b30c6e09b511f0 (diff)
add `binds` example and make it work
Diffstat (limited to 'examples')
-rw-r--r--examples/binds.rs48
1 files changed, 48 insertions, 0 deletions
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();
+ }
+};