mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-29 15:04:32 +01:00
fix codegen
This commit is contained in:
parent
37a0692a0f
commit
22d758ddac
3 changed files with 26 additions and 18 deletions
|
@ -711,18 +711,26 @@ fn prelude(
|
|||
exprs.push(quote!(#name: <#name as owned_singleton::Singleton>::new()));
|
||||
} else {
|
||||
needs_unsafe = true;
|
||||
if ownership.is_owned() {
|
||||
defs.push(quote!(pub #name: &'a mut #name));
|
||||
exprs.push(quote!(
|
||||
#name: &mut <#name as owned_singleton::Singleton>::new()
|
||||
if ownership.is_owned() || mut_.is_none() {
|
||||
defs.push(quote!(pub #name: &'a #mut_ #name));
|
||||
let alias = mk_ident();
|
||||
items.push(quote!(
|
||||
let #mut_ #alias = unsafe {
|
||||
<#name as owned_singleton::Singleton>::new()
|
||||
};
|
||||
));
|
||||
exprs.push(quote!(#name: &#mut_ #alias));
|
||||
} else {
|
||||
may_call_lock = true;
|
||||
defs.push(quote!(pub #name: rtfm::Exclusive<'a, #name>));
|
||||
let alias = mk_ident();
|
||||
items.push(quote!(
|
||||
let #mut_ #alias = unsafe {
|
||||
<#name as owned_singleton::Singleton>::new()
|
||||
};
|
||||
));
|
||||
exprs.push(quote!(
|
||||
#name: rtfm::Exclusive(
|
||||
&mut <#name as owned_singleton::Singleton>::new()
|
||||
)
|
||||
#name: rtfm::Exclusive(&mut #alias)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ extern crate lm3s6965;
|
|||
extern crate panic_halt;
|
||||
extern crate rtfm;
|
||||
|
||||
use rtfm::app;
|
||||
use rtfm::{app, Exclusive};
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
@ -59,11 +59,11 @@ const APP: () = {
|
|||
// owned by interrupt == `&mut`
|
||||
let _: &mut u32 = resources.O3;
|
||||
|
||||
// no `Mutex` when access from highest priority task
|
||||
let _: &mut u32 = resources.S1;
|
||||
// no `Mutex` proxy when access from highest priority task
|
||||
let _: Exclusive<u32> = resources.S1;
|
||||
|
||||
// no `Mutex` when co-owned by cooperative (same priority) tasks
|
||||
let _: &mut u32 = resources.S2;
|
||||
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
|
||||
let _: Exclusive<u32> = resources.S2;
|
||||
|
||||
// `&` if read-only
|
||||
let _: &u32 = resources.S3;
|
||||
|
@ -74,7 +74,7 @@ const APP: () = {
|
|||
// 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;
|
||||
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
|
||||
let _: Exclusive<u32> = resources.S2;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -7,7 +7,7 @@ extern crate owned_singleton;
|
|||
extern crate panic_halt;
|
||||
extern crate rtfm;
|
||||
|
||||
use rtfm::app;
|
||||
use rtfm::{app, Exclusive};
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
@ -27,7 +27,7 @@ const APP: () = {
|
|||
#[Singleton]
|
||||
static mut S1: u32 = 0;
|
||||
#[Singleton]
|
||||
static mut S2: u32 = 0;
|
||||
static S2: u32 = 0;
|
||||
|
||||
#[init(resources = [O1, O2, O3, O4, O5, O6, S1, S2])]
|
||||
fn init() {
|
||||
|
@ -55,13 +55,13 @@ const APP: () = {
|
|||
let _: &mut O3 = resources.O3;
|
||||
let _: &O6 = resources.O6;
|
||||
|
||||
let _: &mut S1 = resources.S1;
|
||||
let _: Exclusive<S1> = resources.S1;
|
||||
let _: &S2 = resources.S2;
|
||||
}
|
||||
|
||||
#[interrupt(resources = [S1, S2])]
|
||||
fn UART1() {
|
||||
let _: &mut S1 = resources.S1;
|
||||
let _: Exclusive<S1> = resources.S1;
|
||||
let _: &S2 = resources.S2;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue