rtic/tests/cpass/resource.rs

82 lines
2.2 KiB
Rust
Raw Normal View History

2018-11-03 17:02:41 +01:00
//! Check code generation of resources
2019-04-21 20:13:15 +02:00
#![deny(unsafe_code)]
#![deny(warnings)]
2018-11-03 17:02:41 +01:00
#![no_main]
#![no_std]
extern crate lm3s6965;
extern crate panic_halt;
extern crate rtfm;
2019-04-21 20:13:15 +02:00
use rtfm::Exclusive;
2018-11-03 17:02:41 +01:00
2019-04-21 20:13:15 +02:00
#[rtfm::app(device = lm3s6965)]
2018-11-03 17:02:41 +01:00
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])]
2019-04-21 20:13:15 +02:00
fn init(c: init::Context) {
2018-11-03 17:02:41 +01:00
// owned by `init` == `&'static mut`
2019-04-21 20:13:15 +02:00
let _: &'static mut u32 = c.resources.O1;
2018-11-03 17:02:41 +01:00
// owned by `init` == `&'static` if read-only
2019-04-21 20:13:15 +02:00
let _: &'static u32 = c.resources.O6;
2018-11-03 17:02:41 +01:00
// `init` has exclusive access to all resources
2019-04-21 20:13:15 +02:00
let _: &mut u32 = c.resources.O4;
let _: &mut u32 = c.resources.O5;
let _: &mut u32 = c.resources.S3;
2018-11-03 17:02:41 +01:00
}
#[idle(resources = [O2, O4, S1, S3])]
2019-04-21 20:13:15 +02:00
fn idle(mut c: idle::Context) -> ! {
2018-11-03 17:02:41 +01:00
// owned by `idle` == `&'static mut`
2019-04-21 20:13:15 +02:00
let _: &'static mut u32 = c.resources.O2;
2018-11-03 17:02:41 +01:00
// owned by `idle` == `&'static` if read-only
2019-04-21 20:13:15 +02:00
let _: &'static u32 = c.resources.O4;
2018-11-03 17:02:41 +01:00
// shared with `idle` == `Mutex`
2019-04-21 20:13:15 +02:00
c.resources.S1.lock(|_| {});
2018-11-03 17:02:41 +01:00
// `&` if read-only
2019-04-21 20:13:15 +02:00
let _: &u32 = c.resources.S3;
2018-11-03 17:02:41 +01:00
loop {}
}
#[interrupt(resources = [O3, S1, S2, S3])]
2019-04-21 20:13:15 +02:00
fn UART0(c: UART0::Context) {
2018-11-03 17:02:41 +01:00
// owned by interrupt == `&mut`
2019-04-21 20:13:15 +02:00
let _: &mut u32 = c.resources.O3;
2018-11-03 17:02:41 +01:00
2018-11-04 19:46:49 +01:00
// no `Mutex` proxy when access from highest priority task
2019-04-21 20:13:15 +02:00
let _: Exclusive<u32> = c.resources.S1;
2018-11-03 17:02:41 +01:00
2018-11-04 19:46:49 +01:00
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
2019-04-21 20:13:15 +02:00
let _: Exclusive<u32> = c.resources.S2;
2018-11-03 17:02:41 +01:00
// `&` if read-only
2019-04-21 20:13:15 +02:00
let _: &u32 = c.resources.S3;
2018-11-03 17:02:41 +01:00
}
#[interrupt(resources = [S2, O5])]
2019-04-21 20:13:15 +02:00
fn UART1(c: UART1::Context) {
2018-11-03 17:02:41 +01:00
// owned by interrupt == `&` if read-only
2019-04-21 20:13:15 +02:00
let _: &u32 = c.resources.O5;
2018-11-03 17:02:41 +01:00
2018-11-04 19:46:49 +01:00
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
2019-04-21 20:13:15 +02:00
let _: Exclusive<u32> = c.resources.S2;
2018-11-03 17:02:41 +01:00
}
};