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
use crate::lib_bitfield;
mod attribute;
pub use attribute::*;
use super::{ExtCsd, ExtCsdIndex};
lib_bitfield! {
/// Represents the `PARTITIONS_ATTRIBUTE` field of the [ExtCsd] register.
PartitionsAttribute: u8,
mask: 0x1f,
default: 0,
{
/// Enhanced attribute setting for the `General Purpose partition 4`.
enh4: EnhancedAttribute, 4;
/// Enhanced attribute setting for the `General Purpose partition 3`.
enh3: EnhancedAttribute, 3;
/// Enhanced attribute setting for the `General Purpose partition 2`.
enh2: EnhancedAttribute, 2;
/// Enhanced attribute setting for the `General Purpose partition 1`.
enh1: EnhancedAttribute, 1;
/// Enhanced attribute setting for the `User Data Area`.
enh_usr: EnhancedAttribute, 0;
}
}
impl PartitionsAttribute {
/// Converts an inner representation into a [PartitionsAttribute].
pub const fn from_inner(val: u8) -> Self {
Self(val & Self::MASK)
}
}
impl ExtCsd {
/// Gets the `PARTITIONS_ATTRIBUTE` field of the [ExtCsd] register.
pub const fn partitions_attribute(&self) -> PartitionsAttribute {
PartitionsAttribute::from_inner(self.0[ExtCsdIndex::PartitionsAttribute.into_inner()])
}
/// Sets the `PARTITIONS_ATTRIBUTE` field of the [ExtCsd] register.
pub fn set_partitions_attribute(&mut self, val: PartitionsAttribute) {
self.0[ExtCsdIndex::PartitionsAttribute.into_inner()] = val.into_inner();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_partitions_attribute() {
let mut ext_csd = ExtCsd::new();
assert_eq!(ext_csd.partitions_attribute(), PartitionsAttribute::new());
(0..=u8::MAX)
.map(PartitionsAttribute::from_inner)
.for_each(|pa| {
ext_csd.set_partitions_attribute(pa);
assert_eq!(ext_csd.partitions_attribute(), pa);
});
}
}