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
#[cfg(not(armv6m))]
use volatile_register::WO;
use volatile_register::{RO, RW};
use crate::peripheral::DWT;
#[repr(C)]
pub struct RegisterBlock {
pub ctrl: RW<u32>,
#[cfg(not(armv6m))]
pub cyccnt: RW<u32>,
#[cfg(not(armv6m))]
pub cpicnt: RW<u32>,
#[cfg(not(armv6m))]
pub exccnt: RW<u32>,
#[cfg(not(armv6m))]
pub sleepcnt: RW<u32>,
#[cfg(not(armv6m))]
pub lsucnt: RW<u32>,
#[cfg(not(armv6m))]
pub foldcnt: RW<u32>,
#[cfg(armv6m)]
reserved: [u32; 6],
pub pcsr: RO<u32>,
#[cfg(armv6m)]
pub c: [Comparator; 2],
#[cfg(not(armv6m))]
pub c: [Comparator; 16],
#[cfg(not(armv6m))]
reserved: [u32; 932],
#[cfg(not(armv6m))]
pub lar: WO<u32>,
#[cfg(not(armv6m))]
pub lsr: RO<u32>,
}
#[repr(C)]
pub struct Comparator {
pub comp: RW<u32>,
pub mask: RW<u32>,
pub function: RW<u32>,
reserved: u32,
}
impl DWT {
#[cfg(not(armv6m))]
#[inline]
pub fn enable_cycle_counter(&mut self) {
unsafe { self.ctrl.modify(|r| r | 1) }
}
#[cfg(not(armv6m))]
#[inline]
pub fn get_cycle_count() -> u32 {
unsafe { (*Self::ptr()).cyccnt.read() }
}
#[cfg(not(armv6m))]
#[inline]
pub fn unlock() {
unsafe { (*Self::ptr()).lar.write(0xC5AC_CE55) }
}
}