implement RFC #212

This commit is contained in:
Jorge Aparicio 2019-07-10 22:42:44 +02:00
parent 14d63f4961
commit 9195038c87
25 changed files with 369 additions and 311 deletions

View file

@ -1,6 +1,6 @@
UART1(STATE = 0) UART1(STATE = 0)
SHARED: 0 -> 1 shared: 0 -> 1
UART0(STATE = 0) UART0(STATE = 0)
SHARED: 1 -> 2 shared: 1 -> 2
UART1(STATE = 1) UART1(STATE = 1)
SHARED: 2 -> 4 shared: 2 -> 4

View file

@ -1,5 +1,5 @@
A A
B - SHARED = 1 B - shared = 1
C C
D - SHARED = 2 D - shared = 2
E E

View file

@ -1,2 +1,2 @@
UART0: SHARED = 1 UART0: shared = 1
UART1: SHARED = 2 UART1: shared = 2

View file

@ -1,2 +1,2 @@
UART1(KEY = 0xdeadbeef) UART1(key = 0xdeadbeef)
UART0(KEY = 0xdeadbeef) UART0(key = 0xdeadbeef)

View file

@ -11,25 +11,28 @@ use panic_semihosting as _;
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
struct Resources {
#[cfg(debug_assertions)] // <- `true` when using the `dev` profile #[cfg(debug_assertions)] // <- `true` when using the `dev` profile
static mut COUNT: u32 = 0; #[init(0)]
count: u32,
}
#[init] #[init]
fn init(_: init::Context) { fn init(_: init::Context) {
// .. // ..
} }
#[task(priority = 3, resources = [COUNT], spawn = [log])] #[task(priority = 3, resources = [count], spawn = [log])]
fn foo(_c: foo::Context) { fn foo(_c: foo::Context) {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ {
*_c.resources.COUNT += 1; *_c.resources.count += 1;
_c.spawn.log(*_c.resources.COUNT).ok(); _c.spawn.log(*_c.resources.count).ok();
} }
// this wouldn't compile in `release` mode // this wouldn't compile in `release` mode
// *resources.COUNT += 1; // *resources.count += 1;
// .. // ..
} }

View file

@ -12,7 +12,10 @@ use rtfm::{Exclusive, Mutex};
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
static mut SHARED: u32 = 0; struct Resources {
#[init(0)]
shared: u32,
}
#[init] #[init]
fn init(_: init::Context) { fn init(_: init::Context) {
@ -20,29 +23,29 @@ const APP: () = {
rtfm::pend(Interrupt::UART1); rtfm::pend(Interrupt::UART1);
} }
#[task(binds = UART0, resources = [SHARED])] #[task(binds = UART0, resources = [shared])]
fn uart0(c: uart0::Context) { fn uart0(c: uart0::Context) {
static mut STATE: u32 = 0; static mut STATE: u32 = 0;
hprintln!("UART0(STATE = {})", *STATE).unwrap(); hprintln!("UART0(STATE = {})", *STATE).unwrap();
advance(STATE, c.resources.SHARED); advance(STATE, c.resources.shared);
rtfm::pend(Interrupt::UART1); rtfm::pend(Interrupt::UART1);
debug::exit(debug::EXIT_SUCCESS); debug::exit(debug::EXIT_SUCCESS);
} }
#[task(binds = UART1, priority = 2, resources = [SHARED])] #[task(binds = UART1, priority = 2, resources = [shared])]
fn uart1(c: uart1::Context) { fn uart1(c: uart1::Context) {
static mut STATE: u32 = 0; static mut STATE: u32 = 0;
hprintln!("UART1(STATE = {})", *STATE).unwrap(); hprintln!("UART1(STATE = {})", *STATE).unwrap();
// just to show that `SHARED` can be accessed directly // just to show that `shared` can be accessed directly
*c.resources.SHARED += 0; *c.resources.shared += 0;
advance(STATE, Exclusive(c.resources.SHARED)); advance(STATE, Exclusive(c.resources.shared));
} }
}; };
@ -55,5 +58,5 @@ fn advance(state: &mut u32, mut shared: impl Mutex<T = u32>) {
(old, *shared) (old, *shared)
}); });
hprintln!("SHARED: {} -> {}", old, new).unwrap(); hprintln!("shared: {} -> {}", old, new).unwrap();
} }

View file

@ -16,9 +16,9 @@ use panic_semihosting as _;
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
// Late resources // Late resources
extern "C" { struct Resources {
static mut P: Producer<'static, u32, U4>; p: Producer<'static, u32, U4>,
static mut C: Consumer<'static, u32, U4>; c: Consumer<'static, u32, U4>,
} }
#[init] #[init]
@ -31,13 +31,13 @@ const APP: () = {
let (p, c) = Q.as_mut().unwrap().split(); let (p, c) = Q.as_mut().unwrap().split();
// Initialization of late resources // Initialization of late resources
init::LateResources { P: p, C: c } init::LateResources { p, c }
} }
#[idle(resources = [C])] #[idle(resources = [c])]
fn idle(c: idle::Context) -> ! { fn idle(c: idle::Context) -> ! {
loop { loop {
if let Some(byte) = c.resources.C.dequeue() { if let Some(byte) = c.resources.c.dequeue() {
hprintln!("received message: {}", byte).unwrap(); hprintln!("received message: {}", byte).unwrap();
debug::exit(debug::EXIT_SUCCESS); debug::exit(debug::EXIT_SUCCESS);
@ -47,8 +47,8 @@ const APP: () = {
} }
} }
#[task(binds = UART0, resources = [P])] #[task(binds = UART0, resources = [p])]
fn uart0(c: uart0::Context) { fn uart0(c: uart0::Context) {
c.resources.P.enqueue(42).unwrap(); c.resources.p.enqueue(42).unwrap();
} }
}; };

View file

@ -11,7 +11,10 @@ use panic_semihosting as _;
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
static mut SHARED: u32 = 0; struct Resources {
#[init(0)]
shared: u32,
}
#[init] #[init]
fn init(_: init::Context) { fn init(_: init::Context) {
@ -19,21 +22,21 @@ const APP: () = {
} }
// when omitted priority is assumed to be `1` // when omitted priority is assumed to be `1`
#[task(binds = GPIOA, resources = [SHARED])] #[task(binds = GPIOA, resources = [shared])]
fn gpioa(mut c: gpioa::Context) { fn gpioa(mut c: gpioa::Context) {
hprintln!("A").unwrap(); hprintln!("A").unwrap();
// the lower priority task requires a critical section to access the data // the lower priority task requires a critical section to access the data
c.resources.SHARED.lock(|shared| { c.resources.shared.lock(|shared| {
// data can only be modified within this critical section (closure) // data can only be modified within this critical section (closure)
*shared += 1; *shared += 1;
// GPIOB will *not* run right now due to the critical section // GPIOB will *not* run right now due to the critical section
rtfm::pend(Interrupt::GPIOB); rtfm::pend(Interrupt::GPIOB);
hprintln!("B - SHARED = {}", *shared).unwrap(); hprintln!("B - shared = {}", *shared).unwrap();
// GPIOC does not contend for `SHARED` so it's allowed to run now // GPIOC does not contend for `shared` so it's allowed to run now
rtfm::pend(Interrupt::GPIOC); rtfm::pend(Interrupt::GPIOC);
}); });
@ -44,12 +47,12 @@ const APP: () = {
debug::exit(debug::EXIT_SUCCESS); debug::exit(debug::EXIT_SUCCESS);
} }
#[task(binds = GPIOB, priority = 2, resources = [SHARED])] #[task(binds = GPIOB, priority = 2, resources = [shared])]
fn gpiob(c: gpiob::Context) { fn gpiob(c: gpiob::Context) {
// the higher priority task does *not* need a critical section // the higher priority task does *not* need a critical section
*c.resources.SHARED += 1; *c.resources.shared += 1;
hprintln!("D - SHARED = {}", *c.resources.SHARED).unwrap(); hprintln!("D - shared = {}", *c.resources.shared).unwrap();
} }
#[task(binds = GPIOC, priority = 3)] #[task(binds = GPIOC, priority = 3)]

View file

@ -17,7 +17,10 @@ pub struct NotSend {
#[app(device = lm3s6965)] #[app(device = lm3s6965)]
const APP: () = { const APP: () = {
static mut SHARED: Option<NotSend> = None; struct Resources {
#[init(None)]
shared: Option<NotSend>,
}
#[init(spawn = [baz, quux])] #[init(spawn = [baz, quux])]
fn init(c: init::Context) { fn init(c: init::Context) {
@ -36,16 +39,16 @@ const APP: () = {
// scenario 1 // scenario 1
} }
#[task(priority = 2, resources = [SHARED])] #[task(priority = 2, resources = [shared])]
fn baz(c: baz::Context) { fn baz(c: baz::Context) {
// scenario 2: resource shared between tasks that run at the same priority // scenario 2: resource shared between tasks that run at the same priority
*c.resources.SHARED = Some(NotSend { _0: PhantomData }); *c.resources.shared = Some(NotSend { _0: PhantomData });
} }
#[task(priority = 2, resources = [SHARED])] #[task(priority = 2, resources = [shared])]
fn quux(c: quux::Context) { fn quux(c: quux::Context) {
// scenario 2 // scenario 2
let _not_send = c.resources.SHARED.take().unwrap(); let _not_send = c.resources.shared.take().unwrap();
debug::exit(debug::EXIT_SUCCESS); debug::exit(debug::EXIT_SUCCESS);
} }

View file

@ -16,21 +16,24 @@ pub struct NotSync {
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
static SHARED: NotSync = NotSync { _0: PhantomData }; struct Resources {
#[init(NotSync { _0: PhantomData })]
shared: NotSync,
}
#[init] #[init]
fn init(_: init::Context) { fn init(_: init::Context) {
debug::exit(debug::EXIT_SUCCESS); debug::exit(debug::EXIT_SUCCESS);
} }
#[task(resources = [SHARED])] #[task(resources = [shared])]
fn foo(c: foo::Context) { fn foo(c: foo::Context) {
let _: &NotSync = c.resources.SHARED; let _: &NotSync = c.resources.shared;
} }
#[task(resources = [SHARED])] #[task(resources = [shared])]
fn bar(c: bar::Context) { fn bar(c: bar::Context) {
let _: &NotSync = c.resources.SHARED; let _: &NotSync = c.resources.shared;
} }
extern "C" { extern "C" {

View file

@ -11,8 +11,11 @@ use panic_semihosting as _;
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
struct Resources {
// A resource // A resource
static mut SHARED: u32 = 0; #[init(0)]
shared: u32,
}
#[init] #[init]
fn init(_: init::Context) { fn init(_: init::Context) {
@ -24,25 +27,25 @@ const APP: () = {
fn idle(_: idle::Context) -> ! { fn idle(_: idle::Context) -> ! {
debug::exit(debug::EXIT_SUCCESS); debug::exit(debug::EXIT_SUCCESS);
// error: `SHARED` can't be accessed from this context // error: `shared` can't be accessed from this context
// SHARED += 1; // shared += 1;
loop {} loop {}
} }
// `SHARED` can be access from this context // `shared` can be access from this context
#[task(binds = UART0, resources = [SHARED])] #[task(binds = UART0, resources = [shared])]
fn uart0(c: uart0::Context) { 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 // `shared` can be access from this context
#[task(binds = UART1, resources = [SHARED])] #[task(binds = UART1, resources = [shared])]
fn uart1(c: uart1::Context) { 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();
} }
}; };

View file

@ -14,20 +14,23 @@ pub struct MustBeSend;
#[app(device = lm3s6965)] #[app(device = lm3s6965)]
const APP: () = { const APP: () = {
static mut SHARED: Option<MustBeSend> = None; struct Resources {
#[init(None)]
shared: Option<MustBeSend>,
}
#[init(resources = [SHARED])] #[init(resources = [shared])]
fn init(c: init::Context) { fn init(c: init::Context) {
// this `message` will be sent to task `UART0` // this `message` will be sent to task `UART0`
let message = MustBeSend; let message = MustBeSend;
*c.resources.SHARED = Some(message); *c.resources.shared = Some(message);
rtfm::pend(Interrupt::UART0); rtfm::pend(Interrupt::UART0);
} }
#[task(binds = UART0, resources = [SHARED])] #[task(binds = UART0, resources = [shared])]
fn uart0(c: uart0::Context) { fn uart0(c: uart0::Context) {
if let Some(message) = c.resources.SHARED.take() { if let Some(message) = c.resources.shared.take() {
// `message` has been received // `message` has been received
drop(message); drop(message);

View file

@ -11,8 +11,8 @@ use panic_semihosting as _;
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
extern "C" { struct Resources {
static KEY: u32; key: u32,
} }
#[init] #[init]
@ -20,18 +20,18 @@ const APP: () = {
rtfm::pend(Interrupt::UART0); rtfm::pend(Interrupt::UART0);
rtfm::pend(Interrupt::UART1); rtfm::pend(Interrupt::UART1);
init::LateResources { KEY: 0xdeadbeef } init::LateResources { key: 0xdeadbeef }
} }
#[task(binds = UART0, resources = [KEY])] #[task(binds = UART0, resources = [&key])]
fn uart0(c: uart0::Context) { fn uart0(c: uart0::Context) {
hprintln!("UART0(KEY = {:#x})", c.resources.KEY).unwrap(); hprintln!("UART0(key = {:#x})", c.resources.key).unwrap();
debug::exit(debug::EXIT_SUCCESS); debug::exit(debug::EXIT_SUCCESS);
} }
#[task(binds = UART1, priority = 2, resources = [KEY])] #[task(binds = UART1, priority = 2, resources = [&key])]
fn uart1(c: uart1::Context) { fn uart1(c: uart1::Context) {
hprintln!("UART1(KEY = {:#x})", c.resources.KEY).unwrap(); hprintln!("UART1(key = {:#x})", c.resources.key).unwrap();
} }
}; };

View file

@ -7,8 +7,11 @@ use panic_halt as _;
#[rtfm::app(device = lm3s6965, monotonic = rtfm::cyccnt::CYCCNT)] #[rtfm::app(device = lm3s6965, monotonic = rtfm::cyccnt::CYCCNT)]
const APP: () = { const APP: () = {
struct Resources {
#[cfg(never)] #[cfg(never)]
static mut FOO: u32 = 0; #[init(0)]
foo: u32,
}
#[init] #[init]
fn init(_: init::Context) { fn init(_: init::Context) {
@ -24,13 +27,13 @@ const APP: () = {
loop {} loop {}
} }
#[task(resources = [FOO], schedule = [quux], spawn = [quux])] #[task(resources = [foo], schedule = [quux], spawn = [quux])]
fn foo(_: foo::Context) { fn foo(_: foo::Context) {
#[cfg(never)] #[cfg(never)]
static mut BAR: u32 = 0; static mut BAR: u32 = 0;
} }
#[task(priority = 3, resources = [FOO], schedule = [quux], spawn = [quux])] #[task(priority = 3, resources = [foo], schedule = [quux], spawn = [quux])]
fn bar(_: bar::Context) { fn bar(_: bar::Context) {
#[cfg(never)] #[cfg(never)]
static mut BAR: u32 = 0; static mut BAR: u32 = 0;

View file

@ -13,23 +13,23 @@ pub struct NotSend {
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
extern "C" { struct Resources {
static mut X: NotSend; x: NotSend,
#[init(None)]
y: Option<NotSend>,
} }
static mut Y: Option<NotSend> = None; #[init(resources = [y])]
#[init(resources = [Y])]
fn init(c: init::Context) -> init::LateResources { fn init(c: init::Context) -> init::LateResources {
// equivalent to late resource initialization // equivalent to late resource initialization
*c.resources.Y = Some(NotSend { _0: PhantomData }); *c.resources.y = Some(NotSend { _0: PhantomData });
init::LateResources { init::LateResources {
X: NotSend { _0: PhantomData }, x: NotSend { _0: PhantomData },
} }
} }
#[idle(resources = [X, Y])] #[idle(resources = [x, y])]
fn idle(_: idle::Context) -> ! { fn idle(_: idle::Context) -> ! {
loop {} loop {}
} }

View file

@ -9,69 +9,79 @@ use panic_halt as _;
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
static mut O1: u32 = 0; // init struct Resources {
static mut O2: u32 = 0; // idle #[init(0)]
static mut O3: u32 = 0; // EXTI0 o1: u32, // init
static O4: u32 = 0; // idle #[init(0)]
static O5: u32 = 0; // EXTI1 o2: u32, // idle
static O6: u32 = 0; // init #[init(0)]
o3: u32, // EXTI0
static mut S1: u32 = 0; // idle & EXTI0 #[init(0)]
static mut S2: u32 = 0; // EXTI0 & EXTI1 o4: u32, // idle
static S3: u32 = 0; #[init(0)]
o5: u32, // EXTI1
#[init(resources = [O1, O4, O5, O6, S3])] #[init(0)]
fn init(c: init::Context) { o6: u32, // init
// owned by `init` == `&'static mut` #[init(0)]
let _: &'static mut u32 = c.resources.O1; s1: u32, // idle & uart0
#[init(0)]
// owned by `init` == `&'static` if read-only s2: u32, // uart0 & uart1
let _: &'static u32 = c.resources.O6; #[init(0)]
s3: u32, // idle & uart0
// `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])] #[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) -> ! { fn idle(mut c: idle::Context) -> ! {
// owned by `idle` == `&'static mut` // owned by `idle` == `&'static mut`
let _: &'static mut u32 = c.resources.O2; let _: &'static mut u32 = c.resources.o2;
// owned by `idle` == `&'static` if read-only // owned by `idle` == `&'static` if read-only
let _: &'static u32 = c.resources.O4; let _: &'static u32 = c.resources.o4;
// shared with `idle` == `Mutex` // shared with `idle` == `Mutex`
c.resources.S1.lock(|_| {}); c.resources.s1.lock(|_| {});
// `&` if read-only // `&` if read-only
let _: &u32 = c.resources.S3; let _: &u32 = c.resources.s3;
loop {} loop {}
} }
#[task(binds = UART0, resources = [O3, S1, S2, S3])] #[task(binds = UART0, resources = [o3, s1, s2, &s3])]
fn uart0(c: uart0::Context) { fn uart0(c: uart0::Context) {
// owned by interrupt == `&mut` // owned by interrupt == `&mut`
let _: &mut u32 = c.resources.O3; let _: &mut u32 = c.resources.o3;
// no `Mutex` proxy when access from highest priority task // no `Mutex` proxy when access from highest priority task
let _: &mut u32 = c.resources.S1; let _: &mut u32 = c.resources.s1;
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks // no `Mutex` proxy when co-owned by cooperative (same priority) tasks
let _: &mut u32 = c.resources.S2; let _: &mut u32 = c.resources.s2;
// `&` if read-only // `&` if read-only
let _: &u32 = c.resources.S3; let _: &u32 = c.resources.s3;
} }
#[task(binds = UART1, resources = [S2, O5])] #[task(binds = UART1, resources = [s2, &o5])]
fn uart1(c: uart1::Context) { fn uart1(c: uart1::Context) {
// owned by interrupt == `&` if read-only // owned by interrupt == `&` if read-only
let _: &u32 = c.resources.O5; let _: &u32 = c.resources.o5;
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks // no `Mutex` proxy when co-owned by cooperative (same priority) tasks
let _: &mut u32 = c.resources.S2; let _: &mut u32 = c.resources.s2;
} }
}; };

View file

@ -11,7 +11,10 @@ use rtfm::cyccnt::Instant;
#[rtfm::app(device = lm3s6965, peripherals = true, monotonic = rtfm::cyccnt::CYCCNT)] #[rtfm::app(device = lm3s6965, peripherals = true, monotonic = rtfm::cyccnt::CYCCNT)]
const APP: () = { const APP: () = {
static mut SHARED: u32 = 0; struct Resources {
#[init(0)]
shared: u32,
}
#[init(schedule = [foo], spawn = [foo])] #[init(schedule = [foo], spawn = [foo])]
fn init(c: init::Context) { fn init(c: init::Context) {
@ -31,18 +34,18 @@ const APP: () = {
let _: svcall::Spawn = c.spawn; let _: svcall::Spawn = c.spawn;
} }
#[task(binds = UART0, resources = [SHARED], schedule = [foo], spawn = [foo])] #[task(binds = UART0, resources = [shared], schedule = [foo], spawn = [foo])]
fn uart0(c: uart0::Context) { fn uart0(c: uart0::Context) {
let _: Instant = c.start; let _: Instant = c.start;
let _: resources::SHARED = c.resources.SHARED; let _: resources::shared = c.resources.shared;
let _: uart0::Schedule = c.schedule; let _: uart0::Schedule = c.schedule;
let _: uart0::Spawn = c.spawn; let _: uart0::Spawn = c.spawn;
} }
#[task(priority = 2, resources = [SHARED], schedule = [foo], spawn = [foo])] #[task(priority = 2, resources = [shared], schedule = [foo], spawn = [foo])]
fn foo(c: foo::Context) { fn foo(c: foo::Context) {
let _: Instant = c.scheduled; let _: Instant = c.scheduled;
let _: &mut u32 = c.resources.SHARED; let _: &mut u32 = c.resources.shared;
let _: foo::Resources = c.resources; let _: foo::Resources = c.resources;
let _: foo::Schedule = c.schedule; let _: foo::Schedule = c.schedule;
let _: foo::Spawn = c.spawn; let _: foo::Spawn = c.spawn;

View file

@ -9,30 +9,30 @@ use panic_halt as _;
#[rtfm::app(cores = 2, device = heterogeneous)] #[rtfm::app(cores = 2, device = heterogeneous)]
const APP: () = { const APP: () = {
extern "C" { struct Resources {
// owned by core #1 but initialized by core #0 // owned by core #1 but initialized by core #0
static mut X: u32; x: u32,
// owned by core #0 but initialized by core #1 // owned by core #0 but initialized by core #1
static mut Y: u32; y: u32,
} }
#[init(core = 0, late = [X])] #[init(core = 0, late = [x])]
fn a(_: a::Context) -> a::LateResources { fn a(_: a::Context) -> a::LateResources {
a::LateResources { X: 0 } a::LateResources { x: 0 }
} }
#[idle(core = 0, resources = [Y])] #[idle(core = 0, resources = [y])]
fn b(_: b::Context) -> ! { fn b(_: b::Context) -> ! {
loop {} loop {}
} }
#[init(core = 1)] #[init(core = 1)]
fn c(_: c::Context) -> c::LateResources { fn c(_: c::Context) -> c::LateResources {
c::LateResources { Y: 0 } c::LateResources { y: 0 }
} }
#[idle(core = 1, resources = [X])] #[idle(core = 1, resources = [x])]
fn d(_: d::Context) -> ! { fn d(_: d::Context) -> ! {
loop {} loop {}
} }

View file

@ -9,18 +9,18 @@ use panic_halt as _;
#[rtfm::app(cores = 2, device = heterogeneous)] #[rtfm::app(cores = 2, device = heterogeneous)]
const APP: () = { const APP: () = {
extern "C" { struct Resources {
static mut X: u32; x: u32,
static mut Y: u32; y: u32,
} }
#[init(core = 0, late = [X])] #[init(core = 0, late = [x])]
fn a(_: a::Context) -> a::LateResources { fn a(_: a::Context) -> a::LateResources {
a::LateResources { X: 0 } a::LateResources { x: 0 }
} }
#[init(core = 1)] #[init(core = 1)]
fn b(_: b::Context) -> b::LateResources { fn b(_: b::Context) -> b::LateResources {
b::LateResources { Y: 0 } b::LateResources { y: 0 }
} }
}; };

View file

@ -9,30 +9,30 @@ use panic_halt as _;
#[rtfm::app(cores = 2, device = homogeneous)] #[rtfm::app(cores = 2, device = homogeneous)]
const APP: () = { const APP: () = {
extern "C" { struct Resources {
// owned by core #1 but initialized by core #0 // owned by core #1 but initialized by core #0
static mut X: u32; x: u32,
// owned by core #0 but initialized by core #1 // owned by core #0 but initialized by core #1
static mut Y: u32; y: u32,
} }
#[init(core = 0, late = [X])] #[init(core = 0, late = [x])]
fn a(_: a::Context) -> a::LateResources { fn a(_: a::Context) -> a::LateResources {
a::LateResources { X: 0 } a::LateResources { x: 0 }
} }
#[idle(core = 0, resources = [Y])] #[idle(core = 0, resources = [y])]
fn b(_: b::Context) -> ! { fn b(_: b::Context) -> ! {
loop {} loop {}
} }
#[init(core = 1)] #[init(core = 1)]
fn c(_: c::Context) -> c::LateResources { fn c(_: c::Context) -> c::LateResources {
c::LateResources { Y: 0 } c::LateResources { y: 0 }
} }
#[idle(core = 1, resources = [X])] #[idle(core = 1, resources = [x])]
fn d(_: d::Context) -> ! { fn d(_: d::Context) -> ! {
loop {} loop {}
} }

View file

@ -9,18 +9,18 @@ use panic_halt as _;
#[rtfm::app(cores = 2, device = homogeneous)] #[rtfm::app(cores = 2, device = homogeneous)]
const APP: () = { const APP: () = {
extern "C" { struct Resources {
static mut X: u32; x: u32,
static mut Y: u32; y: u32,
} }
#[init(core = 0, late = [X])] #[init(core = 0, late = [x])]
fn a(_: a::Context) -> a::LateResources { fn a(_: a::Context) -> a::LateResources {
a::LateResources { X: 0 } a::LateResources { x: 0 }
} }
#[init(core = 1)] #[init(core = 1)]
fn b(_: b::Context) -> b::LateResources { fn b(_: b::Context) -> b::LateResources {
b::LateResources { Y: 0 } b::LateResources { y: 0 }
} }
}; };

View file

@ -57,6 +57,7 @@ pub fn codegen(
let attrs = &res.attrs; let attrs = &res.attrs;
const_app.push(quote!( const_app.push(quote!(
#[allow(non_upper_case_globals)]
#(#attrs)* #(#attrs)*
#(#cfgs)* #(#cfgs)*
#loc_attr #loc_attr
@ -65,12 +66,11 @@ pub fn codegen(
)); ));
} }
// generate a resource proxy if needed if let Some(Ownership::Contended { ceiling }) = analysis.ownerships.get(name) {
if res.mutability.is_some() {
if let Some(Ownership::Shared { ceiling }) = analysis.ownerships.get(name) {
let cfg_core = util::cfg_core(loc.core().expect("UNREACHABLE"), app.args.cores); let cfg_core = util::cfg_core(loc.core().expect("UNREACHABLE"), app.args.cores);
mod_resources.push(quote!( mod_resources.push(quote!(
#[allow(non_camel_case_types)]
#(#cfgs)* #(#cfgs)*
#cfg_core #cfg_core
pub struct #name<'a> { pub struct #name<'a> {
@ -110,7 +110,6 @@ pub fn codegen(
)); ));
} }
} }
}
let mod_resources = if mod_resources.is_empty() { let mod_resources = if mod_resources.is_empty() {
quote!() quote!()

View file

@ -24,13 +24,17 @@ pub fn codegen(
let mut values = vec![]; let mut values = vec![];
let mut has_cfgs = false; let mut has_cfgs = false;
for name in resources { for (name, access) in resources {
let (res, expr) = app.resource(name).expect("UNREACHABLE"); let (res, expr) = app.resource(name).expect("UNREACHABLE");
let cfgs = &res.cfgs; let cfgs = &res.cfgs;
has_cfgs |= !cfgs.is_empty(); has_cfgs |= !cfgs.is_empty();
let mut_ = res.mutability; let mut_ = if access.is_exclusive() {
Some(quote!(mut))
} else {
None
};
let ty = &res.ty; let ty = &res.ty;
if ctxt.is_init() { if ctxt.is_init() {

View file

@ -2,56 +2,74 @@
#[rtfm::app(device = lm3s6965)] #[rtfm::app(device = lm3s6965)]
const APP: () = { const APP: () = {
struct Resources {
#[cfg(never)] #[cfg(never)]
static mut O1: u32 = 0; // init #[init(0)]
#[cfg(never)] o1: u32, // init
static mut O2: u32 = 0; // idle
#[cfg(never)]
static mut O3: u32 = 0; // EXTI0
#[cfg(never)]
static O4: u32 = 0; // idle
#[cfg(never)]
static O5: u32 = 0; // EXTI1
#[cfg(never)]
static O6: u32 = 0; // init
#[cfg(never)] #[cfg(never)]
static mut S1: u32 = 0; // idle & EXTI0 #[init(0)]
#[cfg(never)] o2: u32, // idle
static mut S2: u32 = 0; // EXTI0 & EXTI1
#[cfg(never)]
static S3: u32 = 0;
#[init(resources = [O1, O4, O5, O6, S3])] #[cfg(never)]
fn init(c: init::Context) { #[init(0)]
c.resources.O1; o3: u32, // EXTI0
c.resources.O4;
c.resources.O5; #[cfg(never)]
c.resources.O6; #[init(0)]
c.resources.S3; o4: u32, // idle
#[cfg(never)]
#[init(0)]
o5: u32, // EXTI1
#[cfg(never)]
#[init(0)]
o6: u32, // init
#[cfg(never)]
#[init(0)]
s1: u32, // idle & EXTI0
#[cfg(never)]
#[init(0)]
s2: u32, // EXTI0 & EXTI1
#[cfg(never)]
#[init(0)]
s3: u32,
} }
#[idle(resources = [O2, O4, S1, S3])] #[init(resources = [o1, o4, o5, o6, s3])]
fn init(c: init::Context) {
c.resources.o1;
c.resources.o4;
c.resources.o5;
c.resources.o6;
c.resources.s3;
}
#[idle(resources = [o2, &o4, s1, &s3])]
fn idle(c: idle::Context) -> ! { fn idle(c: idle::Context) -> ! {
c.resources.O2; c.resources.o2;
c.resources.O4; c.resources.o4;
c.resources.S1; c.resources.s1;
c.resources.S3; c.resources.s3;
loop {} loop {}
} }
#[task(binds = UART0, resources = [O3, S1, S2, S3])] #[task(binds = UART0, resources = [o3, s1, s2, &s3])]
fn uart0(c: uart0::Context) { fn uart0(c: uart0::Context) {
c.resources.O3; c.resources.o3;
c.resources.S1; c.resources.s1;
c.resources.S2; c.resources.s2;
c.resources.S3; c.resources.s3;
} }
#[task(binds = UART1, resources = [S2, O5])] #[task(binds = UART1, resources = [s2, &o5])]
fn uart1(c: uart1::Context) { fn uart1(c: uart1::Context) {
c.resources.S2; c.resources.s2;
c.resources.O5; c.resources.o5;
} }
}; };

View file

@ -1,119 +1,119 @@
error[E0609]: no field `O1` on type `initResources<'_>` error[E0609]: no field `o1` on type `initResources<'_>`
--> $DIR/resources-cfg.rs:27:21 --> $DIR/resources-cfg.rs:45:21
| |
27 | c.resources.O1; 45 | c.resources.o1;
| ^^ unknown field | ^^ unknown field
| |
= note: available fields are: `__marker__` = note: available fields are: `__marker__`
error[E0609]: no field `O4` on type `initResources<'_>` error[E0609]: no field `o4` on type `initResources<'_>`
--> $DIR/resources-cfg.rs:28:21
|
28 | c.resources.O4;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `O5` on type `initResources<'_>`
--> $DIR/resources-cfg.rs:29:21
|
29 | c.resources.O5;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `O6` on type `initResources<'_>`
--> $DIR/resources-cfg.rs:30:21
|
30 | c.resources.O6;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `S3` on type `initResources<'_>`
--> $DIR/resources-cfg.rs:31:21
|
31 | c.resources.S3;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `O2` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:36:21
|
36 | c.resources.O2;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `O4` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:37:21
|
37 | c.resources.O4;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `S1` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:38:21
|
38 | c.resources.S1;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `S3` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:39:21
|
39 | c.resources.S3;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `O3` on type `uart0Resources<'_>`
--> $DIR/resources-cfg.rs:46:21 --> $DIR/resources-cfg.rs:46:21
| |
46 | c.resources.O3; 46 | c.resources.o4;
| ^^ unknown field | ^^ unknown field
| |
= note: available fields are: `__marker__` = note: available fields are: `__marker__`
error[E0609]: no field `S1` on type `uart0Resources<'_>` error[E0609]: no field `o5` on type `initResources<'_>`
--> $DIR/resources-cfg.rs:47:21 --> $DIR/resources-cfg.rs:47:21
| |
47 | c.resources.S1; 47 | c.resources.o5;
| ^^ unknown field | ^^ unknown field
| |
= note: available fields are: `__marker__` = note: available fields are: `__marker__`
error[E0609]: no field `S2` on type `uart0Resources<'_>` error[E0609]: no field `o6` on type `initResources<'_>`
--> $DIR/resources-cfg.rs:48:21 --> $DIR/resources-cfg.rs:48:21
| |
48 | c.resources.S2; 48 | c.resources.o6;
| ^^ unknown field | ^^ unknown field
| |
= note: available fields are: `__marker__` = note: available fields are: `__marker__`
error[E0609]: no field `S3` on type `uart0Resources<'_>` error[E0609]: no field `s3` on type `initResources<'_>`
--> $DIR/resources-cfg.rs:49:21 --> $DIR/resources-cfg.rs:49:21
| |
49 | c.resources.S3; 49 | c.resources.s3;
| ^^ unknown field | ^^ unknown field
| |
= note: available fields are: `__marker__` = note: available fields are: `__marker__`
error[E0609]: no field `S2` on type `uart1Resources<'_>` error[E0609]: no field `o2` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:54:21 --> $DIR/resources-cfg.rs:54:21
| |
54 | c.resources.S2; 54 | c.resources.o2;
| ^^ unknown field | ^^ unknown field
| |
= note: available fields are: `__marker__` = note: available fields are: `__marker__`
error[E0609]: no field `O5` on type `uart1Resources<'_>` error[E0609]: no field `o4` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:55:21 --> $DIR/resources-cfg.rs:55:21
| |
55 | c.resources.O5; 55 | c.resources.o4;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s1` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:56:21
|
56 | c.resources.s1;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s3` on type `idleResources<'_>`
--> $DIR/resources-cfg.rs:57:21
|
57 | c.resources.s3;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `o3` on type `uart0Resources<'_>`
--> $DIR/resources-cfg.rs:64:21
|
64 | c.resources.o3;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s1` on type `uart0Resources<'_>`
--> $DIR/resources-cfg.rs:65:21
|
65 | c.resources.s1;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s2` on type `uart0Resources<'_>`
--> $DIR/resources-cfg.rs:66:21
|
66 | c.resources.s2;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s3` on type `uart0Resources<'_>`
--> $DIR/resources-cfg.rs:67:21
|
67 | c.resources.s3;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `s2` on type `uart1Resources<'_>`
--> $DIR/resources-cfg.rs:72:21
|
72 | c.resources.s2;
| ^^ unknown field
|
= note: available fields are: `__marker__`
error[E0609]: no field `o5` on type `uart1Resources<'_>`
--> $DIR/resources-cfg.rs:73:21
|
73 | c.resources.o5;
| ^^ unknown field | ^^ unknown field
| |
= note: available fields are: `__marker__` = note: available fields are: `__marker__`