Skip to main content

aarch32_cpu/register/imp/
imp_cbar.rs

1//! Code for managing IMP_CBAR (*Configuration Base Address Register*)
2
3use crate::register::{SysReg, SysRegRead};
4
5/// IMP_CBAR (*Configuration Base Address Register*)
6#[derive(Clone, Copy)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct ImpCbar(pub u32);
9
10impl SysReg for ImpCbar {
11    const CP: u32 = 15;
12    const CRN: u32 = 15;
13    const OP1: u32 = 1;
14    const CRM: u32 = 3;
15    const OP2: u32 = 0;
16}
17
18impl SysRegRead for ImpCbar {}
19
20impl ImpCbar {
21    /// Read IMP_CBAR (*Configuration Base Address Register*)
22    #[inline]
23    pub fn read() -> ImpCbar {
24        Self(<Self as SysRegRead>::read_raw())
25    }
26
27    /// Get the periphbase address
28    pub fn periphbase(self) -> *mut u32 {
29        (self.0 & 0xFFF00000) as *mut u32
30    }
31}
32
33impl core::fmt::Debug for ImpCbar {
34    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
35        write!(f, "IMP_CBAR {{ {:010p} }}", self.periphbase())
36    }
37}
38
39#[cfg(feature = "defmt")]
40impl defmt::Format for ImpCbar {
41    fn format(&self, f: defmt::Formatter) {
42        defmt::write!(f, "IMP_CBAR {{ 0x{=usize:08x} }}", self.0 as usize)
43    }
44}