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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! Core peripherals
//!
//! # Notes
//!
//! - Although the `*_mut()` functions always return a valid/live reference, the API doesn't prevent
//!   the user from creating multiple mutable aliases. It's up to the user to ensure that no
//!   unsynchonized concurrent access is performed through these references.
//!
//! # Caveats
//!
//! - The API doesn't check if the value passed to `write` is valid (e.g. reserved bits are not
//!   modified) or not. It's up to the user to verify that.
//!
//! # References
//!
//! - ARMv7-M Architecture Reference Manual (Issue E.b) - Chapter B3

pub mod cpuid;
pub mod dcb;
pub mod dwt;
pub mod fpb;
pub mod fpu;
pub mod itm;
pub mod mpu;
pub mod nvic;
pub mod scb;
pub mod syst;
pub mod tpiu;

mod test;

const CPUID: usize = 0xE000_ED00;
const DCB: usize = 0xE000_EDF0;
const DWT: usize = 0xE000_1000;
const FPB: usize = 0xE000_2000;
const FPU: usize = 0xE000_EF30;
const ITM: usize = 0xE000_0000;
const MPU: usize = 0xE000_ED90;
const NVIC: usize = 0xE000_E100;
const SCB: usize = 0xE000_ED04;
const SYST: usize = 0xE000_E010;
const TPIU: usize = 0xE004_0000;

// TODO stand-alone registers: ICTR, ACTLR and STIR

/// `&cpuid::Registers`
pub fn cpuid() -> &'static cpuid::Registers {
    unsafe { ::deref(CPUID) }
}

/// `&dcb::Registers`
pub fn dcb() -> &'static dcb::Registers {
    unsafe { ::deref(DCB) }
}

/// `&mut dcb::Registers`
pub unsafe fn dcb_mut() -> &'static mut dcb::Registers {
    ::deref_mut(DCB)
}

/// `&dwt::Registers`
pub fn dwt() -> &'static dwt::Registers {
    unsafe { ::deref(DWT) }
}

/// `&mut dwt::Registers`
pub unsafe fn dwt_mut() -> &'static mut dwt::Registers {
    ::deref_mut(DWT)
}

/// `&fpb::Registers`
pub fn fpb() -> &'static fpb::Registers {
    unsafe { ::deref(FPB) }
}

/// `&mut fpb::Registers`
pub unsafe fn fpb_mut() -> &'static mut fpb::Registers {
    ::deref_mut(FPB)
}

/// `&fpu::Registers`
pub fn fpu() -> &'static fpu::Registers {
    unsafe { ::deref(FPU) }
}

/// `&mut fpu::Registers`
pub unsafe fn fpu_mut() -> &'static mut fpu::Registers {
    ::deref_mut(FPU)
}

/// `&itm::Registers`
pub fn itm() -> &'static itm::Registers {
    unsafe { ::deref(ITM) }
}

/// `&mut itm::Registers`
pub unsafe fn itm_mut() -> &'static mut itm::Registers {
    ::deref_mut(ITM)
}

/// `&mpu::Registers`
pub fn mpu() -> &'static mpu::Registers {
    unsafe { ::deref(MPU) }
}

/// `&mut mpu::Registers`
pub unsafe fn mpu_mut() -> &'static mut mpu::Registers {
    ::deref_mut(MPU)
}

/// `&nvic::Registers`
pub fn nvic() -> &'static nvic::Registers {
    unsafe { ::deref(NVIC) }
}

/// `&mut nvic::Registers`
pub unsafe fn nvic_mut() -> &'static mut nvic::Registers {
    ::deref_mut(NVIC)
}

/// `&scb::Registers`
pub fn scb() -> &'static scb::Registers {
    unsafe { ::deref(SCB) }
}

/// `&mut scb::Registers`
pub unsafe fn scb_mut() -> &'static mut scb::Registers {
    ::deref_mut(SCB)
}

/// `&syst::Registers`
pub fn syst() -> &'static syst::Registers {
    unsafe { ::deref(SYST) }
}

/// `&mut syst::Registers`
pub unsafe fn syst_mut() -> &'static mut syst::Registers {
    ::deref_mut(SYST)
}

/// `&tpiu::Registers`
pub fn tpiu() -> &'static tpiu::Registers {
    unsafe { ::deref(TPIU) }
}

/// `&mut tpiu::Registers`
pub unsafe fn tpiu_mut() -> &'static mut tpiu::Registers {
    ::deref_mut(TPIU)
}