Skip to content

Commit 22cbf3a

Browse files
committed
riscv: define mvendorid CSR with macro helpers
Uses CSR macro helpers to define the `mvendorid` CSR register.
1 parent bc21d25 commit 22cbf3a

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

Diff for: riscv/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2828
- Use CSR helper macros to define `mstatus` register
2929
- Use CSR helper macros to define `mstatush` register
3030
- Use CSR helper macros to define `mtvec` register
31+
- Use CSR helper macros to define `mtvendorid` register
3132

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

Diff for: riscv/src/register/mvendorid.rs

+17-27
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
//! mvendorid register
22
3-
use core::num::NonZeroUsize;
4-
5-
/// mvendorid register
6-
#[derive(Clone, Copy, Debug)]
7-
pub struct Mvendorid {
8-
bits: NonZeroUsize,
3+
read_only_csr! {
4+
/// `mvendorid` register
5+
Mvendorid: 0xF11,
6+
mask: 0xffff_ffff,
7+
sentinel: 0,
98
}
109

11-
impl Mvendorid {
12-
/// Returns the contents of the register as raw bits
13-
#[inline]
14-
pub fn bits(&self) -> usize {
15-
self.bits.get()
16-
}
17-
18-
/// Returns the JEDEC manufacturer ID
19-
#[inline]
20-
pub fn jedec_manufacturer(&self) -> usize {
21-
self.bits() >> 7
22-
}
10+
read_only_csr_field! {
11+
Mvendorid,
12+
/// Represents the number of continuation bytes (`0x7f`) in the JEDEC manufacturer ID.
13+
bank: [7:31],
2314
}
2415

25-
read_csr!(0xF11);
26-
27-
/// Reads the CSR
28-
#[inline]
29-
pub fn read() -> Option<Mvendorid> {
30-
let r = unsafe { _read() };
31-
// When mvendorid is hardwired to zero it means that the mvendorid
32-
// csr isn't implemented.
33-
NonZeroUsize::new(r).map(|bits| Mvendorid { bits })
16+
read_only_csr_field! {
17+
Mvendorid,
18+
/// Represents the final offset field in the JEDEC manufacturer ID.
19+
///
20+
/// # Note
21+
///
22+
/// The encoded value returned by `offset` does not include the odd parity bit (`0x80`).
23+
offset: [0:6],
3424
}

0 commit comments

Comments
 (0)