Skip to content

Commit ed7e67e

Browse files
committed
riscv: re-add Mvendorid::jedec_manufacturer implementation
Adds a corrected `Mvendorid::jedec_manufacturer` implementation to return the decoded JEDEC manufacturer ID.
1 parent 22cbf3a commit ed7e67e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

riscv/src/register/mvendorid.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,36 @@ read_only_csr_field! {
2222
/// The encoded value returned by `offset` does not include the odd parity bit (`0x80`).
2323
offset: [0:6],
2424
}
25+
26+
impl Mvendorid {
27+
/// Represents the JEDEC manufacture continuation byte.
28+
pub const CONTINUATION: u8 = 0x7f;
29+
30+
/// Gets the decoded JEDEC manufacturer ID from the `mvendorid` value.
31+
///
32+
/// # Note
33+
///
34+
/// This function returns an iterator over the decoded bytes.
35+
///
36+
/// An iterator is needed because the encoding can theoretically return a max count (`0x1ff_ffff`) of continuation bytes (`0x7f`).
37+
///
38+
/// The final byte in the iterator is the `offset`, including the odd parity bit (set only if even).
39+
pub fn jedec_manufacturer(&self) -> impl Iterator<Item = u8> {
40+
let mut done = false;
41+
let mut bank = self.bank();
42+
let offset = self.offset();
43+
let parity = ((1 - (offset.count_ones() % 2)) << 7) as usize;
44+
45+
core::iter::from_fn(move || match bank {
46+
0 if done => None,
47+
0 => {
48+
done = true;
49+
Some((parity | offset) as u8)
50+
}
51+
_ => {
52+
bank -= 1;
53+
Some(Self::CONTINUATION)
54+
}
55+
})
56+
}
57+
}

0 commit comments

Comments
 (0)