1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! [System Timer][1]
//!
//! [1]: https://datasheets.raspberrypi.com/bcm2711/bcm2711-peripherals.pdf#%5B%7B%22num%22%3A145%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C115%2C841.89%2Cnull%5D
use tock_registers::{
    fields::{Field, FieldValue},
    register_structs,
    registers::{ReadOnly, ReadWrite},
    RegisterLongName,
};

use crate::Vpa;

/// The base address of [the System Timer peripheral register block](Registers).
pub const BASE: Vpa = Vpa(0x4_7e00_3000);

register_structs! {
    pub Registers {
        /// Control/status
        (0x00 => pub cs: ReadWrite<u32, CS::Register>),
        /// Counter lower 32 bits
        (0x04 => pub clo: ReadOnly<u32>),
        /// Counter higher 32 bits
        (0x08 => pub chi: ReadOnly<u32>),
        /// Compare `0..4`
        (0x0c => pub c: [ReadWrite<u32>; 4]),
        (0x1c => @END),
    }
}

#[allow(non_snake_case)]
pub mod CS {
    use super::*;
    pub struct Register;
    impl RegisterLongName for Register {}

    /// Construct a [`Field`] representing the `M` bit (System Timer Match, W1C)
    /// corresponding to the specified comparator number.
    ///
    /// # Panic
    ///
    /// Panics if `i` is outside the range `0..4`.
    #[inline]
    pub const fn M(i: usize) -> Field<u32, Register> {
        assert!(i < 4);
        Field::new(0b1, i)
    }

    /// Construct a [`FieldValue`] to clear the [`M`] bit corresponding to
    /// the specified comparator number.
    ///
    /// # Panic
    ///
    /// Panics if `i` is outside the range `0..4`.
    #[inline]
    pub const fn M_clear(i: usize) -> FieldValue<u32, Register> {
        FieldValue::<u32, _>::new(0b1, i, 0b1)
    }
}