1
+ //! Abstractions common to microcontrollers
2
+
3
+ #![ deny( missing_docs) ]
4
+ #![ deny( warnings) ]
1
5
#![ feature( const_fn) ]
2
6
#![ no_std]
3
7
4
- use core:: cell:: UnsafeCell ;
5
8
use core:: marker:: PhantomData ;
6
-
7
- pub mod ctxt;
9
+ use core:: cell:: UnsafeCell ;
8
10
9
11
/// A peripheral
10
12
#[ derive( Debug ) ]
@@ -46,6 +48,10 @@ pub struct CriticalSection {
46
48
}
47
49
48
50
impl CriticalSection {
51
+ /// Creates a critical section token
52
+ ///
53
+ /// This method is meant to be used to create safe abstractions rather than
54
+ /// meant to be directly used in applications.
49
55
pub unsafe fn new ( ) -> Self {
50
56
CriticalSection { _0 : ( ) }
51
57
}
@@ -65,22 +71,22 @@ impl<T> Mutex<T> {
65
71
66
72
impl < T > Mutex < T > {
67
73
/// Borrows the data for the duration of the critical section
68
- pub fn borrow < ' cs > ( & self , _ctxt : & ' cs CriticalSection ) -> & ' cs T {
74
+ pub fn borrow < ' cs > ( & self , _cs : & ' cs CriticalSection ) -> & ' cs T {
69
75
unsafe { & * self . inner . get ( ) }
70
76
}
71
77
}
72
78
73
- // NOTE `Mutex` can be used as a channel so, the protected data must be `Send`
74
- // to prevent sending non-Sendable stuff (e.g. interrupt tokens) across
75
- // different execution contexts (e.g. interrupts)
79
+ /// Interrupt number
80
+ pub unsafe trait Nr {
81
+ /// Returns the number associated with an interrupt
82
+ fn nr ( & self ) -> u8 ;
83
+ }
84
+
85
+ // NOTE A `Mutex` can be used as a channel so the protected data must be `Send`
86
+ // to prevent sending non-Sendable stuff (e.g. access tokens) across different
87
+ // execution contexts (e.g. interrupts)
76
88
unsafe impl < T > Sync for Mutex < T >
77
89
where
78
90
T : Send ,
79
91
{
80
92
}
81
-
82
- /// Interrupt number
83
- pub unsafe trait Nr {
84
- /// Returns the number associated with this interrupt
85
- fn nr ( & self ) -> u8 ;
86
- }
0 commit comments