Skip to content

Commit ffe20a5

Browse files
committed
riscv: define mip using CSR macros
Uses CSR helper macros to define the `mip` register.
1 parent 517d52b commit ffe20a5

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

riscv/src/register/mip.rs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,47 @@
11
//! mip register
22
3-
/// mip register
4-
#[derive(Clone, Copy, Debug)]
5-
pub struct Mip {
6-
bits: usize,
3+
read_write_csr! {
4+
/// `mip` register
5+
Mip: 0x344,
6+
mask: 0xaaa,
77
}
88

9-
impl Mip {
10-
/// Returns the contents of the register as raw bits
11-
#[inline]
12-
pub fn bits(&self) -> usize {
13-
self.bits
14-
}
15-
9+
read_write_csr_field! {
10+
Mip,
1611
/// Supervisor Software Interrupt Pending
17-
#[inline]
18-
pub fn ssoft(&self) -> bool {
19-
self.bits & (1 << 1) != 0
20-
}
12+
ssoft: 1,
13+
}
2114

15+
read_only_csr_field! {
16+
Mip,
2217
/// Machine Software Interrupt Pending
23-
#[inline]
24-
pub fn msoft(&self) -> bool {
25-
self.bits & (1 << 3) != 0
26-
}
18+
msoft: 3,
19+
}
2720

21+
read_write_csr_field! {
22+
Mip,
2823
/// Supervisor Timer Interrupt Pending
29-
#[inline]
30-
pub fn stimer(&self) -> bool {
31-
self.bits & (1 << 5) != 0
32-
}
24+
stimer: 5,
25+
}
3326

27+
read_only_csr_field! {
28+
Mip,
3429
/// Machine Timer Interrupt Pending
35-
#[inline]
36-
pub fn mtimer(&self) -> bool {
37-
self.bits & (1 << 7) != 0
38-
}
30+
mtimer: 7,
31+
}
3932

33+
read_write_csr_field! {
34+
Mip,
4035
/// Supervisor External Interrupt Pending
41-
#[inline]
42-
pub fn sext(&self) -> bool {
43-
self.bits & (1 << 9) != 0
44-
}
36+
sext: 9,
37+
}
4538

39+
read_only_csr_field! {
40+
Mip,
4641
/// Machine External Interrupt Pending
47-
#[inline]
48-
pub fn mext(&self) -> bool {
49-
self.bits & (1 << 11) != 0
50-
}
42+
mext: 11,
5143
}
5244

53-
read_csr_as!(Mip, 0x344);
5445
set!(0x344);
5546
clear!(0x344);
5647

0 commit comments

Comments
 (0)