micro.c

来自「适合KS8695X」· C语言 代码 · 共 1,848 行 · 第 1/5 页

C
1,848
字号
/*
 * (C) Copyright 2003
 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

/*****************************************************************************
 * file:         micro.c
 * abstract:     This file contains the function, xsvfExecute(),
 *               call for interpreting the XSVF commands.
 * Usage:        Call xsvfExecute() to process XSVF data.
 *               The XSVF data is retrieved by readByte() in ports.c
 *               Remove the main function if you already have one.
 * Options:      XSVF_SUPPORT_COMPRESSION
 *                   This define supports the XC9500/XL compression scheme.
 *                   This define adds support for XSDRINC and XSETSDRMASKS.
 *               XSVF_SUPPORT_ERRORCODES
 *                   This define causes the xsvfExecute function to return
 *                   an error code for specific errors.  See error codes below.
 *                   If this is not defined, the return value defaults to the
 *                   legacy values for backward compatibility:
 *                   1 = success;  0 = failure.
 * Debugging:    DEBUG_MODE (Legacy name)
 *               Define DEBUG_MODE to compile with debugging features.
 *               Both micro.c and ports.c must be compiled with the DEBUG_MODE
 *               defined to enable the standalone main implementation in
 *               micro.c that reads XSVF from a file.
 * History:      v2.00   - Original XSVF implementation.
 *               v4.04   - Added delay at end of XSIR for XC18v00 support.
 *                         Added new commands for CoolRunner support:
 *                         XSTATE, XENDIR, XENDDR
 *               v4.05   - Cleanup micro.c but leave ports.c intact.
 *               v4.06   - Fix xsvfGotoTapState for retry transition.
 *               v4.07   - Update example waitTime implementations for
 *                         compatibility with Virtex-II.
 *               v4.10   - Add new XSIR2 command that supports a 2-byte
 *                         IR-length parameter for IR shifts > 255 bits.
 *               v4.11   - No change.  Update version to match SVF2XSVF xlator.
 *               v4.14   - Added XCOMMENT.
 *               v5.00   - Improve XSTATE support.
 *                         Added XWAIT.
 *****************************************************************************/

#include <common.h>
#include <command.h>
#include <asm/processor.h>

#include "micro.h"
#include "lenval.h"
#include "ports.h"


extern const unsigned char fpgadata[];
extern int filesize;


/*============================================================================
 * XSVF #define
 ============================================================================*/

#define XSVF_VERSION    "5.00"

/*****************************************************************************
 * Define:       XSVF_SUPPORT_COMPRESSION
 * Description:  Define this to support the XC9500/XL XSVF data compression
 *               scheme.
 *               Code size can be reduced by NOT supporting this feature.
 *               However, you must use the -nc (no compress) option when
 *               translating SVF to XSVF using the SVF2XSVF translator.
 *               Corresponding, uncompressed XSVF may be larger.
 *****************************************************************************/
#ifndef XSVF_SUPPORT_COMPRESSION
#define XSVF_SUPPORT_COMPRESSION    1
#endif

/*****************************************************************************
 * Define:       XSVF_SUPPORT_ERRORCODES
 * Description:  Define this to support the new XSVF error codes.
 *               (The original XSVF player just returned 1 for success and
 *               0 for an unspecified failure.)
 *****************************************************************************/
#ifndef XSVF_SUPPORT_ERRORCODES
#define XSVF_SUPPORT_ERRORCODES     1
#endif

#ifdef  XSVF_SUPPORT_ERRORCODES
#define XSVF_ERRORCODE(errorCode)   errorCode
#else   /* Use legacy error code */
#define XSVF_ERRORCODE(errorCode)   ((errorCode==XSVF_ERROR_NONE)?1:0)
#endif  /* XSVF_SUPPORT_ERRORCODES */


/*============================================================================
 * DEBUG_MODE #define
 ============================================================================*/
#define DEBUG_MODE

#ifdef  DEBUG_MODE
#define XSVFDBG_PRINTF(iDebugLevel,pzFormat) \
		{ if ( xsvf_iDebugLevel >= iDebugLevel ) \
		    printf( pzFormat ); }
#define XSVFDBG_PRINTF1(iDebugLevel,pzFormat,arg1) \
		{ if ( xsvf_iDebugLevel >= iDebugLevel ) \
		    printf( pzFormat, arg1 ); }
#define XSVFDBG_PRINTF2(iDebugLevel,pzFormat,arg1,arg2) \
		{ if ( xsvf_iDebugLevel >= iDebugLevel ) \
		    printf( pzFormat, arg1, arg2 ); }
#define XSVFDBG_PRINTF3(iDebugLevel,pzFormat,arg1,arg2,arg3) \
		{ if ( xsvf_iDebugLevel >= iDebugLevel ) \
		    printf( pzFormat, arg1, arg2, arg3 ); }
#define XSVFDBG_PRINTLENVAL(iDebugLevel,plenVal) \
		{ if ( xsvf_iDebugLevel >= iDebugLevel ) \
		    xsvfPrintLenVal(plenVal); }
#else   /* !DEBUG_MODE */
#define XSVFDBG_PRINTF(iDebugLevel,pzFormat)
#define XSVFDBG_PRINTF1(iDebugLevel,pzFormat,arg1)
#define XSVFDBG_PRINTF2(iDebugLevel,pzFormat,arg1,arg2)
#define XSVFDBG_PRINTF3(iDebugLevel,pzFormat,arg1,arg2,arg3)
#define XSVFDBG_PRINTLENVAL(iDebugLevel,plenVal)
#endif  /* DEBUG_MODE */


/*============================================================================
 * XSVF Type Declarations
 ============================================================================*/

/*****************************************************************************
 * Struct:       SXsvfInfo
 * Description:  This structure contains all of the data used during the
 *               execution of the XSVF.  Some data is persistent, predefined
 *               information (e.g. lRunTestTime).  The bulk of this struct's
 *               size is due to the lenVal structs (defined in lenval.h)
 *               which contain buffers for the active shift data.  The MAX_LEN
 *               #define in lenval.h defines the size of these buffers.
 *               These buffers must be large enough to store the longest
 *               shift data in your XSVF file.  For example:
 *                   MAX_LEN >= ( longest_shift_data_in_bits / 8 )
 *               Because the lenVal struct dominates the space usage of this
 *               struct, the rough size of this struct is:
 *                   sizeof( SXsvfInfo ) ~= MAX_LEN * 7 (number of lenVals)
 *               xsvfInitialize() contains initialization code for the data
 *               in this struct.
 *               xsvfCleanup() contains cleanup code for the data in this
 *               struct.
 *****************************************************************************/
typedef struct tagSXsvfInfo
{
	/* XSVF status information */
	unsigned char   ucComplete;         /* 0 = running; 1 = complete */
	unsigned char   ucCommand;          /* Current XSVF command byte */
	long            lCommandCount;      /* Number of commands processed */
	int             iErrorCode;         /* An error code. 0 = no error. */

	/* TAP state/sequencing information */
	unsigned char   ucTapState;         /* Current TAP state */
	unsigned char   ucEndIR;            /* ENDIR TAP state (See SVF) */
	unsigned char   ucEndDR;            /* ENDDR TAP state (See SVF) */

	/* RUNTEST information */
	unsigned char   ucMaxRepeat;        /* Max repeat loops (for xc9500/xl) */
	long            lRunTestTime;       /* Pre-specified RUNTEST time (usec) */

	/* Shift Data Info and Buffers */
	long            lShiftLengthBits;   /* Len. current shift data in bits */
	short           sShiftLengthBytes;  /* Len. current shift data in bytes */

	lenVal          lvTdi;              /* Current TDI shift data */
	lenVal          lvTdoExpected;      /* Expected TDO shift data */
	lenVal          lvTdoCaptured;      /* Captured TDO shift data */
	lenVal          lvTdoMask;          /* TDO mask: 0=dontcare; 1=compare */

#ifdef  XSVF_SUPPORT_COMPRESSION
	/* XSDRINC Data Buffers */
	lenVal          lvAddressMask;      /* Address mask for XSDRINC */
	lenVal          lvDataMask;         /* Data mask for XSDRINC */
	lenVal          lvNextData;         /* Next data for XSDRINC */
#endif  /* XSVF_SUPPORT_COMPRESSION */
} SXsvfInfo;

/* Declare pointer to functions that perform XSVF commands */
typedef int (*TXsvfDoCmdFuncPtr)( SXsvfInfo* );

/*============================================================================
 * XSVF Command Bytes
 ============================================================================*/

/* encodings of xsvf instructions */
#define XCOMPLETE        0
#define XTDOMASK         1
#define XSIR             2
#define XSDR             3
#define XRUNTEST         4
/* Reserved              5 */
/* Reserved              6 */
#define XREPEAT          7
#define XSDRSIZE         8
#define XSDRTDO          9
#define XSETSDRMASKS     10
#define XSDRINC          11
#define XSDRB            12
#define XSDRC            13
#define XSDRE            14
#define XSDRTDOB         15
#define XSDRTDOC         16
#define XSDRTDOE         17
#define XSTATE           18         /* 4.00 */
#define XENDIR           19         /* 4.04 */
#define XENDDR           20         /* 4.04 */
#define XSIR2            21         /* 4.10 */
#define XCOMMENT         22         /* 4.14 */
#define XWAIT            23         /* 5.00 */
/* Insert new commands here */
/* and add corresponding xsvfDoCmd function to xsvf_pfDoCmd below. */
#define XLASTCMD         24         /* Last command marker */


/*============================================================================
 * XSVF Command Parameter Values
 ============================================================================*/

#define XSTATE_RESET     0          /* 4.00 parameter for XSTATE */
#define XSTATE_RUNTEST   1          /* 4.00 parameter for XSTATE */

#define XENDXR_RUNTEST   0          /* 4.04 parameter for XENDIR/DR */
#define XENDXR_PAUSE     1          /* 4.04 parameter for XENDIR/DR */

/* TAP states */
#define XTAPSTATE_RESET     0x00
#define XTAPSTATE_RUNTEST   0x01    /* a.k.a. IDLE */
#define XTAPSTATE_SELECTDR  0x02
#define XTAPSTATE_CAPTUREDR 0x03
#define XTAPSTATE_SHIFTDR   0x04
#define XTAPSTATE_EXIT1DR   0x05
#define XTAPSTATE_PAUSEDR   0x06
#define XTAPSTATE_EXIT2DR   0x07
#define XTAPSTATE_UPDATEDR  0x08
#define XTAPSTATE_IRSTATES  0x09    /* All IR states begin here */
#define XTAPSTATE_SELECTIR  0x09
#define XTAPSTATE_CAPTUREIR 0x0A
#define XTAPSTATE_SHIFTIR   0x0B
#define XTAPSTATE_EXIT1IR   0x0C
#define XTAPSTATE_PAUSEIR   0x0D
#define XTAPSTATE_EXIT2IR   0x0E
#define XTAPSTATE_UPDATEIR  0x0F

/*============================================================================
 * XSVF Function Prototypes
 ============================================================================*/

int xsvfDoIllegalCmd( SXsvfInfo* pXsvfInfo );   /* Illegal command function */
int xsvfDoXCOMPLETE( SXsvfInfo* pXsvfInfo );
int xsvfDoXTDOMASK( SXsvfInfo* pXsvfInfo );
int xsvfDoXSIR( SXsvfInfo* pXsvfInfo );
int xsvfDoXSIR2( SXsvfInfo* pXsvfInfo );
int xsvfDoXSDR( SXsvfInfo* pXsvfInfo );
int xsvfDoXRUNTEST( SXsvfInfo* pXsvfInfo );
int xsvfDoXREPEAT( SXsvfInfo* pXsvfInfo );
int xsvfDoXSDRSIZE( SXsvfInfo* pXsvfInfo );
int xsvfDoXSDRTDO( SXsvfInfo* pXsvfInfo );
int xsvfDoXSETSDRMASKS( SXsvfInfo* pXsvfInfo );
int xsvfDoXSDRINC( SXsvfInfo* pXsvfInfo );
int xsvfDoXSDRBCE( SXsvfInfo* pXsvfInfo );
int xsvfDoXSDRTDOBCE( SXsvfInfo* pXsvfInfo );
int xsvfDoXSTATE( SXsvfInfo* pXsvfInfo );
int xsvfDoXENDXR( SXsvfInfo* pXsvfInfo );
int xsvfDoXCOMMENT( SXsvfInfo* pXsvfInfo );
int xsvfDoXWAIT( SXsvfInfo* pXsvfInfo );
/* Insert new command functions here */

/*============================================================================
 * XSVF Global Variables
 ============================================================================*/

/* Array of XSVF command functions.  Must follow command byte value order! */
/* If your compiler cannot take this form, then convert to a switch statement*/
TXsvfDoCmdFuncPtr   xsvf_pfDoCmd[]  =
{
	xsvfDoXCOMPLETE,        /*  0 */
	xsvfDoXTDOMASK,         /*  1 */
	xsvfDoXSIR,             /*  2 */
	xsvfDoXSDR,             /*  3 */
	xsvfDoXRUNTEST,         /*  4 */
	xsvfDoIllegalCmd,       /*  5 */
	xsvfDoIllegalCmd,       /*  6 */
	xsvfDoXREPEAT,          /*  7 */
	xsvfDoXSDRSIZE,         /*  8 */
	xsvfDoXSDRTDO,          /*  9 */
#ifdef  XSVF_SUPPORT_COMPRESSION
	xsvfDoXSETSDRMASKS,     /* 10 */
	xsvfDoXSDRINC,          /* 11 */
#else
	xsvfDoIllegalCmd,       /* 10 */
	xsvfDoIllegalCmd,       /* 11 */
#endif  /* XSVF_SUPPORT_COMPRESSION */
	xsvfDoXSDRBCE,          /* 12 */
	xsvfDoXSDRBCE,          /* 13 */
	xsvfDoXSDRBCE,          /* 14 */
	xsvfDoXSDRTDOBCE,       /* 15 */
	xsvfDoXSDRTDOBCE,       /* 16 */
	xsvfDoXSDRTDOBCE,       /* 17 */
	xsvfDoXSTATE,           /* 18 */
	xsvfDoXENDXR,           /* 19 */
	xsvfDoXENDXR,           /* 20 */
	xsvfDoXSIR2,            /* 21 */
	xsvfDoXCOMMENT,         /* 22 */
	xsvfDoXWAIT             /* 23 */
/* Insert new command functions here */
};

#ifdef  DEBUG_MODE
char* xsvf_pzCommandName[]  =
{
	"XCOMPLETE",
	"XTDOMASK",
	"XSIR",
	"XSDR",
	"XRUNTEST",
	"Reserved5",
	"Reserved6",
	"XREPEAT",
	"XSDRSIZE",
	"XSDRTDO",
	"XSETSDRMASKS",
	"XSDRINC",
	"XSDRB",
	"XSDRC",
	"XSDRE",
	"XSDRTDOB",
	"XSDRTDOC",
	"XSDRTDOE",
	"XSTATE",
	"XENDIR",
	"XENDDR",
	"XSIR2",
	"XCOMMENT",
	"XWAIT"
};

char*   xsvf_pzErrorName[]  =
{
	"No error",
	"ERROR:  Unknown",
	"ERROR:  TDO mismatch",
	"ERROR:  TDO mismatch and exceeded max retries",
	"ERROR:  Unsupported XSVF command",
	"ERROR:  Illegal state specification",
	"ERROR:  Data overflows allocated MAX_LEN buffer size"
};

char*   xsvf_pzTapState[] =
{
	"RESET",        /* 0x00 */
	"RUNTEST/IDLE", /* 0x01 */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?