mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
drop the Static wrapper
This commit is contained in:
parent
0f5784c240
commit
219e172680
8 changed files with 28 additions and 26 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
*.org
|
*.org
|
||||||
|
.#*
|
||||||
.gdb_history
|
.gdb_history
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
target/
|
target/
|
||||||
|
|
|
@ -15,7 +15,8 @@ version = "0.3.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = { git = "https://github.com/japaric/cortex-m" }
|
cortex-m = { git = "https://github.com/japaric/cortex-m" }
|
||||||
untagged-option = "0.1.1"
|
untagged-option = "0.1.1"
|
||||||
rtfm-core = "0.1.0"
|
# rtfm-core = "0.1.0"
|
||||||
|
rtfm-core = { git = "https://github.com/japaric/rtfm-core", branch = "no-static" }
|
||||||
cortex-m-rtfm-macros = { path = "macros" }
|
cortex-m-rtfm-macros = { path = "macros" }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "x86_64")'.dev-dependencies]
|
[target.'cfg(target_arch = "x86_64")'.dev-dependencies]
|
||||||
|
|
|
@ -63,22 +63,22 @@ mod main {
|
||||||
*r.OWNED != *r.OWNED;
|
*r.OWNED != *r.OWNED;
|
||||||
|
|
||||||
if *r.OWNED {
|
if *r.OWNED {
|
||||||
if r.SHARED.claim(t, |shared, _| **shared) {
|
if r.SHARED.claim(t, |shared, _| *shared) {
|
||||||
rtfm::wfi();
|
rtfm::wfi();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
r.SHARED.claim_mut(t, |shared, _| **shared = !**shared);
|
r.SHARED.claim_mut(t, |shared, _| *shared = !*shared);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
|
fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
|
||||||
**r.ON = !**r.ON;
|
*r.ON = !*r.ON;
|
||||||
|
|
||||||
**r.CO_OWNED += 1;
|
*r.CO_OWNED += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tim2(_t: &mut Threshold, r: TIM2::Resources) {
|
fn tim2(_t: &mut Threshold, r: TIM2::Resources) {
|
||||||
**r.CO_OWNED += 1;
|
*r.CO_OWNED += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,9 +79,9 @@ fn idle() -> ! {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
|
fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
|
||||||
// toggle state
|
// toggle state
|
||||||
**r.ON = !**r.ON;
|
*r.ON = !*r.ON;
|
||||||
|
|
||||||
if **r.ON {
|
if *r.ON {
|
||||||
// set the pin PC13 high
|
// set the pin PC13 high
|
||||||
// NOTE(unsafe) atomic write to a stateless register
|
// NOTE(unsafe) atomic write to a stateless register
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -47,7 +47,7 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
|
||||||
|
|
||||||
// This task can't be preempted by `tim2` so it has direct access to the
|
// This task can't be preempted by `tim2` so it has direct access to the
|
||||||
// resource data
|
// resource data
|
||||||
**r.COUNTER += 1;
|
*r.COUNTER += 1;
|
||||||
|
|
||||||
// ..
|
// ..
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ fn tim2(t: &mut Threshold, mut r: TIM2::Resources) {
|
||||||
// lead to undefined behavior.
|
// lead to undefined behavior.
|
||||||
r.COUNTER.claim_mut(t, |counter, _t| {
|
r.COUNTER.claim_mut(t, |counter, _t| {
|
||||||
// `claim_mut` creates a critical section
|
// `claim_mut` creates a critical section
|
||||||
**counter += 1;
|
*counter += 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
// ..
|
// ..
|
||||||
|
|
|
@ -45,7 +45,7 @@ fn idle() -> ! {
|
||||||
fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
|
fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
|
||||||
// ..
|
// ..
|
||||||
|
|
||||||
**r.COUNTER += 1;
|
*r.COUNTER += 1;
|
||||||
|
|
||||||
// ..
|
// ..
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
|
||||||
fn tim2(_t: &mut Threshold, r: TIM2::Resources) {
|
fn tim2(_t: &mut Threshold, r: TIM2::Resources) {
|
||||||
// ..
|
// ..
|
||||||
|
|
||||||
**r.COUNTER += 1;
|
*r.COUNTER += 1;
|
||||||
|
|
||||||
// ..
|
// ..
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,11 +176,11 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
|
||||||
let ty = &resource.ty;
|
let ty = &resource.ty;
|
||||||
|
|
||||||
fields.push(quote! {
|
fields.push(quote! {
|
||||||
pub #name: &'a mut #krate::Static<#ty>,
|
pub #name: &'a mut #ty,
|
||||||
});
|
});
|
||||||
|
|
||||||
rexprs.push(quote! {
|
rexprs.push(quote! {
|
||||||
#name: ::#krate::Static::ref_mut(&mut ::#_name),
|
#name: &mut ::#_name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,20 +369,20 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
fn borrow<'cs>(
|
fn borrow<'cs>(
|
||||||
&'cs self,
|
&'cs self,
|
||||||
t: &'cs #krate::Threshold,
|
t: &'cs #krate::Threshold,
|
||||||
) -> &'cs #krate::Static<#ty> {
|
) -> &'cs #ty {
|
||||||
assert!(t.value() >= #ceiling);
|
assert!(t.value() >= #ceiling);
|
||||||
|
|
||||||
unsafe { #krate::Static::ref_(&#res_rvalue) }
|
unsafe { &#res_rvalue }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrow_mut<'cs>(
|
fn borrow_mut<'cs>(
|
||||||
&'cs mut self,
|
&'cs mut self,
|
||||||
t: &'cs #krate::Threshold,
|
t: &'cs #krate::Threshold,
|
||||||
) -> &'cs mut #krate::Static<#ty> {
|
) -> &'cs mut #ty {
|
||||||
assert!(t.value() >= #ceiling);
|
assert!(t.value() >= #ceiling);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
#krate::Static::ref_mut(&mut #res_rvalue)
|
&mut #res_rvalue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,12 +393,12 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
) -> R
|
) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(
|
F: FnOnce(
|
||||||
&#krate::Static<#ty>,
|
&#ty,
|
||||||
&mut #krate::Threshold) -> R
|
&mut #krate::Threshold) -> R
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
#krate::claim(
|
#krate::claim(
|
||||||
#krate::Static::ref_(&#res_rvalue),
|
&#res_rvalue,
|
||||||
#ceiling,
|
#ceiling,
|
||||||
#device::NVIC_PRIO_BITS,
|
#device::NVIC_PRIO_BITS,
|
||||||
t,
|
t,
|
||||||
|
@ -414,12 +414,12 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
) -> R
|
) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(
|
F: FnOnce(
|
||||||
&mut #krate::Static<#ty>,
|
&mut #ty,
|
||||||
&mut #krate::Threshold) -> R
|
&mut #krate::Threshold) -> R
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
#krate::claim(
|
#krate::claim(
|
||||||
#krate::Static::ref_mut(&mut #res_rvalue),
|
&mut #res_rvalue,
|
||||||
#ceiling,
|
#ceiling,
|
||||||
#device::NVIC_PRIO_BITS,
|
#device::NVIC_PRIO_BITS,
|
||||||
t,
|
t,
|
||||||
|
@ -510,16 +510,16 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
let ty = &resource.ty;
|
let ty = &resource.ty;
|
||||||
|
|
||||||
fields.push(quote! {
|
fields.push(quote! {
|
||||||
pub #name: &'a mut ::#krate::Static<#ty>,
|
pub #name: &'a mut #ty,
|
||||||
});
|
});
|
||||||
|
|
||||||
exprs.push(if resource.expr.is_some() {
|
exprs.push(if resource.expr.is_some() {
|
||||||
quote! {
|
quote! {
|
||||||
#name: ::#krate::Static::ref_mut(&mut ::#_name),
|
#name: &mut ::#_name,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {
|
quote! {
|
||||||
#name: ::#krate::Static::ref_mut(::#_name.as_mut()),
|
#name: ::#_name.as_mut(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ extern crate untagged_option;
|
||||||
|
|
||||||
use core::u8;
|
use core::u8;
|
||||||
|
|
||||||
pub use rtfm_core::{Resource, Static, Threshold};
|
pub use rtfm_core::{Resource, Threshold};
|
||||||
pub use cortex_m::asm::{bkpt, wfi};
|
pub use cortex_m::asm::{bkpt, wfi};
|
||||||
pub use cortex_m_rtfm_macros::app;
|
pub use cortex_m_rtfm_macros::app;
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|
Loading…
Reference in a new issue