sdmmc_core/register/ext_csd/
partition_switch_time.rs

1use crate::lib_bitfield;
2use crate::result::Result;
3
4use super::{ExtCsd, ExtCsdIndex};
5
6lib_bitfield! {
7    /// Represents the `PARTITION_SWITCH_TIME` field of the [ExtCsd] register.
8    PartitionSwitchTime: u8,
9    mask: 0xff,
10    default: 0,
11    {
12        /// Represents the partition switch timeout value.
13        timeout: 7, 0;
14    }
15}
16
17impl PartitionSwitchTime {
18    /// Represents the timeout multiplier in millisecond units.
19    pub const TIMEOUT_MULT: u16 = 10;
20
21    /// Gets the effective timeout in units of 10ms.
22    ///
23    /// The value is calculated with the equation:
24    ///
25    /// ```no_build,no_run
26    /// timeout = PARTITION_SWITCH_TIME * 10ms
27    /// ```
28    #[inline]
29    pub const fn timeout_ms(&self) -> u16 {
30        (self.0 as u16) * Self::TIMEOUT_MULT
31    }
32}
33
34impl ExtCsd {
35    /// Gets the `PARTITION_SWITCH_TIME` field of the [ExtCsd] register.
36    pub const fn partition_switch_time(&self) -> PartitionSwitchTime {
37        PartitionSwitchTime::from_inner(self.0[ExtCsdIndex::PartitionSwitchTime.into_inner()])
38    }
39
40    /// Sets the `PARTITION_SWITCH_TIME` field of the [ExtCsd] register.
41    pub(crate) fn set_partition_switch_time(&mut self, val: PartitionSwitchTime) {
42        self.0[ExtCsdIndex::PartitionSwitchTime.into_inner()] = val.into_inner();
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_partition_switch_time() {
52        let mut ext_csd = ExtCsd::new();
53
54        assert_eq!(ext_csd.partition_switch_time(), PartitionSwitchTime::new());
55
56        (0..=u8::MAX)
57            .map(PartitionSwitchTime::from_inner)
58            .for_each(|time| {
59                ext_csd.set_partition_switch_time(time);
60                assert_eq!(ext_csd.partition_switch_time(), time);
61            });
62    }
63}