@@ -9,19 +9,19 @@ pub struct Control {
9
9
impl Control {
10
10
/// Creates a `Control` value from raw bits.
11
11
#[ inline]
12
- pub fn from_bits ( bits : u32 ) -> Self {
12
+ pub const fn from_bits ( bits : u32 ) -> Self {
13
13
Self { bits }
14
14
}
15
15
16
16
/// Returns the contents of the register as raw bits
17
17
#[ inline]
18
- pub fn bits ( self ) -> u32 {
18
+ pub const fn bits ( self ) -> u32 {
19
19
self . bits
20
20
}
21
21
22
22
/// Thread mode privilege level
23
23
#[ inline]
24
- pub fn npriv ( self ) -> Npriv {
24
+ pub const fn npriv ( self ) -> Npriv {
25
25
if self . bits & ( 1 << 0 ) == ( 1 << 0 ) {
26
26
Npriv :: Unprivileged
27
27
} else {
@@ -31,7 +31,7 @@ impl Control {
31
31
32
32
/// Sets the thread mode privilege level value (nPRIV).
33
33
#[ inline]
34
- pub fn set_npriv ( & mut self , npriv : Npriv ) {
34
+ pub const fn set_npriv ( & mut self , npriv : Npriv ) {
35
35
let mask = 1 << 0 ;
36
36
match npriv {
37
37
Npriv :: Unprivileged => self . bits |= mask,
@@ -41,7 +41,7 @@ impl Control {
41
41
42
42
/// Currently active stack pointer
43
43
#[ inline]
44
- pub fn spsel ( self ) -> Spsel {
44
+ pub const fn spsel ( self ) -> Spsel {
45
45
if self . bits & ( 1 << 1 ) == ( 1 << 1 ) {
46
46
Spsel :: Psp
47
47
} else {
@@ -51,7 +51,7 @@ impl Control {
51
51
52
52
/// Sets the SPSEL value.
53
53
#[ inline]
54
- pub fn set_spsel ( & mut self , spsel : Spsel ) {
54
+ pub const fn set_spsel ( & mut self , spsel : Spsel ) {
55
55
let mask = 1 << 1 ;
56
56
match spsel {
57
57
Spsel :: Psp => self . bits |= mask,
@@ -61,7 +61,7 @@ impl Control {
61
61
62
62
/// Whether context floating-point is currently active
63
63
#[ inline]
64
- pub fn fpca ( self ) -> Fpca {
64
+ pub const fn fpca ( self ) -> Fpca {
65
65
if self . bits & ( 1 << 2 ) == ( 1 << 2 ) {
66
66
Fpca :: Active
67
67
} else {
@@ -71,7 +71,7 @@ impl Control {
71
71
72
72
/// Sets the FPCA value.
73
73
#[ inline]
74
- pub fn set_fpca ( & mut self , fpca : Fpca ) {
74
+ pub const fn set_fpca ( & mut self , fpca : Fpca ) {
75
75
let mask = 1 << 2 ;
76
76
match fpca {
77
77
Fpca :: Active => self . bits |= mask,
@@ -92,14 +92,17 @@ pub enum Npriv {
92
92
impl Npriv {
93
93
/// Is in privileged thread mode?
94
94
#[ 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
+ }
97
100
}
98
101
99
102
/// Is in unprivileged thread mode?
100
103
#[ inline]
101
- pub fn is_unprivileged ( self ) -> bool {
102
- self == Npriv :: Unprivileged
104
+ pub const fn is_unprivileged ( self ) -> bool {
105
+ ! self . is_privileged ( )
103
106
}
104
107
}
105
108
@@ -115,14 +118,17 @@ pub enum Spsel {
115
118
impl Spsel {
116
119
/// Is MSP the current stack pointer?
117
120
#[ 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
+ }
120
126
}
121
127
122
128
/// Is PSP the current stack pointer?
123
129
#[ inline]
124
- pub fn is_psp ( self ) -> bool {
125
- self == Spsel :: Psp
130
+ pub const fn is_psp ( self ) -> bool {
131
+ ! self . is_msp ( )
126
132
}
127
133
}
128
134
@@ -138,14 +144,17 @@ pub enum Fpca {
138
144
impl Fpca {
139
145
/// Is a floating-point context active?
140
146
#[ 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
+ }
143
152
}
144
153
145
154
/// Is a floating-point context not active?
146
155
#[ 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 ( )
149
158
}
150
159
}
151
160
0 commit comments