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
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum LocalTimestampOptions {
Disabled,
Enabled,
EnabledDiv4,
EnabledDiv16,
EnabledDiv64,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum VectActive {
ThreadMode,
Exception(Exception),
Interrupt {
irqn: u16,
},
}
impl VectActive {
#[inline]
pub fn from(vect_active: u16) -> Option<Self> {
Some(match vect_active {
0 => VectActive::ThreadMode,
2 => VectActive::Exception(Exception::NonMaskableInt),
3 => VectActive::Exception(Exception::HardFault),
4 => VectActive::Exception(Exception::MemoryManagement),
5 => VectActive::Exception(Exception::BusFault),
6 => VectActive::Exception(Exception::UsageFault),
7 => VectActive::Exception(Exception::SecureFault),
11 => VectActive::Exception(Exception::SVCall),
12 => VectActive::Exception(Exception::DebugMonitor),
14 => VectActive::Exception(Exception::PendSV),
15 => VectActive::Exception(Exception::SysTick),
irqn if (16..512).contains(&irqn) => VectActive::Interrupt { irqn: irqn - 16 },
_ => return None,
})
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Exception {
NonMaskableInt,
HardFault,
MemoryManagement,
BusFault,
UsageFault,
SecureFault,
SVCall,
DebugMonitor,
PendSV,
SysTick,
}
impl Exception {
#[inline]
pub fn irqn(self) -> i8 {
match self {
Exception::NonMaskableInt => -14,
Exception::HardFault => -13,
Exception::MemoryManagement => -12,
Exception::BusFault => -11,
Exception::UsageFault => -10,
Exception::SecureFault => -9,
Exception::SVCall => -5,
Exception::DebugMonitor => -4,
Exception::PendSV => -2,
Exception::SysTick => -1,
}
}
}