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
68
69
70
71
72
use crate::lib_bitfield;
use super::{EraseTimeoutMult, ExtCsd, ExtCsdIndex};
lib_bitfield! {
/// Represents the `SEC_TRIM_MULT` field of the [ExtCsd] register.
SecureTrimMult: u8,
mask: 0xff,
default: 0,
{
/// Represents the secure trim multiplier value.
sec_trim_mult: 7, 0;
}
}
impl SecureTrimMult {
/// Represents the secure trim multiplier unit (in milliseconds).
pub const TRIM_UNIT: u32 = 300;
/// Gets the effective timeout value (in milliseconds).
///
/// # Note
///
/// The timeout value is calculated with the algorithm:
///
/// ```no_build,no_run
/// timeout = 300ms * ERASE_TIMEOUT_MULT * SEC_TRIM_MULT
/// ```
pub const fn timeout(&self, erase_timeout: EraseTimeoutMult) -> u32 {
erase_timeout.timeout() * self.sec_trim_mult() as u32
}
}
impl ExtCsd {
/// Gets the `SEC_TRIM_MULT` field of the [ExtCsd] register.
pub const fn sec_trim_mult(&self) -> SecureTrimMult {
SecureTrimMult::from_inner(self.0[ExtCsdIndex::SecTrimMult.into_inner()])
}
/// Sets the `SEC_TRIM_MULT` field of the [ExtCsd] register.
pub(crate) fn set_sec_trim_mult(&mut self, val: SecureTrimMult) {
self.0[ExtCsdIndex::SecTrimMult.into_inner()] = val.into_inner();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sec_trim_mult() {
let mut ext_csd = ExtCsd::new();
assert_eq!(ext_csd.sec_trim_mult(), SecureTrimMult::new());
(0..u8::MAX)
.map(SecureTrimMult::from_inner)
.for_each(|trim_mult| {
ext_csd.set_sec_trim_mult(trim_mult);
assert_eq!(ext_csd.sec_trim_mult(), trim_mult);
(0..u8::MAX)
.map(EraseTimeoutMult::from_inner)
.for_each(|timeout| {
assert_eq!(
trim_mult.timeout(timeout),
timeout.timeout() * trim_mult.sec_trim_mult() as u32
);
});
});
}
}