sdmmc_core/register/ext_csd/
bkops_status.rs

1use crate::lib_bitfield;
2use crate::result::Result;
3
4use super::{ExtCsd, ExtCsdIndex};
5
6mod outstanding;
7
8pub use outstanding::*;
9
10lib_bitfield! {
11    /// Represents the `BKOPS_STATUS` field of the [ExtCsd] register.
12    BackgroundOperationsStatus: u8,
13    mask: 0x3,
14    default: 0,
15    {
16        /// Represents the status of outstanding background operations.
17        outstanding: OutstandingStatus, 1, 0;
18    }
19}
20
21impl ExtCsd {
22    /// Gets the `BKOPS_STATUS` field of the [ExtCsd] register.
23    pub const fn bkops_status(&self) -> Result<BackgroundOperationsStatus> {
24        BackgroundOperationsStatus::try_from_inner(self.0[ExtCsdIndex::BkopsStatus.into_inner()])
25    }
26
27    /// Sets the `BKOPS_STATUS` field of the [ExtCsd] register.
28    pub(crate) fn set_bkops_status(&mut self, val: BackgroundOperationsStatus) {
29        self.0[ExtCsdIndex::BkopsStatus.into_inner()] = val.into_inner();
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn test_bkops_status() {
39        let mut ext_csd = ExtCsd::new();
40
41        assert_eq!(
42            ext_csd.bkops_status(),
43            Ok(BackgroundOperationsStatus::new())
44        );
45
46        (0..=u8::MAX).for_each(|raw_bkops| {
47            // set a potentially invalid BackgroundOperationsStatus
48            ext_csd.set_bkops_status(BackgroundOperationsStatus(raw_bkops));
49
50            match BackgroundOperationsStatus::try_from_inner(raw_bkops) {
51                Ok(bkops) => assert_eq!(ext_csd.bkops_status(), Ok(bkops)),
52                Err(err) => assert_eq!(ext_csd.bkops_status(), Err(err)),
53            }
54        });
55    }
56}