diff options
author | 2019-09-15 17:09:40 +0000 | |
---|---|---|
committer | 2019-09-15 17:09:40 +0000 | |
commit | 4ff28e9d13e845abf39c662643ae2ff5df57ec16 (patch) | |
tree | 7d9770cd357e584d85ef6ddc32bddd1a937d1020 /examples/t-resource.rs | |
parent | fafeeb27270ef24fc3852711c6032f65aa7dbcc0 (diff) | |
parent | 7aa270cb92180abfc9102a69efdde378c3396b5e (diff) | |
download | rtic-4ff28e9d13e845abf39c662643ae2ff5df57ec16.tar.gz rtic-4ff28e9d13e845abf39c662643ae2ff5df57ec16.tar.zst rtic-4ff28e9d13e845abf39c662643ae2ff5df57ec16.zip |
Merge pull request #205 from japaric/heterogeneous
rtfm-syntax refactor + heterogeneous multi-core support
Diffstat (limited to 'examples/t-resource.rs')
-rw-r--r-- | examples/t-resource.rs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/examples/t-resource.rs b/examples/t-resource.rs new file mode 100644 index 00000000..303340ed --- /dev/null +++ b/examples/t-resource.rs @@ -0,0 +1,87 @@ +//! [compile-pass] Check code generation of resources + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +use panic_halt as _; + +#[rtfm::app(device = lm3s6965)] +const APP: () = { + struct Resources { + #[init(0)] + o1: u32, // init + #[init(0)] + o2: u32, // idle + #[init(0)] + o3: u32, // EXTI0 + #[init(0)] + o4: u32, // idle + #[init(0)] + o5: u32, // EXTI1 + #[init(0)] + o6: u32, // init + #[init(0)] + s1: u32, // idle & uart0 + #[init(0)] + s2: u32, // uart0 & uart1 + #[init(0)] + s3: u32, // idle & uart0 + } + + #[init(resources = [o1, o4, o5, o6, s3])] + fn init(c: init::Context) { + // owned by `init` == `&'static mut` + let _: &'static mut u32 = c.resources.o1; + + // owned by `init` == `&'static` if read-only + let _: &'static u32 = c.resources.o6; + + // `init` has exclusive access to all resources + let _: &mut u32 = c.resources.o4; + let _: &mut u32 = c.resources.o5; + let _: &mut u32 = c.resources.s3; + } + + #[idle(resources = [o2, &o4, s1, &s3])] + fn idle(mut c: idle::Context) -> ! { + // owned by `idle` == `&'static mut` + let _: &'static mut u32 = c.resources.o2; + + // owned by `idle` == `&'static` if read-only + let _: &'static u32 = c.resources.o4; + + // shared with `idle` == `Mutex` + c.resources.s1.lock(|_| {}); + + // `&` if read-only + let _: &u32 = c.resources.s3; + + loop {} + } + + #[task(binds = UART0, resources = [o3, s1, s2, &s3])] + fn uart0(c: uart0::Context) { + // owned by interrupt == `&mut` + let _: &mut u32 = c.resources.o3; + + // no `Mutex` proxy when access from highest priority task + let _: &mut u32 = c.resources.s1; + + // no `Mutex` proxy when co-owned by cooperative (same priority) tasks + let _: &mut u32 = c.resources.s2; + + // `&` if read-only + let _: &u32 = c.resources.s3; + } + + #[task(binds = UART1, resources = [s2, &o5])] + fn uart1(c: uart1::Context) { + // owned by interrupt == `&` if read-only + let _: &u32 = c.resources.o5; + + // no `Mutex` proxy when co-owned by cooperative (same priority) tasks + let _: &mut u32 = c.resources.s2; + } +}; |