aboutsummaryrefslogtreecommitdiff
path: root/examples/lock.rs
diff options
context:
space:
mode:
authorEmil Fresk <emil.fresk@gmail.com>2023-01-23 20:05:47 +0100
committerHenrik Tjäder <henrik@tjaders.com>2023-03-01 00:33:31 +0100
commit306aa47170fd59369b7a184924e287dc3706d64d (patch)
tree75a331a63a4021f078e330bf2ce4edb1228e2ecf /examples/lock.rs
parentb8b881f446a226d6f3c4a7db7c9174590b47dbf6 (diff)
Add rtic-timer (timerqueue + monotonic) and rtic-monotonics (systick-monotonic)
Diffstat (limited to 'examples/lock.rs')
-rw-r--r--examples/lock.rs73
1 files changed, 0 insertions, 73 deletions
diff --git a/examples/lock.rs b/examples/lock.rs
deleted file mode 100644
index 203ae6f..0000000
--- a/examples/lock.rs
+++ /dev/null
@@ -1,73 +0,0 @@
-//! examples/lock.rs
-
-#![deny(unsafe_code)]
-#![deny(warnings)]
-#![deny(missing_docs)]
-#![no_main]
-#![no_std]
-#![feature(type_alias_impl_trait)]
-
-use panic_semihosting as _;
-
-#[rtic::app(device = lm3s6965, dispatchers = [GPIOA, GPIOB, GPIOC])]
-mod app {
- use cortex_m_semihosting::{debug, hprintln};
-
- #[shared]
- struct Shared {
- shared: u32,
- }
-
- #[local]
- struct Local {}
-
- #[init]
- fn init(_: init::Context) -> (Shared, Local) {
- foo::spawn().unwrap();
-
- (Shared { shared: 0 }, Local {})
- }
-
- // when omitted priority is assumed to be `1`
- #[task(shared = [shared])]
- async fn foo(mut c: foo::Context) {
- hprintln!("A");
-
- // the lower priority task requires a critical section to access the data
- c.shared.shared.lock(|shared| {
- // data can only be modified within this critical section (closure)
- *shared += 1;
-
- // bar will *not* run right now due to the critical section
- bar::spawn().unwrap();
-
- hprintln!("B - shared = {}", *shared);
-
- // baz does not contend for `shared` so it's allowed to run now
- baz::spawn().unwrap();
- });
-
- // critical section is over: bar can now start
-
- hprintln!("E");
-
- debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
- }
-
- #[task(priority = 2, shared = [shared])]
- async fn bar(mut c: bar::Context) {
- // the higher priority task does still need a critical section
- let shared = c.shared.shared.lock(|shared| {
- *shared += 1;
-
- *shared
- });
-
- hprintln!("D - shared = {}", shared);
- }
-
- #[task(priority = 3)]
- async fn baz(_: baz::Context) {
- hprintln!("C");
- }
-}