1 /*-----------------------------------------------------------------------------
\r
5 * Hardware-dependent code for usb_jtag
\r
7 *-----------------------------------------------------------------------------
\r
9 * Copyright (C) 2007 Kolja Waschk, ixo.de
\r
11 *-----------------------------------------------------------------------------
\r
13 * This code is part of usbjtag. usbjtag is free software; you can redistribute
\r
15 * it and/or modify it under the terms of the GNU General Public License as
\r
17 * published by the Free Software Foundation; either version 2 of the License,
\r
19 * or (at your option) any later version. usbjtag is distributed in the hope
\r
21 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
\r
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
25 * GNU General Public License for more details. You should have received a
\r
27 * copy of the GNU General Public License along with this program in the file
\r
29 * COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin
\r
31 * St, Fifth Floor, Boston, MA 02110-1301 USA
\r
33 *-----------------------------------------------------------------------------
\r
39 #include "hardware.h"
\r
41 #include "fx2regs.h"
\r
43 #include "syncdelay.h"
\r
47 //---------------------------------------------------------------------------
\r
51 #define SetTCK(x) do{if(x) IOE|=0x08; else IOE&=~0x08; }while(0)
\r
53 #define SetTMS(x) do{if(x) IOE|=0x10; else IOE&=~0x10; }while(0)
\r
55 #define SetTDI(x) do{if(x) IOE|=0x40; else IOE&=~0x40; }while(0)
\r
57 #define GetTDO() ((IOE>>5)&1)
\r
61 /* XPCU has neither AS nor PS mode pins */
\r
65 #define HAVE_OE_LED 1
\r
67 /* +0=green led, +1=red led */
\r
69 sbit at 0x80+1 OELED;
\r
71 #define SetOELED(x) do{OELED=(x);}while(0)
\r
75 //-----------------------------------------------------------------------------
\r
79 void ProgIO_Poll(void) {}
\r
81 void ProgIO_Enable(void) {}
\r
83 void ProgIO_Disable(void) {}
\r
85 void ProgIO_Deinit(void) {}
\r
89 void ProgIO_Init(void)
\r
93 /* The following code depends on your actual circuit design.
\r
95 Make required changes _before_ you try the code! */
\r
99 // set the CPU clock to 48MHz, enable clock output to FPGA
\r
101 CPUCS = bmCLKOE | bmCLKSPD1;
\r
105 // Use internal 48 MHz, enable output, use "Port" mode for all pins
\r
107 IFCONFIG = bmIFCLKSRC | bm3048MHZ | bmIFCLKOE;
\r
115 PORTACFG = 0x00; OEA = 0x03; IOA=0x01;
\r
117 PORTCCFG = 0x00; OEC = 0x00; IOC=0x00;
\r
119 PORTECFG = 0x00; OEE = 0x58; IOE=0x00;
\r
125 void ProgIO_Set_State(unsigned char d)
\r
129 /* Set state of output pins:
\r
137 * d.2 => nCE (only #ifdef HAVE_AS_MODE)
\r
139 * d.3 => nCS (only #ifdef HAVE_AS_MODE)
\r
143 * d.6 => LED / Output Enable
\r
149 SetTCK((d & bmBIT0) ? 1 : 0);
\r
151 SetTMS((d & bmBIT1) ? 1 : 0);
\r
153 SetTDI((d & bmBIT4) ? 1 : 0);
\r
157 SetOELED((d & bmBIT5) ? 1 : 0);
\r
165 unsigned char ProgIO_Set_Get_State(unsigned char d)
\r
169 /* Read state of input pins:
\r
175 * DATAOUT => d.1 (only #ifdef HAVE_AS_MODE)
\r
181 ProgIO_Set_State(d);
\r
189 void ProgIO_ShiftOut(unsigned char c)
\r
193 /* Shift out byte C:
\r
199 * Output least significant bit on TDI
\r
213 unsigned char lc=c;
\r
217 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
219 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
221 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
223 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
227 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
229 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
231 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
233 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
239 unsigned char ProgIO_ShiftInOut(unsigned char c)
\r
243 /* Shift out byte C, shift in from TDO:
\r
249 * Read carry from TDO
\r
251 * Output least significant bit on TDI
\r
255 * Shift c right, append carry (TDO) at left
\r
267 unsigned char carry;
\r
269 unsigned char lc=c;
\r
273 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
275 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
277 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
279 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
283 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
285 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
287 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
289 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r