File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,36 @@ read_only_csr_field! {
22
22
/// The encoded value returned by `offset` does not include the odd parity bit (`0x80`).
23
23
offset: [ 0 : 6 ] ,
24
24
}
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
+ }
You can’t perform that action at this time.
0 commit comments