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
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Exception {
NMI,
HardFault,
MenManage,
BusFault,
UsageFault,
SVCall,
PendSV,
SysTick,
Interrupt(u8),
#[doc(hidden)]
Reserved,
}
impl Exception {
pub fn active() -> Option<Exception> {
let icsr = unsafe { (*::peripheral::SCB.get()).icsr.read() };
Some(match icsr as u8 {
0 => return None,
2 => Exception::NMI,
3 => Exception::HardFault,
4 => Exception::MenManage,
5 => Exception::BusFault,
6 => Exception::UsageFault,
11 => Exception::SVCall,
14 => Exception::PendSV,
15 => Exception::SysTick,
n if n >= 16 => Exception::Interrupt(n - 16),
_ => Exception::Reserved,
})
}
}
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct ExceptionFrame {
pub r0: u32,
pub r1: u32,
pub r2: u32,
pub r3: u32,
pub r12: u32,
pub lr: u32,
pub pc: u32,
pub xpsr: u32,
}