1 /*-----------------------------------------------------------------------------
\r
2 * Hardware-dependent code for usb_jtag
\r
3 *-----------------------------------------------------------------------------
\r
4 * Copyright (C) 2007 Kolja Waschk, ixo.de
\r
5 *-----------------------------------------------------------------------------
\r
6 * This code is part of usbjtag. usbjtag is free software; you can redistribute
\r
7 * it and/or modify it under the terms of the GNU General Public License as
\r
8 * published by the Free Software Foundation; either version 2 of the License,
\r
9 * or (at your option) any later version. usbjtag is distributed in the hope
\r
10 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
\r
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details. You should have received a
\r
13 * copy of the GNU General Public License along with this program in the file
\r
14 * COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin
\r
15 * St, Fifth Floor, Boston, MA 02110-1301 USA
\r
16 *-----------------------------------------------------------------------------
\r
20 #include "syncdelay.h"
\r
21 #include "hardware.h"
\r
26 #include "fx2regs.h"
\r
27 #include "fx2utils.h"
\r
28 #include "usb_common.h"
\r
29 #include "usb_descriptors.h"
\r
30 #include "usb_requests.h"
\r
31 #include "syncdelay.h"
\r
36 #define HAVE_OE_LED 1
\r
38 sbit at 0x80+1 OELED; // red LED on S3E Starter Kit (0x80+0 is green one)
\r
40 #define SetOELED(x) do{OELED=(x);}while(0)
\r
44 void ProgIO_Poll(void) {}
\r
45 void ProgIO_Enable(void) {}
\r
46 void ProgiO_Disable(void) {}
\r
47 void ProgiO_Deinit(void) {}
\r
49 static unsigned char curios;
\r
51 const unsigned char wavedata[64] =
\r
54 s0: BITS=D0 NEXT/SGLCRC DATA WAIT 4
\r
55 s1: BITS= DATA WAIT 4
\r
56 s2: BITS=D1|D0 DATA WAIT 4
\r
57 s3: BITS=D1 DATA WAIT 3
\r
58 s4: BITS=D1 DATA DP IF(RDY0) THEN 5 ELSE 2
\r
59 s5: BITS=D1|D0 DATA WAIT 4
\r
60 s6: BITS=D1 DATA WAIT 3
\r
61 s7: BITS=D1 DATA FIN */
\r
63 4, 4, 4, 3, 0x2A, 4, 3, 7,
\r
64 6, 2, 2, 2, 3, 2, 2, 2,
\r
65 1, 0, 3, 2, 2, 3, 2, 2,
\r
66 0, 0, 0, 0, 0, 0, 0, 0x3F,
\r
71 s2: BITS=D1|D0 WAIT 4
\r
73 s4: BITS=D1|D0 WAIT 3
\r
74 s5: BITS=D1|D0 DP IF(RDY0) THEN 6 ELSE 3
\r
75 s6: BITS=D1 DATA WAIT 4
\r
78 4, 4, 4, 4, 3, 0x33, 4, 7,
\r
79 0, 0, 0, 0, 0, 1, 2, 0,
\r
80 1, 0, 3, 2, 3, 3, 2, 2,
\r
81 0, 0, 0, 0, 0, 0, 0, 0x3F
\r
84 void ProgIO_Init(void)
\r
88 /* The following code depends on your actual circuit design.
\r
89 Make required changes _before_ you try the code! */
\r
91 // set the CPU clock to 48MHz, enable clock output to FPGA
\r
92 CPUCS = bmCLKOE | bmCLKSPD1;
\r
94 // Use internal 48 MHz, enable output, GPIF Master mode
\r
95 IFCONFIG = bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmIFGPIF;
\r
97 PORTACFG = 0x00; OEA = 0xFB; IOA = 0x20;
\r
98 PORTCCFG = 0x00; OEC = 0xFF; IOC = 0x10;
\r
99 PORTECFG = 0x00; OEE = 0xFC; IOE = 0xC0;
\r
103 GPIFREADYCFG = 0xA0;
\r
106 GPIFIDLECTL = 0x00;
\r
107 GPIFWFSELECT = 0x01;
\r
109 // Copy waveform data
\r
110 AUTOPTRSETUP = 0x07;
\r
111 APTR1H = MSB( &wavedata );
\r
112 APTR1L = LSB( &wavedata );
\r
115 for ( i = 0; i < 64; i++ ) EXTAUTODAT2 = EXTAUTODAT1;
\r
126 FLOWHOLDOFF = 0x00;
\r
128 FLOWSTBEDGE = 0x00;
\r
129 FLOWSTBHPERIOD = 0x00;
\r
134 unsigned char GetTDO(unsigned char r)
\r
139 while(!(GPIFTRIG & 0x80)); x = XGPIFSGLDATLX;
\r
140 while(!(GPIFTRIG & 0x80)); x = XGPIFSGLDATLNOX;
\r
142 if(IOA & 0x20) IOA |= 0x40; else IOA &= ~0x40;
\r
144 return (x&1) ? r : 0;
\r
147 #define SetPins(x) while(!(GPIFTRIG & 0x80)); XGPIFSGLDATLX = (x)
\r
149 void ProgIO_Set_State(unsigned char d)
\r
151 /* Set state of output pins:
\r
153 * d.0 => TCK (PE.6)
\r
154 * d.1 => TMS (PE.5)
\r
155 * d.4 => TDI (PE.4)
\r
156 * d.6 => LED / Output Enable
\r
159 curios = (d & bmBIT0) ? 0x40 : 0; // TCK
\r
160 curios |= (d & bmBIT1) ? 0x20 : 0; // TMS
\r
161 curios |= (d & bmBIT4) ? 0x10 : 0; // TDI
\r
163 IOC = 0x81; /* Select direction */
\r
166 if(d & bmBIT6) IOA=(IOA&~3)|1; else IOA=(IOA&~3)|2;
\r
169 unsigned char ProgIO_Set_Get_State(unsigned char d)
\r
172 ProgIO_Set_State(d);
\r
174 /* Read state of input pins:
\r
177 * DATAOUT => d.1 (only #ifdef HAVE_AS_MODE)
\r
180 return 2|GetTDO(0x01);
\r
185 void ProgIO_ShiftOut(unsigned char c)
\r
188 unsigned char locios = curios & ~0x50;
\r
190 IOC = 0x81; /* Select direction */
\r
192 for(i=0,r=1;i<8;i++)
\r
194 unsigned char t = locios;
\r
195 if(c & r) t |= 0x10;
\r
206 unsigned char ProgIO_ShiftInOut(unsigned char c)
\r
208 unsigned char r,i,n;
\r
209 unsigned char locios = curios & ~0x50;
\r
211 for(i=0,r=1,n=0;i<8;i++)
\r
213 unsigned char t = locios;
\r
219 if(c & r) t |= 0x10;
\r