Skip to content

Commit 4605597

Browse files
Merge pull request #240 from rmsyn/riscv/mie-csr-macro
riscv: define mie using CSR macros
2 parents 29dd75d + f5eef5b commit 4605597

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

riscv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919
- Use CSR helper macros to define `medeleg` register
2020
- Use CSR helper macros to define `mideleg` register
2121
- Use CSR helper macros to define `mcounteren` register
22+
- Use CSR helper macros to define `mie` register
2223

2324
## [v0.12.1] - 2024-10-20
2425

riscv/src/register/mie.rs

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

9-
impl Mie {
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+
Mie,
1611
/// Supervisor Software Interrupt Enable
17-
#[inline]
18-
pub fn ssoft(&self) -> bool {
19-
self.bits & (1 << 1) != 0
20-
}
12+
ssoft: 1,
13+
}
2114

15+
read_write_csr_field! {
16+
Mie,
2217
/// Machine Software Interrupt Enable
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+
Mie,
2823
/// Supervisor Timer Interrupt Enable
29-
#[inline]
30-
pub fn stimer(&self) -> bool {
31-
self.bits & (1 << 5) != 0
32-
}
24+
stimer: 5,
25+
}
3326

27+
read_write_csr_field! {
28+
Mie,
3429
/// Machine Timer Interrupt Enable
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+
Mie,
4035
/// Supervisor External Interrupt Enable
41-
#[inline]
42-
pub fn sext(&self) -> bool {
43-
self.bits & (1 << 9) != 0
44-
}
36+
sext: 9,
37+
}
4538

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

53-
read_csr_as!(Mie, 0x304);
5445
set!(0x304);
5546
clear!(0x304);
5647

@@ -72,3 +63,20 @@ set_clear_csr!(
7263
set_clear_csr!(
7364
/// Machine External Interrupt Enable
7465
, set_mext, clear_mext, 1 << 11);
66+
67+
#[cfg(test)]
68+
mod tests {
69+
use super::*;
70+
71+
#[test]
72+
fn test_mie() {
73+
let mut m = Mie::from_bits(0);
74+
75+
test_csr_field!(m, ssoft);
76+
test_csr_field!(m, msoft);
77+
test_csr_field!(m, stimer);
78+
test_csr_field!(m, mtimer);
79+
test_csr_field!(m, sext);
80+
test_csr_field!(m, mext);
81+
}
82+
}

0 commit comments

Comments
 (0)