diff options
author | 2019-07-10 22:42:44 +0200 | |
---|---|---|
committer | 2019-07-10 22:42:44 +0200 | |
commit | 9195038c87703fc94b6e99f6de593886d51c2b19 (patch) | |
tree | 56855952357fe5bb689504ed8a6348dc3c1f3718 /examples/resource.rs | |
parent | 14d63f496118f4243f28ddf3218523aa36a80322 (diff) | |
download | rtic-9195038c87703fc94b6e99f6de593886d51c2b19.tar.gz rtic-9195038c87703fc94b6e99f6de593886d51c2b19.tar.zst rtic-9195038c87703fc94b6e99f6de593886d51c2b19.zip |
implement RFC #212
Diffstat (limited to 'examples/resource.rs')
-rw-r--r-- | examples/resource.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/examples/resource.rs b/examples/resource.rs index 661f8c35..2506a2cb 100644 --- a/examples/resource.rs +++ b/examples/resource.rs @@ -11,8 +11,11 @@ use panic_semihosting as _; #[rtfm::app(device = lm3s6965)] const APP: () = { - // A resource - static mut SHARED: u32 = 0; + struct Resources { + // A resource + #[init(0)] + shared: u32, + } #[init] fn init(_: init::Context) { @@ -24,25 +27,25 @@ const APP: () = { fn idle(_: idle::Context) -> ! { debug::exit(debug::EXIT_SUCCESS); - // error: `SHARED` can't be accessed from this context - // SHARED += 1; + // error: `shared` can't be accessed from this context + // shared += 1; loop {} } - // `SHARED` can be access from this context - #[task(binds = UART0, resources = [SHARED])] + // `shared` can be access from this context + #[task(binds = UART0, resources = [shared])] fn uart0(c: uart0::Context) { - *c.resources.SHARED += 1; + *c.resources.shared += 1; - hprintln!("UART0: SHARED = {}", c.resources.SHARED).unwrap(); + hprintln!("UART0: shared = {}", c.resources.shared).unwrap(); } - // `SHARED` can be access from this context - #[task(binds = UART1, resources = [SHARED])] + // `shared` can be access from this context + #[task(binds = UART1, resources = [shared])] fn uart1(c: uart1::Context) { - *c.resources.SHARED += 1; + *c.resources.shared += 1; - hprintln!("UART1: SHARED = {}", c.resources.SHARED).unwrap(); + hprintln!("UART1: shared = {}", c.resources.shared).unwrap(); } }; |