fxload fx2lp dev board
[fx2fw-sdcc] / fx2 / isr.h
1 /* -*- c++ -*- */\r
2 /*-----------------------------------------------------------------------------\r
3  * Interrupt handling for FX2\r
4  *-----------------------------------------------------------------------------\r
5  * Code taken from USRP2 firmware (GNU Radio Project), version 3.0.2,\r
6  * Copyright 2003 Free Software Foundation, Inc.\r
7  *-----------------------------------------------------------------------------\r
8  * This code is part of usbjtag. usbjtag is free software; you can redistribute\r
9  * it and/or modify it under the terms of the GNU General Public License as\r
10  * published by the Free Software Foundation; either version 2 of the License,\r
11  * or (at your option) any later version. usbjtag is distributed in the hope\r
12  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied\r
13  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.  You should have received a\r
15  * copy of the GNU General Public License along with this program in the file\r
16  * COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin\r
17  * St, Fifth Floor, Boston, MA  02110-1301  USA\r
18  *-----------------------------------------------------------------------------\r
19  */\r
20 \r
21 #ifndef _ISR_H_\r
22 #define _ISR_H_\r
23 \r
24 /*\r
25  * ----------------------------------------------------------------\r
26  *      routines for managing interrupt services routines\r
27  * ----------------------------------------------------------------\r
28  */\r
29 \r
30 /*\r
31  * The FX2 has three discrete sets of interrupt vectors.\r
32 \r
33  * The first set is the standard 8051 vector (13 8-byte entries).\r
34  * The second set is USB interrupt autovector (32 4-byte entries).\r
35  * The third set is the FIFO/GPIF autovector (14 4-byte entries).\r
36  *\r
37  * Since all the code we're running in the FX2 is ram based, we\r
38  * forego the typical "initialize the interrupt vectors at link time"\r
39  * strategy, in favor of calls at run time that install the correct\r
40  * pointers to functions.\r
41  */\r
42 \r
43 /*\r
44  * Standard Vector numbers\r
45  */\r
46 \r
47 #define SV_INT_0                0x03\r
48 #define SV_TIMER_0              0x0b\r
49 #define SV_INT_1                0x13\r
50 #define SV_TIMER_1              0x1b\r
51 #define SV_SERIAL_0             0x23\r
52 #define SV_TIMER_2              0x2b\r
53 #define SV_RESUME               0x33\r
54 #define SV_SERIAL_1             0x3b\r
55 #define SV_INT_2                0x43            // (INT_2) points at USB autovector\r
56 #define SV_I2C                  0x4b\r
57 #define SV_INT_4                0x53            // (INT_4) points at FIFO/GPIF autovector\r
58 #define SV_INT_5                0x5b\r
59 #define SV_INT_6                0x63\r
60 \r
61 #define SV_MIN                  SV_INT_0\r
62 #define SV_MAX                  SV_INT_6\r
63 \r
64 /*\r
65  * USB Auto Vector numbers\r
66  */\r
67 \r
68 #define UV_SUDAV                0x00\r
69 #define UV_SOF                  0x04\r
70 #define UV_SUTOK                0x08\r
71 #define UV_SUSPEND              0x0c\r
72 #define UV_USBRESET             0x10\r
73 #define UV_HIGHSPEED            0x14\r
74 #define UV_EP0ACK               0x18\r
75 #define UV_SPARE_1C             0x1c\r
76 #define UV_EP0IN                0x20\r
77 #define UV_EP0OUT               0x24\r
78 #define UV_EP1IN                0x28\r
79 #define UV_EP1OUT               0x2c\r
80 #define UV_EP2                  0x30\r
81 #define UV_EP4                  0x34\r
82 #define UV_EP6                  0x38\r
83 #define UV_EP8                  0x3c\r
84 #define UV_IBN                  0x40\r
85 #define UV_SPARE_44             0x44\r
86 #define UV_EP0PINGNAK           0x48\r
87 #define UV_EP1PINGNAK           0x4c\r
88 #define UV_EP2PINGNAK           0x50\r
89 #define UV_EP4PINGNAK           0x54\r
90 #define UV_EP6PINGNAK           0x58\r
91 #define UV_EP8PINGNAK           0x5c\r
92 #define UV_ERRLIMIT             0x60\r
93 #define UV_SPARE_64             0x64\r
94 #define UV_SPARE_68             0x68\r
95 #define UV_SPARE_6C             0x6c\r
96 #define UV_EP2ISOERR            0x70\r
97 #define UV_EP4ISOERR            0x74\r
98 #define UV_EP6ISOERR            0x78\r
99 #define UV_EP8ISOERR            0x7c\r
100 \r
101 #define UV_MIN                  UV_SUDAV\r
102 #define UV_MAX                  UV_EP8ISOERR\r
103 \r
104 /*\r
105  * FIFO/GPIF Auto Vector numbers\r
106  */\r
107 \r
108 #define FGV_EP2PF               0x80\r
109 #define FGV_EP4PF               0x84\r
110 #define FGV_EP6PF               0x88\r
111 #define FGV_EP8PF               0x8c\r
112 #define FGV_EP2EF               0x90\r
113 #define FGV_EP4EF               0x94\r
114 #define FGV_EP6EF               0x98\r
115 #define FGV_EP8EF               0x9c\r
116 #define FGV_EP2FF               0xa0\r
117 #define FGV_EP4FF               0xa4\r
118 #define FGV_EP6FF               0xa8\r
119 #define FGV_EP8FF               0xac\r
120 #define FGV_GPIFDONE            0xb0\r
121 #define FGV_GPIFWF              0xb4\r
122 \r
123 #define FGV_MIN                 FGV_EP2PF\r
124 #define FGV_MAX                 FGV_GPIFWF\r
125 \r
126 \r
127 /*\r
128  * Hook standard interrupt vector.\r
129  *\r
130  * vector_number is from the SV_<foo> list above.\r
131  * addr is the address of the interrupt service routine.\r
132  */\r
133 void hook_sv (unsigned char vector_number, unsigned short addr);\r
134 \r
135 /*\r
136  * Hook usb interrupt vector.\r
137  *\r
138  * vector_number is from the UV_<foo> list above.\r
139  * addr is the address of the interrupt service routine.\r
140  */\r
141 void hook_uv (unsigned char vector_number, unsigned short addr);\r
142 \r
143 /*\r
144  * Hook fifo/gpif interrupt vector.\r
145  *\r
146  * vector_number is from the FGV_<foo> list above.\r
147  * addr is the address of the interrupt service routine.\r
148  */\r
149 void hook_fgv (unsigned char vector_number, unsigned short addr);\r
150 \r
151 /*\r
152  * One time call to enable autovectoring for both USB and FIFO/GPIF\r
153  */\r
154 void setup_autovectors (void);\r
155 \r
156 \r
157 /*\r
158  * Must be called in each usb interrupt handler\r
159  */\r
160 #define clear_usb_irq()                 \\r
161         EXIF &= ~bmEXIF_USBINT;         \\r
162         INT2CLR = 0\r
163 \r
164 /*\r
165  * Must be calledin each fifo/gpif interrupt handler\r
166  */\r
167 #define clear_fifo_gpif_irq()           \\r
168         EXIF &= ~bmEXIF_IE4;            \\r
169         INT4CLR = 0\r
170 \r
171 #endif /* _ISR_H_ */\r