* device/include/pic16/signal.h: avoid multiline inline
[fw/sdcc] / device / include / pic16 / signal.h
1 /*
2  * Signal handler header
3  *
4  * written by Vangelis Rokas, 2005 <vrokas AT otenet.gr>
5  *
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.
10  *
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.
15  *
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.
19  *
20  *
21  * $Id$
22  */
23
24 #ifndef __SIGNAL_H__
25 #define __SIGNAL_H__
26
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
48
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    \
52 {                                                       \
53   __asm goto _ ## name __endasm;                        \
54 }
55
56 /* Define name to be the handler for high priority interrupts,
57  * use like this:
58  *   DEF_INTHIGH(high_handler)
59  *     DEF_HANDLER(SIG_TMR0, timer0_handler)
60  *     DEF_HANDLER2(SIG_TMR1, SIG_TMR1IE, timer1_handler)
61  *     ...
62  *   END_DEF
63  *
64  *   SIGHANDLER(timer0_handler)
65  *   {
66  *     // code to handle timer0 interrupts
67  *   }
68  *   SIGHANDLER(timer1_handler)
69  *   {
70  *     // code to handle timer1 interrupts
71  *   }
72  */
73 #define DEF_INTHIGH(name)                \
74 DEF_ABSVECTOR(1, name)                   \
75 void name(void) __naked __interrupt      \
76 {
77   
78 /* Define name to be the handler for high priority interrupts,
79  * use like this:
80  *   DEF_INTLOW(low_handler)
81  *     DEF_HANDLER(SIG_RB, portb_handler)
82  *     DEF_HANDLER2(SIG_LVD, SIG_LVDIE, lowvolt_handler)
83  *     ...
84  *   END_DEF
85  *
86  *   SIGHANDLER(portb_handler)
87  *   {
88  *     // code to handle PORTB change interrupts
89  *   }
90  *   SIGHANDLER(lowvolt_handler)
91  *   {
92  *     // code to handle low voltage interrupts
93  *   }
94  */
95 #define DEF_INTLOW(name)                 \
96 DEF_ABSVECTOR(2, name)                   \
97 void name(void) __naked __interrupt      \
98 {
99
100 /* finish an interrupt handler definition */
101 #define END_DEF                                 \
102   __asm retfie __endasm;                        \
103 }
104
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.
112  */
113 #define DEF_HANDLER(sig, handler)               \
114     __asm btfsc sig __endasm;                   \
115     __asm goto  _ ## handler __endasm;
116
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.
123  */
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;
129
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
133
134
135 /*
136  * inline assembly compatible bit definitions
137  */
138 #define SIG_RBIF        _INTCON, 0
139 #define SIG_RBIE        _INTCON, 3
140 #define SIG_RBIP        _INTCON2, 0
141
142 #define SIG_INT0IF      _INTCON, 1
143 #define SIG_INT0IE      _INTCON, 4
144 /*#define SIG_INT0IP not selectable, always ? */
145
146 #define SIG_TMR0IF      _INTCON, 2
147 #define SIG_TMR0IE      _INTCON, 5
148 #define SIG_TMR0IP      _INTCON2, 2
149
150 #define SIG_INT1IF      _INTCON3, 0
151 #define SIG_INT1IE      _INTCON3, 3
152 #define SIG_INT1IP      _INTCON3, 6
153
154 #define SIG_INT2IF      _INTCON3, 1
155 #define SIG_INT2IE      _INTCON3, 4
156 #define SIG_INT2IP      _INTCON3, 7
157
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
165 #define SIG_SSPIDX      3
166 #define SIG_SSPSUF      1
167 #define SIG_TXIDX       4
168 #define SIG_TXSUF       1
169 #define SIG_RCIDX       5
170 #define SIG_RCSUF       1
171 #define SIG_ADIDX       6
172 #define SIG_ADSUF       1
173 #define SIG_PSPIDX      7
174 #define SIG_PSPSUF      1
175
176 #define SIG_CCP2IDX     0
177 #define SIG_CCP2SUF     2
178 #define SIG_TMR3IDX     1
179 #define SIG_TMR3SUF     2
180 #define SIG_LVDIDX      2
181 #define SIG_LVDSUF      2
182 #define SIG_BCOLIDX     3
183 #define SIG_BCOLSUF     2
184 #define SIG_EEIDX       4
185 #define SIG_EESUF       2
186 #define SIG_USBIDX      5
187 #define SIG_USBSUF      2
188
189 /* device independent */
190 #define __concat(a,b)   __concat2(a,b)
191 #define __concat2(a,b)  a ## b
192
193 #define SIG_PIR(suf)    __concat(_PIR,suf)
194 #define SIG_PIE(suf)    __concat(_PIE,suf)
195 #define SIG_IPR(suf)    __concat(_IPR,suf)
196
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
200
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
204
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
208
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
212 /* aliases: MSSP */
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
216
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
220
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
224
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
228
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
232
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
236
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
240
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
244
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
248
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
252
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
256
257 #endif  /* __SIGNAL_H__ */