mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
Fix shared resource handling and extend example.
The extended example tests that this actually works this time.
This commit is contained in:
parent
70e243694d
commit
1556948458
2 changed files with 24 additions and 5 deletions
|
@ -26,13 +26,24 @@ app! {
|
||||||
// the initializer. Doing that will require `init` to return the values of all "late"
|
// the initializer. Doing that will require `init` to return the values of all "late"
|
||||||
// resources.
|
// resources.
|
||||||
static IP_ADDRESS: u32;
|
static IP_ADDRESS: u32;
|
||||||
|
|
||||||
|
// PORT is used by 2 tasks, making it a shared resource. This just tests another internal
|
||||||
|
// code path and is not important for the example.
|
||||||
|
static PORT: u16;
|
||||||
},
|
},
|
||||||
|
|
||||||
tasks: {
|
tasks: {
|
||||||
SYS_TICK: {
|
SYS_TICK: {
|
||||||
|
priority: 1,
|
||||||
path: sys_tick,
|
path: sys_tick,
|
||||||
resources: [IP_ADDRESS, ON],
|
resources: [IP_ADDRESS, PORT, ON],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
EXTI0: {
|
||||||
|
priority: 2,
|
||||||
|
path: exti0,
|
||||||
|
resources: [PORT],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +58,7 @@ fn init(_p: init::Peripherals, _r: init::Resources) -> init::LateResourceValues
|
||||||
init::LateResourceValues {
|
init::LateResourceValues {
|
||||||
// This struct will contain fields for all resources with omitted initializers.
|
// This struct will contain fields for all resources with omitted initializers.
|
||||||
IP_ADDRESS: ip_address,
|
IP_ADDRESS: ip_address,
|
||||||
|
PORT: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +69,8 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
|
||||||
r.IP_ADDRESS;
|
r.IP_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {}
|
||||||
|
|
||||||
fn idle() -> ! {
|
fn idle() -> ! {
|
||||||
loop {
|
loop {
|
||||||
rtfm::wfi();
|
rtfm::wfi();
|
||||||
|
|
|
@ -351,6 +351,11 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
Ownership::Shared { ceiling } => {
|
Ownership::Shared { ceiling } => {
|
||||||
if let Some(resource) = app.resources.get(name) {
|
if let Some(resource) = app.resources.get(name) {
|
||||||
let ty = &resource.ty;
|
let ty = &resource.ty;
|
||||||
|
let res_rvalue = if resource.expr.is_some() {
|
||||||
|
quote!(#_name)
|
||||||
|
} else {
|
||||||
|
quote!(#_name.some)
|
||||||
|
};
|
||||||
|
|
||||||
impl_items.push(quote! {
|
impl_items.push(quote! {
|
||||||
type Data = #ty;
|
type Data = #ty;
|
||||||
|
@ -361,7 +366,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
) -> &'cs #krate::Static<#ty> {
|
) -> &'cs #krate::Static<#ty> {
|
||||||
assert!(t.value() >= #ceiling);
|
assert!(t.value() >= #ceiling);
|
||||||
|
|
||||||
unsafe { #krate::Static::ref_(&#_name) }
|
unsafe { #krate::Static::ref_(&#res_rvalue) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrow_mut<'cs>(
|
fn borrow_mut<'cs>(
|
||||||
|
@ -371,7 +376,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
assert!(t.value() >= #ceiling);
|
assert!(t.value() >= #ceiling);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
#krate::Static::ref_mut(&mut #_name)
|
#krate::Static::ref_mut(&mut #res_rvalue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +392,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
#krate::claim(
|
#krate::claim(
|
||||||
#krate::Static::ref_(&#_name),
|
#krate::Static::ref_(&#res_rvalue),
|
||||||
#ceiling,
|
#ceiling,
|
||||||
#device::NVIC_PRIO_BITS,
|
#device::NVIC_PRIO_BITS,
|
||||||
t,
|
t,
|
||||||
|
@ -408,7 +413,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
#krate::claim(
|
#krate::claim(
|
||||||
#krate::Static::ref_mut(&mut #_name),
|
#krate::Static::ref_mut(&mut #res_rvalue),
|
||||||
#ceiling,
|
#ceiling,
|
||||||
#device::NVIC_PRIO_BITS,
|
#device::NVIC_PRIO_BITS,
|
||||||
t,
|
t,
|
||||||
|
|
Loading…
Reference in a new issue