aboutsummaryrefslogtreecommitdiff
path: root/examples/periodic-at.no_rs
diff options
context:
space:
mode:
authorGravatar Per Lindgren <per.lindgren@ltu.se> 2023-01-07 17:59:39 +0100
committerGravatar Henrik Tjäder <henrik@tjaders.com> 2023-03-01 00:33:24 +0100
commit9a4f97ca5ebf19e6612115db5c763d0d61dd28a1 (patch)
tree1f37d247f715ad3d5215aa7de3aa6d4eb94a7027 /examples/periodic-at.no_rs
parent5606ba3cf38c80be5d3e9c88ad4da9982b114851 (diff)
downloadrtic-9a4f97ca5ebf19e6612115db5c763d0d61dd28a1.tar.gz
rtic-9a4f97ca5ebf19e6612115db5c763d0d61dd28a1.tar.zst
rtic-9a4f97ca5ebf19e6612115db5c763d0d61dd28a1.zip
more examples
Diffstat (limited to 'examples/periodic-at.no_rs')
-rw-r--r--examples/periodic-at.no_rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/periodic-at.no_rs b/examples/periodic-at.no_rs
new file mode 100644
index 00000000..ca68ed5e
--- /dev/null
+++ b/examples/periodic-at.no_rs
@@ -0,0 +1,49 @@
+//! examples/periodic-at.rs
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use panic_semihosting as _;
+
+#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
+mod app {
+ use cortex_m_semihosting::{debug, hprintln};
+ use systick_monotonic::*;
+
+ #[monotonic(binds = SysTick, default = true)]
+ type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
+
+ #[shared]
+ struct Shared {}
+
+ #[local]
+ struct Local {}
+
+ #[init]
+ fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
+ let systick = cx.core.SYST;
+
+ // Initialize the monotonic (SysTick rate in QEMU is 12 MHz)
+ let mut mono = Systick::new(systick, 12_000_000);
+
+ foo::spawn_after(1.secs(), mono.now()).unwrap();
+
+ (Shared {}, Local {}, init::Monotonics(mono))
+ }
+
+ #[task(local = [cnt: u32 = 0])]
+ fn foo(cx: foo::Context, instant: fugit::TimerInstantU64<100>) {
+ hprintln!("foo {:?}", instant).ok();
+ *cx.local.cnt += 1;
+
+ if *cx.local.cnt == 4 {
+ debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
+ }
+
+ // Periodic every 100 milliseconds
+ let next_instant = instant + 100.millis();
+ foo::spawn_at(next_instant, next_instant).unwrap();
+ }
+}