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
|
/// Kind of exception
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Exception {
/// i.e. currently not servicing an exception
ThreadMode,
/// Non-maskable interrupt.
Nmi,
/// All class of fault.
HardFault,
/// Memory management.
MemoryManagementFault,
/// Pre-fetch fault, memory access fault.
BusFault,
/// Undefined instruction or illegal state.
UsageFault,
/// System service call via SWI instruction
SVCall,
/// Pendable request for system service
PendSV,
/// System tick timer
Systick,
/// An interrupt
Interrupt(u8),
// Unreachable variant
#[doc(hidden)]
Reserved,
}
impl Exception {
/// Returns the kind of exception that's currently being serviced
pub fn current() -> Exception {
match ::peripheral::scb().icsr.read() as u8 {
0 => Exception::ThreadMode,
2 => Exception::Nmi,
3 => Exception::HardFault,
4 => Exception::MemoryManagementFault,
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,
}
}
}
|