@@ -168,13 +168,33 @@ impl SCB {
168
168
}
169
169
170
170
impl SCB {
171
+ #[ inline]
172
+ fn icsr ( ) -> u32 {
173
+ unsafe { ptr:: read_volatile ( & ( * Self :: PTR ) . icsr as * const _ as * const u32 ) }
174
+ }
175
+
176
+ /// Return the `Vector` containing the pending exception number, if any.
177
+ #[ inline]
178
+ pub fn vect_pending ( ) -> Option < Vector > {
179
+ let icsr = Self :: icsr ( ) ;
180
+ let isrn = ( ( icsr >> 12 ) & 0x7F ) as u16 ;
181
+
182
+ match isrn {
183
+ // No pending exceptions.
184
+ 0 => return None ,
185
+ // SAFETY: `isrn` is in range [1, 127] and contains
186
+ // a valid `Exception` if in range [2, 15].
187
+ isrn => unsafe { Some ( Vector :: new_unchecked ( isrn) ) } ,
188
+ }
189
+ }
190
+
171
191
/// Returns the `Vector` containing the active exception number.
172
192
#[ inline]
173
193
pub fn vect_active ( ) -> Vector {
174
- let icsr = unsafe { ptr :: read_volatile ( & ( * SCB :: PTR ) . icsr as * const _ as * const u32 ) } ;
194
+ let icsr = Self :: icsr ( ) ;
175
195
let isrn = ( icsr & 0x1FF ) as u16 ;
176
196
177
- // NOTE(unsafe) : `isrn` is in range [0, 511] and contains
197
+ // SAFETY : `isrn` is in range [0, 511] and contains
178
198
// a valid `Exception` if in range [2, 15].
179
199
unsafe { Vector :: new_unchecked ( isrn) }
180
200
}
@@ -283,7 +303,7 @@ impl TryFrom<i8> for Exception {
283
303
}
284
304
}
285
305
286
- /// Exception/Interrupt Vector
306
+ /// Active exception number
287
307
#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
288
308
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
289
309
#[ cfg_attr( feature = "std" , derive( PartialOrd , Hash ) ) ]
0 commit comments