@@ -1014,6 +1014,20 @@ impl SCB {
1014
1014
}
1015
1015
}
1016
1016
1017
+ /// Return the bit position of the exception enable bit in the SHCSR register
1018
+ #[ inline]
1019
+ #[ cfg( not( any( armv6m, armv8m_base) ) ) ]
1020
+ fn shcsr_enable_shift ( exception : Exception ) -> Option < u32 > {
1021
+ match exception {
1022
+ Exception :: MemoryManagement => Some ( 16 ) ,
1023
+ Exception :: BusFault => Some ( 17 ) ,
1024
+ Exception :: UsageFault => Some ( 18 ) ,
1025
+ #[ cfg( armv8m_main) ]
1026
+ Exception :: SecureFault => Some ( 19 ) ,
1027
+ _ => None ,
1028
+ }
1029
+ }
1030
+
1017
1031
/// Enable the exception
1018
1032
///
1019
1033
/// If the exception is enabled, when the exception is triggered, the exception handler will be executed instead of the
@@ -1032,20 +1046,11 @@ impl SCB {
1032
1046
return ;
1033
1047
}
1034
1048
1035
- // Make sure that the read-modify-write sequence happens during a critical section to avoid
1036
- // modifying pending and active interrupts.
1037
- interrupt:: free ( |_| {
1038
- let shift = match exception {
1039
- Exception :: MemoryManagement => 16 ,
1040
- Exception :: BusFault => 17 ,
1041
- Exception :: UsageFault => 18 ,
1042
- #[ cfg( armv8m_main) ]
1043
- Exception :: SecureFault => 19 ,
1044
- _ => return ,
1045
- } ;
1046
-
1047
- unsafe { self . shcsr . modify ( |value| value | ( 1 << shift) ) }
1048
- } )
1049
+ if let Some ( shift) = SCB :: shcsr_enable_shift ( exception) {
1050
+ // Make sure that the read-modify-write sequence happens during a critical section to
1051
+ // avoid modifying pending and active interrupts.
1052
+ interrupt:: free ( |_| unsafe { self . shcsr . modify ( |value| value | ( 1 << shift) ) } )
1053
+ }
1049
1054
}
1050
1055
1051
1056
/// Disable the exception
@@ -1066,20 +1071,11 @@ impl SCB {
1066
1071
return ;
1067
1072
}
1068
1073
1069
- // Make sure that the read-modify-write sequence happens during a critical section to avoid
1070
- // modifying pending and active interrupts.
1071
- interrupt:: free ( |_| {
1072
- let shift = match exception {
1073
- Exception :: MemoryManagement => 16 ,
1074
- Exception :: BusFault => 17 ,
1075
- Exception :: UsageFault => 18 ,
1076
- #[ cfg( armv8m_main) ]
1077
- Exception :: SecureFault => 19 ,
1078
- _ => return ,
1079
- } ;
1080
-
1081
- unsafe { self . shcsr . modify ( |value| value & !( 1 << shift) ) }
1082
- } )
1074
+ if let Some ( shift) = SCB :: shcsr_enable_shift ( exception) {
1075
+ // Make sure that the read-modify-write sequence happens during a critical section to
1076
+ // avoid modifying pending and active interrupts.
1077
+ interrupt:: free ( |_| unsafe { self . shcsr . modify ( |value| value & !( 1 << shift) ) } )
1078
+ }
1083
1079
}
1084
1080
1085
1081
/// Check if an exception is enabled
@@ -1094,15 +1090,10 @@ impl SCB {
1094
1090
#[ inline]
1095
1091
#[ cfg( not( any( armv6m, armv8m_base) ) ) ]
1096
1092
pub fn is_enabled ( & mut self , exception : Exception ) -> bool {
1097
- let shift = match exception {
1098
- Exception :: MemoryManagement => 16 ,
1099
- Exception :: BusFault => 17 ,
1100
- Exception :: UsageFault => 18 ,
1101
- #[ cfg( armv8m_main) ]
1102
- Exception :: SecureFault => 19 ,
1103
- _ => return false ,
1104
- } ;
1105
-
1106
- ( self . shcsr . read ( ) & ( 1 << shift) ) > 0
1093
+ if let Some ( shift) = SCB :: shcsr_enable_shift ( exception) {
1094
+ ( self . shcsr . read ( ) & ( 1 << shift) ) > 0
1095
+ } else {
1096
+ false
1097
+ }
1107
1098
}
1108
1099
}
0 commit comments