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
/// FPGA state
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FPGAState {
    pub(crate) state: u8,
}

impl FPGAState {
    /// Check if thermal sensor is asserted
    pub const fn is_thermal_assert(&self) -> bool {
        (self.state & 0x01) != 0
    }

    pub const fn state(&self) -> u8 {
        self.state
    }
}

#[cfg(test)]
mod tests {
    use std::mem::size_of;

    use super::*;

    #[test]
    fn fpga_state() {
        assert_eq!(size_of::<FPGAState>(), 1);

        let info = FPGAState { state: 0x00 };
        assert!(!info.is_thermal_assert());
        assert_eq!(info.state(), 0x00);

        let info = FPGAState { state: 0x01 };
        assert!(info.is_thermal_assert());
        assert_eq!(info.state(), 0x01);
    }

    #[test]
    fn fpga_state_derive() {
        let info = FPGAState { state: 0x00 };
        let info2 = info.clone();

        assert_eq!(info, info2);
        assert_eq!(format!("{:?}", info), "FPGAState { state: 0 }");
    }
}