diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2017-03-22 14:33:52 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2017-03-22 14:33:52 -0500 |
| commit | 85c628c2af6974ee7b13777f920ce54654d98f63 (patch) | |
| tree | 6ca6d7481a015dfbb62126c92379ab14be268ee6 /src | |
| parent | 441a8227804fc4609a94f062205bf2199beb38be (diff) | |
add methods to borrow resources within `interrupt::free`
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -11,6 +11,7 @@ extern crate cortex_m; use cortex_m::ctxt::Context; +use cortex_m::interrupt::CriticalSection; use cortex_m::peripheral::Peripheral; use cortex_m::register::{basepri, basepri_max}; @@ -76,6 +77,16 @@ where peripheral: p, } } + + /// Borrows the resource for the duration of `interrupt::free` + pub fn cs_borrow<'cs>(&self, _ctxt: &'cs CriticalSection) -> &'cs P { + unsafe { &*self.peripheral.get() } + } + + /// Mutably borrows the resource for the duration of `interrupt::free` + pub fn cs_borrow_mut<'cs>(&self, _ctxt: &'cs mut CriticalSection) -> &'cs mut P { + unsafe { &mut *self.peripheral.get() } + } } impl<P, C> ResourceP<P, C> @@ -171,6 +182,16 @@ impl<T, C> Resource<T, C> { data: UnsafeCell::new(data), } } + + /// Borrows the resource for the duration of `interrupt::free` + pub fn cs_borrow<'cs>(&self, _ctxt: &'cs CriticalSection) -> &'cs T { + unsafe { &*self.data.get() } + } + + /// Mutably borrows the resource for the duration of `interrupt::free` + pub fn cs_borrow_mut<'cs>(&self, _ctxt: &'cs mut CriticalSection) -> &'cs mut T { + unsafe { &mut *self.data.get() } + } } impl<T, C> Resource<T, C> |
