source: trunk/FirmwareFX2/fx2/isr.c@ 169

Last change on this file since 169 was 4, checked in by demin, 15 years ago

initial commit

File size: 4.4 KB
Line 
1/* -*- c++ -*- */
2/*-----------------------------------------------------------------------------
3 * Interrupt handling for FX2
4 *-----------------------------------------------------------------------------
5 * Code taken from USRP2 firmware (GNU Radio Project), version 3.0.2,
6 * Copyright 2003 Free Software Foundation, Inc.
7 *-----------------------------------------------------------------------------
8 * This code is part of usbjtag. usbjtag is free software; you can redistribute
9 * it and/or modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version. usbjtag is distributed in the hope
12 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. You should have received a
15 * copy of the GNU General Public License along with this program in the file
16 * COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin
17 * St, Fifth Floor, Boston, MA 02110-1301 USA
18 *-----------------------------------------------------------------------------
19 */
20
21#include "isr.h"
22#include "fx2regs.h"
23#include "syncdelay.h"
24
25extern xdata unsigned char _standard_interrupt_vector[];
26extern xdata unsigned char _usb_autovector[];
27extern xdata unsigned char _fifo_gpif_autovector[];
28
29#define LJMP_OPCODE 0x02
30
31/*
32 * Hook standard interrupt vector.
33 *
34 * vector_number is from the SV_<foo> list.
35 * addr is the address of the interrupt service routine.
36 */
37void
38hook_sv (unsigned char vector_number, unsigned short addr)
39{
40 bit t;
41
42 // sanity checks
43
44 if (vector_number < SV_MIN || vector_number > SV_MAX)
45 return;
46
47 if ((vector_number & 0x0f) != 0x03 && (vector_number & 0x0f) != 0x0b)
48 return;
49
50 t = EA;
51 EA = 0;
52 _standard_interrupt_vector[vector_number] = LJMP_OPCODE;
53 _standard_interrupt_vector[vector_number + 1] = addr >> 8;
54 _standard_interrupt_vector[vector_number + 2] = addr & 0xff;
55 EA = t;
56}
57
58/*
59 * Hook usb interrupt vector.
60 *
61 * vector_number is from the UV_<foo> list.
62 * addr is the address of the interrupt service routine.
63 */
64void
65hook_uv (unsigned char vector_number, unsigned short addr)
66{
67 bit t;
68
69 // sanity checks
70
71#if UV_MIN>0
72 if (vector_number < UV_MIN) return;
73#endif
74 if (vector_number > UV_MAX)
75 return;
76
77 if ((vector_number & 0x3) != 0)
78 return;
79
80 t = EA;
81 EA = 0;
82 _usb_autovector[vector_number] = LJMP_OPCODE;
83 _usb_autovector[vector_number + 1] = addr >> 8;
84 _usb_autovector[vector_number + 2] = addr & 0xff;
85 EA = t;
86}
87
88/*
89 * Hook fifo/gpif interrupt vector.
90 *
91 * vector_number is from the FGV_<foo> list.
92 * addr is the address of the interrupt service routine.
93 */
94void
95hook_fgv (unsigned char vector_number, unsigned short addr)
96{
97 bit t;
98
99 // sanity checks
100
101 if (vector_number < FGV_MIN || vector_number > FGV_MAX)
102 return;
103
104 if ((vector_number & 0x3) != 0)
105 return;
106
107 t = EA;
108 EA = 0;
109 _fifo_gpif_autovector[vector_number] = LJMP_OPCODE;
110 _fifo_gpif_autovector[vector_number + 1] = addr >> 8;
111 _fifo_gpif_autovector[vector_number + 2] = addr & 0xff;
112 EA = t;
113}
114
115/*
116 * One time call to enable autovectoring for both USB and FIFO/GPIF.
117 *
118 * This disables all USB and FIFO/GPIF interrupts and clears
119 * any pending interrupts too. It leaves the master USB and FIFO/GPIF
120 * interrupts enabled.
121 */
122void
123setup_autovectors (void)
124{
125 // disable master usb and fifo/gpif interrupt enables
126 EIUSB = 0;
127 EIEX4 = 0;
128
129 hook_sv (SV_INT_2, (unsigned short) _usb_autovector);
130 hook_sv (SV_INT_4, (unsigned short) _fifo_gpif_autovector);
131
132 // disable all fifo interrupt enables
133 SYNCDELAY;
134 EP2FIFOIE = 0; SYNCDELAY;
135 EP4FIFOIE = 0; SYNCDELAY;
136 EP6FIFOIE = 0; SYNCDELAY;
137 EP8FIFOIE = 0; SYNCDELAY;
138
139 // clear all pending fifo irqs
140 EP2FIFOIRQ = 0xff; SYNCDELAY;
141 EP4FIFOIRQ = 0xff; SYNCDELAY;
142 EP6FIFOIRQ = 0xff; SYNCDELAY;
143 EP8FIFOIRQ = 0xff; SYNCDELAY;
144
145 IBNIE = 0;
146 IBNIRQ = 0xff;
147 NAKIE = 0;
148 NAKIRQ = 0xff;
149 USBIE = 0;
150 USBIRQ = 0xff;
151 EPIE = 0;
152 EPIRQ = 0xff;
153 SYNCDELAY; GPIFIE = 0;
154 SYNCDELAY; GPIFIRQ = 0xff;
155 USBERRIE = 0;
156 USBERRIRQ = 0xff;
157 CLRERRCNT = 0;
158
159 INTSETUP = bmAV2EN | bmAV4EN | bmINT4IN;
160
161 // clear master irq's for usb and fifo/gpif
162 EXIF &= ~bmEXIF_USBINT;
163 EXIF &= ~bmEXIF_IE4;
164
165 // enable master usb and fifo/gpif interrrupts
166 EIUSB = 1;
167 EIEX4 = 1;
168}
Note: See TracBrowser for help on using the repository browser.