sdmmc_core/register/ext_csd/
boot_size_mult.rs1use crate::lib_bitfield;
2
3use super::{ExtCsd, ExtCsdIndex};
4
5lib_bitfield! {
6 BootSizeMult: u8,
8 mask: 0xff,
9 default: 0,
10 {
11 boot_size_mult: 7, 0;
13 }
14}
15
16impl BootSizeMult {
17 pub const BOOT_UNIT: u32 = 128 * 1024;
19
20 pub const fn size(&self) -> u32 {
30 Self::BOOT_UNIT * self.boot_size_mult() as u32
31 }
32}
33
34impl ExtCsd {
35 pub const fn boot_size_mult(&self) -> BootSizeMult {
37 BootSizeMult::from_inner(self.0[ExtCsdIndex::BootSizeMult.into_inner()])
38 }
39
40 pub(crate) fn set_boot_size_mult(&mut self, val: BootSizeMult) {
42 self.0[ExtCsdIndex::BootSizeMult.into_inner()] = val.into_inner();
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_boot_size_mult() {
52 let mut ext_csd = ExtCsd::new();
53
54 assert_eq!(ext_csd.boot_size_mult(), BootSizeMult::new());
55
56 (0..=u8::MAX)
57 .map(BootSizeMult::from_inner)
58 .for_each(|size| {
59 ext_csd.set_boot_size_mult(size);
60 assert_eq!(ext_csd.boot_size_mult(), size);
61 assert_eq!(
62 size.size(),
63 BootSizeMult::BOOT_UNIT * (size.boot_size_mult() as u32)
64 );
65 });
66 }
67}