aboutsummaryrefslogtreecommitdiff
path: root/examples/resource.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-07-10 22:42:44 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-07-10 22:42:44 +0200
commit9195038c87703fc94b6e99f6de593886d51c2b19 (patch)
tree56855952357fe5bb689504ed8a6348dc3c1f3718 /examples/resource.rs
parent14d63f496118f4243f28ddf3218523aa36a80322 (diff)
downloadrtic-9195038c87703fc94b6e99f6de593886d51c2b19.tar.gz
rtic-9195038c87703fc94b6e99f6de593886d51c2b19.tar.zst
rtic-9195038c87703fc94b6e99f6de593886d51c2b19.zip
implement RFC #212
Diffstat (limited to 'examples/resource.rs')
-rw-r--r--examples/resource.rs27
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();
}
};