aboutsummaryrefslogtreecommitdiff
path: root/examples/callback.rs
diff options
context:
space:
mode:
authorGravatar Per Lindgren <per.lindgren@ltu.se> 2021-03-12 02:08:46 +0100
committerGravatar Per Lindgren <per.lindgren@ltu.se> 2021-03-12 02:08:46 +0100
commite85baee30b182145d64bc8c6959ce2e8fd1c397f (patch)
treeac6284c60d04db9ec510f9e0baf52044b7b79ce3 /examples/callback.rs
parent2e028abc1c9daaa75b14b74f00aa2780ccf88edc (diff)
downloadrtic-e85baee30b182145d64bc8c6959ce2e8fd1c397f.tar.gz
rtic-e85baee30b182145d64bc8c6959ce2e8fd1c397f.tar.zst
rtic-e85baee30b182145d64bc8c6959ce2e8fd1c397f.zip
more examples
Diffstat (limited to '')
-rw-r--r--examples/callback.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/callback.rs b/examples/callback.rs
new file mode 100644
index 00000000..299c9410
--- /dev/null
+++ b/examples/callback.rs
@@ -0,0 +1,39 @@
+//! 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()]
+ fn init(c: init::Context) -> (init::LateResources, init::Monotonics) {
+ hprintln!("init").unwrap();
+ driver(&bar::spawn);
+ foo::spawn(123).unwrap();
+ (init::LateResources {}, init::Monotonics())
+ }
+
+ #[task()]
+ fn foo(c: foo::Context, data: u32) {
+ hprintln!("foo {}", data).unwrap();
+ bar::spawn().unwrap();
+ }
+
+ #[task()]
+ fn bar(_c: bar::Context) {
+ 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();
+}