aarch32_cpu/register/
mpuir.rs

1//! Code for managing MPUIR (*MPU Type Register*)
2
3use crate::register::{SysReg, SysRegRead};
4
5/// MPUIR (*MPU Type Register*)
6#[bitbybit::bitfield(u32)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct Mpuir {
9    /// Specifies the number of Instruction regions implemented by the MPU.
10    ///
11    /// If the MPU implements a Unified memory map this field is UNK/SBZ.
12    #[bits(16..=23, r)]
13    iregions: u8,
14    /// Specifies the number of Data or Unified regions implemented by the MPU.
15    #[bits(8..=15, r)]
16    dregions: u8,
17    /// Is the MPU non-unified
18    #[bits(0..=0, r)]
19    non_unified: bool,
20}
21
22impl SysReg for Mpuir {
23    const CP: u32 = 15;
24    const CRN: u32 = 0;
25    const OP1: u32 = 0;
26    const CRM: u32 = 0;
27    const OP2: u32 = 4;
28}
29
30impl crate::register::SysRegRead for Mpuir {}
31
32impl Mpuir {
33    #[inline]
34    /// Reads MPUIR (*MPU Type Register*)
35    pub fn read() -> Mpuir {
36        unsafe { Self::new_with_raw_value(<Self as SysRegRead>::read_raw()) }
37    }
38}
39
40impl core::fmt::Debug for Mpuir {
41    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42        f.debug_struct("Mpuir")
43            .field("iregions", &self.iregions())
44            .field("dregions", &self.dregions())
45            .field("non_unified", &self.non_unified())
46            .finish()
47    }
48}
49
50#[cfg(feature = "defmt")]
51impl defmt::Format for Mpuir {
52    fn format(&self, f: defmt::Formatter) {
53        defmt::write!(
54            f,
55            "MPUIR {{ iregions={=u8}, dregions={=u8}, non_unified={=bool} }}",
56            self.iregions(),
57            self.dregions(),
58            self.non_unified()
59        )
60    }
61}