rtic/examples/binds.rs

49 lines
923 B
Rust
Raw Normal View History

2019-02-23 22:20:30 +01:00
//! examples/binds.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use cortex_m_semihosting::{debug, hprintln};
use lm3s6965::Interrupt;
use panic_semihosting as _;
2019-02-23 22:20:30 +01:00
// `examples/interrupt.rs` rewritten to use `binds`
2020-06-11 19:18:29 +02:00
#[rtic::app(device = lm3s6965)]
2019-02-23 22:20:30 +01:00
const APP: () = {
#[init]
2019-04-21 20:10:40 +02:00
fn init(_: init::Context) {
2020-06-11 19:18:29 +02:00
rtic::pend(Interrupt::UART0);
2019-02-23 22:20:30 +01:00
hprintln!("init").unwrap();
}
#[idle]
2019-04-21 20:10:40 +02:00
fn idle(_: idle::Context) -> ! {
2019-02-23 22:20:30 +01:00
hprintln!("idle").unwrap();
2020-06-11 19:18:29 +02:00
rtic::pend(Interrupt::UART0);
2019-02-23 22:20:30 +01:00
debug::exit(debug::EXIT_SUCCESS);
loop {
cortex_m::asm::nop();
}
2019-02-23 22:20:30 +01:00
}
2019-06-20 06:19:59 +02:00
#[task(binds = UART0)]
2019-04-21 20:10:40 +02:00
fn foo(_: foo::Context) {
2019-02-23 22:20:30 +01:00
static mut TIMES: u32 = 0;
*TIMES += 1;
hprintln!(
"foo called {} time{}",
*TIMES,
if *TIMES > 1 { "s" } else { "" }
)
.unwrap();
}
};