-
Notifications
You must be signed in to change notification settings - Fork 2
/
Interrupts.c
315 lines (286 loc) · 11.2 KB
/
Interrupts.c
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
/*******************************************************************************
* File: Interrupts.c
* Author: Will Flores [email protected]
* Usage:
* Description: This file contains all the interrupt routines for the peripherals.
* Environment: Windows 7, x64 build
* Built in HEW with MC16 Series Compiler V.5.44 Release 00
* Notes: NONE
* Revisions: 0.0, Initial Release
* 1.0, Better documented file header with function headers
* 2.0, Interrupts for buttons added
* Created on March 12, 2012
*******************************************************************************/
#include "proto.h"
#include "QSKDefines.h"
#include "extern.h"
#include "ports.h"
#define FALLING_EDGE (0x0)
#define RISING_EDGE (0x1)
#pragma INTERRUPT UART0TransmitInterrupt
#pragma INTERRUPT KeyBoardInterrupt
#pragma INTERRUPT DMA0Interrupt
#pragma INTERRUPT RTCInterrupt
#pragma INTERRUPT WatchDogInterrupt
/*******************************************************************************
* Purpose: Initializes interrupts for this board.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void init_interrupts(void) {
enable_LeftBtn_isr();
enable_MiddleBtn_isr();
enable_RightBtn_isr();
}
/*******************************************************************************
* Purpose: Initializes interrupt for the left button.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void enable_LeftBtn_isr(void) {
/* Set interrupt priority level for int1
* to 7 (binary 111)
*/
DISABLE_IRQ
int1ic = HIGHEST_PRIORITY_LEVEL;
ENABLE_IRQ
/* set int0 to trigger on negative edge */
pol_int1ic = FALLING_EDGE;
}
/*******************************************************************************
* Purpose: Initializes interrupt for the middle button.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void enable_MiddleBtn_isr(void) {
ta4mr = CLEAR_REGISTER; // Clear Timer A4 Mode Register
ta4mr |= EVENT_MODE; // Event mode
/* Trigger select register information */
ta4tgh = TA4IN_AS_INPUT; // input on TA4in
ta4tgl = TA4IN_AS_INPUT;
// just count whenever
ta4 = COUNT_NOTHING;
// disable irqs before setting irq registers - macro defined in skp_bsp.h
DISABLE_IRQ
// Set the timer A4's IPL (interrupt priority level) to 7
ta4ic = HIGHEST_PRIORITY_LEVEL;
ENABLE_IRQ // enable interrupts macro defined in skp_bsp.h
start_MiddleBtn_isr();
}
/*******************************************************************************
* Purpose: This function starts Middle Button Interrupt.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void start_MiddleBtn_isr(void) {
ta4s = TIMER_START;
}
/*******************************************************************************
* Purpose: This function stops Middle Button Interrupt.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void stop_MiddleBtn_isr(void) {
ta4s = TIMER_STOP;
}
/*******************************************************************************
* Purpose: Initializes interrupt for the right button.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void enable_RightBtn_isr(void) {
/* Set interrupt priority level for int0
* to 7 (binary 111)
*/
DISABLE_IRQ
int0ic = HIGHEST_PRIORITY_LEVEL;
ENABLE_IRQ
/* set int0 to trigger on negative edge */
pol_int0ic = FALLING_EDGE;
}
/*******************************************************************************
* Purpose: Keeps Left Wheel on until l_count reaches zero.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT TimerA0Interrupt
void TimerA0Interrupt(void) {
if (l_count > WHEELS_STOPPED) --l_count;
else {
// l_count is zero, turn left motor off
left_motor_off();
stop_timerA0();
}
return;
}
/*******************************************************************************
* Purpose: Counts down every 5 ms until A1_ticks is 0
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT TimerA1Interrupt
void TimerA1Interrupt(void) {
if (A1_ticks > TIMER_STOP) --A1_ticks;
else {
ta1s = TIMER_STOP; // stop these interrupts
timerA1_started = TIMER_STOP;
}
return;
}
/*******************************************************************************
* Purpose: Not used in this project.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT TimerA2Interrupt
void TimerA2Interrupt(void) {
// Toggle an LED to test 5ms timer
LED0 ^= LED_OFF;
}
/*******************************************************************************
* Purpose: Keeps Right Wheel on until r_count reaches zero.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT TimerB0Interrupt
void TimerB0Interrupt(void) {
if (r_count > WHEELS_STOPPED) --r_count;
else {
// r_count is zero, turn right motor off
right_motor_off();
stop_timerB0();
}
return;
}
/*******************************************************************************
* Purpose: Sets flag for Switch 1 being pressed.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT LeftBtnInterrupt
void LeftBtnInterrupt(void) {
buttonPressed |= SW1_PRESSED;
}
/*******************************************************************************
* Purpose: Sets flag for Switch 2 being pressed.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT MiddleBtnInterrupt
void MiddleBtnInterrupt(void) {
buttonPressed |= SW2_PRESSED;
}
/*******************************************************************************
* Purpose: Sets flag for Switch 3 being pressed..
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT RightBtnInterrupt
void RightBtnInterrupt(void) {
buttonPressed |= SW3_PRESSED;
}
/*******************************************************************************
* Purpose: Processes serial input on UART0.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT UART0ReceiveInterrupt
void UART0ReceiveInterrupt(void) {
while (ri_u0c1 == RECEIVING); // make sure receive is complete
u0BUFFER[u0_wr++] = u0rb;
if (u0_wr == U0_BUF_SIZE) u0_wr = CLEAR_INDEX;
}
/*******************************************************************************
* Purpose: Processes serial input on UART2.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT UART2ReceiveInterrupt
void UART2ReceiveInterrupt(void) {
while (ri_u2c1 == RECEIVING); // make sure receive is complete
u2BUFFER[u2_wr++] = u2rb;
if (u2_wr == U2_BUF_SIZE) {
u2BuffFull = TRUE;
u2_wr = CLEAR_INDEX;
}
}
/*******************************************************************************
* Purpose: Not used in this project.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
#pragma INTERRUPT A2DInterrupt
void A2DInterrupt(void) {
}
/*******************************************************************************
* Purpose: Not used in this project.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void KeyBoardInterrupt(void) {}
/*******************************************************************************
* Purpose: Not used in this project.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void RTCInterrupt(void) {}
/*******************************************************************************
* Purpose: Not used in this project.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void WatchDogInterrupt(void) {}
/*******************************************************************************
* Purpose: Not used in this project.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void UART0TransmitInterrupt(void) {}
/*******************************************************************************
* Purpose: Not used in this project.
* Passed: No arguments passed.
* Locals: No locals variables used.
* Returned: No values returned.
* Author: Will Flores [email protected]
*******************************************************************************/
void DMA0Interrupt(void) {}