aboutsummaryrefslogtreecommitdiff
path: root/tests/cpass/resource.rs
diff options
context:
space:
mode:
authorJorge Aparicio <jorge@japaric.io>2018-11-03 17:02:41 +0100
committerJorge Aparicio <jorge@japaric.io>2018-11-03 17:16:55 +0100
commitc631049efcadca8b07940c794cce2be58fa48444 (patch)
treef6bd73e5c396fc06072557ee965cc59e9c8e3e9f /tests/cpass/resource.rs
parent653338e7997a0cdc5deaed98b1bb5f60006717ed (diff)
v0.4.0
closes #32 closes #33
Diffstat (limited to 'tests/cpass/resource.rs')
-rw-r--r--tests/cpass/resource.rs80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/cpass/resource.rs b/tests/cpass/resource.rs
new file mode 100644
index 0000000..6a7a873
--- /dev/null
+++ b/tests/cpass/resource.rs
@@ -0,0 +1,80 @@
+//! Check code generation of resources
+
+#![feature(extern_crate_item_prelude)] // ???
+#![no_main]
+#![no_std]
+
+extern crate lm3s6965;
+extern crate panic_halt;
+extern crate rtfm;
+
+use rtfm::app;
+
+#[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() {
+ // owned by `init` == `&'static mut`
+ let _: &'static mut u32 = resources.O1;
+
+ // owned by `init` == `&'static` if read-only
+ let _: &'static u32 = resources.O6;
+
+ // `init` has exclusive access to all resources
+ let _: &mut u32 = resources.O4;
+ let _: &mut u32 = resources.O5;
+ let _: &mut u32 = resources.S3;
+ }
+
+ #[idle(resources = [O2, O4, S1, S3])]
+ fn idle() -> ! {
+ // owned by `idle` == `&'static mut`
+ let _: &'static mut u32 = resources.O2;
+
+ // owned by `idle` == `&'static` if read-only
+ let _: &'static u32 = resources.O4;
+
+ // shared with `idle` == `Mutex`
+ resources.S1.lock(|_| {});
+
+ // `&` if read-only
+ let _: &u32 = resources.S3;
+
+ loop {}
+ }
+
+ #[interrupt(resources = [O3, S1, S2, S3])]
+ fn UART0() {
+ // owned by interrupt == `&mut`
+ let _: &mut u32 = resources.O3;
+
+ // no `Mutex` when access from highest priority task
+ let _: &mut u32 = resources.S1;
+
+ // no `Mutex` when co-owned by cooperative (same priority) tasks
+ let _: &mut u32 = resources.S2;
+
+ // `&` if read-only
+ let _: &u32 = resources.S3;
+ }
+
+ #[interrupt(resources = [S2, O5])]
+ fn UART1() {
+ // owned by interrupt == `&` if read-only
+ let _: &u32 = resources.O5;
+
+ // no `Mutex` when co-owned by cooperative (same priority) tasks
+ let _: &mut u32 = resources.S2;
+ }
+};