aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-14 18:54:54 -0500
committerGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-14 18:57:02 -0500
commit98596554b3d88a7619bdbc3ac7462a95b7263e96 (patch)
treeb04a8e1e6011f741e045044389e6189d49abf78a /src
parent59afbf02aa06d976dfd22df4cb87fadf6027a0fb (diff)
downloadrtic-98596554b3d88a7619bdbc3ac7462a95b7263e96.tar.gz
rtic-98596554b3d88a7619bdbc3ac7462a95b7263e96.tar.zst
rtic-98596554b3d88a7619bdbc3ac7462a95b7263e96.zip
split macro parser into its own crate and improve error handling / reporting
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 23f3abd1..daca2d0d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -83,6 +83,14 @@ impl<P> Peripheral<P> {
}
#[inline(always)]
+ pub unsafe fn borrow<'cs>(
+ &'static self,
+ _cs: &'cs CriticalSection,
+ ) -> &'cs P {
+ &*self.peripheral.get()
+ }
+
+ #[inline(always)]
pub unsafe fn claim<R, F>(
&'static self,
ceiling: u8,
@@ -123,7 +131,25 @@ pub struct Resource<T> {
impl<T> Resource<T> {
pub const fn new(value: T) -> Self {
- Resource { data: UnsafeCell::new(value) }
+ Resource {
+ data: UnsafeCell::new(value),
+ }
+ }
+
+ #[inline(always)]
+ pub unsafe fn borrow<'cs>(
+ &'static self,
+ _cs: &'cs CriticalSection,
+ ) -> &'cs Static<T> {
+ Static::ref_(&*self.data.get())
+ }
+
+ #[inline(always)]
+ pub unsafe fn borrow_mut<'cs>(
+ &'static self,
+ _cs: &'cs CriticalSection,
+ ) -> &'cs mut Static<T> {
+ Static::ref_mut(&mut *self.data.get())
}
#[inline(always)]