diff options
author | 2022-03-04 13:26:33 +0100 | |
---|---|---|
committer | 2022-03-05 11:14:36 +0100 | |
commit | ca2577e3b8b5e05923f0d0d9deba6990940869e5 (patch) | |
tree | 237aed39ae4f1da4a197a5c9d374c19ea9ef2f31 /examples-runner/src/bin/resource-user-struct.rs | |
parent | a765f3fffac95f270ce416dc15acd063b215f027 (diff) | |
download | rtic-ca2577e3b8b5e05923f0d0d9deba6990940869e5.tar.gz rtic-ca2577e3b8b5e05923f0d0d9deba6990940869e5.tar.zst rtic-ca2577e3b8b5e05923f0d0d9deba6990940869e5.zip |
Embedded ci works
Diffstat (limited to 'examples-runner/src/bin/resource-user-struct.rs')
-rw-r--r-- | examples-runner/src/bin/resource-user-struct.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/examples-runner/src/bin/resource-user-struct.rs b/examples-runner/src/bin/resource-user-struct.rs new file mode 100644 index 00000000..5051c1f9 --- /dev/null +++ b/examples-runner/src/bin/resource-user-struct.rs @@ -0,0 +1,71 @@ +//! examples/resource.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use examples_runner as _; + +#[rtic::app(device = examples_runner::pac)] +mod app { + use examples_runner::{println, exit}; + use examples_runner::pac::Interrupt; + + #[shared] + struct Shared { + // A resource + shared: u32, + } + + // Should not collide with the struct above + #[allow(dead_code)] + struct Shared2 { + // A resource + shared: u32, + } + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local, init::Monotonics) { + rtic::pend(Interrupt::UART0); + rtic::pend(Interrupt::UART1); + + (Shared { shared: 0 }, Local {}, init::Monotonics()) + } + + // `shared` cannot be accessed from this context + #[idle] + fn idle(_cx: idle::Context) -> ! { + exit(); + + // error: no `shared` field in `idle::Context` + // _cx.shared.shared += 1; + + // loop {} + } + + // `shared` can be accessed from this context + #[task(binds = UART0, shared = [shared])] + fn uart0(mut cx: uart0::Context) { + let shared = cx.shared.shared.lock(|shared| { + *shared += 1; + *shared + }); + + println!("UART0: shared = {}", shared); + } + + // `shared` can be accessed from this context + #[task(binds = UART1, shared = [shared])] + fn uart1(mut cx: uart1::Context) { + let shared = cx.shared.shared.lock(|shared| { + *shared += 1; + *shared + }); + + println!("UART1: shared = {}", shared); + } +} |