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
|
#ifndef INTERRUPT_H
#define INTERRUPT_H
#include "stm32.h"
namespace Interrupt {
enum Exception {
NMI = 2,
HardFault = 3,
MemManage = 4,
BusFault = 5,
UsageFault = 6,
SVCall = 11,
PendSV = 14,
SysTick = 15
};
enum IRQ {
WWDG,
PVD,
TAMPER,
RTC,
FLASH,
RCC,
EXTI0,
EXTI1,
EXTI2,
EXTI3,
EXTI4,
DMA1_Channel1,
DMA1_Channel2,
DMA1_Channel3,
DMA1_Channel4,
DMA1_Channel5,
DMA1_Channel6,
DMA1_Channel7,
ADC1_2,
USB_HP_CAN_TX,
USB_LP_CAN_RX0,
CAN_RX1,
CAN_SCE,
EXTI9_5,
TIM1_BRK,
TIM1_UP,
TIM1_TRG_COM,
TIM1_CC,
TIM2,
TIM3,
TIM4,
I2C1_EV,
I2C1_ER,
I2C2_EV,
I2C2_ER,
SPI1,
SPI2,
USART1,
USART2,
USART3,
EXTI15_10,
RTCAlarm,
USBWakeup,
TIM8_BRK,
TIM8_UP,
TIM8_TRG_COM,
TIM8_CC,
ADC3,
FSMC,
SDIO,
TIM5,
SPI3,
UART4,
UART5,
TIM6,
TIM7,
DMA2_Channel1,
DMA2_Channel2,
DMA2_Channel3,
DMA2_Channel4_5,
NUM_IRQs
};
inline void enable(IRQ n) {
NVIC.ISER[n >> 5] = 1 << (n & 0x1f);
}
inline void set_priority(Exception n, uint8_t priority) {
SCB.SHPR[n - 4] = priority;
}
inline void set_priority(IRQ n, uint8_t priority) {
NVIC.IPR[n] = priority;
}
struct MFP {
void (*func_p)(void*);
void* instance_p;
};
extern MFP mf_vectors[];
template<class T>
inline void set_handler(IRQ n, void (T::*f)(), T* i) {
MFP& mfp = mf_vectors[16 + n];
mfp.func_p = reinterpret_cast<void (*)(void*)>(f);
mfp.instance_p = i;
}
template<class T>
inline void enable(IRQ n, void (T::*f)(), T* i) {
set_handler(n, f, i);
enable(n);
}
};
template<Interrupt::Exception>
void interrupt();
template<Interrupt::IRQ>
void interrupt();
#endif
|