Skip to content

Commit

Permalink
riscv: define mvendorid CSR with macro helpers
Browse files Browse the repository at this point in the history
Uses CSR macro helpers to define the `mvendorid` CSR register.
  • Loading branch information
rmsyn committed Jan 11, 2025
1 parent bc21d25 commit 2a24146
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
1 change: 1 addition & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Use CSR helper macros to define `mstatus` register
- Use CSR helper macros to define `mstatush` register
- Use CSR helper macros to define `mtvec` register
- Use CSR helper macros to define `mtvendorid` register

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

Expand Down
36 changes: 5 additions & 31 deletions riscv/src/register/mvendorid.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
//! mvendorid register
use core::num::NonZeroUsize;

/// mvendorid register
#[derive(Clone, Copy, Debug)]
pub struct Mvendorid {
bits: NonZeroUsize,
}

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

/// Returns the JEDEC manufacturer ID
#[inline]
pub fn jedec_manufacturer(&self) -> usize {
self.bits() >> 7
}
}

read_csr!(0xF11);

/// Reads the CSR
#[inline]
pub fn read() -> Option<Mvendorid> {
let r = unsafe { _read() };
// When mvendorid is hardwired to zero it means that the mvendorid
// csr isn't implemented.
NonZeroUsize::new(r).map(|bits| Mvendorid { bits })
read_only_csr! {
/// `mvendorid` register
Mvendorid: 0xF11,
mask: 0xffff_ffff,
sentinel: 0,
}

0 comments on commit 2a24146

Please sign in to comment.