-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
riscv: define mvendorid CSR with macro helpers
Uses CSR macro helpers to define the `mvendorid` CSR register.
- Loading branch information
Showing
2 changed files
with
6 additions
and
31 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,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, | ||
} |