File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,37 @@ 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+ const DONE : usize = usize:: MAX ;
41+
42+ let mut bank = self . bank ( ) ;
43+ let offset = self . offset ( ) ;
44+
45+ core:: iter:: from_fn ( move || match bank {
46+ DONE => None ,
47+ 0 => {
48+ bank = DONE ;
49+ let parity = ( ( 1 - ( offset. count_ones ( ) % 2 ) ) << 7 ) as usize ;
50+ Some ( ( parity | offset) as u8 )
51+ }
52+ _ => {
53+ bank -= 1 ;
54+ Some ( Self :: CONTINUATION )
55+ }
56+ } )
57+ }
58+ }
You can’t perform that action at this time.
0 commit comments