aboutsummaryrefslogtreecommitdiff
path: root/examples/t-resource.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-06-13 23:56:59 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-06-13 23:56:59 +0200
commit81275bfa4f41e2066770087f3a33cad4227eab41 (patch)
treec779a68e7cecf4c2613c7593376f980cea5dbc05 /examples/t-resource.rs
parentfafeeb27270ef24fc3852711c6032f65aa7dbcc0 (diff)
downloadrtic-81275bfa4f41e2066770087f3a33cad4227eab41.tar.gz
rtic-81275bfa4f41e2066770087f3a33cad4227eab41.tar.zst
rtic-81275bfa4f41e2066770087f3a33cad4227eab41.zip
rtfm-syntax refactor + heterogeneous multi-core support
Diffstat (limited to 'examples/t-resource.rs')
-rw-r--r--examples/t-resource.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/examples/t-resource.rs b/examples/t-resource.rs
new file mode 100644
index 00000000..40dc2a65
--- /dev/null
+++ b/examples/t-resource.rs
@@ -0,0 +1,77 @@
+//! [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: () = {
+ static mut O1: u32 = 0; // init
+ static mut O2: u32 = 0; // idle
+ static mut O3: u32 = 0; // EXTI0
+ static O4: u32 = 0; // idle
+ static O5: u32 = 0; // EXTI1
+ static O6: u32 = 0; // init
+
+ static mut S1: u32 = 0; // idle & EXTI0
+ static mut S2: u32 = 0; // EXTI0 & EXTI1
+ static S3: u32 = 0;
+
+ #[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 {}
+ }
+
+ #[interrupt(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;
+ }
+
+ #[interrupt(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;
+ }
+};