-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from rmsyn/riscv/sip-csr-macro
riscv: define `sip` CSR with macro helpers
- Loading branch information
Showing
2 changed files
with
33 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |