Skip to content

Commit

Permalink
Merge pull request #265 from rmsyn/riscv/sip-csr-macro
Browse files Browse the repository at this point in the history
riscv: define `sip` CSR with macro helpers
  • Loading branch information
romancardenas authored Feb 12, 2025
2 parents edb3e6c + a093eb8 commit f463f22
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Use CSR helper macros to define `scause` field types
- Use CSR helper macros to define `sie` register
- Use CSR helper macros to define `scounteren` field types
- Use CSR helper macros to define `sip` register

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

Expand Down
56 changes: 32 additions & 24 deletions riscv/src/register/sip.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
//! sip register
/// sip register
#[derive(Clone, Copy, Debug)]
pub struct Sip {
bits: usize,
read_write_csr! {
/// sip register
Sip: 0x144,
mask: 0x222,
}

impl Sip {
/// Returns the contents of the register as raw bits
#[inline]
pub fn bits(&self) -> usize {
self.bits
}

read_write_csr_field! {
Sip,
/// Supervisor Software Interrupt Pending
#[inline]
pub fn ssoft(&self) -> bool {
self.bits & (1 << 1) != 0
}
ssoft: 1,
}

read_only_csr_field! {
Sip,
/// Supervisor Timer Interrupt Pending
#[inline]
pub fn stimer(&self) -> bool {
self.bits & (1 << 5) != 0
}
stimer: 5,
}

read_only_csr_field! {
Sip,
/// Supervisor External Interrupt Pending
#[inline]
pub fn sext(&self) -> bool {
self.bits & (1 << 9) != 0
}
sext: 9,
}

read_csr_as!(Sip, 0x144);
set!(0x144);
clear!(0x144);

set_clear_csr!(
/// Supervisor Software Interrupt Pending
, set_ssoft, clear_ssoft, 1 << 1);

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_sip() {
let mut sip = Sip::from_bits(0);

test_csr_field!(sip, ssoft);
assert!(!sip.stimer());
assert!(!sip.sext());

assert!(Sip::from_bits(1 << 5).stimer());
assert!(Sip::from_bits(1 << 9).sext());
}
}

0 comments on commit f463f22

Please sign in to comment.