Skip to content

Commit

Permalink
riscv: re-add Mvendorid::jedec_manufacturer implementation
Browse files Browse the repository at this point in the history
Adds a corrected `Mvendorid::jedec_manufacturer` implementation to
return the decoded JEDEC manufacturer ID.
  • Loading branch information
rmsyn committed Jan 13, 2025
1 parent 22cbf3a commit 27e6eb4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions riscv/src/register/mvendorid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,35 @@ read_only_csr_field! {
/// The encoded value returned by `offset` does not include the odd parity bit (`0x80`).
offset: [0:6],
}

impl Mvendorid {
/// Gets the decoded JEDEC manufacturer ID from the `mvendorid` value.
///
/// # Note
///
/// This function returns an iterator over the decoded bytes.
///
/// An iterator is needed because the encoding can theoretically return a max count (`0x1ff_ffff`) of continuation bytes (`0x7f`).
///
/// The final byte in the iterator is the `offset`, including the odd parity bit (set only if even).
pub fn jedec_manufacturer(&self) -> impl Iterator<Item = u8> {
const CONTINUATION: u8 = 0x7f;

let mut done = false;
let mut bank = self.bank();
let offset = self.offset();
let parity = (1 - (offset % 2)) << 7;

core::iter::from_fn(move || match bank {
0 if done => None,
0 => {
done = true;
Some((parity | offset) as u8)
}
_ => {
bank -= 1;
Some(CONTINUATION)
}
})
}
}

0 comments on commit 27e6eb4

Please sign in to comment.