mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
remove claim, add Priority.as_ceiling
This commit is contained in:
parent
0827c40a26
commit
4e6818eb2c
3 changed files with 14 additions and 28 deletions
10
build.rs
10
build.rs
|
@ -56,6 +56,7 @@ fn main() {
|
|||
|
||||
// Priorities
|
||||
for i in 1..(1 << bits) + 1 {
|
||||
let c = Ident::new(format!("C{}", i));
|
||||
let p = Ident::new(format!("P{}", i));
|
||||
let u = Ident::new(format!("U{}", i));
|
||||
|
||||
|
@ -64,6 +65,15 @@ fn main() {
|
|||
/// Priority
|
||||
pub type #p = P<::typenum::#u>;
|
||||
|
||||
impl #p {
|
||||
/// Turns this priority into a ceiling
|
||||
pub fn as_ceiling(&self) -> &#c {
|
||||
unsafe {
|
||||
::core::mem::transmute(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Priority for #p {}
|
||||
|
||||
unsafe impl Level for ::typenum::#u {
|
||||
|
|
26
src/lib.rs
26
src/lib.rs
|
@ -18,7 +18,7 @@ use cortex_m::interrupt::Nr;
|
|||
#[cfg(not(thumbv6m))]
|
||||
use cortex_m::register::{basepri, basepri_max};
|
||||
use static_ref::Ref;
|
||||
use typenum::{Cmp, Equal, Unsigned};
|
||||
use typenum::{Cmp, Unsigned};
|
||||
#[cfg(not(thumbv6m))]
|
||||
use typenum::{Greater, Less};
|
||||
|
||||
|
@ -74,19 +74,6 @@ impl<T, CEILING> Resource<T, C<CEILING>> {
|
|||
unsafe { Ref::new(&*self.data.get()) }
|
||||
}
|
||||
|
||||
/// Claims the resource at the task with highest priority
|
||||
///
|
||||
/// This operation is zero cost and doesn't impose any additional blocking
|
||||
pub fn claim<'task, PRIORITY>(
|
||||
&'static self,
|
||||
_priority: &'task P<PRIORITY>,
|
||||
) -> Ref<'task, T>
|
||||
where
|
||||
CEILING: Cmp<PRIORITY, Output = Equal>,
|
||||
{
|
||||
unsafe { Ref::new(&*self.data.get()) }
|
||||
}
|
||||
|
||||
/// Locks the resource for the duration of the critical section `f`
|
||||
///
|
||||
/// For the duration of the critical section, tasks whose priority level is
|
||||
|
@ -161,17 +148,6 @@ impl<Periph, CEILING> Peripheral<Periph, C<CEILING>> {
|
|||
unsafe { Ref::new(&*self.peripheral.get()) }
|
||||
}
|
||||
|
||||
/// See [Resource.claim](./struct.Resource.html#method.claim)
|
||||
pub fn claim<'task, PRIORITY>(
|
||||
&'static self,
|
||||
_priority: &'task P<PRIORITY>,
|
||||
) -> Ref<'task, Periph>
|
||||
where
|
||||
CEILING: Cmp<PRIORITY, Output = Equal>,
|
||||
{
|
||||
unsafe { Ref::new(&*self.peripheral.get()) }
|
||||
}
|
||||
|
||||
/// See [Resource.lock](./struct.Resource.html#method.lock)
|
||||
#[cfg(not(thumbv6m))]
|
||||
pub fn lock<R, PRIORITY, F>(&'static self, _priority: &P<PRIORITY>, f: F) -> R
|
||||
|
|
|
@ -11,13 +11,13 @@ fn j1(prio: P3) {
|
|||
}
|
||||
|
||||
// DON'T lock a resource with ceiling equal to the task priority.
|
||||
// Instead use `claim`
|
||||
// Instead use `borrow`
|
||||
fn j2(prio: P2) {
|
||||
R1.lock(&prio, |_, _| {});
|
||||
//~^ error
|
||||
|
||||
// OK
|
||||
let r1 = R1.claim(&prio);
|
||||
let r1 = R1.borrow(&prio, prio.as_ceiling());
|
||||
}
|
||||
|
||||
// You CAN lock a resource with ceiling C from a task with priority P if C > P
|
||||
|
@ -37,5 +37,5 @@ fn j4(prio: P1) {
|
|||
// Only tasks with priority P16 can claim a resource with ceiling C16
|
||||
fn j5(prio: P16) {
|
||||
// OK
|
||||
let r2 = R2.claim(&prio);
|
||||
let r2 = R2.borrow(&prio, prio.as_ceiling());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue