aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Babak <alexanderbabak@proton.me>2025-05-15 14:52:26 +0200
committerHenrik Tjäder <henrik@tjaders.com>2025-06-15 09:03:30 +0000
commit6a68e8e54d2b006a888edab0f75e99a04675bb0a (patch)
tree38c50ba0583636b6b53ff6914dee15a1bcf5f5c4
parent14803e66399d4f5f6377c487b50cff2565aeaea5 (diff)
feat: example of wait-queue
-rw-r--r--ci/expected/lm3s6965/wait-queue.run4
-rw-r--r--examples/lm3s6965/Cargo.toml1
-rw-r--r--examples/lm3s6965/examples/wait-queue.rs64
3 files changed, 69 insertions, 0 deletions
diff --git a/ci/expected/lm3s6965/wait-queue.run b/ci/expected/lm3s6965/wait-queue.run
new file mode 100644
index 0000000..ed8f8f0
--- /dev/null
+++ b/ci/expected/lm3s6965/wait-queue.run
@@ -0,0 +1,4 @@
+Inc
+Inc
+Inc
+Got 3
diff --git a/examples/lm3s6965/Cargo.toml b/examples/lm3s6965/Cargo.toml
index 5e2cc50..78ae168 100644
--- a/examples/lm3s6965/Cargo.toml
+++ b/examples/lm3s6965/Cargo.toml
@@ -16,6 +16,7 @@ bare-metal = "1.0.0"
cortex-m-semihosting = "0.5.0"
rtic-time = { path = "../../rtic-time" }
rtic-sync = { path = "../../rtic-sync" }
+rtic-common = { path = "../../rtic-common" }
rtic-monotonics = { path = "../../rtic-monotonics", features = ["cortex-m-systick"] }
rtic = { path = "../../rtic" }
cfg-if = "1.0"
diff --git a/examples/lm3s6965/examples/wait-queue.rs b/examples/lm3s6965/examples/wait-queue.rs
new file mode 100644
index 0000000..7be1c0a
--- /dev/null
+++ b/examples/lm3s6965/examples/wait-queue.rs
@@ -0,0 +1,64 @@
+//! examples/wait-queue.rs
+
+#![no_main]
+#![no_std]
+#![deny(warnings)]
+#![deny(unsafe_code)]
+#![deny(missing_docs)]
+
+use panic_semihosting as _;
+
+#[rtic::app(device = lm3s6965, dispatchers = [GPIOA])]
+mod app {
+ use cortex_m_semihosting::{debug, hprintln};
+ use rtic_common::wait_queue::WaitQueue;
+
+ use rtic_monotonics::systick::prelude::*;
+ systick_monotonic!(Mono, 100);
+
+ #[shared]
+ struct Shared {
+ count: u32,
+ }
+
+ #[local]
+ struct Local {}
+
+ #[init(local = [wait_queue: WaitQueue = WaitQueue::new()])]
+ fn init(cx: init::Context) -> (Shared, Local) {
+ Mono::start(cx.core.SYST, 12_000_000);
+
+ incrementer::spawn(cx.local.wait_queue).ok().unwrap();
+ waiter::spawn(cx.local.wait_queue).ok().unwrap();
+
+ let count = 0;
+
+ (Shared { count }, Local {})
+ }
+
+ #[task(shared = [count])]
+ async fn incrementer(mut c: incrementer::Context, wait_queue: &'static WaitQueue) {
+ loop {
+ hprintln!("Inc");
+
+ c.shared.count.lock(|c| *c += 1);
+
+ while let Some(waker) = wait_queue.pop() {
+ waker.wake();
+ }
+
+ Mono::delay(10.millis()).await;
+ }
+ }
+
+ #[task(shared = [count])]
+ async fn waiter(mut c: waiter::Context, wait_queue: &'static WaitQueue) {
+ let value = wait_queue
+ .wait_until(|| c.shared.count.lock(|c| (*c >= 3).then_some(*c)))
+ .await;
+
+ hprintln!("Got {}", value);
+
+ debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
+ }
+}