Skip to content

Commit

Permalink
Merge pull request rust-embedded#198 from dreiss/master
Browse files Browse the repository at this point in the history
Add some utility methods to Mstatus and Mcause
  • Loading branch information
almindor authored Mar 27, 2024
2 parents 62a54a7 + b3c100a commit aca6410
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Add `Mcause::from(usize)` for use in unit tests
- Add `Mstatus.bits()`

### Fixed

- Fixed `sip::set_ssoft` and `sip::clear_ssoft` using wrong address
Expand Down
7 changes: 7 additions & 0 deletions riscv/src/register/mcause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ pub struct Mcause {
bits: usize,
}

impl From<usize> for Mcause {
#[inline]
fn from(bits: usize) -> Self {
Self { bits }
}
}

/// Trap Cause
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Trap {
Expand Down
6 changes: 6 additions & 0 deletions riscv/src/register/mstatus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ impl From<bool> for Endianness {
}

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

/// Supervisor Interrupt Enable
#[inline]
pub fn sie(&self) -> bool {
Expand Down

0 comments on commit aca6410

Please sign in to comment.