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