1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::lib_bitfield;
use super::{ExtCsd, ExtCsdIndex};
lib_bitfield! {
/// Represents the `BOOT_WP` field of the [ExtCsd] register.
BootAreaWriteProtection: u8,
mask: 0xdf,
default: 0,
{
/// Indicates whether write protection settings apply to partitions selected by `B_PERM_WP_SEC_SEL` and `B_PWR_WP_SEC_SEL` fields.
b_sec_wp_sel: 7;
/// Indicates whether to disable the use of `B_PWR_WP_EN` setting.
b_pwr_wp_dis: 6;
/// Indicates whether to disable permanent write protection.
b_perm_wp_dis: 4;
/// Indicates whether to apply permanent write protection to a boot area.
///
/// Values:
///
/// - `false`: `Area 1`
/// - `true`: `Area 2`
b_perm_wp_sec_sel: 3;
/// Indicates whether to apply permanent write protection.
b_perm_wp_en: 2;
/// Indicates whether to apply write protection to a boot area.
///
/// Values:
///
/// - `false`: `Area 1`
/// - `true`: `Area 2`
b_pwr_wp_sec_sel: 1;
/// Indicates whether to apply power-on write protection.
b_pwr_wp_en: 0;
}
}
impl ExtCsd {
/// Gets the `BOOT_WP` field of the [ExtCsd] register.
pub const fn boot_wp(&self) -> BootAreaWriteProtection {
BootAreaWriteProtection::from_inner(self.0[ExtCsdIndex::BootWp.into_inner()])
}
/// Sets the `BOOT_WP` field of the [ExtCsd] register.
pub fn set_boot_wp(&mut self, val: BootAreaWriteProtection) {
self.0[ExtCsdIndex::BootWp.into_inner()] = val.into_inner();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_boot_wp() {
let mut ext_csd = ExtCsd::new();
assert_eq!(ext_csd.boot_wp(), BootAreaWriteProtection::new());
(0..=u8::MAX)
.map(BootAreaWriteProtection::from_inner)
.for_each(|user_wp| {
ext_csd.set_boot_wp(user_wp);
assert_eq!(ext_csd.boot_wp(), user_wp);
});
}
}