/*-----------------------------------------------------------------------------\r
-\r
* Hardware-dependent code for usb_jtag\r
-\r
*-----------------------------------------------------------------------------\r
-\r
* Copyright (C) 2007 Kolja Waschk, ixo.de\r
-\r
*-----------------------------------------------------------------------------\r
-\r
* This code is part of usbjtag. usbjtag is free software; you can redistribute\r
-\r
* it and/or modify it under the terms of the GNU General Public License as\r
-\r
* published by the Free Software Foundation; either version 2 of the License,\r
-\r
* or (at your option) any later version. usbjtag is distributed in the hope\r
-\r
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied\r
-\r
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-\r
* GNU General Public License for more details. You should have received a\r
-\r
* copy of the GNU General Public License along with this program in the file\r
-\r
* COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin\r
-\r
* St, Fifth Floor, Boston, MA 02110-1301 USA\r
-\r
*-----------------------------------------------------------------------------\r
-\r
*/\r
\r
-\r
-\r
#include "delay.h"\r
-\r
#include "syncdelay.h"\r
-\r
#include "hardware.h"\r
\r
-\r
-\r
#include "isr.h"\r
-\r
#include "timer.h"\r
-\r
#include "delay.h"\r
-\r
#include "fx2regs.h"\r
-\r
#include "fx2utils.h"\r
-\r
#include "usb_common.h"\r
-\r
#include "usb_descriptors.h"\r
-\r
#include "usb_requests.h"\r
-\r
#include "syncdelay.h"\r
-\r
#include "eeprom.h"\r
\r
\r
\r
\r
void ProgIO_Poll(void) {}\r
-\r
void ProgIO_Enable(void) {}\r
-\r
void ProgiO_Disable(void) {}\r
-\r
void ProgiO_Deinit(void) {}\r
\r
-\r
-\r
static unsigned char curios;\r
\r
-\r
-\r
const unsigned char wavedata[64] =\r
-\r
{\r
-\r
/* Single Write:\r
-\r
s0: BITS=D0 NEXT/SGLCRC DATA WAIT 4\r
-\r
s1: BITS= DATA WAIT 4\r
-\r
s2: BITS=D1|D0 DATA WAIT 4\r
-\r
s3: BITS=D1 DATA WAIT 3\r
-\r
s4: BITS=D1 DATA DP IF(RDY0) THEN 5 ELSE 2\r
-\r
s5: BITS=D1|D0 DATA WAIT 4\r
-\r
s6: BITS=D1 DATA WAIT 3\r
-\r
s7: BITS=D1 DATA FIN */\r
\r
-\r
-\r
4, 4, 4, 3, 0x2A, 4, 3, 7,\r
-\r
6, 2, 2, 2, 3, 2, 2, 2,\r
-\r
1, 0, 3, 2, 2, 3, 2, 2,\r
-\r
0, 0, 0, 0, 0, 0, 0, 0x3F,\r
\r
-\r
-\r
/* Single Read:\r
-\r
s0: BITS=D0 WAIT 4\r
-\r
s1: BITS= WAIT 4\r
-\r
s2: BITS=D1|D0 WAIT 4\r
-\r
s3: BITS=D1 WAIT 4\r
-\r
s4: BITS=D1|D0 WAIT 3\r
-\r
s5: BITS=D1|D0 DP IF(RDY0) THEN 6 ELSE 3\r
-\r
s6: BITS=D1 DATA WAIT 4\r
-\r
s7: BITS=D1 FIN */\r
\r
-\r
-\r
4, 4, 4, 4, 3, 0x33, 4, 7,\r
-\r
0, 0, 0, 0, 0, 1, 2, 0,\r
-\r
1, 0, 3, 2, 3, 3, 2, 2,\r
-\r
0, 0, 0, 0, 0, 0, 0, 0x3F\r
-\r
};\r
\r
-\r
-\r
void ProgIO_Init(void)\r
-\r
{\r
-\r
unsigned char i;\r
\r
-\r
-\r
/* The following code depends on your actual circuit design.\r
-\r
Make required changes _before_ you try the code! */\r
\r
-\r
-\r
// set the CPU clock to 48MHz, enable clock output to FPGA\r
-\r
CPUCS = bmCLKOE | bmCLKSPD1;\r
\r
-\r
-\r
// Use internal 48 MHz, enable output, GPIF Master mode\r
-\r
IFCONFIG = bmIFCLKSRC | bm3048MHZ | bmIFCLKOE | bmIFGPIF;\r
\r
-\r
-\r
PORTACFG = 0x00; OEA = 0xFB; IOA = 0x20;\r
-\r
PORTCCFG = 0x00; OEC = 0xFF; IOC = 0x10;\r
-\r
PORTECFG = 0x00; OEE = 0xFC; IOE = 0xC0;\r
-\r
\r
-\r
GPIFABORT = 0xFF;\r
\r
-\r
-\r
GPIFREADYCFG = 0xA0;\r
-\r
GPIFCTLCFG = 0x00;\r
-\r
GPIFIDLECS = 0x00;\r
-\r
GPIFIDLECTL = 0x00;\r
-\r
GPIFWFSELECT = 0x01;\r
\r
-\r
-\r
// Copy waveform data\r
-\r
AUTOPTRSETUP = 0x07;\r
-\r
APTR1H = MSB( &wavedata );\r
-\r
APTR1L = LSB( &wavedata );\r
-\r
AUTOPTRH2 = 0xE4;\r
-\r
AUTOPTRL2 = 0x00;\r
-\r
for ( i = 0; i < 64; i++ ) EXTAUTODAT2 = EXTAUTODAT1;\r
\r
-\r
-\r
SYNCDELAY;\r
-\r
GPIFADRH = 0x00;\r
-\r
SYNCDELAY;\r
-\r
GPIFADRL = 0x00;\r
\r
-\r
-\r
FLOWSTATE = 0x00;\r
-\r
FLOWLOGIC = 0x00;\r
-\r
FLOWEQ0CTL = 0x00;\r
-\r
FLOWEQ1CTL = 0x00;\r
-\r
FLOWHOLDOFF = 0x00;\r
-\r
FLOWSTB = 0x00;\r
-\r
FLOWSTBEDGE = 0x00;\r
-\r
FLOWSTBHPERIOD = 0x00;\r
\r
-\r
-\r
curios = 0;\r
-\r
}\r
\r
-\r
-\r
unsigned char GetTDO(unsigned char r)\r
-\r
{\r
-\r
unsigned char x;\r
\r
-\r
-\r
IOC = 0x41;\r
-\r
while(!(GPIFTRIG & 0x80)); x = XGPIFSGLDATLX;\r
-\r
while(!(GPIFTRIG & 0x80)); x = XGPIFSGLDATLNOX;\r
\r
-\r
-\r
if(IOA & 0x20) IOA |= 0x40; else IOA &= ~0x40;\r
\r
-\r
-\r
return (x&1) ? r : 0;\r
-\r
}\r
\r
-\r
-\r
#define SetPins(x) while(!(GPIFTRIG & 0x80)); XGPIFSGLDATLX = (x)\r
\r
-\r
-\r
void ProgIO_Set_State(unsigned char d)\r
-\r
{\r
-\r
/* Set state of output pins:\r
-\r
*\r
-\r
* d.0 => TCK (PE.6)\r
-\r
* d.1 => TMS (PE.5)\r
-\r
* d.4 => TDI (PE.4)\r
-\r
* d.6 => LED / Output Enable\r
-\r
*/\r
\r
- \r
-\r
curios = (d & bmBIT0) ? 0x40 : 0; // TCK\r
-\r
curios |= (d & bmBIT1) ? 0x20 : 0; // TMS\r
-\r
curios |= (d & bmBIT4) ? 0x10 : 0; // TDI\r
\r
-\r
-\r
- IOC = 0x81;\r
-\r
+ IOC = 0x81; /* Select direction */\r
SetPins(curios);\r
\r
-\r
-\r
if(d & bmBIT6) IOA=(IOA&~3)|1; else IOA=(IOA&~3)|2;\r
-\r
}\r
\r
-\r
-\r
unsigned char ProgIO_Set_Get_State(unsigned char d)\r
-\r
{\r
\r
ProgIO_Set_State(d);\r
\r
-\r
-\r
/* Read state of input pins:\r
-\r
*\r
-\r
* TDO => d.0\r
-\r
* DATAOUT => d.1 (only #ifdef HAVE_AS_MODE)\r
-\r
*/\r
\r
-\r
-\r
return 2|GetTDO(0x01);\r
-\r
}\r
\r
\r
\r
void ProgIO_ShiftOut(unsigned char c)\r
-\r
{\r
-\r
unsigned char r,i;\r
-\r
unsigned char locios = curios & ~0x50;\r
\r
-\r
-\r
- IOC = 0x81;\r
-\r
-\r
+ IOC = 0x81; /* Select direction */\r
\r
for(i=0,r=1;i<8;i++)\r
-\r
{\r
-\r
unsigned char t = locios;\r
-\r
if(c & r) t |= 0x10;\r
-\r
SetPins(t);\r
-\r
SetPins(t|0x40);\r
-\r
r <<= 1;\r
-\r
SetPins(t);\r
-\r
};\r
\r
-\r
-\r
curios = locios;\r
-\r
}\r
\r
\r
-\r
-\r
-\r
unsigned char ProgIO_ShiftInOut(unsigned char c)\r
-\r
{\r
-\r
unsigned char r,i,n;\r
-\r
unsigned char locios = curios & ~0x50;\r
\r
-\r
-\r
for(i=0,r=1,n=0;i<8;i++)\r
-\r
{\r
-\r
unsigned char t = locios;\r
\r
-\r
-\r
n |= GetTDO(r);\r
\r
-\r
-\r
IOC = 0x81;\r
\r
if(c & r) t |= 0x10;\r
\r
SetPins(t);\r
-\r
SetPins(t|0x40);\r
-\r
r <<= 1;\r
-\r
SetPins(t);\r
-\r
};\r
\r
-\r
-\r
curios = locios;\r
-\r
return n;\r
-\r
}\r
\r
\r
-\r
-\r
-\r