rtic/examples/callback.rs

40 lines
889 B
Rust
Raw Normal View History

2021-03-12 02:08:46 +01:00
//! examples/callback.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use cortex_m_semihosting::{debug, hprintln};
use panic_semihosting as _;
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
mod app {
use super::*;
#[init()]
2021-03-12 12:03:12 +01:00
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
2021-03-12 02:08:46 +01:00
hprintln!("init").unwrap();
driver(&bar::spawn);
foo::spawn(123).unwrap();
(init::LateResources {}, init::Monotonics())
}
#[task()]
2021-03-12 12:03:12 +01:00
fn foo(_: foo::Context, data: u32) {
2021-03-12 02:08:46 +01:00
hprintln!("foo {}", data).unwrap();
bar::spawn().unwrap();
}
#[task()]
2021-03-12 12:03:12 +01:00
fn bar(_: bar::Context) {
2021-03-12 02:08:46 +01:00
hprintln!("bar").unwrap();
debug::exit(debug::EXIT_SUCCESS);
}
}
// some external code (e.g. driver)
fn driver<E>(_callback: &dyn Fn() -> Result<(), E>) {
hprintln!("driver").unwrap();
}