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 `INI_TIMEOUT_AP` field of the [ExtCsd] register.
InitTimeoutAtPowerUp: u8,
mask: 0xff,
default: 0,
{
/// Represents the timeout multiplier during initialization power up.
ini_timeout_ap: 7, 0;
}
}
impl InitTimeoutAtPowerUp {
/// Represents the timeout unit (in milliseconds).
pub const TIMEOUT_UNIT: u32 = 100;
/// Represents the effective timeout value during initialization power up.
///
/// # Note
///
/// The timeout value is calculated with the algorithm:
///
/// ```no_build,no_run
/// timeout = 100ms * INI_TIMEOUT_AP
/// ```
pub const fn timeout(&self) -> u32 {
Self::TIMEOUT_UNIT * self.ini_timeout_ap() as u32
}
}
impl ExtCsd {
/// Gets the `INI_TIMEOUT_AP` field of the [ExtCsd] register.
pub const fn ini_timeout_ap(&self) -> InitTimeoutAtPowerUp {
InitTimeoutAtPowerUp::from_inner(self.0[ExtCsdIndex::IniTimeoutAp.into_inner()])
}
/// Sets the `INI_TIMEOUT_AP` field of the [ExtCsd] register.
pub(crate) fn set_ini_timeout_ap(&mut self, val: InitTimeoutAtPowerUp) {
self.0[ExtCsdIndex::IniTimeoutAp.into_inner()] = val.into_inner();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_init_timeout_ap() {
let mut ext_csd = ExtCsd::new();
assert_eq!(ext_csd.ini_timeout_ap(), InitTimeoutAtPowerUp::new());
(0..=u8::MAX)
.map(InitTimeoutAtPowerUp::from_inner)
.for_each(|timeout| {
ext_csd.set_ini_timeout_ap(timeout);
assert_eq!(ext_csd.ini_timeout_ap(), timeout);
assert_eq!(
timeout.timeout(),
InitTimeoutAtPowerUp::TIMEOUT_UNIT * timeout.ini_timeout_ap() as u32
);
});
}
}