rp2040/
sysinfo.rs

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

use kernel::utilities::registers::interfaces::Readable;
use kernel::utilities::StaticRef;

use kernel::utilities::registers::{register_bitfields, register_structs, ReadWrite};

register_structs! {

    SysInfoRegisters {

        (0x000 => chip_id: ReadWrite<u32, CHIP_ID::Register>),

        (0x004 => platform: ReadWrite<u32, PLATFORM::Register>),

        (0x008 => _reserved1),

        (0x040 => gitref_rp2040: ReadWrite<u32, GITREF_RP2040::Register>),

        (0x044 => @END),
    }
}
register_bitfields![u32,
    CHIP_ID [

        REVISION OFFSET(28) NUMBITS(4) [],

        PART OFFSET(12) NUMBITS(16) [],

        MANUFACTURER OFFSET(0) NUMBITS(12) []

    ],
    PLATFORM [
        ASIC OFFSET(1) NUMBITS(1) [],

        FPGA OFFSET(0) NUMBITS(1) []

    ],
    GITREF_RP2040 [
        SOURCE_GIT_HASH OFFSET(0) NUMBITS(32) []
    ]
];

const SYSINFO_BASE: StaticRef<SysInfoRegisters> =
    unsafe { StaticRef::new(0x40000000 as *const SysInfoRegisters) };

pub enum Platform {
    Asic,
    Fpga,
}

pub struct SysInfo {
    registers: StaticRef<SysInfoRegisters>,
}

impl SysInfo {
    pub const fn new() -> SysInfo {
        SysInfo {
            registers: SYSINFO_BASE,
        }
    }

    pub fn get_revision(&self) -> u8 {
        self.registers.chip_id.read(CHIP_ID::REVISION) as u8
    }

    pub fn get_part(&self) -> u16 {
        self.registers.chip_id.read(CHIP_ID::PART) as u16
    }

    pub fn get_manufacturer_rp2040(&self) -> u16 {
        self.registers.chip_id.read(CHIP_ID::MANUFACTURER) as u16
    }

    pub fn get_asic(&self) -> u32 {
        self.registers.platform.read(PLATFORM::ASIC)
    }

    pub fn get_fpga(&self) -> u32 {
        self.registers.platform.read(PLATFORM::FPGA)
    }

    pub fn get_platform(&self) -> Platform {
        if self.registers.platform.is_set(PLATFORM::ASIC) {
            Platform::Asic
        } else {
            Platform::Fpga
        }
    }

    pub fn get_git_ref(&self) -> u32 {
        self.registers
            .gitref_rp2040
            .read(GITREF_RP2040::SOURCE_GIT_HASH)
    }
}