Skip to content

Commit e884b55

Browse files
romancardenasrmsyn
andauthored
Apply suggestions from code review
Co-authored-by: rmsyn <[email protected]>
1 parent 350fec3 commit e884b55

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

riscv/src/register/mie.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! mie register
22
33
use riscv_pac::CoreInterruptNumber;
4+
use crate::bits::{bf_extract, bf_insert};
45

56
read_write_csr! {
67
/// `mie` register
@@ -48,19 +49,19 @@ impl Mie {
4849
/// Check if a specific core interrupt source is enabled.
4950
#[inline]
5051
pub fn is_enabled<I: CoreInterruptNumber>(&self, interrupt: I) -> bool {
51-
(self.bits & (1 << interrupt.number())) != 0
52+
bf_extract(self.bits, interrupt.number(), 1) != 0
5253
}
5354

5455
/// Enable a specific core interrupt source.
5556
#[inline]
5657
pub fn enable<I: CoreInterruptNumber>(&mut self, interrupt: I) {
57-
self.bits |= 1 << interrupt.number();
58+
self.bits = bf_insert(self.bits, interrupt.number(), 1, 1);
5859
}
5960

6061
/// Disable a specific core interrupt source.
6162
#[inline]
6263
pub fn disable<I: CoreInterruptNumber>(&mut self, interrupt: I) {
63-
self.bits &= !(1 << interrupt.number());
64+
self.bits = bf_insert(self.bits, interrupt.number(), 1, 0);
6465
}
6566
}
6667

riscv/src/register/sie.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! sie register
22
33
use riscv_pac::CoreInterruptNumber;
4+
use crate::bits::{bf_insert, bf_extract};
45

56
read_write_csr! {
67
/// sie register
@@ -30,19 +31,19 @@ impl Sie {
3031
/// Check if a specific core interrupt source is enabled.
3132
#[inline]
3233
pub fn is_enabled<I: CoreInterruptNumber>(&self, interrupt: I) -> bool {
33-
(self.bits & (1 << interrupt.number())) != 0
34+
bf_extract(self.bits, interrupt.number(), 1) != 0
3435
}
3536

3637
/// Enable a specific core interrupt source.
3738
#[inline]
3839
pub fn enable<I: CoreInterruptNumber>(&mut self, interrupt: I) {
39-
self.bits |= 1 << interrupt.number();
40+
self.bits = bf_insert(self.bits, interrupt.number(), 1, 1);
4041
}
4142

4243
/// Disable a specific core interrupt source.
4344
#[inline]
4445
pub fn disable<I: CoreInterruptNumber>(&mut self, interrupt: I) {
45-
self.bits &= !(1 << interrupt.number());
46+
self.bits = bf_insert(self.bits, interrupt.number(), 1, 0);
4647
}
4748
}
4849

0 commit comments

Comments
 (0)