source code from XAPP058 for CPLD programming from the microcontroller
This commit is contained in:
10
firmware/common/xapp058/README
Normal file
10
firmware/common/xapp058/README
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
The code in this directory is taken from:
|
||||||
|
http://www.xilinx.com/support/documentation/application_notes/xapp058.zip
|
||||||
|
(v.5.01)
|
||||||
|
|
||||||
|
Ian Lesnet wrote: "I contacted Xilinx support and they said the license is do
|
||||||
|
what you want, no warranty. (BSD I guess...)"
|
||||||
|
(http://dangerousprototypes.com/forum/viewtopic.php?f=51&t=2239#p21257)
|
||||||
|
|
||||||
|
Refer to XAPP058 for more information:
|
||||||
|
http://www.xilinx.com/support/documentation/application_notes/xapp058.pdf
|
190
firmware/common/xapp058/lenval.c
Normal file
190
firmware/common/xapp058/lenval.c
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
/*******************************************************/
|
||||||
|
/* file: lenval.c */
|
||||||
|
/* abstract: This file contains routines for using */
|
||||||
|
/* the lenVal data structure. */
|
||||||
|
/*******************************************************/
|
||||||
|
#include "lenval.h"
|
||||||
|
#include "ports.h"
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Function: value
|
||||||
|
* Description: Extract the long value from the lenval array.
|
||||||
|
* Parameters: plvValue - ptr to lenval.
|
||||||
|
* Returns: long - the extracted value.
|
||||||
|
*****************************************************************************/
|
||||||
|
long value( lenVal* plvValue )
|
||||||
|
{
|
||||||
|
long lValue; /* result to hold the accumulated result */
|
||||||
|
short sIndex;
|
||||||
|
|
||||||
|
lValue = 0;
|
||||||
|
for ( sIndex = 0; sIndex < plvValue->len ; ++sIndex )
|
||||||
|
{
|
||||||
|
lValue <<= 8; /* shift the accumulated result */
|
||||||
|
lValue |= plvValue->val[ sIndex]; /* get the last byte first */
|
||||||
|
}
|
||||||
|
|
||||||
|
return( lValue );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Function: initLenVal
|
||||||
|
* Description: Initialize the lenval array with the given value.
|
||||||
|
* Assumes lValue is less than 256.
|
||||||
|
* Parameters: plv - ptr to lenval.
|
||||||
|
* lValue - the value to set.
|
||||||
|
* Returns: void.
|
||||||
|
*****************************************************************************/
|
||||||
|
void initLenVal( lenVal* plv,
|
||||||
|
long lValue )
|
||||||
|
{
|
||||||
|
plv->len = 1;
|
||||||
|
plv->val[0] = (unsigned char)lValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Function: EqualLenVal
|
||||||
|
* Description: Compare two lenval arrays with an optional mask.
|
||||||
|
* Parameters: plvTdoExpected - ptr to lenval #1.
|
||||||
|
* plvTdoCaptured - ptr to lenval #2.
|
||||||
|
* plvTdoMask - optional ptr to mask (=0 if no mask).
|
||||||
|
* Returns: short - 0 = mismatch; 1 = equal.
|
||||||
|
*****************************************************************************/
|
||||||
|
short EqualLenVal( lenVal* plvTdoExpected,
|
||||||
|
lenVal* plvTdoCaptured,
|
||||||
|
lenVal* plvTdoMask )
|
||||||
|
{
|
||||||
|
short sEqual;
|
||||||
|
short sIndex;
|
||||||
|
unsigned char ucByteVal1;
|
||||||
|
unsigned char ucByteVal2;
|
||||||
|
unsigned char ucByteMask;
|
||||||
|
|
||||||
|
sEqual = 1;
|
||||||
|
sIndex = plvTdoExpected->len;
|
||||||
|
|
||||||
|
while ( sEqual && sIndex-- )
|
||||||
|
{
|
||||||
|
ucByteVal1 = plvTdoExpected->val[ sIndex ];
|
||||||
|
ucByteVal2 = plvTdoCaptured->val[ sIndex ];
|
||||||
|
if ( plvTdoMask )
|
||||||
|
{
|
||||||
|
ucByteMask = plvTdoMask->val[ sIndex ];
|
||||||
|
ucByteVal1 &= ucByteMask;
|
||||||
|
ucByteVal2 &= ucByteMask;
|
||||||
|
}
|
||||||
|
if ( ucByteVal1 != ucByteVal2 )
|
||||||
|
{
|
||||||
|
sEqual = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return( sEqual );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Function: RetBit
|
||||||
|
* Description: return the (byte, bit) of lv (reading from left to right).
|
||||||
|
* Parameters: plv - ptr to lenval.
|
||||||
|
* iByte - the byte to get the bit from.
|
||||||
|
* iBit - the bit number (0=msb)
|
||||||
|
* Returns: short - the bit value.
|
||||||
|
*****************************************************************************/
|
||||||
|
short RetBit( lenVal* plv,
|
||||||
|
int iByte,
|
||||||
|
int iBit )
|
||||||
|
{
|
||||||
|
/* assert( ( iByte >= 0 ) && ( iByte < plv->len ) ); */
|
||||||
|
/* assert( ( iBit >= 0 ) && ( iBit < 8 ) ); */
|
||||||
|
return( (short)( ( plv->val[ iByte ] >> ( 7 - iBit ) ) & 0x1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Function: SetBit
|
||||||
|
* Description: set the (byte, bit) of lv equal to val
|
||||||
|
* Example: SetBit("00000000",byte, 1) equals "01000000".
|
||||||
|
* Parameters: plv - ptr to lenval.
|
||||||
|
* iByte - the byte to get the bit from.
|
||||||
|
* iBit - the bit number (0=msb).
|
||||||
|
* sVal - the bit value to set.
|
||||||
|
* Returns: void.
|
||||||
|
*****************************************************************************/
|
||||||
|
void SetBit( lenVal* plv,
|
||||||
|
int iByte,
|
||||||
|
int iBit,
|
||||||
|
short sVal )
|
||||||
|
{
|
||||||
|
unsigned char ucByteVal;
|
||||||
|
unsigned char ucBitMask;
|
||||||
|
|
||||||
|
ucBitMask = (unsigned char)(1 << ( 7 - iBit ));
|
||||||
|
ucByteVal = (unsigned char)(plv->val[ iByte ] & (~ucBitMask));
|
||||||
|
|
||||||
|
if ( sVal )
|
||||||
|
{
|
||||||
|
ucByteVal |= ucBitMask;
|
||||||
|
}
|
||||||
|
plv->val[ iByte ] = ucByteVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Function: AddVal
|
||||||
|
* Description: add val1 to val2 and store in resVal;
|
||||||
|
* assumes val1 and val2 are of equal length.
|
||||||
|
* Parameters: plvResVal - ptr to result.
|
||||||
|
* plvVal1 - ptr of addendum.
|
||||||
|
* plvVal2 - ptr of addendum.
|
||||||
|
* Returns: void.
|
||||||
|
*****************************************************************************/
|
||||||
|
void addVal( lenVal* plvResVal,
|
||||||
|
lenVal* plvVal1,
|
||||||
|
lenVal* plvVal2 )
|
||||||
|
{
|
||||||
|
unsigned char ucCarry;
|
||||||
|
unsigned short usSum;
|
||||||
|
unsigned short usVal1;
|
||||||
|
unsigned short usVal2;
|
||||||
|
short sIndex;
|
||||||
|
|
||||||
|
plvResVal->len = plvVal1->len; /* set up length of result */
|
||||||
|
|
||||||
|
/* start at least significant bit and add bytes */
|
||||||
|
ucCarry = 0;
|
||||||
|
sIndex = plvVal1->len;
|
||||||
|
while ( sIndex-- )
|
||||||
|
{
|
||||||
|
usVal1 = plvVal1->val[ sIndex ]; /* i'th byte of val1 */
|
||||||
|
usVal2 = plvVal2->val[ sIndex ]; /* i'th byte of val2 */
|
||||||
|
|
||||||
|
/* add the two bytes plus carry from previous addition */
|
||||||
|
usSum = (unsigned short)( usVal1 + usVal2 + ucCarry );
|
||||||
|
|
||||||
|
/* set up carry for next byte */
|
||||||
|
ucCarry = (unsigned char)( ( usSum > 255 ) ? 1 : 0 );
|
||||||
|
|
||||||
|
/* set the i'th byte of the result */
|
||||||
|
plvResVal->val[ sIndex ] = (unsigned char)usSum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Function: readVal
|
||||||
|
* Description: read from XSVF numBytes bytes of data into x.
|
||||||
|
* Parameters: plv - ptr to lenval in which to put the bytes read.
|
||||||
|
* sNumBytes - the number of bytes to read.
|
||||||
|
* Returns: void.
|
||||||
|
*****************************************************************************/
|
||||||
|
void readVal( lenVal* plv,
|
||||||
|
short sNumBytes )
|
||||||
|
{
|
||||||
|
unsigned char* pucVal;
|
||||||
|
|
||||||
|
plv->len = sNumBytes; /* set the length of the lenVal */
|
||||||
|
for ( pucVal = plv->val; sNumBytes; --sNumBytes, ++pucVal )
|
||||||
|
{
|
||||||
|
/* read a byte of data into the lenVal */
|
||||||
|
readByte( pucVal );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
93
firmware/common/xapp058/lenval.h
Normal file
93
firmware/common/xapp058/lenval.h
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/*******************************************************/
|
||||||
|
/* file: lenval.h */
|
||||||
|
/* abstract: This file contains a description of the */
|
||||||
|
/* data structure "lenval". */
|
||||||
|
/*******************************************************/
|
||||||
|
|
||||||
|
#ifndef lenval_dot_h
|
||||||
|
#define lenval_dot_h
|
||||||
|
|
||||||
|
/* the lenVal structure is a byte oriented type used to store an */
|
||||||
|
/* arbitrary length binary value. As an example, the hex value */
|
||||||
|
/* 0x0e3d is represented as a lenVal with len=2 (since 2 bytes */
|
||||||
|
/* and val[0]=0e and val[1]=3d. val[2-MAX_LEN] are undefined */
|
||||||
|
|
||||||
|
/* maximum length (in bytes) of value to read in */
|
||||||
|
/* this needs to be at least 4, and longer than the */
|
||||||
|
/* length of the longest SDR instruction. If there is, */
|
||||||
|
/* only 1 device in the chain, MAX_LEN must be at least */
|
||||||
|
/* ceil(27/8) == 4. For 6 devices in a chain, MAX_LEN */
|
||||||
|
/* must be 5, for 14 devices MAX_LEN must be 6, for 20 */
|
||||||
|
/* devices MAX_LEN must be 7, etc.. */
|
||||||
|
/* You can safely set MAX_LEN to a smaller number if you*/
|
||||||
|
/* know how many devices will be in your chain. */
|
||||||
|
/* #define MAX_LEN (Actual #define is below this comment block)
|
||||||
|
This #define defines the maximum length (in bytes) of predefined
|
||||||
|
buffers in which the XSVF player stores the current shift data.
|
||||||
|
This length must be greater than the longest shift length (in bytes)
|
||||||
|
in the XSVF files that will be processed. 7000 is a very conservative
|
||||||
|
number. The buffers are stored on the stack and if you have limited
|
||||||
|
stack space, you may decrease the MAX_LEN value.
|
||||||
|
|
||||||
|
How to find the "shift length" in bits?
|
||||||
|
Look at the ASCII version of the XSVF (generated with the -a option
|
||||||
|
for the SVF2XSVF translator) and search for the XSDRSIZE command
|
||||||
|
with the biggest parameter. XSDRSIZE is equivalent to the SVF's
|
||||||
|
SDR length plus the lengths of applicable HDR and TDR commands.
|
||||||
|
Remember that the MAX_LEN is defined in bytes. Therefore, the
|
||||||
|
minimum MAX_LEN = ceil( max( XSDRSIZE ) / 8 );
|
||||||
|
|
||||||
|
The following MAX_LEN values have been tested and provide relatively
|
||||||
|
good margin for the corresponding devices:
|
||||||
|
|
||||||
|
DEVICE MAX_LEN Resulting Shift Length Max (in bits)
|
||||||
|
--------- ------- ----------------------------------------------
|
||||||
|
XC9500/XL/XV 32 256
|
||||||
|
|
||||||
|
CoolRunner/II 256 2048 - actual max 1 device = 1035 bits
|
||||||
|
|
||||||
|
FPGA 128 1024 - svf2xsvf -rlen 1024
|
||||||
|
|
||||||
|
XC18V00/XCF00
|
||||||
|
1100 8800 - no blank check performed (default)
|
||||||
|
- actual max 1 device = 8192 bits verify
|
||||||
|
- max 1 device = 4096 bits program-only
|
||||||
|
|
||||||
|
XC18V00/XCF00 when using the optional Blank Check operation
|
||||||
|
2500 20000 - required for blank check
|
||||||
|
- blank check max 1 device = 16384 bits
|
||||||
|
*/
|
||||||
|
#define MAX_LEN 7000
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct var_len_byte
|
||||||
|
{
|
||||||
|
short len; /* number of chars in this value */
|
||||||
|
unsigned char val[MAX_LEN+1]; /* bytes of data */
|
||||||
|
} lenVal;
|
||||||
|
|
||||||
|
|
||||||
|
/* return the long representation of a lenVal */
|
||||||
|
extern long value(lenVal *x);
|
||||||
|
|
||||||
|
/* set lenVal equal to value */
|
||||||
|
extern void initLenVal(lenVal *x, long value);
|
||||||
|
|
||||||
|
/* check if expected equals actual (taking the mask into account) */
|
||||||
|
extern short EqualLenVal(lenVal *expected, lenVal *actual, lenVal *mask);
|
||||||
|
|
||||||
|
/* add val1+val2 and put the result in resVal */
|
||||||
|
extern void addVal(lenVal *resVal, lenVal *val1, lenVal *val2);
|
||||||
|
|
||||||
|
/* return the (byte, bit) of lv (reading from left to right) */
|
||||||
|
extern short RetBit(lenVal *lv, int byte, int bit);
|
||||||
|
|
||||||
|
/* set the (byte, bit) of lv equal to val (e.g. SetBit("00000000",byte, 1)
|
||||||
|
equals "01000000" */
|
||||||
|
extern void SetBit(lenVal *lv, int byte, int bit, short val);
|
||||||
|
|
||||||
|
/* read from XSVF numBytes bytes of data into x */
|
||||||
|
extern void readVal(lenVal *x, short numBytes);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
1827
firmware/common/xapp058/micro.c
Normal file
1827
firmware/common/xapp058/micro.c
Normal file
File diff suppressed because it is too large
Load Diff
42
firmware/common/xapp058/micro.h
Normal file
42
firmware/common/xapp058/micro.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* File: micro.h
|
||||||
|
* Description: This header file contains the function prototype to the
|
||||||
|
* primary interface function for the XSVF player.
|
||||||
|
* Usage: FIRST - PORTS.C
|
||||||
|
* Customize the ports.c function implementations to establish
|
||||||
|
* the correct protocol for communicating with your JTAG ports
|
||||||
|
* (setPort() and readTDOBit()) and tune the waitTime() delay
|
||||||
|
* function. Also, establish access to the XSVF data source
|
||||||
|
* in the readByte() function.
|
||||||
|
* FINALLY - Call xsvfExecute().
|
||||||
|
*****************************************************************************/
|
||||||
|
#ifndef XSVF_MICRO_H
|
||||||
|
#define XSVF_MICRO_H
|
||||||
|
|
||||||
|
/* Legacy error codes for xsvfExecute from original XSVF player v2.0 */
|
||||||
|
#define XSVF_LEGACY_SUCCESS 1
|
||||||
|
#define XSVF_LEGACY_ERROR 0
|
||||||
|
|
||||||
|
/* 4.04 [NEW] Error codes for xsvfExecute. */
|
||||||
|
/* Must #define XSVF_SUPPORT_ERRORCODES in micro.c to get these codes */
|
||||||
|
#define XSVF_ERROR_NONE 0
|
||||||
|
#define XSVF_ERROR_UNKNOWN 1
|
||||||
|
#define XSVF_ERROR_TDOMISMATCH 2
|
||||||
|
#define XSVF_ERROR_MAXRETRIES 3 /* TDO mismatch after max retries */
|
||||||
|
#define XSVF_ERROR_ILLEGALCMD 4
|
||||||
|
#define XSVF_ERROR_ILLEGALSTATE 5
|
||||||
|
#define XSVF_ERROR_DATAOVERFLOW 6 /* Data > lenVal MAX_LEN buffer size*/
|
||||||
|
/* Insert new errors here */
|
||||||
|
#define XSVF_ERROR_LAST 7
|
||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
* Function: xsvfExecute
|
||||||
|
* Description: Process, interpret, and apply the XSVF commands.
|
||||||
|
* See port.c:readByte for source of XSVF data.
|
||||||
|
* Parameters: none.
|
||||||
|
* Returns: int - For error codes see above.
|
||||||
|
*****************************************************************************/
|
||||||
|
extern int xsvfExecute();
|
||||||
|
|
||||||
|
#endif /* XSVF_MICRO_H */
|
||||||
|
|
203
firmware/common/xapp058/ports.c
Normal file
203
firmware/common/xapp058/ports.c
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
/*******************************************************/
|
||||||
|
/* file: ports.c */
|
||||||
|
/* abstract: This file contains the routines to */
|
||||||
|
/* output values on the JTAG ports, to read */
|
||||||
|
/* the TDO bit, and to read a byte of data */
|
||||||
|
/* from the prom */
|
||||||
|
/* Revisions: */
|
||||||
|
/* 12/01/2008: Same code as before (original v5.01). */
|
||||||
|
/* Updated comments to clarify instructions.*/
|
||||||
|
/* Add print in setPort for xapp058_example.exe.*/
|
||||||
|
/*******************************************************/
|
||||||
|
#include "ports.h"
|
||||||
|
/*#include "prgispx.h"*/
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
extern FILE *in;
|
||||||
|
static int g_iTCK = 0; /* For xapp058_example .exe */
|
||||||
|
static int g_iTMS = 0; /* For xapp058_example .exe */
|
||||||
|
static int g_iTDI = 0; /* For xapp058_example .exe */
|
||||||
|
|
||||||
|
#ifdef WIN95PP
|
||||||
|
#include "conio.h"
|
||||||
|
|
||||||
|
#define DATA_OFFSET (unsigned short) 0
|
||||||
|
#define STATUS_OFFSET (unsigned short) 1
|
||||||
|
#define CONTROL_OFFSET (unsigned short) 2
|
||||||
|
|
||||||
|
typedef union outPortUnion {
|
||||||
|
unsigned char value;
|
||||||
|
struct opBitsStr {
|
||||||
|
unsigned char tdi:1;
|
||||||
|
unsigned char tck:1;
|
||||||
|
unsigned char tms:1;
|
||||||
|
unsigned char zero:1;
|
||||||
|
unsigned char one:1;
|
||||||
|
unsigned char bit5:1;
|
||||||
|
unsigned char bit6:1;
|
||||||
|
unsigned char bit7:1;
|
||||||
|
} bits;
|
||||||
|
} outPortType;
|
||||||
|
|
||||||
|
typedef union inPortUnion {
|
||||||
|
unsigned char value;
|
||||||
|
struct ipBitsStr {
|
||||||
|
unsigned char bit0:1;
|
||||||
|
unsigned char bit1:1;
|
||||||
|
unsigned char bit2:1;
|
||||||
|
unsigned char bit3:1;
|
||||||
|
unsigned char tdo:1;
|
||||||
|
unsigned char bit5:1;
|
||||||
|
unsigned char bit6:1;
|
||||||
|
unsigned char bit7:1;
|
||||||
|
} bits;
|
||||||
|
} inPortType;
|
||||||
|
|
||||||
|
static inPortType in_word;
|
||||||
|
static outPortType out_word;
|
||||||
|
static unsigned short base_port = 0x378;
|
||||||
|
static int once = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*BYTE *xsvf_data=0;*/
|
||||||
|
|
||||||
|
|
||||||
|
/* setPort: Implement to set the named JTAG signal (p) to the new value (v).*/
|
||||||
|
/* if in debugging mode, then just set the variables */
|
||||||
|
void setPort(short p,short val)
|
||||||
|
{
|
||||||
|
#ifdef WIN95PP
|
||||||
|
/* Old Win95 example that is similar to a GPIO register implementation.
|
||||||
|
The old Win95 example maps individual bits of the
|
||||||
|
8-bit register (out_word) to the JTAG signals: TCK, TMS, TDI.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Initialize static out_word register bits just once */
|
||||||
|
if (once == 0) {
|
||||||
|
out_word.bits.one = 1;
|
||||||
|
out_word.bits.zero = 0;
|
||||||
|
once = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update the local out_word copy of the JTAG signal to the new value. */
|
||||||
|
if (p==TMS)
|
||||||
|
out_word.bits.tms = (unsigned char) val;
|
||||||
|
if (p==TDI)
|
||||||
|
out_word.bits.tdi = (unsigned char) val;
|
||||||
|
if (p==TCK) {
|
||||||
|
out_word.bits.tck = (unsigned char) val;
|
||||||
|
(void) _outp( (unsigned short) (base_port + 0), out_word.value );
|
||||||
|
/* To save HW write cycles, this example only writes the local copy
|
||||||
|
of the JTAG signal values to the HW register when TCK changes. */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* Printing code for the xapp058_example.exe. You must set the specified
|
||||||
|
JTAG signal (p) to the new value (v). See the above, old Win95 code
|
||||||
|
as an implementation example. */
|
||||||
|
if (p==TMS)
|
||||||
|
g_iTMS = val;
|
||||||
|
if (p==TDI)
|
||||||
|
g_iTDI = val;
|
||||||
|
if (p==TCK) {
|
||||||
|
g_iTCK = val;
|
||||||
|
printf( "TCK = %d; TMS = %d; TDI = %d\n", g_iTCK, g_iTMS, g_iTDI );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* toggle tck LH. No need to modify this code. It is output via setPort. */
|
||||||
|
void pulseClock()
|
||||||
|
{
|
||||||
|
setPort(TCK,0); /* set the TCK port to low */
|
||||||
|
setPort(TCK,1); /* set the TCK port to high */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* readByte: Implement to source the next byte from your XSVF file location */
|
||||||
|
/* read in a byte of data from the prom */
|
||||||
|
void readByte(unsigned char *data)
|
||||||
|
{
|
||||||
|
/* pretend reading using a file */
|
||||||
|
*data = (unsigned char)fgetc( in );
|
||||||
|
/**data=*xsvf_data++;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/* readTDOBit: Implement to return the current value of the JTAG TDO signal.*/
|
||||||
|
/* read the TDO bit from port */
|
||||||
|
unsigned char readTDOBit()
|
||||||
|
{
|
||||||
|
#ifdef WIN95PP
|
||||||
|
/* Old Win95 example that is similar to a GPIO register implementation.
|
||||||
|
The old Win95 reads the hardware input register and extracts the TDO
|
||||||
|
value from the bit within the register that is assigned to the
|
||||||
|
physical JTAG TDO signal.
|
||||||
|
*/
|
||||||
|
in_word.value = (unsigned char) _inp( (unsigned short) (base_port + STATUS_OFFSET) );
|
||||||
|
if (in_word.bits.tdo == 0x1) {
|
||||||
|
return( (unsigned char) 1 );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* You must return the current value of the JTAG TDO signal. */
|
||||||
|
return( (unsigned char) 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* waitTime: Implement as follows: */
|
||||||
|
/* REQUIRED: This function must consume/wait at least the specified number */
|
||||||
|
/* of microsec, interpreting microsec as a number of microseconds.*/
|
||||||
|
/* REQUIRED FOR SPARTAN/VIRTEX FPGAs and indirect flash programming: */
|
||||||
|
/* This function must pulse TCK for at least microsec times, */
|
||||||
|
/* interpreting microsec as an integer value. */
|
||||||
|
/* RECOMMENDED IMPLEMENTATION: Pulse TCK at least microsec times AND */
|
||||||
|
/* continue pulsing TCK until the microsec wait */
|
||||||
|
/* requirement is also satisfied. */
|
||||||
|
void waitTime(long microsec)
|
||||||
|
{
|
||||||
|
static long tckCyclesPerMicrosec = 1; /* must be at least 1 */
|
||||||
|
long tckCycles = microsec * tckCyclesPerMicrosec;
|
||||||
|
long i;
|
||||||
|
|
||||||
|
/* This implementation is highly recommended!!! */
|
||||||
|
/* This implementation requires you to tune the tckCyclesPerMicrosec
|
||||||
|
variable (above) to match the performance of your embedded system
|
||||||
|
in order to satisfy the microsec wait time requirement. */
|
||||||
|
for ( i = 0; i < tckCycles; ++i )
|
||||||
|
{
|
||||||
|
pulseClock();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* Alternate implementation */
|
||||||
|
/* For systems with TCK rates << 1 MHz; Consider this implementation. */
|
||||||
|
/* This implementation does not work with Spartan-3AN or indirect flash
|
||||||
|
programming. */
|
||||||
|
if ( microsec >= 50L )
|
||||||
|
{
|
||||||
|
/* Make sure TCK is low during wait for XC18V00/XCFxxS */
|
||||||
|
/* Or, a running TCK implementation as shown above is an OK alternate */
|
||||||
|
setPort( TCK, 0 );
|
||||||
|
|
||||||
|
/* Use Windows Sleep(). Round up to the nearest millisec */
|
||||||
|
_sleep( ( microsec + 999L ) / 1000L );
|
||||||
|
}
|
||||||
|
else /* Satisfy FPGA JTAG configuration, startup TCK cycles */
|
||||||
|
{
|
||||||
|
for ( i = 0; i < microsec; ++i )
|
||||||
|
{
|
||||||
|
pulseClock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* Alternate implementation */
|
||||||
|
/* This implementation is valid for only XC9500/XL/XV, CoolRunner/II CPLDs,
|
||||||
|
XC18V00 PROMs, or Platform Flash XCFxxS/XCFxxP PROMs.
|
||||||
|
This implementation does not work with FPGAs JTAG configuration. */
|
||||||
|
/* Make sure TCK is low during wait for XC18V00/XCFxxS PROMs */
|
||||||
|
/* Or, a running TCK implementation as shown above is an OK alternate */
|
||||||
|
setPort( TCK, 0 );
|
||||||
|
/* Use Windows Sleep(). Round up to the nearest millisec */
|
||||||
|
_sleep( ( microsec + 999L ) / 1000L );
|
||||||
|
#endif
|
||||||
|
}
|
31
firmware/common/xapp058/ports.h
Normal file
31
firmware/common/xapp058/ports.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*******************************************************/
|
||||||
|
/* file: ports.h */
|
||||||
|
/* abstract: This file contains extern declarations */
|
||||||
|
/* for providing stimulus to the JTAG ports.*/
|
||||||
|
/*******************************************************/
|
||||||
|
|
||||||
|
#ifndef ports_dot_h
|
||||||
|
#define ports_dot_h
|
||||||
|
|
||||||
|
/* these constants are used to send the appropriate ports to setPort */
|
||||||
|
/* they should be enumerated types, but some of the microcontroller */
|
||||||
|
/* compilers don't like enumerated types */
|
||||||
|
#define TCK (short) 0
|
||||||
|
#define TMS (short) 1
|
||||||
|
#define TDI (short) 2
|
||||||
|
|
||||||
|
/* set the port "p" (TCK, TMS, or TDI) to val (0 or 1) */
|
||||||
|
extern void setPort(short p, short val);
|
||||||
|
|
||||||
|
/* read the TDO bit and store it in val */
|
||||||
|
extern unsigned char readTDOBit();
|
||||||
|
|
||||||
|
/* make clock go down->up->down*/
|
||||||
|
extern void pulseClock();
|
||||||
|
|
||||||
|
/* read the next byte of data from the xsvf file */
|
||||||
|
extern void readByte(unsigned char *data);
|
||||||
|
|
||||||
|
extern void waitTime(long microsec);
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user