@@ -9,19 +9,19 @@ pub struct Control {
99impl Control {
1010 /// Creates a `Control` value from raw bits.
1111 #[ inline]
12- pub fn from_bits ( bits : u32 ) -> Self {
12+ pub const fn from_bits ( bits : u32 ) -> Self {
1313 Self { bits }
1414 }
1515
1616 /// Returns the contents of the register as raw bits
1717 #[ inline]
18- pub fn bits ( self ) -> u32 {
18+ pub const fn bits ( self ) -> u32 {
1919 self . bits
2020 }
2121
2222 /// Thread mode privilege level
2323 #[ inline]
24- pub fn npriv ( self ) -> Npriv {
24+ pub const fn npriv ( self ) -> Npriv {
2525 if self . bits & ( 1 << 0 ) == ( 1 << 0 ) {
2626 Npriv :: Unprivileged
2727 } else {
@@ -31,7 +31,7 @@ impl Control {
3131
3232 /// Sets the thread mode privilege level value (nPRIV).
3333 #[ inline]
34- pub fn set_npriv ( & mut self , npriv : Npriv ) {
34+ pub const fn set_npriv ( & mut self , npriv : Npriv ) {
3535 let mask = 1 << 0 ;
3636 match npriv {
3737 Npriv :: Unprivileged => self . bits |= mask,
@@ -41,7 +41,7 @@ impl Control {
4141
4242 /// Currently active stack pointer
4343 #[ inline]
44- pub fn spsel ( self ) -> Spsel {
44+ pub const fn spsel ( self ) -> Spsel {
4545 if self . bits & ( 1 << 1 ) == ( 1 << 1 ) {
4646 Spsel :: Psp
4747 } else {
@@ -51,7 +51,7 @@ impl Control {
5151
5252 /// Sets the SPSEL value.
5353 #[ inline]
54- pub fn set_spsel ( & mut self , spsel : Spsel ) {
54+ pub const fn set_spsel ( & mut self , spsel : Spsel ) {
5555 let mask = 1 << 1 ;
5656 match spsel {
5757 Spsel :: Psp => self . bits |= mask,
@@ -61,7 +61,7 @@ impl Control {
6161
6262 /// Whether context floating-point is currently active
6363 #[ inline]
64- pub fn fpca ( self ) -> Fpca {
64+ pub const fn fpca ( self ) -> Fpca {
6565 if self . bits & ( 1 << 2 ) == ( 1 << 2 ) {
6666 Fpca :: Active
6767 } else {
@@ -71,7 +71,7 @@ impl Control {
7171
7272 /// Sets the FPCA value.
7373 #[ inline]
74- pub fn set_fpca ( & mut self , fpca : Fpca ) {
74+ pub const fn set_fpca ( & mut self , fpca : Fpca ) {
7575 let mask = 1 << 2 ;
7676 match fpca {
7777 Fpca :: Active => self . bits |= mask,
@@ -92,14 +92,17 @@ pub enum Npriv {
9292impl Npriv {
9393 /// Is in privileged thread mode?
9494 #[ inline]
95- pub fn is_privileged ( self ) -> bool {
96- self == Npriv :: Privileged
95+ pub const fn is_privileged ( self ) -> bool {
96+ match self {
97+ Npriv :: Privileged => true ,
98+ Npriv :: Unprivileged => false ,
99+ }
97100 }
98101
99102 /// Is in unprivileged thread mode?
100103 #[ inline]
101- pub fn is_unprivileged ( self ) -> bool {
102- self == Npriv :: Unprivileged
104+ pub const fn is_unprivileged ( self ) -> bool {
105+ ! self . is_privileged ( )
103106 }
104107}
105108
@@ -115,14 +118,17 @@ pub enum Spsel {
115118impl Spsel {
116119 /// Is MSP the current stack pointer?
117120 #[ inline]
118- pub fn is_msp ( self ) -> bool {
119- self == Spsel :: Msp
121+ pub const fn is_msp ( self ) -> bool {
122+ match self {
123+ Spsel :: Msp => true ,
124+ Spsel :: Psp => false ,
125+ }
120126 }
121127
122128 /// Is PSP the current stack pointer?
123129 #[ inline]
124- pub fn is_psp ( self ) -> bool {
125- self == Spsel :: Psp
130+ pub const fn is_psp ( self ) -> bool {
131+ ! self . is_msp ( )
126132 }
127133}
128134
@@ -138,14 +144,17 @@ pub enum Fpca {
138144impl Fpca {
139145 /// Is a floating-point context active?
140146 #[ inline]
141- pub fn is_active ( self ) -> bool {
142- self == Fpca :: Active
147+ pub const fn is_active ( self ) -> bool {
148+ match self {
149+ Fpca :: Active => true ,
150+ Fpca :: NotActive => false ,
151+ }
143152 }
144153
145154 /// Is a floating-point context not active?
146155 #[ inline]
147- pub fn is_not_active ( self ) -> bool {
148- self == Fpca :: NotActive
156+ pub const fn is_not_active ( self ) -> bool {
157+ ! self . is_active ( )
149158 }
150159}
151160
0 commit comments