@@ -168,13 +168,32 @@ impl SCB {
168168}
169169
170170impl 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+
171190 /// Returns the `Vector` containing the active exception number.
172191 #[ inline]
173192 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 ( ) ;
175194 let isrn = ( icsr & 0x1FF ) as u16 ;
176195
177- // NOTE(unsafe) : `isrn` is in range [0, 511] and contains
196+ // SAFETY : `isrn` is in range [0, 511] and contains
178197 // a valid `Exception` if in range [2, 15].
179198 unsafe { Vector :: new_unchecked ( isrn) }
180199 }
@@ -283,7 +302,7 @@ impl TryFrom<i8> for Exception {
283302 }
284303}
285304
286- /// Exception/Interrupt Vector
305+ /// Active exception number
287306#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
288307#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
289308#[ cfg_attr( feature = "std" , derive( PartialOrd , Hash ) ) ]
0 commit comments