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
use crate::lib_bitfield;
use super::{ExtCsd, ExtCsdIndex};
lib_bitfield! {
/// Represents the `GENERIC_CMD6_TIME` field of the [ExtCsd] register.
GenericCmd6Time: u8,
mask: 0xff,
default: 0,
{
/// Represents the multiplier value for the generic CMD6 timeout.
generic_cmd6_time: 7, 0;
}
}
impl GenericCmd6Time {
/// Represents the timeout unit value (in milliseconds).
pub const TIMEOUT_UNIT: u16 = 10;
/// Gets the effective generic CMD6 timeout value.
///
/// # Note
///
/// The timeout value is calculated with the algorithm:
///
/// ```no_build,no_run
/// timeout = 10ms * GENERIC_CMD6_TIME
/// ```
pub const fn timeout(&self) -> u16 {
Self::TIMEOUT_UNIT * self.generic_cmd6_time() as u16
}
}
impl ExtCsd {
/// Gets the `GENERIC_CMD6_TIME` field of the [ExtCsd] register.
pub const fn generic_cmd6_time(&self) -> GenericCmd6Time {
GenericCmd6Time::from_inner(self.0[ExtCsdIndex::GenericCmd6Time.into_inner()])
}
/// Sets the `GENERIC_CMD6_TIME` field of the [ExtCsd] register.
pub(crate) fn set_generic_cmd6_time(&mut self, val: GenericCmd6Time) {
self.0[ExtCsdIndex::GenericCmd6Time.into_inner()] = val.into_inner();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generic_cmd6_time() {
let mut ext_csd = ExtCsd::new();
assert_eq!(ext_csd.generic_cmd6_time(), GenericCmd6Time::new());
(0..=u8::MAX)
.map(GenericCmd6Time::from_inner)
.for_each(|time| {
ext_csd.set_generic_cmd6_time(time);
assert_eq!(ext_csd.generic_cmd6_time(), time);
});
}
}