-
Notifications
You must be signed in to change notification settings - Fork 3
/
traps.c
172 lines (134 loc) · 5.46 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
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
/* Device header file */
#if defined(__XC16__)
#include <xc.h>
#elif defined(__C30__)
#if defined(__dsPIC33E__)
#include <p33Exxxx.h>
#elif defined(__dsPIC33F__)
#include <p33Fxxxx.h>
#endif
#endif
#include <stdint.h> /* Includes uint16_t definition */
#include <stdbool.h> /* Includes true/false definition */
/******************************************************************************/
/* Trap Function Prototypes */
/******************************************************************************/
/* <Other function prototypes for debugging trap code may be inserted here> */
/* Use if INTCON2 ALTIVT=1 */
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);
#if defined(__HAS_DMA__)
void __attribute__((interrupt,no_auto_psv)) _DMACError(void);
#endif
#if defined(__dsPIC33F__)
/* Use if INTCON2 ALTIVT=0 */
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);
#if defined(__HAS_DMA__)
void __attribute__((interrupt,no_auto_psv)) _AltDMACError(void);
#endif
#endif
/* Default interrupt handler */
void __attribute__((interrupt,no_auto_psv)) _DefaultInterrupt(void);
#if defined(__dsPIC33E__)
/* These are additional traps in the 33E family. Refer to the PIC33E
migration guide. There are no Alternate Vectors in the 33E family. */
void __attribute__((interrupt,no_auto_psv)) _HardTrapError(void);
void __attribute__((interrupt,no_auto_psv)) _SoftTrapError(void);
#endif
/******************************************************************************/
/* Trap Handling */
/* */
/* These trap routines simply ensure that the device continuously loops */
/* within each routine. Users who actually experience one of these traps */
/* can add code to handle the error. Some basic examples for trap code, */
/* including assembly routines that process trap sources, are available at */
/* www.microchip.com/codeexamples */
/******************************************************************************/
/* Primary (non-alternate) address error trap function declarations */
void __attribute__((interrupt,no_auto_psv)) _OscillatorFail(void)
{
INTCON1bits.OSCFAIL = 0; /* Clear the trap flag */
while(1);
}
void __attribute__((interrupt,no_auto_psv)) _AddressError(void)
{
INTCON1bits.ADDRERR = 0; /* Clear the trap flag */
while (1);
}
void __attribute__((interrupt,no_auto_psv)) _StackError(void)
{
INTCON1bits.STKERR = 0; /* Clear the trap flag */
while (1);
}
void __attribute__((interrupt,no_auto_psv)) _MathError(void)
{
INTCON1bits.MATHERR = 0; /* Clear the trap flag */
while (1);
}
#if defined(__HAS_DMA__)
void __attribute__((interrupt,no_auto_psv)) _DMACError(void)
{
INTCON1bits.DMACERR = 0; /* Clear the trap flag */
while (1);
}
#endif
#if defined(__dsPIC33F__)
/* Alternate address error trap function declarations */
void __attribute__((interrupt,no_auto_psv)) _AltOscillatorFail(void)
{
INTCON1bits.OSCFAIL = 0; /* Clear the trap flag */
while (1);
}
void __attribute__((interrupt,no_auto_psv)) _AltAddressError(void)
{
INTCON1bits.ADDRERR = 0; /* Clear the trap flag */
while (1);
}
void __attribute__((interrupt,no_auto_psv)) _AltStackError(void)
{
INTCON1bits.STKERR = 0; /* Clear the trap flag */
while (1);
}
void __attribute__((interrupt,no_auto_psv)) _AltMathError(void)
{
INTCON1bits.MATHERR = 0; /* Clear the trap flag */
while (1);
}
#if defined(__HAS_DMA__)
void __attribute__((interrupt,no_auto_psv)) _AltDMACError(void)
{
INTCON1bits.DMACERR = 0; /* Clear the trap flag */
while (1);
}
#endif
#endif
/******************************************************************************/
/* Default Interrupt Handler */
/* */
/* This executes when an interrupt occurs for an interrupt source with an */
/* improperly defined or undefined interrupt handling routine. */
/******************************************************************************/
void __attribute__((interrupt,no_auto_psv)) _DefaultInterrupt(void)
{
while(1);
}
#if defined(__dsPIC33E__)
/* These traps are new to the dsPIC33E family. Refer to the device Interrupt
chapter of the FRM to understand trap priority. */
void __attribute__((interrupt,no_auto_psv)) _HardTrapError(void)
{
while(1);
}
void __attribute__((interrupt,no_auto_psv)) _SoftTrapError(void)
{
while(1);
}
#endif