diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-11-14 16:11:13 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-14 16:11:13 +0000 |
| commit | 9527c921923f6b8e19767b1bf52be758817d7035 (patch) | |
| tree | de8ea7d2f2a38a1fb0ea3043d2daf33b44e8dd34 /examples/multilock.rs | |
| parent | 2ebd81fee2dc4c793a7c684c5c9050d4a5313bde (diff) | |
| parent | f111c825ba3ab886a1a6bf63a0689c3d63b0f441 (diff) | |
Merge #415
415: Multilock support r=AfoHT a=korken89
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'examples/multilock.rs')
| -rw-r--r-- | examples/multilock.rs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/examples/multilock.rs b/examples/multilock.rs new file mode 100644 index 0000000..a6985df --- /dev/null +++ b/examples/multilock.rs @@ -0,0 +1,78 @@ +//! examples/mutlilock.rs +//! +//! The multi-lock feature example. + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use panic_semihosting as _; + +#[rtic::app(device = lm3s6965)] +mod app { + use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; + + #[resources] + struct Resources { + #[init(0)] + shared1: u32, + #[init(0)] + shared2: u32, + #[init(0)] + shared3: u32, + } + + #[init] + fn init(_: init::Context) -> init::LateResources { + rtic::pend(Interrupt::GPIOA); + + init::LateResources {} + } + + // when omitted priority is assumed to be `1` + #[task(binds = GPIOA, resources = [shared1, shared2, shared3])] + fn locks(c: locks::Context) { + let mut s1 = c.resources.shared1; + let mut s2 = c.resources.shared2; + let mut s3 = c.resources.shared3; + + hprintln!("Multiple single locks").unwrap(); + s1.lock(|s1| { + s2.lock(|s2| { + s3.lock(|s3| { + *s1 += 1; + *s2 += 1; + *s3 += 1; + + hprintln!( + "Multiple single locks, s1: {}, s2: {}, s3: {}", + *s1, + *s2, + *s3 + ) + .unwrap(); + }) + }) + }); + + hprintln!("Multilock!").unwrap(); + + (s1, s2, s3).lock(|s1, s2, s3| { + *s1 += 1; + *s2 += 1; + *s3 += 1; + + hprintln!( + "Multiple single locks, s1: {}, s2: {}, s3: {}", + *s1, + *s2, + *s3 + ) + .unwrap(); + }); + + debug::exit(debug::EXIT_SUCCESS); + } +} |
