1 /*-------------------------------------------------------------------------
2 signal.h - Signal handler header
4 Copyright (C) 2005, Vangelis Rokas <vrokas AT otenet.gr>
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
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 library; see the file COPYING. If not, write to the
18 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 As a special exception, if you link this library with other files,
22 some of which are compiled with SDCC, to produce an executable,
23 this library does not by itself cause the resulting executable to
24 be covered by the GNU General Public License. This exception does
25 not however invalidate any other reasons why the executable file
26 might be covered by the GNU General Public License.
27 -------------------------------------------------------------------------*/
32 /* interrupt testing arguments */
33 #define SIG_RB SIG_RBIF
34 #define SIG_INT0 SIG_INT0IF
35 #define SIG_INT1 SIG_INT1IF
36 #define SIG_INT2 SIG_INT2IF
37 #define SIG_CCP1 SIG_CCP1IF
38 #define SIG_CCP2 SIG_CCP2IF
39 #define SIG_TMR0 SIG_TMR0IF
40 #define SIG_TMR1 SIG_TMR1IF
41 #define SIG_TMR2 SIG_TMR2IF
42 #define SIG_TMR3 SIG_TMR3IF
43 #define SIG_EE SIG_EEIF
44 #define SIG_BCOL SIG_BCOLIF
45 #define SIG_LVD SIG_LVDIF
46 #define SIG_PSP SIG_PSPIF
47 #define SIG_AD SIG_ADIF
48 #define SIG_RC SIG_RCIF
49 #define SIG_TX SIG_TXIF
50 #define SIG_SSP SIG_SSPIF
51 #define SIG_MSSP SIG_SSPIF /* just an alias */
52 #define SIG_USB SIG_USBIF
54 /* define name to be the interrupt handler for interrupt #vecno */
55 #define DEF_ABSVECTOR(vecno, name) \
56 void __ivt_ ## name(void) __interrupt(vecno) __naked \
58 __asm goto _ ## name __endasm; \
61 /* Define name to be the handler for high priority interrupts,
63 * DEF_INTHIGH(high_handler)
64 * DEF_HANDLER(SIG_TMR0, timer0_handler)
65 * DEF_HANDLER2(SIG_TMR1, SIG_TMR1IE, timer1_handler)
69 * SIGHANDLER(timer0_handler)
71 * // code to handle timer0 interrupts
73 * SIGHANDLER(timer1_handler)
75 * // code to handle timer1 interrupts
78 #define DEF_INTHIGH(name) \
79 DEF_ABSVECTOR(1, name) \
80 void name(void) __naked __interrupt \
83 /* Define name to be the handler for high priority interrupts,
85 * DEF_INTLOW(low_handler)
86 * DEF_HANDLER(SIG_RB, portb_handler)
87 * DEF_HANDLER2(SIG_LVD, SIG_LVDIE, lowvolt_handler)
91 * SIGHANDLER(portb_handler)
93 * // code to handle PORTB change interrupts
95 * SIGHANDLER(lowvolt_handler)
97 * // code to handle low voltage interrupts
100 #define DEF_INTLOW(name) \
101 DEF_ABSVECTOR(2, name) \
102 void name(void) __naked __interrupt \
105 /* finish an interrupt handler definition */
107 __asm retfie __endasm; \
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) \
119 __asm btfsc sig, 0 __endasm; \
120 __asm goto _ ## handler __endasm;
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) \
130 __asm btfss sig1, 0 __endasm; \
131 __asm bra $+8 __endasm; \
132 __asm btfsc sig2, 0 __endasm; \
133 __asm goto _ ## handler __endasm;
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__ */