]>
Commit | Line | Data |
---|---|---|
3608c106 UH |
1 | // Copyright (C) 2010 Ubixum, Inc. |
2 | // | |
3 | // This library is free software; you can redistribute it and/or | |
4 | // modify it under the terms of the GNU Lesser General Public | |
5 | // License as published by the Free Software Foundation; either | |
6 | // version 2.1 of the License, or (at your option) any later version. | |
7 | // | |
8 | // This library is distributed in the hope that it will be useful, | |
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | // Lesser General Public License for more details. | |
12 | // | |
13 | // You should have received a copy of the GNU Lesser General Public | |
040a6eae | 14 | // License along with this library; if not, see <http://www.gnu.org/licenses/>. |
3608c106 UH |
15 | |
16 | ||
17 | ||
18 | /** \file usbjt.h | |
19 | * | |
20 | * To use usbjt, you must tell the linker where to put the IN2JT. | |
21 | * It must lie on a page boundary or your interrupts won't work right. | |
22 | * | |
23 | * example: | |
24 | * -Wl"-b INT2JT = 0x1A00" | |
25 | * | |
26 | * Make sure that INT2JT doesn't overlap your other code! | |
27 | * | |
28 | * Unlike the standard fx2 interrupts (\ref fx2ints.h), the autovectored | |
29 | * interrupts are defined in assemply and have pre-written function names. | |
30 | * Be sure to override the functions defined in this header or your | |
31 | * interrupt handler will not be called. | |
32 | **/ | |
33 | ||
34 | #ifndef USBJT_H | |
35 | #define USBJT_H | |
36 | ||
37 | #include "fx2regs.h" | |
38 | ||
39 | ||
40 | ||
41 | // this causes usbjt to be included from the lib | |
42 | // not used for anything | |
43 | extern volatile BYTE INT2JT; | |
44 | extern volatile BYTE INT4JT; | |
45 | /** | |
46 | * Enable all interrupts (EA=1) separate from this macro. | |
47 | * This macro causes the autovector assembly for int2 interrupts | |
48 | * to be overlayed at 0x43. In addition, the jump table for the | |
49 | * interrupts will be included in the firmware. The jump table | |
50 | * must lie on a page boundary. This is done by passing the linker | |
51 | * arguments to sdcc. | |
52 | * | |
53 | * \code | |
54 | * sdcc <files> -Wl"-b INT2JT = 0xaddr" | |
55 | * \endcode | |
56 | **/ | |
57 | #define USE_USB_INTS() {BYTE dummy=INT2JT;\ | |
58 | EUSB=1;\ | |
59 | INTSETUP|=bmAV2EN;} | |
60 | /** This macro causes the autovector assemby for int4 to be overlayed | |
61 | * at 0x53. Don't use this if you want external pin generated int4 interrupts | |
62 | * and want to define your own interrupt handler. It is possible to use | |
63 | * usb interrupts with autovectoring and not use GPIF interrupts but GPIF | |
64 | * interrupts require the USB jump table. (You can't USE your own usb interrupt | |
65 | * handler if you want to enable GPIF interrupts.) | |
66 | **/ | |
67 | #define USE_GPIF_INTS() {BYTE dummy=INT4JT;\ | |
68 | EIEX4=1;\ | |
69 | INTSETUP|=bmAV4EN|INT4IN;} | |
70 | ||
71 | ||
72 | ||
73 | #define CLEAR_USBINT() EXIF &= ~0x10 | |
74 | #define CLEAR_GPIF() EXIF &= ~0x40 | |
75 | ||
76 | #define ENABLE_SUDAV() USBIE|=bmSUDAV | |
77 | #define CLEAR_SUDAV() CLEAR_USBINT(); USBIRQ=bmSUDAV | |
78 | ||
79 | #define ENABLE_SUTOK() USBIE|=bmSUTOK; | |
80 | #define CLEAR_SUTOK() CLEAR_USBINT(); USBIRQ=bmSUTOK | |
81 | ||
82 | #define ENABLE_SOF() USBIE|=bmSOF | |
83 | #define CLEAR_SOF() CLEAR_USBINT(); USBIRQ=bmSOF | |
84 | ||
85 | #define ENABLE_SUSPEND() USBIE|=bmSUSP | |
86 | #define CLEAR_SUSPEND() CLEAR_USBINT(); USBIRQ=bmSUSP | |
87 | ||
88 | #define ENABLE_USBRESET() USBIE|= bmURES | |
89 | #define CLEAR_USBRESET() CLEAR_USBINT(); USBIRQ=bmURES | |
90 | ||
91 | #define ENABLE_HISPEED() USBIE|=bmHSGRANT | |
92 | #define CLEAR_HISPEED() CLEAR_USBINT(); USBIRQ=bmHSGRANT | |
93 | ||
94 | #define ENABLE_EP1IN() EPIE|=bmEP1IN | |
95 | #define CLEAR_EP1IN() CLEAR_USBINT(); EPIRQ=bmEP1IN | |
96 | ||
97 | #define ENABLE_EP2() EPIE|=bmEP2 | |
98 | #define CLEAR_EP2() CLEAR_USBINT(); EPIRQ=bmEP2 | |
99 | ||
100 | #define ENABLE_EP6() EPIE|=bmEP6 | |
101 | #define CLEAR_EP6() CLEAR_USBINT(); EPIRQ=bmEP6 | |
102 | ||
103 | #define ENABLE_EP2ISOERR() USBERRIE |= bmISOEP2 | |
104 | #define CLEAR_EP2ISOERR() CLEAR_USBINT(); USBERRIRQ = bmISOEP2 | |
105 | ||
106 | #define ENABLE_EP6PF() EP6FIFOIE |= bmBIT2 | |
107 | #define CLEAR_EP6PF() CLEAR_GPIF(); EP6FIFOIRQ=bmBIT2 | |
108 | ||
109 | #define ENABLE_EP6FF() EP6FIFOIE |= bmBIT0 | |
110 | #define CLEAR_EP6FF() CLEAR_GPIF(); EP6FIFOIRQ=bmBIT0 | |
111 | ||
112 | #define ENABLE_GPIFDONE() GPIFIE |= 0x01; | |
113 | #define CLEAR_GPIFDONE() CLEAR_GPIF(); GPIFIRQ = 0x01; | |
114 | ||
115 | #define ENABLE_GPIFWF() GPIFIE |= 0x02; | |
116 | #define CLEAR_GPIFWF() GLEAR_GPIF(); GPIFIRQ = 0x02; | |
117 | ||
118 | /** | |
119 | * ez-usb has 12 built in ISRs, to get | |
120 | * sdcc to put these USB ISRs immediately | |
121 | * after the other ISRs (and not waste space) | |
122 | * we start at 13 | |
123 | **/ | |
124 | typedef enum { | |
125 | SUDAV_ISR=13, | |
126 | SOF_ISR, | |
127 | SUTOK_ISR, | |
128 | SUSPEND_ISR, | |
129 | USBRESET_ISR, | |
130 | HISPEED_ISR, | |
131 | EP0ACK_ISR, | |
132 | EP0IN_ISR, | |
133 | EP0OUT_ISR, | |
134 | EP1IN_ISR, | |
135 | EP1OUT_ISR, | |
136 | EP2_ISR, | |
137 | EP4_ISR, | |
138 | EP6_ISR, | |
139 | EP8_ISR, | |
140 | IBN_ISR, | |
141 | EP0PING_ISR, | |
142 | EP1PING_ISR, | |
143 | EP2PING_ISR, | |
144 | EP4PING_ISR, | |
145 | EP6PING_ISR, | |
146 | EP8PING_ISR, | |
147 | ERRLIMIT_ISR, | |
148 | EP2ISOERR_ISR, | |
149 | EP4ISOERR_ISR, | |
150 | EP6ISOERR_ISR, | |
151 | EP8ISOERR_ISR, | |
152 | RESERVED_ISR, | |
153 | EP2PF_ISR, | |
154 | EP4PF_ISR, | |
155 | EP6PF_ISR, | |
156 | EP8PF_ISR, | |
157 | EP2EF_ISR, | |
158 | EP4EF_ISR, | |
159 | EP6EF_ISR, | |
160 | EP8EF_ISR, | |
161 | EP2FF_ISR, | |
162 | EP4FF_ISR, | |
163 | EP6FF_ISR, | |
164 | EP8FF_ISR, | |
165 | GPIFDONE_ISR, | |
166 | GPIFWF_ISR | |
167 | } USB_ISR; | |
168 | ||
169 | // you must include the predef of these in the file with your main | |
170 | // so lets just define them here | |
171 | ||
172 | void sudav_isr() __interrupt SUDAV_ISR; | |
173 | void sof_isr() __interrupt SOF_ISR; | |
174 | void sutok_isr() __interrupt SUTOK_ISR; | |
175 | void suspend_isr() __interrupt SUSPEND_ISR; | |
176 | void usbreset_isr() __interrupt USBRESET_ISR; | |
177 | void hispeed_isr() __interrupt HISPEED_ISR; | |
178 | void ep0ack_isr() __interrupt EP0ACK_ISR; | |
179 | void ep0in_isr() __interrupt EP0IN_ISR; | |
180 | void ep0out_isr() __interrupt EP0OUT_ISR; | |
181 | void ep1in_isr() __interrupt EP1IN_ISR; | |
182 | void ep1out_isr() __interrupt EP1OUT_ISR; | |
183 | void ep2_isr() __interrupt EP2_ISR; | |
184 | void ep4_isr() __interrupt EP4_ISR; | |
185 | void ep6_isr() __interrupt EP6_ISR; | |
186 | void ep8_isr() __interrupt EP8_ISR; | |
187 | void ibn_isr() __interrupt IBN_ISR; | |
188 | void ep0ping_isr() __interrupt EP0PING_ISR; | |
189 | void ep1ping_isr() __interrupt EP1PING_ISR; | |
190 | void ep2ping_isr() __interrupt EP2PING_ISR; | |
191 | void ep4ping_isr() __interrupt EP4PING_ISR; | |
192 | void ep6ping_isr() __interrupt EP6PING_ISR; | |
193 | void ep8ping_isr() __interrupt EP8PING_ISR; | |
194 | void errlimit_isr() __interrupt ERRLIMIT_ISR; | |
195 | void ep2isoerr_isr() __interrupt EP2ISOERR_ISR; | |
196 | void ep4isoerr_isr() __interrupt EP4ISOERR_ISR; | |
197 | void ep6isoerr_isr() __interrupt EP6ISOERR_ISR; | |
198 | void ep8isoerr_isr() __interrupt EP8ISOERR_ISR; | |
199 | void spare_isr() __interrupt RESERVED_ISR; // not used | |
200 | // gpif ints | |
201 | void ep2pf_isr() __interrupt EP2PF_ISR; | |
202 | void ep4pf_isr() __interrupt EP4PF_ISR; | |
203 | void ep6pf_isr() __interrupt EP6PF_ISR; | |
204 | void ep8pf_isr() __interrupt EP8PF_ISR; | |
205 | void ep2ef_isr() __interrupt EP2EF_ISR; | |
206 | void ep4ef_isr() __interrupt EP4EF_ISR; | |
207 | void ep6ef_isr() __interrupt EP6EF_ISR; | |
208 | void ep8ef_isr() __interrupt EP8EF_ISR; | |
209 | void ep2ff_isr() __interrupt EP2FF_ISR; | |
210 | void ep4ff_isr() __interrupt EP4FF_ISR; | |
211 | void ep6ff_isr() __interrupt EP6FF_ISR; | |
212 | void ep8ff_isr() __interrupt EP8FF_ISR; | |
213 | void gpifdone_isr() __interrupt GPIFDONE_ISR; | |
214 | void gpifwf_isr() __interrupt GPIFWF_ISR; | |
215 | ||
216 | #endif | |
217 |