svd_rs/protection.rs
1/// Specify the security privilege to access an address region
2///
3/// This information is relevant for the programmer as well as the debugger
4/// when no universal access permissions have been granted.
5/// If no specific information is provided, an address region is accessible in any mode
6#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub enum Protection {
9 /// Secure permission required for access
10 #[cfg_attr(feature = "serde", serde(rename = "s"))]
11 Secure,
12
13 /// Non-secure or secure permission required for access
14 #[cfg_attr(feature = "serde", serde(rename = "n"))]
15 NonSecure,
16
17 /// Privileged permission required for access
18 #[cfg_attr(feature = "serde", serde(rename = "p"))]
19 Privileged,
20}
21
22impl Default for Protection {
23 fn default() -> Self {
24 Self::NonSecure
25 }
26}
27
28impl Protection {
29 /// Parse a string into an [`Protection`] value, returning [`Option::None`] if the string is not valid.
30 pub fn parse_str(s: &str) -> Option<Self> {
31 match s {
32 "s" => Some(Self::Secure),
33 "n" => Some(Self::NonSecure),
34 "p" => Some(Self::Privileged),
35 _ => None,
36 }
37 }
38
39 /// Convert this [`Protection`] into a static string.
40 pub const fn as_str(self) -> &'static str {
41 match self {
42 Self::Secure => "s",
43 Self::NonSecure => "n",
44 Self::Privileged => "p",
45 }
46 }
47}