@@ -119,6 +119,24 @@ mod fpu_consts {
119119#[ cfg( has_fpu) ]
120120use self :: fpu_consts:: * ;
121121
122+ /// Priority Grouping
123+ ///
124+ /// Determines the split of group priority from subpriority.
125+ #[ derive( Debug , Clone , Copy ) ]
126+ #[ repr( u8 ) ]
127+ pub enum PriorityGrouping {
128+ /// 4 bits for group priorities, 0 bits for subpriorities
129+ Group4Sub0 = 0b011 , // 0b0xx
130+ /// 3 bits for group priorities, 1 bit for subpriorities
131+ Group3Sub1 = 0b100 ,
132+ /// 2 bits for group priorities, 2 bits for subpriorities
133+ Group2Sub2 = 0b101 ,
134+ /// 1 bit for group priorities, 3 bits for subpriorities
135+ Group1Sub3 = 0b110 ,
136+ /// 0 bits for group priorities, 4 bits for subpriorities
137+ Group0Sub4 = 0b111 ,
138+ }
139+
122140#[ cfg( has_fpu) ]
123141impl SCB {
124142 /// Shorthand for `set_fpu_access_mode(FpuAccessMode::Disabled)`
@@ -839,7 +857,8 @@ impl SCB {
839857}
840858
841859const SCB_AIRCR_VECTKEY : u32 = 0x05FA << 16 ;
842- const SCB_AIRCR_PRIGROUP_MASK : u32 = 0x7 << 8 ;
860+ const SCB_AIRCR_PRIGROUP_POS : u32 = 8 ;
861+ const SCB_AIRCR_PRIGROUP_MASK : u32 = 0x7 << SCB_AIRCR_PRIGROUP_POS ;
843862const SCB_AIRCR_SYSRESETREQ : u32 = 1 << 2 ;
844863
845864impl SCB {
@@ -848,20 +867,41 @@ impl SCB {
848867 pub fn sys_reset ( ) -> ! {
849868 crate :: asm:: dsb ( ) ;
850869 unsafe {
851- ( * Self :: PTR ) . aircr . modify (
852- |r| {
853- SCB_AIRCR_VECTKEY | // otherwise the write is ignored
854- r & SCB_AIRCR_PRIGROUP_MASK | // keep priority group unchanged
855- SCB_AIRCR_SYSRESETREQ
856- } , // set the bit
857- )
870+ ( * Self :: PTR ) . aircr . modify ( |r| {
871+ SCB_AIRCR_VECTKEY | // Unlock for writing.
872+ r & SCB_AIRCR_PRIGROUP_MASK | // Keep priority grouping unchanged.
873+ SCB_AIRCR_SYSRESETREQ // Set reset bit.
874+ } )
858875 } ;
859876 crate :: asm:: dsb ( ) ;
860877 loop {
861878 // wait for the reset
862879 crate :: asm:: nop ( ) ; // avoid rust-lang/rust#28728
863880 }
864881 }
882+
883+ /// Set the priority grouping.
884+ #[ inline]
885+ pub fn set_priority_grouping ( & mut self , grouping : PriorityGrouping ) {
886+ unsafe {
887+ self . aircr . write ( {
888+ SCB_AIRCR_VECTKEY | // Unlock for writing.
889+ ( grouping as u32 ) << SCB_AIRCR_PRIGROUP_POS
890+ } ) ;
891+ }
892+ }
893+
894+ /// Get the priority grouping.
895+ #[ inline]
896+ pub fn get_priority_grouping ( & self ) -> PriorityGrouping {
897+ match self . aircr . read ( ) & SCB_AIRCR_PRIGROUP_MASK >> SCB_AIRCR_PRIGROUP_POS {
898+ 0b111 => PriorityGrouping :: Group0Sub4 ,
899+ 0b110 => PriorityGrouping :: Group1Sub3 ,
900+ 0b101 => PriorityGrouping :: Group2Sub2 ,
901+ 0b100 => PriorityGrouping :: Group3Sub1 ,
902+ /* 0b0xx */ _ => PriorityGrouping :: Group4Sub0 ,
903+ }
904+ }
865905}
866906
867907const SCB_ICSR_PENDSVSET : u32 = 1 << 28 ;
0 commit comments