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