diff --git a/src/lib.rs b/src/lib.rs index a208786068..c1f6aa188e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,7 +47,8 @@ pub struct Resource { impl Resource { /// Creates a new resource with ceiling `C` pub const fn new(data: T) -> Self - where C: Ceiling + where + C: Ceiling, { Resource { _ceiling: PhantomData, @@ -61,12 +62,14 @@ impl Resource> { /// section /// /// This operation is zero cost and doesn't impose any additional blocking - pub fn borrow<'cs, PRIORITY, SCEILING>(&'static self, - _priority: &P, - _system_ceiling: &'cs C) - -> Ref<'cs, T> - where SCEILING: GreaterThanOrEqual, - CEILING: GreaterThanOrEqual + pub fn borrow<'cs, PRIORITY, SCEILING>( + &'static self, + _priority: &P, + _system_ceiling: &'cs C, + ) -> Ref<'cs, T> + where + SCEILING: GreaterThanOrEqual, + CEILING: GreaterThanOrEqual, { unsafe { Ref::new(&*self.data.get()) } } @@ -74,18 +77,24 @@ impl Resource> { /// 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) -> Ref<'task, T> - where CEILING: Cmp + pub fn claim<'task, PRIORITY>( + &'static self, + _priority: &'task P, + ) -> Ref<'task, T> + where + CEILING: Cmp, { unsafe { Ref::new(&*self.data.get()) } } /// Like [Resource.claim](struct.Resource.html#method.claim) but returns a /// `&mut-` reference - pub fn claim_mut<'task, PRIORITY>(&'static self, - _priority: &'task mut P) - -> RefMut<'task, T> - where CEILING: Cmp + pub fn claim_mut<'task, PRIORITY>( + &'static self, + _priority: &'task mut P, + ) -> RefMut<'task, T> + where + CEILING: Cmp, { unsafe { RefMut::new(&mut *self.data.get()) } } @@ -108,7 +117,8 @@ impl Resource> { let old_basepri = basepri::read(); basepri_max::write(::hw()); barrier!(); - let ret = f(Ref::new(&*self.data.get()), C { _marker: PhantomData }); + let ret = + f(Ref::new(&*self.data.get()), C { _marker: PhantomData }); barrier!(); basepri::write(old_basepri); ret @@ -138,25 +148,32 @@ impl Resource> { } } -unsafe impl Sync for Resource where C: Ceiling {} +unsafe impl Sync for Resource +where + C: Ceiling, +{ +} /// A hardware peripheral as a resource pub struct Peripheral - where P: 'static +where + P: 'static, { peripheral: cortex_m::peripheral::Peripheral

, _ceiling: PhantomData, } impl Peripheral - where C: Ceiling +where + C: Ceiling, { /// Assigns a ceiling `C` to the `peripheral` /// /// # Safety /// /// You MUST not create two resources that point to the same peripheral - pub const unsafe fn new(peripheral: cortex_m::peripheral::Peripheral

) -> Self { + pub const unsafe fn new(peripheral: cortex_m::peripheral::Peripheral

,) + -> Self { Peripheral { _ceiling: PhantomData, peripheral: peripheral, @@ -166,21 +183,25 @@ impl Peripheral impl Peripheral> { /// See [Resource.borrow](./struct.Resource.html#method.borrow) - pub fn borrow<'cs, PRIORITY, SCEILING>(&'static self, - _priority: &P, - _system_ceiling: &'cs C) - -> Ref<'cs, Periph> - where SCEILING: GreaterThanOrEqual, - CEILING: GreaterThanOrEqual + pub fn borrow<'cs, PRIORITY, SCEILING>( + &'static self, + _priority: &P, + _system_ceiling: &'cs C, + ) -> Ref<'cs, Periph> + where + SCEILING: GreaterThanOrEqual, + CEILING: GreaterThanOrEqual, { unsafe { Ref::new(&*self.peripheral.get()) } } /// See [Resource.claim](./struct.Resource.html#method.claim) - pub fn claim<'task, PRIORITY>(&'static self, - _priority: &'task P) - -> Ref<'task, Periph> - where CEILING: Cmp + pub fn claim<'task, PRIORITY>( + &'static self, + _priority: &'task P, + ) -> Ref<'task, Periph> + where + CEILING: Cmp, { unsafe { Ref::new(&*self.peripheral.get()) } } @@ -195,8 +216,10 @@ impl Peripheral> { let old_basepri = basepri::read(); basepri_max::write(::hw()); barrier!(); - let ret = f(Ref::new(&*self.peripheral.get()), - C { _marker: PhantomData }); + let ret = f( + Ref::new(&*self.peripheral.get()), + C { _marker: PhantomData }, + ); barrier!(); basepri::write(old_basepri); ret @@ -204,13 +227,18 @@ impl Peripheral> { } } -unsafe impl Sync for Peripheral where C: Ceiling {} +unsafe impl Sync for Peripheral +where + C: Ceiling, +{ +} /// A global critical section /// /// No task can preempt this critical section pub fn critical(f: F) -> R - where F: FnOnce(CMAX) -> R +where + F: FnOnce(CMAX) -> R, { let primask = ::cortex_m::register::primask::read(); ::cortex_m::interrupt::disable(); @@ -228,8 +256,9 @@ pub fn critical(f: F) -> R /// Requests the execution of a `task` pub fn request(_task: fn(T, P)) - where T: Context + Nr, - P: Priority +where + T: Context + Nr, + P: Priority, { let nvic = unsafe { &*NVIC.get() }; @@ -263,7 +292,8 @@ pub struct P { } impl P - where T: Level +where + T: Level, { #[doc(hidden)] pub fn hw() -> u8 {