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()));
|
exprs.push(quote!(#name: <#name as owned_singleton::Singleton>::new()));
|
||||||
} else {
|
} else {
|
||||||
needs_unsafe = true;
|
needs_unsafe = true;
|
||||||
if ownership.is_owned() {
|
if ownership.is_owned() || mut_.is_none() {
|
||||||
defs.push(quote!(pub #name: &'a mut #name));
|
defs.push(quote!(pub #name: &'a #mut_ #name));
|
||||||
exprs.push(quote!(
|
let alias = mk_ident();
|
||||||
#name: &mut <#name as owned_singleton::Singleton>::new()
|
items.push(quote!(
|
||||||
|
let #mut_ #alias = unsafe {
|
||||||
|
<#name as owned_singleton::Singleton>::new()
|
||||||
|
};
|
||||||
));
|
));
|
||||||
|
exprs.push(quote!(#name: &#mut_ #alias));
|
||||||
} else {
|
} else {
|
||||||
may_call_lock = true;
|
may_call_lock = true;
|
||||||
defs.push(quote!(pub #name: rtfm::Exclusive<'a, #name>));
|
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!(
|
exprs.push(quote!(
|
||||||
#name: rtfm::Exclusive(
|
#name: rtfm::Exclusive(&mut #alias)
|
||||||
&mut <#name as owned_singleton::Singleton>::new()
|
|
||||||
)
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ extern crate lm3s6965;
|
||||||
extern crate panic_halt;
|
extern crate panic_halt;
|
||||||
extern crate rtfm;
|
extern crate rtfm;
|
||||||
|
|
||||||
use rtfm::app;
|
use rtfm::{app, Exclusive};
|
||||||
|
|
||||||
#[app(device = lm3s6965)]
|
#[app(device = lm3s6965)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
|
@ -59,11 +59,11 @@ const APP: () = {
|
||||||
// owned by interrupt == `&mut`
|
// owned by interrupt == `&mut`
|
||||||
let _: &mut u32 = resources.O3;
|
let _: &mut u32 = resources.O3;
|
||||||
|
|
||||||
// no `Mutex` when access from highest priority task
|
// no `Mutex` proxy when access from highest priority task
|
||||||
let _: &mut u32 = resources.S1;
|
let _: Exclusive<u32> = resources.S1;
|
||||||
|
|
||||||
// no `Mutex` when co-owned by cooperative (same priority) tasks
|
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
|
||||||
let _: &mut u32 = resources.S2;
|
let _: Exclusive<u32> = resources.S2;
|
||||||
|
|
||||||
// `&` if read-only
|
// `&` if read-only
|
||||||
let _: &u32 = resources.S3;
|
let _: &u32 = resources.S3;
|
||||||
|
@ -74,7 +74,7 @@ const APP: () = {
|
||||||
// owned by interrupt == `&` if read-only
|
// owned by interrupt == `&` if read-only
|
||||||
let _: &u32 = resources.O5;
|
let _: &u32 = resources.O5;
|
||||||
|
|
||||||
// no `Mutex` when co-owned by cooperative (same priority) tasks
|
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
|
||||||
let _: &mut u32 = resources.S2;
|
let _: Exclusive<u32> = resources.S2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@ extern crate owned_singleton;
|
||||||
extern crate panic_halt;
|
extern crate panic_halt;
|
||||||
extern crate rtfm;
|
extern crate rtfm;
|
||||||
|
|
||||||
use rtfm::app;
|
use rtfm::{app, Exclusive};
|
||||||
|
|
||||||
#[app(device = lm3s6965)]
|
#[app(device = lm3s6965)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
|
@ -27,7 +27,7 @@ const APP: () = {
|
||||||
#[Singleton]
|
#[Singleton]
|
||||||
static mut S1: u32 = 0;
|
static mut S1: u32 = 0;
|
||||||
#[Singleton]
|
#[Singleton]
|
||||||
static mut S2: u32 = 0;
|
static S2: u32 = 0;
|
||||||
|
|
||||||
#[init(resources = [O1, O2, O3, O4, O5, O6, S1, S2])]
|
#[init(resources = [O1, O2, O3, O4, O5, O6, S1, S2])]
|
||||||
fn init() {
|
fn init() {
|
||||||
|
@ -55,13 +55,13 @@ const APP: () = {
|
||||||
let _: &mut O3 = resources.O3;
|
let _: &mut O3 = resources.O3;
|
||||||
let _: &O6 = resources.O6;
|
let _: &O6 = resources.O6;
|
||||||
|
|
||||||
let _: &mut S1 = resources.S1;
|
let _: Exclusive<S1> = resources.S1;
|
||||||
let _: &S2 = resources.S2;
|
let _: &S2 = resources.S2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[interrupt(resources = [S1, S2])]
|
#[interrupt(resources = [S1, S2])]
|
||||||
fn UART1() {
|
fn UART1() {
|
||||||
let _: &mut S1 = resources.S1;
|
let _: Exclusive<S1> = resources.S1;
|
||||||
let _: &S2 = resources.S2;
|
let _: &S2 = resources.S2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue