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 \
53 __asm goto _ ## name __endasm; \
56 /* Define name to be the handler for high priority interrupts,
58 * DEF_INTHIGH(high_handler)
59 * DEF_HANDLER(SIG_TMR0, timer0_handler)
60 * DEF_HANDLER2(SIG_TMR1, SIG_TMR1IE, timer1_handler)
64 * SIGHANDLER(timer0_handler)
66 * // code to handle timer0 interrupts
68 * SIGHANDLER(timer1_handler)
70 * // code to handle timer1 interrupts
73 #define DEF_INTHIGH(name) \
74 DEF_ABSVECTOR(1, name) \
75 void name(void) __naked __interrupt \
78 /* Define name to be the handler for high priority interrupts,
80 * DEF_INTLOW(low_handler)
81 * DEF_HANDLER(SIG_RB, portb_handler)
82 * DEF_HANDLER2(SIG_LVD, SIG_LVDIE, lowvolt_handler)
86 * SIGHANDLER(portb_handler)
88 * // code to handle PORTB change interrupts
90 * SIGHANDLER(lowvolt_handler)
92 * // code to handle low voltage interrupts
95 #define DEF_INTLOW(name) \
96 DEF_ABSVECTOR(2, name) \
97 void name(void) __naked __interrupt \
100 /* finish an interrupt handler definition */
102 __asm retfie __endasm; \
105 /* Declare handler to be the handler function for the given signal.
106 * sig should be one of SIG_xxx from above, handler should be a
107 * function defined using SIGHANDLER(handler) or
108 * SIGHANDLERNAKED(handler).
109 * ATTENTION: This macro ignores the signal's enable bit!
110 * Use DEF_HANDLER2(SIG_xxx, SIGxxxIE, handler) instead!
111 * To be used together with DEF_INTHIGH and DEF_INTLOW.
113 #define DEF_HANDLER(sig, handler) \
114 __asm btfsc sig __endasm; \
115 __asm goto _ ## handler __endasm;
117 /* Declare handler to be the handler function for the given signal.
118 * sig should be one of SIG_xxx from above,
119 * sig2 should also be a signal (probably SIG_xxxIE from below) and
120 * handler should be a function defined using SIGHANDLER(handler)
121 * or SIGHANDLERNAKED(handler).
122 * To be used together with DEF_INTHIGH and DEF_INTLOW.
124 #define DEF_HANDLER2(sig1,sig2,handler) \
125 __asm btfss sig1 __endasm; \
126 __asm bra $+8 __endasm; \
127 __asm btfsc sig2 __endasm; \
128 __asm goto _ ## handler __endasm;
130 /* Declare or define an interrupt handler function. */
131 #define SIGHANDLER(handler) void handler (void) __interrupt
132 #define SIGHANDLERNAKED(handler) void handler (void) __naked __interrupt
136 * inline assembly compatible bit definitions
138 #define SIG_RBIF _INTCON, 0
139 #define SIG_RBIE _INTCON, 3
140 #define SIG_RBIP _INTCON2, 0
142 #define SIG_INT0IF _INTCON, 1
143 #define SIG_INT0IE _INTCON, 4
144 /*#define SIG_INT0IP not selectable, always ? */
146 #define SIG_TMR0IF _INTCON, 2
147 #define SIG_TMR0IE _INTCON, 5
148 #define SIG_TMR0IP _INTCON2, 2
150 #define SIG_INT1IF _INTCON3, 0
151 #define SIG_INT1IE _INTCON3, 3
152 #define SIG_INT1IP _INTCON3, 6
154 #define SIG_INT2IF _INTCON3, 1
155 #define SIG_INT2IE _INTCON3, 4
156 #define SIG_INT2IP _INTCON3, 7
158 /* device dependent -- should be moved to pic18f*.h */
159 #define SIG_TMR1IDX 0
160 #define SIG_TMR1SUF 1
161 #define SIG_TMR2IDX 1
162 #define SIG_TMR2SUF 1
163 #define SIG_CCP1IDX 2
164 #define SIG_CCP1SUF 1
176 #define SIG_CCP2IDX 0
177 #define SIG_CCP2SUF 2
178 #define SIG_TMR3IDX 1
179 #define SIG_TMR3SUF 2
182 #define SIG_BCOLIDX 3
183 #define SIG_BCOLSUF 2
189 /* device independent */
190 #define __concat(a,b) __concat2(a,b)
191 #define __concat2(a,b) a ## b
193 #define SIG_PIR(suf) __concat(_PIR,suf)
194 #define SIG_PIE(suf) __concat(_PIE,suf)
195 #define SIG_IPR(suf) __concat(_IPR,suf)
197 #define SIG_TMR1IF SIG_PIR(SIG_TMR1SUF), SIG_TMR1IDX
198 #define SIG_TMR1IE SIG_PIE(SIG_TMR1SUF), SIG_TMR1IDX
199 #define SIG_TMR1IP SIG_IPR(SIG_TMR1SUF), SIG_TMR1IDX
201 #define SIG_TMR2IF SIG_PIR(SIG_TMR2SUF), SIG_TMR2IDX
202 #define SIG_TMR2IE SIG_PIE(SIG_TMR2SUF), SIG_TMR2IDX
203 #define SIG_TMR2IP SIG_IPR(SIG_TMR2SUF), SIG_TMR2IDX
205 #define SIG_CCP1IF SIG_PIR(SIG_CCP1SUF), SIG_CCP1IDX
206 #define SIG_CCP1IE SIG_PIE(SIG_CCP1SUF), SIG_CCP1IDX
207 #define SIG_CCP1IP SIG_IPR(SIG_CCP1SUF), SIG_CCP1IDX
209 #define SIG_SSPIF SIG_PIR(SIG_SSPSUF), SIG_SSPIDX
210 #define SIG_SSPIE SIG_PIE(SIG_SSPSUF), SIG_SSPIDX
211 #define SIG_SSPIP SIG_IPR(SIG_SSPSUF), SIG_SSPIDX
213 #define SIG_MSSPIF SIG_SSPIF //SIG_PIR(SIG_SSPSUF), SIG_SSPIDX
214 #define SIG_MSSPIE SIG_SSPIE //SIG_PIE(SIG_SSPSUF), SIG_SSPIDX
215 #define SIG_MSSPIP SIG_SSPIP //SIG_IPR(SIG_SSPSUF), SIG_SSPIDX
217 #define SIG_TXIF SIG_PIR(SIG_TXSUF), SIG_TXIDX
218 #define SIG_TXIE SIG_PIE(SIG_TXSUF), SIG_TXIDX
219 #define SIG_TXIP SIG_IPR(SIG_TXSUF), SIG_TXIDX
221 #define SIG_RCIF SIG_PIR(SIG_RCSUF), SIG_RCIDX
222 #define SIG_RCIE SIG_PIE(SIG_RCSUF), SIG_RCIDX
223 #define SIG_RCIP SIG_IPR(SIG_RCSUF), SIG_RCIDX
225 #define SIG_ADIF SIG_PIR(SIG_ADSUF), SIG_ADIDX
226 #define SIG_ADIE SIG_PIE(SIG_ADSUF), SIG_ADIDX
227 #define SIG_ADIP SIG_IPR(SIG_ADSUF), SIG_ADIDX
229 #define SIG_PSPIF SIG_PIR(SIG_PSPSUF), SIG_PSPIDX
230 #define SIG_PSPIE SIG_PIE(SIG_PSPSUF), SIG_PSPIDX
231 #define SIG_PSPIP SIG_IPR(SIG_PSPSUF), SIG_PSPIDX
233 #define SIG_CCP2IF SIG_PIR(SIG_CCP2SUF), SIG_CCP2IDX
234 #define SIG_CCP2IE SIG_PIE(SIG_CCP2SUF), SIG_CCP2IDX
235 #define SIG_CCP2IP SIG_IPR(SIG_CCP2SUF), SIG_CCP2IDX
237 #define SIG_TMR3IF SIG_PIR(SIG_TMR3SUF), SIG_TMR3IDX
238 #define SIG_TMR3IE SIG_PIE(SIG_TMR3SUF), SIG_TMR3IDX
239 #define SIG_TMR3IP SIG_IPR(SIG_TMR3SUF), SIG_TMR3IDX
241 #define SIG_LVDIF SIG_PIR(SIG_LVDSUF), SIG_LVDIDX
242 #define SIG_LVDIE SIG_PIE(SIG_LVDSUF), SIG_LVDIDX
243 #define SIG_LVDIP SIG_IPR(SIG_LVDSUF), SIG_LVDIDX
245 #define SIG_BCOLIF SIG_PIR(SIG_BCOLSUF), SIG_BCOLIDX
246 #define SIG_BCOLIE SIG_PIE(SIG_BCOLSUF), SIG_BCOLIDX
247 #define SIG_BCOLIP SIG_IPR(SIG_BCOLSUF), SIG_BCOLIDX
249 #define SIG_EEIF SIG_PIR(SIG_EESUF), SIG_EEIDX
250 #define SIG_EEIE SIG_PIE(SIG_EESUF), SIG_EEIDX
251 #define SIG_EEIP SIG_IPR(SIG_EESUF), SIG_EEIDX
253 #define SIG_USBIF SIG_PIR(SIG_USBSUF), SIG_USBIDX
254 #define SIG_USBIE SIG_PIE(SIG_USBSUF), SIG_USBIDX
255 #define SIG_USBIP SIG_IPR(SIG_USBSUF), SIG_USBIDX
257 #endif /* __SIGNAL_H__ */