From 27e6eb4c09f16f2984f2a506ad6d190333193790 Mon Sep 17 00:00:00 2001 From: rmsyn Date: Mon, 13 Jan 2025 23:19:19 +0000 Subject: [PATCH] riscv: re-add Mvendorid::jedec_manufacturer implementation Adds a corrected `Mvendorid::jedec_manufacturer` implementation to return the decoded JEDEC manufacturer ID. --- riscv/src/register/mvendorid.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/riscv/src/register/mvendorid.rs b/riscv/src/register/mvendorid.rs index fc6c1f33..88b03fe3 100644 --- a/riscv/src/register/mvendorid.rs +++ b/riscv/src/register/mvendorid.rs @@ -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 { + 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) + } + }) + } +}