2 * Signal handler header
4 * written by Vangelis Rokas, 2005 <vrokas AT otenet.gr>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 /* interrupt testing arguments */
28 #define SIG_RB SIG_RBIF
29 #define SIG_INT0 SIG_INT0IF
30 #define SIG_INT1 SIG_INT1IF
31 #define SIG_INT2 SIG_INT2IF
32 #define SIG_CCP1 SIG_CCP1IF
33 #define SIG_CCP2 SIG_CCP2IF
34 #define SIG_TMR0 SIG_TMR0IF
35 #define SIG_TMR1 SIG_TMR1IF
36 #define SIG_TMR2 SIG_TMR2IF
37 #define SIG_TMR3 SIG_TMR3IF
38 #define SIG_EE SIG_EEIF
39 #define SIG_BCOL SIG_BCOLIF
40 #define SIG_LVD SIG_LVDIF
41 #define SIG_PSP SIG_PSPIF
42 #define SIG_AD SIG_ADIF
43 #define SIG_RC SIG_RCIF
44 #define SIG_TX SIG_TXIF
45 #define SIG_SSP SIG_SSPIF
46 #define SIG_MSSP SIG_SSPIF /* just an alias */
47 #define SIG_USB SIG_USBIF
49 /* define name to be the interrupt handler for interrupt #vecno */
50 #define DEF_ABSVECTOR(vecno, name) \
51 void __ivt_ ## name(void) __interrupt vecno __naked \
58 /* Define name to be the handler for high priority interrupts,
60 * DEF_INTHIGH(high_handler)
61 * DEF_HANDLER(SIG_TMR0, timer0_handler)
62 * DEF_HANDLER2(SIG_TMR1, SIG_TMR1IE, timer1_handler)
66 * SIGHANDLER(timer0_handler)
68 * // code to handle timer0 interrupts
70 * SIGHANDLER(timer1_handler)
72 * // code to handle timer1 interrupts
75 #define DEF_INTHIGH(name) \
76 DEF_ABSVECTOR(1, name) \
77 void name(void) __naked __interrupt \
81 /* Define name to be the handler for high priority interrupts,
83 * DEF_INTLOW(low_handler)
84 * DEF_HANDLER(SIG_RB, portb_handler)
85 * DEF_HANDLER2(SIG_LVD, SIG_LVDIE, lowvolt_handler)
89 * SIGHANDLER(portb_handler)
91 * // code to handle PORTB change interrupts
93 * SIGHANDLER(lowvolt_handler)
95 * // code to handle low voltage interrupts
98 #define DEF_INTLOW(name) \
99 DEF_ABSVECTOR(2, name) \
100 void name(void) __naked __interrupt \
104 /* finish an interrupt handler definition */
110 /* Declare handler to be the handler function for the given signal.
111 * sig should be one of SIG_xxx from above, handler should be a
112 * function defined using SIGHANDLER(handler) or
113 * SIGHANDLERNAKED(handler).
114 * ATTENTION: This macro ignores the signal's enable bit!
115 * Use DEF_HANDLER2(SIG_xxx, SIGxxxIE, handler) instead!
116 * To be used together with DEF_INTHIGH and DEF_INTLOW.
118 #define DEF_HANDLER(sig, handler) \
122 /* Declare handler to be the handler function for the given signal.
123 * sig should be one of SIG_xxx from above,
124 * sig2 should also be a signal (probably SIG_xxxIE from below) and
125 * handler should be a function defined using SIGHANDLER(handler)
126 * or SIGHANDLERNAKED(handler).
127 * To be used together with DEF_INTHIGH and DEF_INTLOW.
129 #define DEF_HANDLER2(sig1,sig2,handler) \
135 /* Declare or define an interrupt handler function. */
136 #define SIGHANDLER(handler) void handler (void) __interrupt
137 #define SIGHANDLERNAKED(handler) void handler (void) __naked __interrupt
141 * inline assembly compatible bit definitions
143 #define SIG_RBIF _INTCON, 0
144 #define SIG_RBIE _INTCON, 3
145 #define SIG_RBIP _INTCON2, 0
147 #define SIG_INT0IF _INTCON, 1
148 #define SIG_INT0IE _INTCON, 4
149 /*#define SIG_INT0IP not selectable, always ? */
151 #define SIG_TMR0IF _INTCON, 2
152 #define SIG_TMR0IE _INTCON, 5
153 #define SIG_TMR0IP _INTCON2, 2
155 #define SIG_INT1IF _INTCON3, 0
156 #define SIG_INT1IE _INTCON3, 3
157 #define SIG_INT1IP _INTCON3, 6
159 #define SIG_INT2IF _INTCON3, 1
160 #define SIG_INT2IE _INTCON3, 4
161 #define SIG_INT2IP _INTCON3, 7
163 /* device dependent -- should be moved to pic18f*.h */
164 #define SIG_TMR1IDX 0
165 #define SIG_TMR1SUF 1
166 #define SIG_TMR2IDX 1
167 #define SIG_TMR2SUF 1
168 #define SIG_CCP1IDX 2
169 #define SIG_CCP1SUF 1
181 #define SIG_CCP2IDX 0
182 #define SIG_CCP2SUF 2
183 #define SIG_TMR3IDX 1
184 #define SIG_TMR3SUF 2
187 #define SIG_BCOLIDX 3
188 #define SIG_BCOLSUF 2
194 /* device independent */
195 #define __concat(a,b) __concat2(a,b)
196 #define __concat2(a,b) a ## b
198 #define SIG_PIR(suf) __concat(_PIR,suf)
199 #define SIG_PIE(suf) __concat(_PIE,suf)
200 #define SIG_IPR(suf) __concat(_IPR,suf)
202 #define SIG_TMR1IF SIG_PIR(SIG_TMR1SUF), SIG_TMR1IDX
203 #define SIG_TMR1IE SIG_PIE(SIG_TMR1SUF), SIG_TMR1IDX
204 #define SIG_TMR1IP SIG_IPR(SIG_TMR1SUF), SIG_TMR1IDX
206 #define SIG_TMR2IF SIG_PIR(SIG_TMR2SUF), SIG_TMR2IDX
207 #define SIG_TMR2IE SIG_PIE(SIG_TMR2SUF), SIG_TMR2IDX
208 #define SIG_TMR2IP SIG_IPR(SIG_TMR2SUF), SIG_TMR2IDX
210 #define SIG_CCP1IF SIG_PIR(SIG_CCP1SUF), SIG_CCP1IDX
211 #define SIG_CCP1IE SIG_PIE(SIG_CCP1SUF), SIG_CCP1IDX
212 #define SIG_CCP1IP SIG_IPR(SIG_CCP1SUF), SIG_CCP1IDX
214 #define SIG_SSPIF SIG_PIR(SIG_SSPSUF), SIG_SSPIDX
215 #define SIG_SSPIE SIG_PIE(SIG_SSPSUF), SIG_SSPIDX
216 #define SIG_SSPIP SIG_IPR(SIG_SSPSUF), SIG_SSPIDX
218 #define SIG_MSSPIF SIG_SSPIF //SIG_PIR(SIG_SSPSUF), SIG_SSPIDX
219 #define SIG_MSSPIE SIG_SSPIE //SIG_PIE(SIG_SSPSUF), SIG_SSPIDX
220 #define SIG_MSSPIP SIG_SSPIP //SIG_IPR(SIG_SSPSUF), SIG_SSPIDX
222 #define SIG_TXIF SIG_PIR(SIG_TXSUF), SIG_TXIDX
223 #define SIG_TXIE SIG_PIE(SIG_TXSUF), SIG_TXIDX
224 #define SIG_TXIP SIG_IPR(SIG_TXSUF), SIG_TXIDX
226 #define SIG_RCIF SIG_PIR(SIG_RCSUF), SIG_RCIDX
227 #define SIG_RCIE SIG_PIE(SIG_RCSUF), SIG_RCIDX
228 #define SIG_RCIP SIG_IPR(SIG_RCSUF), SIG_RCIDX
230 #define SIG_ADIF SIG_PIR(SIG_ADSUF), SIG_ADIDX
231 #define SIG_ADIE SIG_PIE(SIG_ADSUF), SIG_ADIDX
232 #define SIG_ADIP SIG_IPR(SIG_ADSUF), SIG_ADIDX
234 #define SIG_PSPIF SIG_PIR(SIG_PSPSUF), SIG_PSPIDX
235 #define SIG_PSPIE SIG_PIE(SIG_PSPSUF), SIG_PSPIDX
236 #define SIG_PSPIP SIG_IPR(SIG_PSPSUF), SIG_PSPIDX
238 #define SIG_CCP2IF SIG_PIR(SIG_CCP2SUF), SIG_CCP2IDX
239 #define SIG_CCP2IE SIG_PIE(SIG_CCP2SUF), SIG_CCP2IDX
240 #define SIG_CCP2IP SIG_IPR(SIG_CCP2SUF), SIG_CCP2IDX
242 #define SIG_TMR3IF SIG_PIR(SIG_TMR3SUF), SIG_TMR3IDX
243 #define SIG_TMR3IE SIG_PIE(SIG_TMR3SUF), SIG_TMR3IDX
244 #define SIG_TMR3IP SIG_IPR(SIG_TMR3SUF), SIG_TMR3IDX
246 #define SIG_LVDIF SIG_PIR(SIG_LVDSUF), SIG_LVDIDX
247 #define SIG_LVDIE SIG_PIE(SIG_LVDSUF), SIG_LVDIDX
248 #define SIG_LVDIP SIG_IPR(SIG_LVDSUF), SIG_LVDIDX
250 #define SIG_BCOLIF SIG_PIR(SIG_BCOLSUF), SIG_BCOLIDX
251 #define SIG_BCOLIE SIG_PIE(SIG_BCOLSUF), SIG_BCOLIDX
252 #define SIG_BCOLIP SIG_IPR(SIG_BCOLSUF), SIG_BCOLIDX
254 #define SIG_EEIF SIG_PIR(SIG_EESUF), SIG_EEIDX
255 #define SIG_EEIE SIG_PIE(SIG_EESUF), SIG_EEIDX
256 #define SIG_EEIP SIG_IPR(SIG_EESUF), SIG_EEIDX
258 #define SIG_USBIF SIG_PIR(SIG_USBSUF), SIG_USBIDX
259 #define SIG_USBIE SIG_PIE(SIG_USBSUF), SIG_USBIDX
260 #define SIG_USBIP SIG_IPR(SIG_USBSUF), SIG_USBIDX
262 #endif /* __SIGNAL_H__ */