1 /*-----------------------------------------------------------------------------
\r
3 * Hardware-dependent code for usb_jtag
\r
4 *-----------------------------------------------------------------------------
\r
5 * Copyright (C) 2007 Kolja Waschk, ixo.de
\r
6 *-----------------------------------------------------------------------------
\r
7 * This code is part of usbjtag. usbjtag is free software; you can redistribute
\r
8 * it and/or modify it under the terms of the GNU General Public License as
\r
9 * published by the Free Software Foundation; either version 2 of the License,
\r
10 * or (at your option) any later version. usbjtag is distributed in the hope
\r
11 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
\r
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details. You should have received a
\r
14 * copy of the GNU General Public License along with this program in the file
\r
15 * COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin
\r
16 * St, Fifth Floor, Boston, MA 02110-1301 USA
\r
17 *-----------------------------------------------------------------------------
\r
20 #include "hardware.h"
\r
21 #include "fx2regs.h"
\r
22 #include "syncdelay.h"
\r
24 //---------------------------------------------------------------------------
\r
26 #define SetTCK(x) do{if(x) IOE|=0x08; else IOE&=~0x08; }while(0)
\r
27 #define SetTMS(x) do{if(x) IOE|=0x10; else IOE&=~0x10; }while(0)
\r
28 #define SetTDI(x) do{if(x) IOE|=0x40; else IOE&=~0x40; }while(0)
\r
29 #define GetTDO() ((IOE>>5)&1)
\r
31 /* XPCU has neither AS nor PS mode pins */
\r
33 #define HAVE_OE_LED 1
\r
34 /* +0=green led, +1=red led */
\r
35 sbit at 0x80+1 OELED;
\r
36 #define SetOELED(x) do{OELED=(x);}while(0)
\r
38 //-----------------------------------------------------------------------------
\r
40 void ProgIO_Poll(void) {}
\r
41 void ProgIO_Enable(void) {}
\r
42 void ProgIO_Disable(void) {}
\r
43 void ProgIO_Deinit(void) {}
\r
45 void ProgIO_Init(void)
\r
47 /* The following code depends on your actual circuit design.
\r
48 Make required changes _before_ you try the code! */
\r
50 // set the CPU clock to 48MHz, enable clock output to FPGA
\r
51 CPUCS = bmCLKOE | bmCLKSPD1;
\r
53 // Use internal 48 MHz, enable output, use "Port" mode for all pins
\r
54 IFCONFIG = bmIFCLKSRC | bm3048MHZ | bmIFCLKOE;
\r
58 PORTACFG = 0x00; OEA = 0x03; IOA=0x01;
\r
59 PORTCCFG = 0x00; OEC = 0x00; IOC=0x00;
\r
60 PORTECFG = 0x00; OEE = 0x58; IOE=0x00;
\r
63 void ProgIO_Set_State(unsigned char d)
\r
65 /* Set state of output pins
\r
66 * (d is the byte from the host):
\r
70 * d.2 => nCE (only #ifdef HAVE_AS_MODE)
\r
71 * d.3 => nCS (only #ifdef HAVE_AS_MODE)
\r
73 * d.6 => LED / Output Enable
\r
76 SetTCK((d & bmBIT0) ? 1 : 0);
\r
77 SetTMS((d & bmBIT1) ? 1 : 0);
\r
78 SetTDI((d & bmBIT4) ? 1 : 0);
\r
80 SetOELED((d & bmBIT5) ? 1 : 0);
\r
84 unsigned char ProgIO_Set_Get_State(unsigned char d)
\r
86 /* Set state of output pins (s.a.)
\r
87 * then read state of input pins:
\r
90 * DATAOUT => d.1 (only #ifdef HAVE_AS_MODE)
\r
93 ProgIO_Set_State(d);
\r
94 return 2|GetTDO(); /* DATAOUT assumed high, no AS mode */
\r
97 void ProgIO_ShiftOut(unsigned char c)
\r
99 /* Shift out byte C:
\r
102 * Output least significant bit on TDI
\r
109 unsigned char lc=c;
\r
111 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
112 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
113 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
114 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
116 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
117 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
118 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
119 if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc>>=1; IOE&=~0x08;
\r
122 unsigned char ProgIO_ShiftInOut(unsigned char c)
\r
124 /* Shift out byte C, shift in from TDO:
\r
127 * Read carry from TDO
\r
128 * Output least significant bit on TDI
\r
130 * Shift c right, append carry (TDO) at left (into MSB)
\r
136 unsigned char carry;
\r
137 unsigned char lc=c;
\r
139 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
140 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
141 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
142 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
144 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
145 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
146 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r
147 carry = (IOE&0x20)<<2; if(lc&1) IOE|=0x40; else IOE&=~0x40; IOE|=0x08; lc=carry|(lc>>1); IOE&=~0x08;
\r