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 `ERASE_TIMEOUT_MULT` field of the [ExtCsd] register.
EraseTimeoutMult: u8,
mask: 0xff,
default: 0,
{
/// Represents the timeout multiplier for high-capacity erase operations.
erase_timeout_mult: 7, 0;
}
}
impl EraseTimeoutMult {
/// Represents the timeout unit value (in milliseconds).
pub const TIMEOUT_UNIT: u32 = 300;
/// Gets the effective timeout value (in milliseconds).
///
/// # Note
///
/// The value is calculated with the algorithm:
///
/// ```no_build,no_run
/// timeout = 300ms * ERASE_TIMEOUT_MULT
/// ```
pub const fn timeout(&self) -> u32 {
Self::TIMEOUT_UNIT * (self.0 as u32)
}
}
impl ExtCsd {
/// Gets the `ERASE_TIMEOUT_MULT` field of the [ExtCsd] register.
pub const fn erase_timeout_mult(&self) -> EraseTimeoutMult {
EraseTimeoutMult::from_inner(self.0[ExtCsdIndex::EraseTimeoutMult.into_inner()])
}
/// Sets the `ERASE_TIMEOUT_MULT` field of the [ExtCsd] register.
pub(crate) fn set_erase_timeout_mult(&mut self, val: EraseTimeoutMult) {
self.0[ExtCsdIndex::EraseTimeoutMult.into_inner()] = val.into_inner();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_erase_timeout_mult() {
let mut ext_csd = ExtCsd::new();
assert_eq!(ext_csd.erase_timeout_mult(), EraseTimeoutMult::new());
(0..=u8::MAX)
.map(EraseTimeoutMult::from_inner)
.for_each(|timeout| {
ext_csd.set_erase_timeout_mult(timeout);
assert_eq!(ext_csd.erase_timeout_mult(), timeout);
assert_eq!(
timeout.timeout(),
EraseTimeoutMult::TIMEOUT_UNIT * (timeout.erase_timeout_mult() as u32)
);
});
}
}