opentitanlib/chip/
alert.rs

1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5use crate::with_unknown;
6
7with_unknown! {
8    pub enum AlertClass: u8 {
9        A = bindgen::alert::AlertClass_kAlertClassA as u8,
10        B = bindgen::alert::AlertClass_kAlertClassB as u8,
11        C = bindgen::alert::AlertClass_kAlertClassC as u8,
12        D = bindgen::alert::AlertClass_kAlertClassD as u8,
13        X = bindgen::alert::AlertClass_kAlertClassX as u8,
14    }
15}
16
17with_unknown! {
18    pub enum AlertEnable: u8 {
19        None = bindgen::alert::AlertEnable_kAlertEnableNone as u8,
20        Enabled = bindgen::alert::AlertEnable_kAlertEnableEnabled as u8,
21        Locked = bindgen::alert::AlertEnable_kAlertEnableLocked as u8,
22    }
23}
24
25with_unknown! {
26    pub enum AlertEscalate: u8 {
27        None = bindgen::alert::AlertEscalate_kAlertEscalateNone as u8,
28        Phase0 = bindgen::alert::AlertEscalate_kAlertEscalatePhase0 as u8,
29        Phase1 = bindgen::alert::AlertEscalate_kAlertEscalatePhase1 as u8,
30        Phase2 = bindgen::alert::AlertEscalate_kAlertEscalatePhase2 as u8,
31        Phase3 = bindgen::alert::AlertEscalate_kAlertEscalatePhase3 as u8,
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38    use anyhow::Result;
39
40    #[test]
41    fn test_trivial_values() -> Result<()> {
42        // Class A has value 238.
43        assert_eq!(AlertClass::A, AlertClass(238));
44        // AlertEnable Locked has value 210.
45        assert_eq!(AlertEnable::Locked, AlertEnable(210));
46        // AlertEscalate Phase0 has value 185.
47        assert_eq!(AlertEscalate::Phase0, AlertEscalate(185));
48        Ok(())
49    }
50}