forked from biomimetics/basestation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraps.c
212 lines (191 loc) · 6.69 KB
/
traps.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
/**********************************************************************
* © 2006 Microchip Technology Inc.
*
* FileName: traps.c
* Dependencies: p33FJ256GP506.h
* Processor: dsPIC33F
* Compiler: MPLAB® C30 v2.01 or higher
*
* SOFTWARE LICENSE AGREEMENT:
* Microchip Technology Inc. (“Microchip”) licenses this software to you
* solely for use with Microchip dsPIC® digital signal controller
* products. The software is owned by Microchip and is protected under
* applicable copyright laws. All rights reserved.
*
* SOFTWARE IS PROVIDED “AS IS.” MICROCHIP EXPRESSLY DISCLAIMS ANY
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP
* BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
* DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
* ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
*
* REVISION HISTORY:
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Author Date Comments on this revision
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Hrushikesh Vasuki 05/03/05 First release of source file
* Richard Fischer 07/14/05 Add DMAC exception handler
* Priyabrata Sinha 01/27/06 Ported to non-prototype devices
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* ADDITIONAL NOTES:
* 1. This file contains trap service routines (handlers) for hardware
* exceptions generated by the dsPIC30F device.
* 2. All trap service routines in this file simply ensure that device
* continuously executes code within the trap service routine. Users
* may modify the basic framework provided here to suit to the needs
* of their application.
*
**********************************************************************/
#include "p33Fxxxx.h"
#include "utils.h"
unsigned int k;
void __attribute__((__interrupt__, no_auto_psv)) _OscillatorFail(void);
void __attribute__((__interrupt__, no_auto_psv)) _AddressError(void);
void __attribute__((__interrupt__, no_auto_psv)) _StackError(void);
void __attribute__((__interrupt__, no_auto_psv)) _MathError(void);
void __attribute__((__interrupt__, no_auto_psv)) _DMACError(void);
void __attribute__((__interrupt__, no_auto_psv)) _AltOscillatorFail(void);
void __attribute__((__interrupt__, no_auto_psv)) _AltAddressError(void);
void __attribute__((__interrupt__, no_auto_psv)) _AltStackError(void);
void __attribute__((__interrupt__, no_auto_psv)) _AltMathError(void);
void __attribute__((__interrupt__, no_auto_psv)) _AltDMACError(void);
/* Primary Exception Vector handlers:
These routines are used if INTCON2bits.ALTIVT = 0.
All trap service routines in this file simply ensure that device
continuously executes code within the trap service routine. Users
may modify the basic framework provided here to suit to the needs
of their application. */
void __attribute__((__interrupt__, no_auto_psv)) _OscillatorFail(void)
{
INTCON1bits.OSCFAIL = 0; //Clear the trap flag
while(1) {
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(1000);
}
}
void __attribute__((__interrupt__, no_auto_psv)) _AddressError(void)
{
INTCON1bits.ADDRERR = 0; //Clear the trap flags
while(1) {
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(1000);
}
while(1) {
asm volatile("btg PORTF, #1");
for (k=0; k<100; k++) { delay_us(500); } // Waste approximatelly 50ms
};
}
void __attribute__((__interrupt__, no_auto_psv)) _StackError(void)
{
INTCON1bits.STKERR = 0; //Clear the trap flag
while(1) {
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(1000);
}
}
void __attribute__((__interrupt__, no_auto_psv)) _MathError(void)
{
INTCON1bits.MATHERR = 0; //Clear the trap flag
while(1) {
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(1000);
}
}
void __attribute__((__interrupt__, no_auto_psv)) _DMACError(void)
{
/* reset status bits, real app should check which ones */
DMACS0 = 0;
INTCON1bits.DMACERR = 0; //Clear the trap flag
while(1) {
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(200);
LED_1 = ON;
delay_ms(200);
LED_1 = OFF;
delay_ms(1000);
}
}
/* Alternate Exception Vector handlers:
These routines are used if INTCON2bits.ALTIVT = 1.
All trap service routines in this file simply ensure that device
continuously executes code within the trap service routine. Users
may modify the basic framework provided here to suit to the needs
of their application. */
void __attribute__((__interrupt__, no_auto_psv)) _AltOscillatorFail(void)
{
INTCON1bits.OSCFAIL = 0;
while (1);
}
void __attribute__((__interrupt__, no_auto_psv)) _AltAddressError(void)
{
INTCON1bits.ADDRERR = 0;
while (1);
}
void __attribute__((__interrupt__, no_auto_psv)) _AltStackError(void)
{
INTCON1bits.STKERR = 0;
while (1);
}
void __attribute__((__interrupt__, no_auto_psv)) _AltMathError(void)
{
INTCON1bits.MATHERR = 0;
while (1);
}
void __attribute__((__interrupt__)) _AltDMACError(void)
{
/* reset status bits, real app should check which ones */
DMACS0 = 0;
INTCON1bits.DMACERR = 0; //Clear the trap flag
while (1);
}