Skip to content

Commit f463f22

Browse files
Merge pull request #265 from rmsyn/riscv/sip-csr-macro
riscv: define `sip` CSR with macro helpers
2 parents edb3e6c + a093eb8 commit f463f22

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

Diff for: riscv/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3636
- Use CSR helper macros to define `scause` field types
3737
- Use CSR helper macros to define `sie` register
3838
- Use CSR helper macros to define `scounteren` field types
39+
- Use CSR helper macros to define `sip` register
3940

4041
## [v0.12.1] - 2024-10-20
4142

Diff for: riscv/src/register/sip.rs

+32-24
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
11
//! sip register
22
3-
/// sip register
4-
#[derive(Clone, Copy, Debug)]
5-
pub struct Sip {
6-
bits: usize,
3+
read_write_csr! {
4+
/// sip register
5+
Sip: 0x144,
6+
mask: 0x222,
77
}
88

9-
impl Sip {
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+
Sip,
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+
Sip,
2217
/// Supervisor Timer Interrupt Pending
23-
#[inline]
24-
pub fn stimer(&self) -> bool {
25-
self.bits & (1 << 5) != 0
26-
}
18+
stimer: 5,
19+
}
2720

21+
read_only_csr_field! {
22+
Sip,
2823
/// Supervisor External Interrupt Pending
29-
#[inline]
30-
pub fn sext(&self) -> bool {
31-
self.bits & (1 << 9) != 0
32-
}
24+
sext: 9,
3325
}
3426

35-
read_csr_as!(Sip, 0x144);
3627
set!(0x144);
3728
clear!(0x144);
3829

3930
set_clear_csr!(
4031
/// Supervisor Software Interrupt Pending
4132
, set_ssoft, clear_ssoft, 1 << 1);
33+
34+
#[cfg(test)]
35+
mod tests {
36+
use super::*;
37+
38+
#[test]
39+
fn test_sip() {
40+
let mut sip = Sip::from_bits(0);
41+
42+
test_csr_field!(sip, ssoft);
43+
assert!(!sip.stimer());
44+
assert!(!sip.sext());
45+
46+
assert!(Sip::from_bits(1 << 5).stimer());
47+
assert!(Sip::from_bits(1 << 9).sext());
48+
}
49+
}

0 commit comments

Comments
 (0)