aarch32_cpu/register/
csselr.rs

1//! Code for managing CSSELR (*Cache Size Selection Register*)
2use arbitrary_int::u3;
3
4use crate::register::{SysReg, SysRegRead, SysRegWrite};
5
6#[bitbybit::bitenum(u1, exhaustive = true)]
7#[derive(Debug, PartialEq, Eq)]
8#[cfg_attr(feature = "defmt", derive(defmt::Format))]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub enum CacheType {
11    DataOrUnified = 0,
12    Instruction = 1,
13}
14
15/// CSSELR (*Cache Size Selection Register*)
16#[bitbybit::bitfield(u32, debug, defmt_fields(feature = "defmt"))]
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18#[derive(PartialEq, Eq)]
19pub struct Csselr {
20    /// 0 for L1 cache, 1 for L2, etc.
21    #[bits(1..=3, rw)]
22    level: u3,
23    #[bit(0, rw)]
24    cache_type: CacheType,
25}
26
27impl SysReg for Csselr {
28    const CP: u32 = 15;
29    const CRN: u32 = 0;
30    const OP1: u32 = 2;
31    const CRM: u32 = 0;
32    const OP2: u32 = 0;
33}
34
35impl crate::register::SysRegRead for Csselr {}
36
37impl Csselr {
38    #[inline]
39    /// Reads CSSELR (*Cache Size Selection Register*)
40    pub fn read() -> Csselr {
41        unsafe { Self::new_with_raw_value(<Self as SysRegRead>::read_raw()) }
42    }
43}
44
45impl crate::register::SysRegWrite for Csselr {}
46
47impl Csselr {
48    #[inline]
49    /// Writes CSSELR (*Cache Size Selection Register*)
50    ///
51    /// # Safety
52    ///
53    /// Ensure that this value is appropriate for this register
54    pub unsafe fn write(value: Self) {
55        unsafe {
56            <Self as SysRegWrite>::write_raw(value.raw_value());
57        }
58    }
59}