-
Notifications
You must be signed in to change notification settings - Fork 0
/
MB1_ISR.cpp
336 lines (268 loc) · 7.63 KB
/
MB1_ISR.cpp
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/**
* @file MB1_ISR.cpp
* @author Pham Huu Dang Nhat <[email protected]>, HLib MBoard team.
* @version 1.0
* @date 21-10-2013
* @brief This is source file for interrupt handlers for MBoard-1.
*
*/
/* Includes */
#include "MB1_ISR.h"
using namespace ISRMgr_ns;
/**<------------------- Sub ISR tables ---------------------*/
/**< SysTick sub ISR table */
void (* SysTick_subISR_table [numOfSubISR_max]) (void);
/**< SysTick sub ISR table */
/**< TIM6 sub ISR table */
void (* TIM6_subISR_table [numOfSubISR_max]) (void);
/**< TIM6 sub ISR table */
/**< USART1 sub ISR table */
void (* USART1_subISR_table [numOfSubISR_max]) (void);
/**< USART1 sub ISR table */
/**<------------------- Sub ISR tables ---------------------*/
/**< class ISRMgr */
ISRMgr :: ISRMgr (void){
/**< Init sub ISR table of SysTick */
SysTick_subISR_table_init ();
TIM6_subISR_table_init ();
USART1_subISR_table_init ();
return;
}
/**
* @brief subISR_assign. Assign a sub ISR function ptr to the sub ISR table of ISR_type
* @param ISR_t ISR_type
* @param void (* subISR_p)(void) (not a NULL ptr)
* @return None.
*/
status_t ISRMgr::subISR_assign (ISR_t ISR_type, void (* subISR_p)(void) ){
status_t retval = failed;
if (subISR_p == NULL)
return failed;
switch (ISR_type){
case ISRMgr_SysTick :
retval = subISR_SysTick_assign (subISR_p);
break;
case ISRMgr_TIM6:
retval = subISR_TIM6_assign (subISR_p);
break;
case ISRMgr_USART1:
retval = subISR_USART1_assign (subISR_p);
break;
default:
break;
}
return retval;
}
/**
* @brief subISR_remove. remove a sub ISR function ptr to the sub ISR table of ISR_type
* @param ISR_t ISR_type
* @param void (* subISR_p)(void) (not a NULL ptr)
* @return None.
*/
status_t ISRMgr::subISR_remove (ISR_t ISR_type, void (* subISR_p)(void) ){
status_t retval = failed;
if (subISR_p == NULL)
return failed;
switch (ISR_type){
case ISRMgr_SysTick:
retval = subISR_SysTick_remove (subISR_p);
break;
case ISRMgr_TIM6:
retval = subISR_TIM6_remove (subISR_p);
break;
case ISRMgr_USART1:
retval = subISR_USART1_assign (subISR_p);
break;
default:
break;
}
return retval;
}
/**< SysTick private */
/**
* @brief subISR_SysTick_assign. assign a sub ISR func ptr to SysTick_subISR_table.
* @param void (* subISR_p)(void)
* @return None.
*/
status_t ISRMgr::subISR_SysTick_assign (void (* subISR_p)(void) ){
uint8_t i;
bool found = false;
for (i = 0; i < numOfSubISR_max; i++){
if (SysTick_subISR_table [i] == NULL){
found = true;
SysTick_subISR_table [i] = subISR_p;
break;
}
}
if (found)
return successful;
return failed;
}
/**
* @brief subISR_SysTick_remove. Remove a sub ISR func ptr to SysTick_subISR_table.
* @param void (* subISR_p)(void)
* @return None.
*/
status_t ISRMgr::subISR_SysTick_remove (void (* subISR_p)(void) ){
uint8_t i;
bool found = false;
for (i = 0; i < numOfSubISR_max; i++){
if (SysTick_subISR_table [i] == subISR_p){
found = true;
SysTick_subISR_table [i] = NULL;
break;
}
}
if (found)
return successful;
return failed;
}
/**
* @brief SysTick_subISR_table_init. Init all value in SysTick_subISR_table.
* @return None.
*/
void ISRMgr::SysTick_subISR_table_init (void){
uint8_t a_count;
for (a_count = 0; a_count < numOfSubISR_max; a_count++ ){
SysTick_subISR_table [a_count] = NULL;
}
}
/**< SysTick private */
/**< TIM6 private */
/**
* @brief subISR_TIM6_assign. assign a sub ISR func ptr to TIM6_subISR_table.
* @param void (* subISR_p)(void)
* @return None.
*/
status_t ISRMgr::subISR_TIM6_assign (void (* subISR_p)(void) ){
uint8_t i;
bool found = false;
for (i = 0; i < numOfSubISR_max; i++){
if (TIM6_subISR_table [i] == NULL){
found = true;
TIM6_subISR_table [i] = subISR_p;
break;
}
}
if (found)
return successful;
return failed;
}
/**
* @brief subISR_TIM6_remove. Remove a sub ISR func ptr to TIM6_subISR_table.
* @param void (* subISR_p)(void)
* @return None.
*/
status_t ISRMgr::subISR_TIM6_remove (void (* subISR_p)(void) ){
uint8_t i;
bool found = false;
for (i = 0; i < numOfSubISR_max; i++){
if (TIM6_subISR_table [i] == subISR_p){
found = true;
TIM6_subISR_table [i] = NULL;
break;
}
}
if (found)
return successful;
return failed;
}
/**
* @brief TIM6_subISR_table_init. Init all value in TIM6_subISR_table.
* @return None.
*/
void ISRMgr::TIM6_subISR_table_init (void){
uint8_t a_count;
for (a_count = 0; a_count < numOfSubISR_max; a_count++ ){
TIM6_subISR_table [a_count] = NULL;
}
}
/**< TIM6 private */
/**< USART1 private */
/**
* @brief subISR_USART1_assign. assign a sub ISR func ptr to USART1_subISR_table.
* @param void (* subISR_p)(void)
* @return None.
*/
status_t ISRMgr::subISR_USART1_assign (void (* subISR_p)(void) ){
uint8_t i;
bool found = false;
for (i = 0; i < numOfSubISR_max; i++){
if (USART1_subISR_table [i] == NULL){
found = true;
USART1_subISR_table [i] = subISR_p;
break;
}
}
if (found)
return successful;
return failed;
}
/**
* @brief subISR_USART1_remove. Remove a sub ISR func ptr to USART1_subISR_table.
* @param void (* subISR_p)(void)
* @return None.
*/
status_t ISRMgr::subISR_USART1_remove (void (* subISR_p)(void) ){
uint8_t i;
bool found = false;
for (i = 0; i < numOfSubISR_max; i++){
if (USART1_subISR_table [i] == subISR_p){
found = true;
USART1_subISR_table [i] = NULL;
break;
}
}
if (found)
return successful;
return failed;
}
/**
* @brief USART1_subISR_table_init. Init all value in USART1_subISR_table.
* @return None.
*/
void ISRMgr::USART1_subISR_table_init (void){
uint8_t a_count;
for (a_count = 0; a_count < numOfSubISR_max; a_count++ ){
USART1_subISR_table [a_count] = NULL;
}
}
/**< USART1 private */
/* ISRs */
void SysTick_Handler (void){
uint8_t a_count;
for (a_count = 0; a_count < numOfSubISR_max; a_count++){
if (SysTick_subISR_table[a_count] != NULL){
SysTick_subISR_table[a_count] ();
}
}
return;
}
void TIM6_IRQHandler (void){
uint8_t a_count;
/**< clear IT flag */
TIM_ClearFlag (TIM6, TIM_FLAG_Update);
for (a_count = 0; a_count < numOfSubISR_max; a_count++){
if (TIM6_subISR_table[a_count] != NULL){
TIM6_subISR_table[a_count] ();
}
}
return;
}
/*
void USART1_IRQHandler (void){
uint8_t a_count;
for (a_count = 0; a_count < numOfSubISR_max; a_count++){
if (USART1_subISR_table[a_count] != NULL){
USART1_subISR_table[a_count] ();
}
}
*/
/**< clear IT flag */
/* USART_ClearITPendingBit (USART1, USART_IT_RXNE);
USART_ClearITPendingBit (USART1, USART_IT_CTS);
USART_ClearITPendingBit (USART1, USART_IT_LBD);
USART_ClearITPendingBit (USART1, USART_IT_TC);
return;
}
*/