Dependencies:   mbed

Committer:
monpjc
Date:
Sat Jun 30 13:17:05 2012 +0000
Revision:
0:1be76329b246
removed returns for debug and corrected usages of fp in main()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
monpjc 0:1be76329b246 1 /*****************************************************************************
monpjc 0:1be76329b246 2 * file: micro.c
monpjc 0:1be76329b246 3 * abstract: This file contains the function, xsvfExecute(),
monpjc 0:1be76329b246 4 * call for interpreting the XSVF commands.
monpjc 0:1be76329b246 5 * Usage: Call xsvfExecute() to process XSVF data.
monpjc 0:1be76329b246 6 * The XSVF data is retrieved by readByte() in ports.c
monpjc 0:1be76329b246 7 * Remove the main function if you already have one.
monpjc 0:1be76329b246 8 * Options: XSVF_SUPPORT_COMPRESSION
monpjc 0:1be76329b246 9 * This define supports the XC9500/XL compression scheme.
monpjc 0:1be76329b246 10 * This define adds support for XSDRINC and XSETSDRMASKS.
monpjc 0:1be76329b246 11 * XSVF_SUPPORT_ERRORCODES
monpjc 0:1be76329b246 12 * This define causes the xsvfExecute function to return
monpjc 0:1be76329b246 13 * an error code for specific errors. See error codes below.
monpjc 0:1be76329b246 14 * If this is not defined, the return value defaults to the
monpjc 0:1be76329b246 15 * legacy values for backward compatibility:
monpjc 0:1be76329b246 16 * 1 = success; 0 = failure.
monpjc 0:1be76329b246 17 * Debugging: DEBUG_MODE (Legacy name)
monpjc 0:1be76329b246 18 * Define DEBUG_MODE to compile with debugging features.
monpjc 0:1be76329b246 19 * Both micro.c and ports.c must be compiled with the DEBUG_MODE
monpjc 0:1be76329b246 20 * defined to enable the standalone main implementation in
monpjc 0:1be76329b246 21 * micro.c that reads XSVF from a file.
monpjc 0:1be76329b246 22 * History: v2.00 - Original XSVF implementation.
monpjc 0:1be76329b246 23 * v4.04 - Added delay at end of XSIR for XC18v00 support.
monpjc 0:1be76329b246 24 * Added new commands for CoolRunner support:
monpjc 0:1be76329b246 25 * XSTATE, XENDIR, XENDDR
monpjc 0:1be76329b246 26 * v4.05 - Cleanup micro.c but leave ports.c intact.
monpjc 0:1be76329b246 27 * v4.06 - Fix xsvfGotoTapState for retry transition.
monpjc 0:1be76329b246 28 * v4.07 - Update example waitTime implementations for
monpjc 0:1be76329b246 29 * compatibility with Virtex-II.
monpjc 0:1be76329b246 30 * v4.10 - Add new XSIR2 command that supports a 2-byte
monpjc 0:1be76329b246 31 * IR-length parameter for IR shifts > 255 bits.
monpjc 0:1be76329b246 32 * v4.11 - No change. Update version to match SVF2XSVF xlator.
monpjc 0:1be76329b246 33 * v4.14 - Added XCOMMENT.
monpjc 0:1be76329b246 34 * v5.00 - Improve XSTATE support.
monpjc 0:1be76329b246 35 * Added XWAIT.
monpjc 0:1be76329b246 36 * v5.01 - make sure that TCK is low during RUNTEST wait for
monpjc 0:1be76329b246 37 * XC18V00/XCF00 support. Only change is in PORTS.C
monpjc 0:1be76329b246 38 * waitTime() function for implementations that do NOT
monpjc 0:1be76329b246 39 * pulse TCK during the waitTime.
monpjc 0:1be76329b246 40 *****************************************************************************/
monpjc 0:1be76329b246 41
monpjc 0:1be76329b246 42 /*============================================================================
monpjc 0:1be76329b246 43 * #pragmas
monpjc 0:1be76329b246 44 ============================================================================*/
monpjc 0:1be76329b246 45 #ifdef _MSC_VER
monpjc 0:1be76329b246 46 #pragma warning( disable : 4100 )
monpjc 0:1be76329b246 47 #endif /* _MSC_VER */
monpjc 0:1be76329b246 48
monpjc 0:1be76329b246 49 /*============================================================================
monpjc 0:1be76329b246 50 * #include files
monpjc 0:1be76329b246 51 ============================================================================*/
monpjc 0:1be76329b246 52 #define DEBUG_MODE
monpjc 0:1be76329b246 53 //#define DEBUG_MODE
monpjc 0:1be76329b246 54 /*#ifdef DEBUG_MODE
monpjc 0:1be76329b246 55 #include <stdio.h>
monpjc 0:1be76329b246 56 #include <stdlib.h>
monpjc 0:1be76329b246 57 #include <string.h>
monpjc 0:1be76329b246 58 #include <time.h>
monpjc 0:1be76329b246 59 #endif*/ /* DEBUG_MODE */
monpjc 0:1be76329b246 60
monpjc 0:1be76329b246 61 #include "micro.h"
monpjc 0:1be76329b246 62 #include "lenval.h"
monpjc 0:1be76329b246 63 #include "ports.h"
monpjc 0:1be76329b246 64 #include "mbed.h"
monpjc 0:1be76329b246 65 extern Serial pc;
monpjc 0:1be76329b246 66
monpjc 0:1be76329b246 67 /*============================================================================
monpjc 0:1be76329b246 68 * XSVF #define
monpjc 0:1be76329b246 69 ============================================================================*/
monpjc 0:1be76329b246 70
monpjc 0:1be76329b246 71 #define XSVF_VERSION "5.01"
monpjc 0:1be76329b246 72
monpjc 0:1be76329b246 73 /*****************************************************************************
monpjc 0:1be76329b246 74 * Define: XSVF_SUPPORT_COMPRESSION
monpjc 0:1be76329b246 75 * Description: Define this to support the XC9500/XL XSVF data compression
monpjc 0:1be76329b246 76 * scheme.
monpjc 0:1be76329b246 77 * Code size can be reduced by NOT supporting this feature.
monpjc 0:1be76329b246 78 * However, you must use the -nc (no compress) option when
monpjc 0:1be76329b246 79 * translating SVF to XSVF using the SVF2XSVF translator.
monpjc 0:1be76329b246 80 * Corresponding, uncompressed XSVF may be larger.
monpjc 0:1be76329b246 81 *****************************************************************************/
monpjc 0:1be76329b246 82 #ifndef XSVF_SUPPORT_COMPRESSION
monpjc 0:1be76329b246 83 #define XSVF_SUPPORT_COMPRESSION 1
monpjc 0:1be76329b246 84 #endif
monpjc 0:1be76329b246 85
monpjc 0:1be76329b246 86 /*****************************************************************************
monpjc 0:1be76329b246 87 * Define: XSVF_SUPPORT_ERRORCODES
monpjc 0:1be76329b246 88 * Description: Define this to support the new XSVF error codes.
monpjc 0:1be76329b246 89 * (The original XSVF player just returned 1 for success and
monpjc 0:1be76329b246 90 * 0 for an unspecified failure.)
monpjc 0:1be76329b246 91 *****************************************************************************/
monpjc 0:1be76329b246 92 #ifndef XSVF_SUPPORT_ERRORCODES
monpjc 0:1be76329b246 93 #define XSVF_SUPPORT_ERRORCODES 1
monpjc 0:1be76329b246 94 #endif
monpjc 0:1be76329b246 95
monpjc 0:1be76329b246 96 #ifdef XSVF_SUPPORT_ERRORCODES
monpjc 0:1be76329b246 97 #define XSVF_ERRORCODE(errorCode) errorCode
monpjc 0:1be76329b246 98 #else /* Use legacy error code */
monpjc 0:1be76329b246 99 #define XSVF_ERRORCODE(errorCode) ((errorCode==XSVF_ERROR_NONE)?1:0)
monpjc 0:1be76329b246 100 #endif /* XSVF_SUPPORT_ERRORCODES */
monpjc 0:1be76329b246 101
monpjc 0:1be76329b246 102
monpjc 0:1be76329b246 103 /*****************************************************************************
monpjc 0:1be76329b246 104 * Define: XSVF_MAIN
monpjc 0:1be76329b246 105 * Description: Define this to compile with a main function for standalone
monpjc 0:1be76329b246 106 * debugging.
monpjc 0:1be76329b246 107 *****************************************************************************/
monpjc 0:1be76329b246 108 #ifndef XSVF_MAIN
monpjc 0:1be76329b246 109 #ifdef DEBUG_MODE
monpjc 0:1be76329b246 110 // #define XSVF_MAIN 1
monpjc 0:1be76329b246 111 #endif /* DEBUG_MODE */
monpjc 0:1be76329b246 112 #endif /* XSVF_MAIN */
monpjc 0:1be76329b246 113
monpjc 0:1be76329b246 114
monpjc 0:1be76329b246 115 /*============================================================================
monpjc 0:1be76329b246 116 * DEBUG_MODE #define
monpjc 0:1be76329b246 117 ============================================================================*/
monpjc 0:1be76329b246 118
monpjc 0:1be76329b246 119 #ifdef DEBUG_MODE
monpjc 0:1be76329b246 120 #define XSVFDBG_PRINTF(iDebugLevel,pzFormat) pc.printf( pzFormat )
monpjc 0:1be76329b246 121 #define XSVFDBG_PRINTF1(iDebugLevel,pzFormat,arg1) pc.printf( pzFormat, arg1 )
monpjc 0:1be76329b246 122 #define XSVFDBG_PRINTF2(iDebugLevel,pzFormat,arg1,arg2) pc.printf( pzFormat, arg1, arg2 )
monpjc 0:1be76329b246 123 #define XSVFDBG_PRINTF3(iDebugLevel,pzFormat,arg1,arg2,arg3) pc.printf( pzFormat, arg1, arg2, arg3 )
monpjc 0:1be76329b246 124 #define XSVFDBG_PRINTLENVAL(iDebugLevel,plenVal)
monpjc 0:1be76329b246 125 #else /* !DEBUG_MODE */
monpjc 0:1be76329b246 126 #define XSVFDBG_PRINTF(iDebugLevel,pzFormat)
monpjc 0:1be76329b246 127 #define XSVFDBG_PRINTF1(iDebugLevel,pzFormat,arg1)
monpjc 0:1be76329b246 128 #define XSVFDBG_PRINTF2(iDebugLevel,pzFormat,arg1,arg2)
monpjc 0:1be76329b246 129 #define XSVFDBG_PRINTF3(iDebugLevel,pzFormat,arg1,arg2,arg3)
monpjc 0:1be76329b246 130 #define XSVFDBG_PRINTLENVAL(iDebugLevel,plenVal)
monpjc 0:1be76329b246 131 #endif /* DEBUG_MODE */
monpjc 0:1be76329b246 132
monpjc 0:1be76329b246 133
monpjc 0:1be76329b246 134 /*============================================================================
monpjc 0:1be76329b246 135 * XSVF Type Declarations
monpjc 0:1be76329b246 136 ============================================================================*/
monpjc 0:1be76329b246 137
monpjc 0:1be76329b246 138 /*****************************************************************************
monpjc 0:1be76329b246 139 * Struct: SXsvfInfo
monpjc 0:1be76329b246 140 * Description: This structure contains all of the data used during the
monpjc 0:1be76329b246 141 * execution of the XSVF. Some data is persistent, predefined
monpjc 0:1be76329b246 142 * information (e.g. lRunTestTime). The bulk of this struct's
monpjc 0:1be76329b246 143 * size is due to the lenVal structs (defined in lenval.h)
monpjc 0:1be76329b246 144 * which contain buffers for the active shift data. The MAX_LEN
monpjc 0:1be76329b246 145 * #define in lenval.h defines the size of these buffers.
monpjc 0:1be76329b246 146 * These buffers must be large enough to store the longest
monpjc 0:1be76329b246 147 * shift data in your XSVF file. For example:
monpjc 0:1be76329b246 148 * MAX_LEN >= ( longest_shift_data_in_bits / 8 )
monpjc 0:1be76329b246 149 * Because the lenVal struct dominates the space usage of this
monpjc 0:1be76329b246 150 * struct, the rough size of this struct is:
monpjc 0:1be76329b246 151 * sizeof( SXsvfInfo ) ~= MAX_LEN * 7 (number of lenVals)
monpjc 0:1be76329b246 152 * xsvfInitialize() contains initialization code for the data
monpjc 0:1be76329b246 153 * in this struct.
monpjc 0:1be76329b246 154 * xsvfCleanup() contains cleanup code for the data in this
monpjc 0:1be76329b246 155 * struct.
monpjc 0:1be76329b246 156 *****************************************************************************/
monpjc 0:1be76329b246 157 typedef struct tagSXsvfInfo
monpjc 0:1be76329b246 158 {
monpjc 0:1be76329b246 159 /* XSVF status information */
monpjc 0:1be76329b246 160 unsigned char ucComplete; /* 0 = running; 1 = complete */
monpjc 0:1be76329b246 161 unsigned char ucCommand; /* Current XSVF command byte */
monpjc 0:1be76329b246 162 long lCommandCount; /* Number of commands processed */
monpjc 0:1be76329b246 163 int iErrorCode; /* An error code. 0 = no error. */
monpjc 0:1be76329b246 164
monpjc 0:1be76329b246 165 /* TAP state/sequencing information */
monpjc 0:1be76329b246 166 unsigned char ucTapState; /* Current TAP state */
monpjc 0:1be76329b246 167 unsigned char ucEndIR; /* ENDIR TAP state (See SVF) */
monpjc 0:1be76329b246 168 unsigned char ucEndDR; /* ENDDR TAP state (See SVF) */
monpjc 0:1be76329b246 169
monpjc 0:1be76329b246 170 /* RUNTEST information */
monpjc 0:1be76329b246 171 unsigned char ucMaxRepeat; /* Max repeat loops (for xc9500/xl) */
monpjc 0:1be76329b246 172 long lRunTestTime; /* Pre-specified RUNTEST time (usec) */
monpjc 0:1be76329b246 173
monpjc 0:1be76329b246 174 /* Shift Data Info and Buffers */
monpjc 0:1be76329b246 175 long lShiftLengthBits; /* Len. current shift data in bits */
monpjc 0:1be76329b246 176 short sShiftLengthBytes; /* Len. current shift data in bytes */
monpjc 0:1be76329b246 177
monpjc 0:1be76329b246 178 lenVal lvTdi; /* Current TDI shift data */
monpjc 0:1be76329b246 179 lenVal lvTdoExpected; /* Expected TDO shift data */
monpjc 0:1be76329b246 180 lenVal lvTdoCaptured; /* Captured TDO shift data */
monpjc 0:1be76329b246 181 lenVal lvTdoMask; /* TDO mask: 0=dontcare; 1=compare */
monpjc 0:1be76329b246 182
monpjc 0:1be76329b246 183 #ifdef XSVF_SUPPORT_COMPRESSION
monpjc 0:1be76329b246 184 /* XSDRINC Data Buffers */
monpjc 0:1be76329b246 185 lenVal lvAddressMask; /* Address mask for XSDRINC */
monpjc 0:1be76329b246 186 lenVal lvDataMask; /* Data mask for XSDRINC */
monpjc 0:1be76329b246 187 lenVal lvNextData; /* Next data for XSDRINC */
monpjc 0:1be76329b246 188 #endif /* XSVF_SUPPORT_COMPRESSION */
monpjc 0:1be76329b246 189 } SXsvfInfo;
monpjc 0:1be76329b246 190
monpjc 0:1be76329b246 191 /* Declare pointer to functions that perform XSVF commands */
monpjc 0:1be76329b246 192 typedef int (*TXsvfDoCmdFuncPtr)( SXsvfInfo* );
monpjc 0:1be76329b246 193
monpjc 0:1be76329b246 194
monpjc 0:1be76329b246 195 /*============================================================================
monpjc 0:1be76329b246 196 * XSVF Command Bytes
monpjc 0:1be76329b246 197 ============================================================================*/
monpjc 0:1be76329b246 198
monpjc 0:1be76329b246 199 /* encodings of xsvf instructions */
monpjc 0:1be76329b246 200 #define XCOMPLETE 0
monpjc 0:1be76329b246 201 #define XTDOMASK 1
monpjc 0:1be76329b246 202 #define XSIR 2
monpjc 0:1be76329b246 203 #define XSDR 3
monpjc 0:1be76329b246 204 #define XRUNTEST 4
monpjc 0:1be76329b246 205 /* Reserved 5 */
monpjc 0:1be76329b246 206 /* Reserved 6 */
monpjc 0:1be76329b246 207 #define XREPEAT 7
monpjc 0:1be76329b246 208 #define XSDRSIZE 8
monpjc 0:1be76329b246 209 #define XSDRTDO 9
monpjc 0:1be76329b246 210 #define XSETSDRMASKS 10
monpjc 0:1be76329b246 211 #define XSDRINC 11
monpjc 0:1be76329b246 212 #define XSDRB 12
monpjc 0:1be76329b246 213 #define XSDRC 13
monpjc 0:1be76329b246 214 #define XSDRE 14
monpjc 0:1be76329b246 215 #define XSDRTDOB 15
monpjc 0:1be76329b246 216 #define XSDRTDOC 16
monpjc 0:1be76329b246 217 #define XSDRTDOE 17
monpjc 0:1be76329b246 218 #define XSTATE 18 /* 4.00 */
monpjc 0:1be76329b246 219 #define XENDIR 19 /* 4.04 */
monpjc 0:1be76329b246 220 #define XENDDR 20 /* 4.04 */
monpjc 0:1be76329b246 221 #define XSIR2 21 /* 4.10 */
monpjc 0:1be76329b246 222 #define XCOMMENT 22 /* 4.14 */
monpjc 0:1be76329b246 223 #define XWAIT 23 /* 5.00 */
monpjc 0:1be76329b246 224 /* Insert new commands here */
monpjc 0:1be76329b246 225 /* and add corresponding xsvfDoCmd function to xsvf_pfDoCmd below. */
monpjc 0:1be76329b246 226 #define XLASTCMD 24 /* Last command marker */
monpjc 0:1be76329b246 227
monpjc 0:1be76329b246 228
monpjc 0:1be76329b246 229 /*============================================================================
monpjc 0:1be76329b246 230 * XSVF Command Parameter Values
monpjc 0:1be76329b246 231 ============================================================================*/
monpjc 0:1be76329b246 232
monpjc 0:1be76329b246 233 #define XSTATE_RESET 0 /* 4.00 parameter for XSTATE */
monpjc 0:1be76329b246 234 #define XSTATE_RUNTEST 1 /* 4.00 parameter for XSTATE */
monpjc 0:1be76329b246 235
monpjc 0:1be76329b246 236 #define XENDXR_RUNTEST 0 /* 4.04 parameter for XENDIR/DR */
monpjc 0:1be76329b246 237 #define XENDXR_PAUSE 1 /* 4.04 parameter for XENDIR/DR */
monpjc 0:1be76329b246 238
monpjc 0:1be76329b246 239 /* TAP states */
monpjc 0:1be76329b246 240 #define XTAPSTATE_RESET 0x00
monpjc 0:1be76329b246 241 #define XTAPSTATE_RUNTEST 0x01 /* a.k.a. IDLE */
monpjc 0:1be76329b246 242 #define XTAPSTATE_SELECTDR 0x02
monpjc 0:1be76329b246 243 #define XTAPSTATE_CAPTUREDR 0x03
monpjc 0:1be76329b246 244 #define XTAPSTATE_SHIFTDR 0x04
monpjc 0:1be76329b246 245 #define XTAPSTATE_EXIT1DR 0x05
monpjc 0:1be76329b246 246 #define XTAPSTATE_PAUSEDR 0x06
monpjc 0:1be76329b246 247 #define XTAPSTATE_EXIT2DR 0x07
monpjc 0:1be76329b246 248 #define XTAPSTATE_UPDATEDR 0x08
monpjc 0:1be76329b246 249 #define XTAPSTATE_IRSTATES 0x09 /* All IR states begin here */
monpjc 0:1be76329b246 250 #define XTAPSTATE_SELECTIR 0x09
monpjc 0:1be76329b246 251 #define XTAPSTATE_CAPTUREIR 0x0A
monpjc 0:1be76329b246 252 #define XTAPSTATE_SHIFTIR 0x0B
monpjc 0:1be76329b246 253 #define XTAPSTATE_EXIT1IR 0x0C
monpjc 0:1be76329b246 254 #define XTAPSTATE_PAUSEIR 0x0D
monpjc 0:1be76329b246 255 #define XTAPSTATE_EXIT2IR 0x0E
monpjc 0:1be76329b246 256 #define XTAPSTATE_UPDATEIR 0x0F
monpjc 0:1be76329b246 257
monpjc 0:1be76329b246 258 /*============================================================================
monpjc 0:1be76329b246 259 * XSVF Function Prototypes
monpjc 0:1be76329b246 260 ============================================================================*/
monpjc 0:1be76329b246 261
monpjc 0:1be76329b246 262 int xsvfDoIllegalCmd( SXsvfInfo* pXsvfInfo ); /* Illegal command function */
monpjc 0:1be76329b246 263 int xsvfDoXCOMPLETE( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 264 int xsvfDoXTDOMASK( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 265 int xsvfDoXSIR( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 266 int xsvfDoXSIR2( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 267 int xsvfDoXSDR( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 268 int xsvfDoXRUNTEST( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 269 int xsvfDoXREPEAT( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 270 int xsvfDoXSDRSIZE( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 271 int xsvfDoXSDRTDO( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 272 int xsvfDoXSETSDRMASKS( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 273 int xsvfDoXSDRINC( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 274 int xsvfDoXSDRBCE( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 275 int xsvfDoXSDRTDOBCE( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 276 int xsvfDoXSTATE( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 277 int xsvfDoXENDXR( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 278 int xsvfDoXCOMMENT( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 279 int xsvfDoXWAIT( SXsvfInfo* pXsvfInfo );
monpjc 0:1be76329b246 280 /* Insert new command functions here */
monpjc 0:1be76329b246 281
monpjc 0:1be76329b246 282 /*============================================================================
monpjc 0:1be76329b246 283 * XSVF Global Variables
monpjc 0:1be76329b246 284 ============================================================================*/
monpjc 0:1be76329b246 285
monpjc 0:1be76329b246 286 /* Array of XSVF command functions. Must follow command byte value order! */
monpjc 0:1be76329b246 287 /* If your compiler cannot take this form, then convert to a switch statement*/
monpjc 0:1be76329b246 288 TXsvfDoCmdFuncPtr xsvf_pfDoCmd[] =
monpjc 0:1be76329b246 289 {
monpjc 0:1be76329b246 290 xsvfDoXCOMPLETE, /* 0 */
monpjc 0:1be76329b246 291 xsvfDoXTDOMASK, /* 1 */
monpjc 0:1be76329b246 292 xsvfDoXSIR, /* 2 */
monpjc 0:1be76329b246 293 xsvfDoXSDR, /* 3 */
monpjc 0:1be76329b246 294 xsvfDoXRUNTEST, /* 4 */
monpjc 0:1be76329b246 295 xsvfDoIllegalCmd, /* 5 */
monpjc 0:1be76329b246 296 xsvfDoIllegalCmd, /* 6 */
monpjc 0:1be76329b246 297 xsvfDoXREPEAT, /* 7 */
monpjc 0:1be76329b246 298 xsvfDoXSDRSIZE, /* 8 */
monpjc 0:1be76329b246 299 xsvfDoXSDRTDO, /* 9 */
monpjc 0:1be76329b246 300 #ifdef XSVF_SUPPORT_COMPRESSION
monpjc 0:1be76329b246 301 xsvfDoXSETSDRMASKS, /* 10 */
monpjc 0:1be76329b246 302 xsvfDoXSDRINC, /* 11 */
monpjc 0:1be76329b246 303 #else
monpjc 0:1be76329b246 304 xsvfDoIllegalCmd, /* 10 */
monpjc 0:1be76329b246 305 xsvfDoIllegalCmd, /* 11 */
monpjc 0:1be76329b246 306 #endif /* XSVF_SUPPORT_COMPRESSION */
monpjc 0:1be76329b246 307 xsvfDoXSDRBCE, /* 12 */
monpjc 0:1be76329b246 308 xsvfDoXSDRBCE, /* 13 */
monpjc 0:1be76329b246 309 xsvfDoXSDRBCE, /* 14 */
monpjc 0:1be76329b246 310 xsvfDoXSDRTDOBCE, /* 15 */
monpjc 0:1be76329b246 311 xsvfDoXSDRTDOBCE, /* 16 */
monpjc 0:1be76329b246 312 xsvfDoXSDRTDOBCE, /* 17 */
monpjc 0:1be76329b246 313 xsvfDoXSTATE, /* 18 */
monpjc 0:1be76329b246 314 xsvfDoXENDXR, /* 19 */
monpjc 0:1be76329b246 315 xsvfDoXENDXR, /* 20 */
monpjc 0:1be76329b246 316 xsvfDoXSIR2, /* 21 */
monpjc 0:1be76329b246 317 xsvfDoXCOMMENT, /* 22 */
monpjc 0:1be76329b246 318 xsvfDoXWAIT /* 23 */
monpjc 0:1be76329b246 319 /* Insert new command functions here */
monpjc 0:1be76329b246 320 };
monpjc 0:1be76329b246 321
monpjc 0:1be76329b246 322 #ifdef DEBUG_MODE
monpjc 0:1be76329b246 323 char* xsvf_pzCommandName[] =
monpjc 0:1be76329b246 324 {
monpjc 0:1be76329b246 325 "XCOMPLETE",
monpjc 0:1be76329b246 326 "XTDOMASK",
monpjc 0:1be76329b246 327 "XSIR",
monpjc 0:1be76329b246 328 "XSDR",
monpjc 0:1be76329b246 329 "XRUNTEST",
monpjc 0:1be76329b246 330 "Reserved5",
monpjc 0:1be76329b246 331 "Reserved6",
monpjc 0:1be76329b246 332 "XREPEAT",
monpjc 0:1be76329b246 333 "XSDRSIZE",
monpjc 0:1be76329b246 334 "XSDRTDO",
monpjc 0:1be76329b246 335 "XSETSDRMASKS",
monpjc 0:1be76329b246 336 "XSDRINC",
monpjc 0:1be76329b246 337 "XSDRB",
monpjc 0:1be76329b246 338 "XSDRC",
monpjc 0:1be76329b246 339 "XSDRE",
monpjc 0:1be76329b246 340 "XSDRTDOB",
monpjc 0:1be76329b246 341 "XSDRTDOC",
monpjc 0:1be76329b246 342 "XSDRTDOE",
monpjc 0:1be76329b246 343 "XSTATE",
monpjc 0:1be76329b246 344 "XENDIR",
monpjc 0:1be76329b246 345 "XENDDR",
monpjc 0:1be76329b246 346 "XSIR2",
monpjc 0:1be76329b246 347 "XCOMMENT",
monpjc 0:1be76329b246 348 "XWAIT"
monpjc 0:1be76329b246 349 };
monpjc 0:1be76329b246 350
monpjc 0:1be76329b246 351 char* xsvf_pzErrorName[] =
monpjc 0:1be76329b246 352 {
monpjc 0:1be76329b246 353 "No error",
monpjc 0:1be76329b246 354 "ERROR: Unknown",
monpjc 0:1be76329b246 355 "ERROR: TDO mismatch",
monpjc 0:1be76329b246 356 "ERROR: TDO mismatch and exceeded max retries",
monpjc 0:1be76329b246 357 "ERROR: Unsupported XSVF command",
monpjc 0:1be76329b246 358 "ERROR: Illegal state specification",
monpjc 0:1be76329b246 359 "ERROR: Data overflows allocated MAX_LEN buffer size"
monpjc 0:1be76329b246 360 };
monpjc 0:1be76329b246 361
monpjc 0:1be76329b246 362 char* xsvf_pzTapState[] =
monpjc 0:1be76329b246 363 {
monpjc 0:1be76329b246 364 "RESET", /* 0x00 */
monpjc 0:1be76329b246 365 "RUNTEST/IDLE", /* 0x01 */
monpjc 0:1be76329b246 366 "DRSELECT", /* 0x02 */
monpjc 0:1be76329b246 367 "DRCAPTURE", /* 0x03 */
monpjc 0:1be76329b246 368 "DRSHIFT", /* 0x04 */
monpjc 0:1be76329b246 369 "DREXIT1", /* 0x05 */
monpjc 0:1be76329b246 370 "DRPAUSE", /* 0x06 */
monpjc 0:1be76329b246 371 "DREXIT2", /* 0x07 */
monpjc 0:1be76329b246 372 "DRUPDATE", /* 0x08 */
monpjc 0:1be76329b246 373 "IRSELECT", /* 0x09 */
monpjc 0:1be76329b246 374 "IRCAPTURE", /* 0x0A */
monpjc 0:1be76329b246 375 "IRSHIFT", /* 0x0B */
monpjc 0:1be76329b246 376 "IREXIT1", /* 0x0C */
monpjc 0:1be76329b246 377 "IRPAUSE", /* 0x0D */
monpjc 0:1be76329b246 378 "IREXIT2", /* 0x0E */
monpjc 0:1be76329b246 379 "IRUPDATE" /* 0x0F */
monpjc 0:1be76329b246 380 };
monpjc 0:1be76329b246 381 #endif /* DEBUG_MODE */
monpjc 0:1be76329b246 382
monpjc 0:1be76329b246 383 #ifdef DEBUG_MODE
monpjc 0:1be76329b246 384 //FILE* in; /* Legacy DEBUG_MODE file pointer */
monpjc 0:1be76329b246 385 int xsvf_iDebugLevel;
monpjc 0:1be76329b246 386 #endif /* DEBUG_MODE */
monpjc 0:1be76329b246 387
monpjc 0:1be76329b246 388 /*============================================================================
monpjc 0:1be76329b246 389 * Utility Functions
monpjc 0:1be76329b246 390 ============================================================================*/
monpjc 0:1be76329b246 391
monpjc 0:1be76329b246 392 /*****************************************************************************
monpjc 0:1be76329b246 393 * Function: xsvfPrintLenVal
monpjc 0:1be76329b246 394 * Description: Print the lenval value in hex.
monpjc 0:1be76329b246 395 * Parameters: plv - ptr to lenval.
monpjc 0:1be76329b246 396 * Returns: void.
monpjc 0:1be76329b246 397 *****************************************************************************/
monpjc 0:1be76329b246 398 #ifdef DEBUG_MODE
monpjc 0:1be76329b246 399 void xsvfPrintLenVal( lenVal *plv )
monpjc 0:1be76329b246 400 {
monpjc 0:1be76329b246 401 int i;
monpjc 0:1be76329b246 402
monpjc 0:1be76329b246 403 if ( plv )
monpjc 0:1be76329b246 404 {
monpjc 0:1be76329b246 405 printf( "0x" );
monpjc 0:1be76329b246 406 for ( i = 0; i < plv->len; ++i )
monpjc 0:1be76329b246 407 {
monpjc 0:1be76329b246 408 printf( "%02x", ((unsigned int)(plv->val[ i ])) );
monpjc 0:1be76329b246 409 }
monpjc 0:1be76329b246 410 }
monpjc 0:1be76329b246 411 }
monpjc 0:1be76329b246 412 #endif /* DEBUG_MODE */
monpjc 0:1be76329b246 413
monpjc 0:1be76329b246 414
monpjc 0:1be76329b246 415 /*****************************************************************************
monpjc 0:1be76329b246 416 * Function: xsvfInfoInit
monpjc 0:1be76329b246 417 * Description: Initialize the xsvfInfo data.
monpjc 0:1be76329b246 418 * Parameters: pXsvfInfo - ptr to the XSVF info structure.
monpjc 0:1be76329b246 419 * Returns: int - 0 = success; otherwise error.
monpjc 0:1be76329b246 420 *****************************************************************************/
monpjc 0:1be76329b246 421 int xsvfInfoInit( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 422 {
monpjc 0:1be76329b246 423 //XSVFDBG_PRINTF1( 4, " sizeof( SXsvfInfo ) = %d bytes\n",
monpjc 0:1be76329b246 424 // sizeof( SXsvfInfo ) );
monpjc 0:1be76329b246 425
monpjc 0:1be76329b246 426 pXsvfInfo->ucComplete = 0;
monpjc 0:1be76329b246 427 pXsvfInfo->ucCommand = XCOMPLETE;
monpjc 0:1be76329b246 428 pXsvfInfo->lCommandCount = 0;
monpjc 0:1be76329b246 429 pXsvfInfo->iErrorCode = XSVF_ERROR_NONE;
monpjc 0:1be76329b246 430 pXsvfInfo->ucMaxRepeat = 0;
monpjc 0:1be76329b246 431 pXsvfInfo->ucTapState = XTAPSTATE_RESET;
monpjc 0:1be76329b246 432 pXsvfInfo->ucEndIR = XTAPSTATE_RUNTEST;
monpjc 0:1be76329b246 433 pXsvfInfo->ucEndDR = XTAPSTATE_RUNTEST;
monpjc 0:1be76329b246 434 pXsvfInfo->lShiftLengthBits = 0L;
monpjc 0:1be76329b246 435 pXsvfInfo->sShiftLengthBytes= 0;
monpjc 0:1be76329b246 436 pXsvfInfo->lRunTestTime = 0L;
monpjc 0:1be76329b246 437
monpjc 0:1be76329b246 438 return( 0 );
monpjc 0:1be76329b246 439 }
monpjc 0:1be76329b246 440
monpjc 0:1be76329b246 441 /*****************************************************************************
monpjc 0:1be76329b246 442 * Function: xsvfInfoCleanup
monpjc 0:1be76329b246 443 * Description: Cleanup the xsvfInfo data.
monpjc 0:1be76329b246 444 * Parameters: pXsvfInfo - ptr to the XSVF info structure.
monpjc 0:1be76329b246 445 * Returns: void.
monpjc 0:1be76329b246 446 *****************************************************************************/
monpjc 0:1be76329b246 447 void xsvfInfoCleanup( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 448 {
monpjc 0:1be76329b246 449 }
monpjc 0:1be76329b246 450
monpjc 0:1be76329b246 451 /*****************************************************************************
monpjc 0:1be76329b246 452 * Function: xsvfGetAsNumBytes
monpjc 0:1be76329b246 453 * Description: Calculate the number of bytes the given number of bits
monpjc 0:1be76329b246 454 * consumes.
monpjc 0:1be76329b246 455 * Parameters: lNumBits - the number of bits.
monpjc 0:1be76329b246 456 * Returns: short - the number of bytes to store the number of bits.
monpjc 0:1be76329b246 457 *****************************************************************************/
monpjc 0:1be76329b246 458 short xsvfGetAsNumBytes( long lNumBits )
monpjc 0:1be76329b246 459 {
monpjc 0:1be76329b246 460 return( (short)( ( lNumBits + 7L ) / 8L ) );
monpjc 0:1be76329b246 461 }
monpjc 0:1be76329b246 462
monpjc 0:1be76329b246 463 /*****************************************************************************
monpjc 0:1be76329b246 464 * Function: xsvfTmsTransition
monpjc 0:1be76329b246 465 * Description: Apply TMS and transition TAP controller by applying one TCK
monpjc 0:1be76329b246 466 * cycle.
monpjc 0:1be76329b246 467 * Parameters: sTms - new TMS value.
monpjc 0:1be76329b246 468 * Returns: void.
monpjc 0:1be76329b246 469 *****************************************************************************/
monpjc 0:1be76329b246 470 void xsvfTmsTransition( short sTms )
monpjc 0:1be76329b246 471 {
monpjc 0:1be76329b246 472 setPort( TMS, sTms );
monpjc 0:1be76329b246 473 setPort( TCK, 0 );
monpjc 0:1be76329b246 474 setPort( TCK, 1 );
monpjc 0:1be76329b246 475 }
monpjc 0:1be76329b246 476
monpjc 0:1be76329b246 477 /*****************************************************************************
monpjc 0:1be76329b246 478 * Function: xsvfGotoTapState
monpjc 0:1be76329b246 479 * Description: From the current TAP state, go to the named TAP state.
monpjc 0:1be76329b246 480 * A target state of RESET ALWAYS causes TMS reset sequence.
monpjc 0:1be76329b246 481 * All SVF standard stable state paths are supported.
monpjc 0:1be76329b246 482 * All state transitions are supported except for the following
monpjc 0:1be76329b246 483 * which cause an XSVF_ERROR_ILLEGALSTATE:
monpjc 0:1be76329b246 484 * - Target==DREXIT2; Start!=DRPAUSE
monpjc 0:1be76329b246 485 * - Target==IREXIT2; Start!=IRPAUSE
monpjc 0:1be76329b246 486 * Parameters: pucTapState - Current TAP state; returns final TAP state.
monpjc 0:1be76329b246 487 * ucTargetState - New target TAP state.
monpjc 0:1be76329b246 488 * Returns: int - 0 = success; otherwise error.
monpjc 0:1be76329b246 489 *****************************************************************************/
monpjc 0:1be76329b246 490 int xsvfGotoTapState( unsigned char* pucTapState,
monpjc 0:1be76329b246 491 unsigned char ucTargetState )
monpjc 0:1be76329b246 492 {
monpjc 0:1be76329b246 493 int i;
monpjc 0:1be76329b246 494 int iErrorCode;
monpjc 0:1be76329b246 495
monpjc 0:1be76329b246 496 iErrorCode = XSVF_ERROR_NONE;
monpjc 0:1be76329b246 497 if ( ucTargetState == XTAPSTATE_RESET )
monpjc 0:1be76329b246 498 {
monpjc 0:1be76329b246 499 /* If RESET, always perform TMS reset sequence to reset/sync TAPs */
monpjc 0:1be76329b246 500 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 501 for ( i = 0; i < 5; ++i )
monpjc 0:1be76329b246 502 {
monpjc 0:1be76329b246 503 setPort( TCK, 0 );
monpjc 0:1be76329b246 504 setPort( TCK, 1 );
monpjc 0:1be76329b246 505 }
monpjc 0:1be76329b246 506 *pucTapState = XTAPSTATE_RESET;
monpjc 0:1be76329b246 507 XSVFDBG_PRINTF( 3, " TMS Reset Sequence -> Test-Logic-Reset\n" );
monpjc 0:1be76329b246 508 XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
monpjc 0:1be76329b246 509 xsvf_pzTapState[ *pucTapState ] );
monpjc 0:1be76329b246 510 }
monpjc 0:1be76329b246 511 else if ( ( ucTargetState != *pucTapState ) &&
monpjc 0:1be76329b246 512 ( ( ( ucTargetState == XTAPSTATE_EXIT2DR ) && ( *pucTapState != XTAPSTATE_PAUSEDR ) ) ||
monpjc 0:1be76329b246 513 ( ( ucTargetState == XTAPSTATE_EXIT2IR ) && ( *pucTapState != XTAPSTATE_PAUSEIR ) ) ) )
monpjc 0:1be76329b246 514 {
monpjc 0:1be76329b246 515 /* Trap illegal TAP state path specification */
monpjc 0:1be76329b246 516 iErrorCode = XSVF_ERROR_ILLEGALSTATE;
monpjc 0:1be76329b246 517 }
monpjc 0:1be76329b246 518 else
monpjc 0:1be76329b246 519 {
monpjc 0:1be76329b246 520 if ( ucTargetState == *pucTapState )
monpjc 0:1be76329b246 521 {
monpjc 0:1be76329b246 522 /* Already in target state. Do nothing except when in DRPAUSE
monpjc 0:1be76329b246 523 or in IRPAUSE to comply with SVF standard */
monpjc 0:1be76329b246 524 if ( ucTargetState == XTAPSTATE_PAUSEDR )
monpjc 0:1be76329b246 525 {
monpjc 0:1be76329b246 526 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 527 *pucTapState = XTAPSTATE_EXIT2DR;
monpjc 0:1be76329b246 528 XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
monpjc 0:1be76329b246 529 xsvf_pzTapState[ *pucTapState ] );
monpjc 0:1be76329b246 530 }
monpjc 0:1be76329b246 531 else if ( ucTargetState == XTAPSTATE_PAUSEIR )
monpjc 0:1be76329b246 532 {
monpjc 0:1be76329b246 533 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 534 *pucTapState = XTAPSTATE_EXIT2IR;
monpjc 0:1be76329b246 535 XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
monpjc 0:1be76329b246 536 xsvf_pzTapState[ *pucTapState ] );
monpjc 0:1be76329b246 537 }
monpjc 0:1be76329b246 538 }
monpjc 0:1be76329b246 539
monpjc 0:1be76329b246 540 /* Perform TAP state transitions to get to the target state */
monpjc 0:1be76329b246 541 while ( ucTargetState != *pucTapState )
monpjc 0:1be76329b246 542 {
monpjc 0:1be76329b246 543 switch ( *pucTapState )
monpjc 0:1be76329b246 544 {
monpjc 0:1be76329b246 545 case XTAPSTATE_RESET:
monpjc 0:1be76329b246 546 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 547 *pucTapState = XTAPSTATE_RUNTEST;
monpjc 0:1be76329b246 548 break;
monpjc 0:1be76329b246 549 case XTAPSTATE_RUNTEST:
monpjc 0:1be76329b246 550 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 551 *pucTapState = XTAPSTATE_SELECTDR;
monpjc 0:1be76329b246 552 break;
monpjc 0:1be76329b246 553 case XTAPSTATE_SELECTDR:
monpjc 0:1be76329b246 554 if ( ucTargetState >= XTAPSTATE_IRSTATES )
monpjc 0:1be76329b246 555 {
monpjc 0:1be76329b246 556 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 557 *pucTapState = XTAPSTATE_SELECTIR;
monpjc 0:1be76329b246 558 }
monpjc 0:1be76329b246 559 else
monpjc 0:1be76329b246 560 {
monpjc 0:1be76329b246 561 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 562 *pucTapState = XTAPSTATE_CAPTUREDR;
monpjc 0:1be76329b246 563 }
monpjc 0:1be76329b246 564 break;
monpjc 0:1be76329b246 565 case XTAPSTATE_CAPTUREDR:
monpjc 0:1be76329b246 566 if ( ucTargetState == XTAPSTATE_SHIFTDR )
monpjc 0:1be76329b246 567 {
monpjc 0:1be76329b246 568 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 569 *pucTapState = XTAPSTATE_SHIFTDR;
monpjc 0:1be76329b246 570 }
monpjc 0:1be76329b246 571 else
monpjc 0:1be76329b246 572 {
monpjc 0:1be76329b246 573 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 574 *pucTapState = XTAPSTATE_EXIT1DR;
monpjc 0:1be76329b246 575 }
monpjc 0:1be76329b246 576 break;
monpjc 0:1be76329b246 577 case XTAPSTATE_SHIFTDR:
monpjc 0:1be76329b246 578 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 579 *pucTapState = XTAPSTATE_EXIT1DR;
monpjc 0:1be76329b246 580 break;
monpjc 0:1be76329b246 581 case XTAPSTATE_EXIT1DR:
monpjc 0:1be76329b246 582 if ( ucTargetState == XTAPSTATE_PAUSEDR )
monpjc 0:1be76329b246 583 {
monpjc 0:1be76329b246 584 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 585 *pucTapState = XTAPSTATE_PAUSEDR;
monpjc 0:1be76329b246 586 }
monpjc 0:1be76329b246 587 else
monpjc 0:1be76329b246 588 {
monpjc 0:1be76329b246 589 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 590 *pucTapState = XTAPSTATE_UPDATEDR;
monpjc 0:1be76329b246 591 }
monpjc 0:1be76329b246 592 break;
monpjc 0:1be76329b246 593 case XTAPSTATE_PAUSEDR:
monpjc 0:1be76329b246 594 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 595 *pucTapState = XTAPSTATE_EXIT2DR;
monpjc 0:1be76329b246 596 break;
monpjc 0:1be76329b246 597 case XTAPSTATE_EXIT2DR:
monpjc 0:1be76329b246 598 if ( ucTargetState == XTAPSTATE_SHIFTDR )
monpjc 0:1be76329b246 599 {
monpjc 0:1be76329b246 600 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 601 *pucTapState = XTAPSTATE_SHIFTDR;
monpjc 0:1be76329b246 602 }
monpjc 0:1be76329b246 603 else
monpjc 0:1be76329b246 604 {
monpjc 0:1be76329b246 605 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 606 *pucTapState = XTAPSTATE_UPDATEDR;
monpjc 0:1be76329b246 607 }
monpjc 0:1be76329b246 608 break;
monpjc 0:1be76329b246 609 case XTAPSTATE_UPDATEDR:
monpjc 0:1be76329b246 610 if ( ucTargetState == XTAPSTATE_RUNTEST )
monpjc 0:1be76329b246 611 {
monpjc 0:1be76329b246 612 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 613 *pucTapState = XTAPSTATE_RUNTEST;
monpjc 0:1be76329b246 614 }
monpjc 0:1be76329b246 615 else
monpjc 0:1be76329b246 616 {
monpjc 0:1be76329b246 617 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 618 *pucTapState = XTAPSTATE_SELECTDR;
monpjc 0:1be76329b246 619 }
monpjc 0:1be76329b246 620 break;
monpjc 0:1be76329b246 621 case XTAPSTATE_SELECTIR:
monpjc 0:1be76329b246 622 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 623 *pucTapState = XTAPSTATE_CAPTUREIR;
monpjc 0:1be76329b246 624 break;
monpjc 0:1be76329b246 625 case XTAPSTATE_CAPTUREIR:
monpjc 0:1be76329b246 626 if ( ucTargetState == XTAPSTATE_SHIFTIR )
monpjc 0:1be76329b246 627 {
monpjc 0:1be76329b246 628 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 629 *pucTapState = XTAPSTATE_SHIFTIR;
monpjc 0:1be76329b246 630 }
monpjc 0:1be76329b246 631 else
monpjc 0:1be76329b246 632 {
monpjc 0:1be76329b246 633 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 634 *pucTapState = XTAPSTATE_EXIT1IR;
monpjc 0:1be76329b246 635 }
monpjc 0:1be76329b246 636 break;
monpjc 0:1be76329b246 637 case XTAPSTATE_SHIFTIR:
monpjc 0:1be76329b246 638 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 639 *pucTapState = XTAPSTATE_EXIT1IR;
monpjc 0:1be76329b246 640 break;
monpjc 0:1be76329b246 641 case XTAPSTATE_EXIT1IR:
monpjc 0:1be76329b246 642 if ( ucTargetState == XTAPSTATE_PAUSEIR )
monpjc 0:1be76329b246 643 {
monpjc 0:1be76329b246 644 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 645 *pucTapState = XTAPSTATE_PAUSEIR;
monpjc 0:1be76329b246 646 }
monpjc 0:1be76329b246 647 else
monpjc 0:1be76329b246 648 {
monpjc 0:1be76329b246 649 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 650 *pucTapState = XTAPSTATE_UPDATEIR;
monpjc 0:1be76329b246 651 }
monpjc 0:1be76329b246 652 break;
monpjc 0:1be76329b246 653 case XTAPSTATE_PAUSEIR:
monpjc 0:1be76329b246 654 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 655 *pucTapState = XTAPSTATE_EXIT2IR;
monpjc 0:1be76329b246 656 break;
monpjc 0:1be76329b246 657 case XTAPSTATE_EXIT2IR:
monpjc 0:1be76329b246 658 if ( ucTargetState == XTAPSTATE_SHIFTIR )
monpjc 0:1be76329b246 659 {
monpjc 0:1be76329b246 660 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 661 *pucTapState = XTAPSTATE_SHIFTIR;
monpjc 0:1be76329b246 662 }
monpjc 0:1be76329b246 663 else
monpjc 0:1be76329b246 664 {
monpjc 0:1be76329b246 665 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 666 *pucTapState = XTAPSTATE_UPDATEIR;
monpjc 0:1be76329b246 667 }
monpjc 0:1be76329b246 668 break;
monpjc 0:1be76329b246 669 case XTAPSTATE_UPDATEIR:
monpjc 0:1be76329b246 670 if ( ucTargetState == XTAPSTATE_RUNTEST )
monpjc 0:1be76329b246 671 {
monpjc 0:1be76329b246 672 xsvfTmsTransition( 0 );
monpjc 0:1be76329b246 673 *pucTapState = XTAPSTATE_RUNTEST;
monpjc 0:1be76329b246 674 }
monpjc 0:1be76329b246 675 else
monpjc 0:1be76329b246 676 {
monpjc 0:1be76329b246 677 xsvfTmsTransition( 1 );
monpjc 0:1be76329b246 678 *pucTapState = XTAPSTATE_SELECTDR;
monpjc 0:1be76329b246 679 }
monpjc 0:1be76329b246 680 break;
monpjc 0:1be76329b246 681 default:
monpjc 0:1be76329b246 682 iErrorCode = XSVF_ERROR_ILLEGALSTATE;
monpjc 0:1be76329b246 683 *pucTapState = ucTargetState; /* Exit while loop */
monpjc 0:1be76329b246 684 break;
monpjc 0:1be76329b246 685 }
monpjc 0:1be76329b246 686 XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
monpjc 0:1be76329b246 687 xsvf_pzTapState[ *pucTapState ] );
monpjc 0:1be76329b246 688 }
monpjc 0:1be76329b246 689 }
monpjc 0:1be76329b246 690
monpjc 0:1be76329b246 691 return( iErrorCode );
monpjc 0:1be76329b246 692 }
monpjc 0:1be76329b246 693
monpjc 0:1be76329b246 694 /*****************************************************************************
monpjc 0:1be76329b246 695 * Function: xsvfShiftOnly
monpjc 0:1be76329b246 696 * Description: Assumes that starting TAP state is SHIFT-DR or SHIFT-IR.
monpjc 0:1be76329b246 697 * Shift the given TDI data into the JTAG scan chain.
monpjc 0:1be76329b246 698 * Optionally, save the TDO data shifted out of the scan chain.
monpjc 0:1be76329b246 699 * Last shift cycle is special: capture last TDO, set last TDI,
monpjc 0:1be76329b246 700 * but does not pulse TCK. Caller must pulse TCK and optionally
monpjc 0:1be76329b246 701 * set TMS=1 to exit shift state.
monpjc 0:1be76329b246 702 * Parameters: lNumBits - number of bits to shift.
monpjc 0:1be76329b246 703 * plvTdi - ptr to lenval for TDI data.
monpjc 0:1be76329b246 704 * plvTdoCaptured - ptr to lenval for storing captured TDO data.
monpjc 0:1be76329b246 705 * iExitShift - 1=exit at end of shift; 0=stay in Shift-DR.
monpjc 0:1be76329b246 706 * Returns: void.
monpjc 0:1be76329b246 707 *****************************************************************************/
monpjc 0:1be76329b246 708 void xsvfShiftOnly( long lNumBits,
monpjc 0:1be76329b246 709 lenVal* plvTdi,
monpjc 0:1be76329b246 710 lenVal* plvTdoCaptured,
monpjc 0:1be76329b246 711 int iExitShift )
monpjc 0:1be76329b246 712 {
monpjc 0:1be76329b246 713 unsigned char* pucTdi;
monpjc 0:1be76329b246 714 unsigned char* pucTdo;
monpjc 0:1be76329b246 715 unsigned char ucTdiByte;
monpjc 0:1be76329b246 716 unsigned char ucTdoByte;
monpjc 0:1be76329b246 717 unsigned char ucTdoBit;
monpjc 0:1be76329b246 718 int i;
monpjc 0:1be76329b246 719
monpjc 0:1be76329b246 720 /* assert( ( ( lNumBits + 7 ) / 8 ) == plvTdi->len ); */
monpjc 0:1be76329b246 721
monpjc 0:1be76329b246 722 /* Initialize TDO storage len == TDI len */
monpjc 0:1be76329b246 723 pucTdo = 0;
monpjc 0:1be76329b246 724 if ( plvTdoCaptured )
monpjc 0:1be76329b246 725 {
monpjc 0:1be76329b246 726 plvTdoCaptured->len = plvTdi->len;
monpjc 0:1be76329b246 727 pucTdo = plvTdoCaptured->val + plvTdi->len;
monpjc 0:1be76329b246 728 }
monpjc 0:1be76329b246 729
monpjc 0:1be76329b246 730 /* Shift LSB first. val[N-1] == LSB. val[0] == MSB. */
monpjc 0:1be76329b246 731 pucTdi = plvTdi->val + plvTdi->len;
monpjc 0:1be76329b246 732 while ( lNumBits )
monpjc 0:1be76329b246 733 {
monpjc 0:1be76329b246 734 /* Process on a byte-basis */
monpjc 0:1be76329b246 735 ucTdiByte = (*(--pucTdi));
monpjc 0:1be76329b246 736 ucTdoByte = 0;
monpjc 0:1be76329b246 737 for ( i = 0; ( lNumBits && ( i < 8 ) ); ++i )
monpjc 0:1be76329b246 738 {
monpjc 0:1be76329b246 739 --lNumBits;
monpjc 0:1be76329b246 740 if ( iExitShift && !lNumBits )
monpjc 0:1be76329b246 741 {
monpjc 0:1be76329b246 742 /* Exit Shift-DR state */
monpjc 0:1be76329b246 743 setPort( TMS, 1 );
monpjc 0:1be76329b246 744 }
monpjc 0:1be76329b246 745
monpjc 0:1be76329b246 746 /* Set the new TDI value */
monpjc 0:1be76329b246 747 setPort( TDI, (short)(ucTdiByte & 1) );
monpjc 0:1be76329b246 748 ucTdiByte >>= 1;
monpjc 0:1be76329b246 749
monpjc 0:1be76329b246 750 /* Set TCK low */
monpjc 0:1be76329b246 751 setPort( TCK, 0 );
monpjc 0:1be76329b246 752
monpjc 0:1be76329b246 753 if ( pucTdo )
monpjc 0:1be76329b246 754 {
monpjc 0:1be76329b246 755 /* Save the TDO value */
monpjc 0:1be76329b246 756 ucTdoBit = readTDOBit();
monpjc 0:1be76329b246 757 ucTdoByte |= ( ucTdoBit << i );
monpjc 0:1be76329b246 758 }
monpjc 0:1be76329b246 759
monpjc 0:1be76329b246 760 /* Set TCK high */
monpjc 0:1be76329b246 761 setPort( TCK, 1 );
monpjc 0:1be76329b246 762 }
monpjc 0:1be76329b246 763
monpjc 0:1be76329b246 764 /* Save the TDO byte value */
monpjc 0:1be76329b246 765 if ( pucTdo )
monpjc 0:1be76329b246 766 {
monpjc 0:1be76329b246 767 (*(--pucTdo)) = ucTdoByte;
monpjc 0:1be76329b246 768 }
monpjc 0:1be76329b246 769 }
monpjc 0:1be76329b246 770 }
monpjc 0:1be76329b246 771
monpjc 0:1be76329b246 772 /*****************************************************************************
monpjc 0:1be76329b246 773 * Function: xsvfShift
monpjc 0:1be76329b246 774 * Description: Goes to the given starting TAP state.
monpjc 0:1be76329b246 775 * Calls xsvfShiftOnly to shift in the given TDI data and
monpjc 0:1be76329b246 776 * optionally capture the TDO data.
monpjc 0:1be76329b246 777 * Compares the TDO captured data against the TDO expected
monpjc 0:1be76329b246 778 * data.
monpjc 0:1be76329b246 779 * If a data mismatch occurs, then executes the exception
monpjc 0:1be76329b246 780 * handling loop upto ucMaxRepeat times.
monpjc 0:1be76329b246 781 * Parameters: pucTapState - Ptr to current TAP state.
monpjc 0:1be76329b246 782 * ucStartState - Starting shift state: Shift-DR or Shift-IR.
monpjc 0:1be76329b246 783 * lNumBits - number of bits to shift.
monpjc 0:1be76329b246 784 * plvTdi - ptr to lenval for TDI data.
monpjc 0:1be76329b246 785 * plvTdoCaptured - ptr to lenval for storing TDO data.
monpjc 0:1be76329b246 786 * plvTdoExpected - ptr to expected TDO data.
monpjc 0:1be76329b246 787 * plvTdoMask - ptr to TDO mask.
monpjc 0:1be76329b246 788 * ucEndState - state in which to end the shift.
monpjc 0:1be76329b246 789 * lRunTestTime - amount of time to wait after the shift.
monpjc 0:1be76329b246 790 * ucMaxRepeat - Maximum number of retries on TDO mismatch.
monpjc 0:1be76329b246 791 * Returns: int - 0 = success; otherwise TDO mismatch.
monpjc 0:1be76329b246 792 * Notes: XC9500XL-only Optimization:
monpjc 0:1be76329b246 793 * Skip the waitTime() if plvTdoMask->val[0:plvTdoMask->len-1]
monpjc 0:1be76329b246 794 * is NOT all zeros and sMatch==1.
monpjc 0:1be76329b246 795 *****************************************************************************/
monpjc 0:1be76329b246 796 int xsvfShift( unsigned char* pucTapState,
monpjc 0:1be76329b246 797 unsigned char ucStartState,
monpjc 0:1be76329b246 798 long lNumBits,
monpjc 0:1be76329b246 799 lenVal* plvTdi,
monpjc 0:1be76329b246 800 lenVal* plvTdoCaptured,
monpjc 0:1be76329b246 801 lenVal* plvTdoExpected,
monpjc 0:1be76329b246 802 lenVal* plvTdoMask,
monpjc 0:1be76329b246 803 unsigned char ucEndState,
monpjc 0:1be76329b246 804 long lRunTestTime,
monpjc 0:1be76329b246 805 unsigned char ucMaxRepeat )
monpjc 0:1be76329b246 806 {
monpjc 0:1be76329b246 807 int iErrorCode;
monpjc 0:1be76329b246 808 int iMismatch;
monpjc 0:1be76329b246 809 unsigned char ucRepeat;
monpjc 0:1be76329b246 810 int iExitShift;
monpjc 0:1be76329b246 811
monpjc 0:1be76329b246 812 iErrorCode = XSVF_ERROR_NONE;
monpjc 0:1be76329b246 813 iMismatch = 0;
monpjc 0:1be76329b246 814 ucRepeat = 0;
monpjc 0:1be76329b246 815 iExitShift = ( ucStartState != ucEndState );
monpjc 0:1be76329b246 816
monpjc 0:1be76329b246 817 XSVFDBG_PRINTF1( 3, " Shift Length = %ld\n", lNumBits );
monpjc 0:1be76329b246 818 XSVFDBG_PRINTF( 4, " TDI = ");
monpjc 0:1be76329b246 819 XSVFDBG_PRINTLENVAL( 4, plvTdi );
monpjc 0:1be76329b246 820 XSVFDBG_PRINTF( 4, "\n");
monpjc 0:1be76329b246 821 XSVFDBG_PRINTF( 4, " TDO Expected = ");
monpjc 0:1be76329b246 822 XSVFDBG_PRINTLENVAL( 4, plvTdoExpected );
monpjc 0:1be76329b246 823 XSVFDBG_PRINTF( 4, "\n");
monpjc 0:1be76329b246 824
monpjc 0:1be76329b246 825 if ( !lNumBits )
monpjc 0:1be76329b246 826 {
monpjc 0:1be76329b246 827 /* Compatibility with XSVF2.00: XSDR 0 = no shift, but wait in RTI */
monpjc 0:1be76329b246 828 if ( lRunTestTime )
monpjc 0:1be76329b246 829 {
monpjc 0:1be76329b246 830 /* Wait for prespecified XRUNTEST time */
monpjc 0:1be76329b246 831 xsvfGotoTapState( pucTapState, XTAPSTATE_RUNTEST );
monpjc 0:1be76329b246 832 XSVFDBG_PRINTF1( 3, " Wait = %ld usec\n", lRunTestTime );
monpjc 0:1be76329b246 833 waitTime( lRunTestTime );
monpjc 0:1be76329b246 834 }
monpjc 0:1be76329b246 835 }
monpjc 0:1be76329b246 836 else
monpjc 0:1be76329b246 837 {
monpjc 0:1be76329b246 838 do
monpjc 0:1be76329b246 839 {
monpjc 0:1be76329b246 840 /* Goto Shift-DR or Shift-IR */
monpjc 0:1be76329b246 841 xsvfGotoTapState( pucTapState, ucStartState );
monpjc 0:1be76329b246 842
monpjc 0:1be76329b246 843 /* Shift TDI and capture TDO */
monpjc 0:1be76329b246 844 xsvfShiftOnly( lNumBits, plvTdi, plvTdoCaptured, iExitShift );
monpjc 0:1be76329b246 845
monpjc 0:1be76329b246 846 if ( plvTdoExpected )
monpjc 0:1be76329b246 847 {
monpjc 0:1be76329b246 848 /* Compare TDO data to expected TDO data */
monpjc 0:1be76329b246 849 iMismatch = !EqualLenVal( plvTdoExpected,
monpjc 0:1be76329b246 850 plvTdoCaptured,
monpjc 0:1be76329b246 851 plvTdoMask );
monpjc 0:1be76329b246 852 }
monpjc 0:1be76329b246 853
monpjc 0:1be76329b246 854 if ( iExitShift )
monpjc 0:1be76329b246 855 {
monpjc 0:1be76329b246 856 /* Update TAP state: Shift->Exit */
monpjc 0:1be76329b246 857 ++(*pucTapState);
monpjc 0:1be76329b246 858 XSVFDBG_PRINTF1( 3, " TAP State = %s\n",
monpjc 0:1be76329b246 859 xsvf_pzTapState[ *pucTapState ] );
monpjc 0:1be76329b246 860
monpjc 0:1be76329b246 861 if ( iMismatch && lRunTestTime && ( ucRepeat < ucMaxRepeat ) )
monpjc 0:1be76329b246 862 {
monpjc 0:1be76329b246 863 XSVFDBG_PRINTF( 4, " TDO Expected = ");
monpjc 0:1be76329b246 864 XSVFDBG_PRINTLENVAL( 4, plvTdoExpected );
monpjc 0:1be76329b246 865 XSVFDBG_PRINTF( 4, "\n");
monpjc 0:1be76329b246 866 XSVFDBG_PRINTF( 4, " TDO Captured = ");
monpjc 0:1be76329b246 867 XSVFDBG_PRINTLENVAL( 4, plvTdoCaptured );
monpjc 0:1be76329b246 868 XSVFDBG_PRINTF( 4, "\n");
monpjc 0:1be76329b246 869 XSVFDBG_PRINTF( 4, " TDO Mask = ");
monpjc 0:1be76329b246 870 XSVFDBG_PRINTLENVAL( 4, plvTdoMask );
monpjc 0:1be76329b246 871 XSVFDBG_PRINTF( 4, "\n");
monpjc 0:1be76329b246 872 XSVFDBG_PRINTF1( 3, " Retry #%d\n", ( ucRepeat + 1 ) );
monpjc 0:1be76329b246 873 /* Do exception handling retry - ShiftDR only */
monpjc 0:1be76329b246 874 xsvfGotoTapState( pucTapState, XTAPSTATE_PAUSEDR );
monpjc 0:1be76329b246 875 /* Shift 1 extra bit */
monpjc 0:1be76329b246 876 xsvfGotoTapState( pucTapState, XTAPSTATE_SHIFTDR );
monpjc 0:1be76329b246 877 /* Increment RUNTEST time by an additional 25% */
monpjc 0:1be76329b246 878 lRunTestTime += ( lRunTestTime >> 2 );
monpjc 0:1be76329b246 879 }
monpjc 0:1be76329b246 880 else
monpjc 0:1be76329b246 881 {
monpjc 0:1be76329b246 882 /* Do normal exit from Shift-XR */
monpjc 0:1be76329b246 883 xsvfGotoTapState( pucTapState, ucEndState );
monpjc 0:1be76329b246 884 }
monpjc 0:1be76329b246 885
monpjc 0:1be76329b246 886 if ( lRunTestTime )
monpjc 0:1be76329b246 887 {
monpjc 0:1be76329b246 888 /* Wait for prespecified XRUNTEST time */
monpjc 0:1be76329b246 889 xsvfGotoTapState( pucTapState, XTAPSTATE_RUNTEST );
monpjc 0:1be76329b246 890 XSVFDBG_PRINTF1( 3, " Wait = %ld usec\n", lRunTestTime );
monpjc 0:1be76329b246 891 waitTime( lRunTestTime );
monpjc 0:1be76329b246 892 }
monpjc 0:1be76329b246 893 }
monpjc 0:1be76329b246 894 } while ( iMismatch && ( ucRepeat++ < ucMaxRepeat ) );
monpjc 0:1be76329b246 895 }
monpjc 0:1be76329b246 896
monpjc 0:1be76329b246 897 if ( iMismatch )
monpjc 0:1be76329b246 898 {
monpjc 0:1be76329b246 899 XSVFDBG_PRINTF( 1, " TDO Expected = ");
monpjc 0:1be76329b246 900 XSVFDBG_PRINTLENVAL( 1, plvTdoExpected );
monpjc 0:1be76329b246 901 XSVFDBG_PRINTF( 1, "\n");
monpjc 0:1be76329b246 902 XSVFDBG_PRINTF( 1, " TDO Captured = ");
monpjc 0:1be76329b246 903 XSVFDBG_PRINTLENVAL( 1, plvTdoCaptured );
monpjc 0:1be76329b246 904 XSVFDBG_PRINTF( 1, "\n");
monpjc 0:1be76329b246 905 XSVFDBG_PRINTF( 1, " TDO Mask = ");
monpjc 0:1be76329b246 906 XSVFDBG_PRINTLENVAL( 1, plvTdoMask );
monpjc 0:1be76329b246 907 XSVFDBG_PRINTF( 1, "\n");
monpjc 0:1be76329b246 908 if ( ucMaxRepeat && ( ucRepeat > ucMaxRepeat ) )
monpjc 0:1be76329b246 909 {
monpjc 0:1be76329b246 910 iErrorCode = XSVF_ERROR_MAXRETRIES;
monpjc 0:1be76329b246 911 }
monpjc 0:1be76329b246 912 else
monpjc 0:1be76329b246 913 {
monpjc 0:1be76329b246 914 iErrorCode = XSVF_ERROR_TDOMISMATCH;
monpjc 0:1be76329b246 915 }
monpjc 0:1be76329b246 916 }
monpjc 0:1be76329b246 917
monpjc 0:1be76329b246 918 return( iErrorCode );
monpjc 0:1be76329b246 919 }
monpjc 0:1be76329b246 920
monpjc 0:1be76329b246 921 /*****************************************************************************
monpjc 0:1be76329b246 922 * Function: xsvfBasicXSDRTDO
monpjc 0:1be76329b246 923 * Description: Get the XSDRTDO parameters and execute the XSDRTDO command.
monpjc 0:1be76329b246 924 * This is the common function for all XSDRTDO commands.
monpjc 0:1be76329b246 925 * Parameters: pucTapState - Current TAP state.
monpjc 0:1be76329b246 926 * lShiftLengthBits - number of bits to shift.
monpjc 0:1be76329b246 927 * sShiftLengthBytes - number of bytes to read.
monpjc 0:1be76329b246 928 * plvTdi - ptr to lenval for TDI data.
monpjc 0:1be76329b246 929 * lvTdoCaptured - ptr to lenval for storing TDO data.
monpjc 0:1be76329b246 930 * iEndState - state in which to end the shift.
monpjc 0:1be76329b246 931 * lRunTestTime - amount of time to wait after the shift.
monpjc 0:1be76329b246 932 * ucMaxRepeat - maximum xc9500/xl retries.
monpjc 0:1be76329b246 933 * Returns: int - 0 = success; otherwise TDO mismatch.
monpjc 0:1be76329b246 934 *****************************************************************************/
monpjc 0:1be76329b246 935 int xsvfBasicXSDRTDO( unsigned char* pucTapState,
monpjc 0:1be76329b246 936 long lShiftLengthBits,
monpjc 0:1be76329b246 937 short sShiftLengthBytes,
monpjc 0:1be76329b246 938 lenVal* plvTdi,
monpjc 0:1be76329b246 939 lenVal* plvTdoCaptured,
monpjc 0:1be76329b246 940 lenVal* plvTdoExpected,
monpjc 0:1be76329b246 941 lenVal* plvTdoMask,
monpjc 0:1be76329b246 942 unsigned char ucEndState,
monpjc 0:1be76329b246 943 long lRunTestTime,
monpjc 0:1be76329b246 944 unsigned char ucMaxRepeat )
monpjc 0:1be76329b246 945 {
monpjc 0:1be76329b246 946 readVal( plvTdi, sShiftLengthBytes );
monpjc 0:1be76329b246 947 if ( plvTdoExpected )
monpjc 0:1be76329b246 948 {
monpjc 0:1be76329b246 949 readVal( plvTdoExpected, sShiftLengthBytes );
monpjc 0:1be76329b246 950 }
monpjc 0:1be76329b246 951 return( xsvfShift( pucTapState, XTAPSTATE_SHIFTDR, lShiftLengthBits,
monpjc 0:1be76329b246 952 plvTdi, plvTdoCaptured, plvTdoExpected, plvTdoMask,
monpjc 0:1be76329b246 953 ucEndState, lRunTestTime, ucMaxRepeat ) );
monpjc 0:1be76329b246 954 }
monpjc 0:1be76329b246 955
monpjc 0:1be76329b246 956 /*****************************************************************************
monpjc 0:1be76329b246 957 * Function: xsvfDoSDRMasking
monpjc 0:1be76329b246 958 * Description: Update the data value with the next XSDRINC data and address.
monpjc 0:1be76329b246 959 * Example: dataVal=0x01ff, nextData=0xab, addressMask=0x0100,
monpjc 0:1be76329b246 960 * dataMask=0x00ff, should set dataVal to 0x02ab
monpjc 0:1be76329b246 961 * Parameters: plvTdi - The current TDI value.
monpjc 0:1be76329b246 962 * plvNextData - the next data value.
monpjc 0:1be76329b246 963 * plvAddressMask - the address mask.
monpjc 0:1be76329b246 964 * plvDataMask - the data mask.
monpjc 0:1be76329b246 965 * Returns: void.
monpjc 0:1be76329b246 966 *****************************************************************************/
monpjc 0:1be76329b246 967 #ifdef XSVF_SUPPORT_COMPRESSION
monpjc 0:1be76329b246 968 void xsvfDoSDRMasking( lenVal* plvTdi,
monpjc 0:1be76329b246 969 lenVal* plvNextData,
monpjc 0:1be76329b246 970 lenVal* plvAddressMask,
monpjc 0:1be76329b246 971 lenVal* plvDataMask )
monpjc 0:1be76329b246 972 {
monpjc 0:1be76329b246 973 int i;
monpjc 0:1be76329b246 974 unsigned char ucTdi;
monpjc 0:1be76329b246 975 unsigned char ucTdiMask;
monpjc 0:1be76329b246 976 unsigned char ucDataMask;
monpjc 0:1be76329b246 977 unsigned char ucNextData;
monpjc 0:1be76329b246 978 unsigned char ucNextMask;
monpjc 0:1be76329b246 979 short sNextData;
monpjc 0:1be76329b246 980
monpjc 0:1be76329b246 981 /* add the address Mask to dataVal and return as a new dataVal */
monpjc 0:1be76329b246 982 addVal( plvTdi, plvTdi, plvAddressMask );
monpjc 0:1be76329b246 983
monpjc 0:1be76329b246 984 ucNextData = 0;
monpjc 0:1be76329b246 985 ucNextMask = 0;
monpjc 0:1be76329b246 986 sNextData = plvNextData->len;
monpjc 0:1be76329b246 987 for ( i = plvDataMask->len - 1; i >= 0; --i )
monpjc 0:1be76329b246 988 {
monpjc 0:1be76329b246 989 /* Go through data mask in reverse order looking for mask (1) bits */
monpjc 0:1be76329b246 990 ucDataMask = plvDataMask->val[ i ];
monpjc 0:1be76329b246 991 if ( ucDataMask )
monpjc 0:1be76329b246 992 {
monpjc 0:1be76329b246 993 /* Retrieve the corresponding TDI byte value */
monpjc 0:1be76329b246 994 ucTdi = plvTdi->val[ i ];
monpjc 0:1be76329b246 995
monpjc 0:1be76329b246 996 /* For each bit in the data mask byte, look for 1's */
monpjc 0:1be76329b246 997 ucTdiMask = 1;
monpjc 0:1be76329b246 998 while ( ucDataMask )
monpjc 0:1be76329b246 999 {
monpjc 0:1be76329b246 1000 if ( ucDataMask & 1 )
monpjc 0:1be76329b246 1001 {
monpjc 0:1be76329b246 1002 if ( !ucNextMask )
monpjc 0:1be76329b246 1003 {
monpjc 0:1be76329b246 1004 /* Get the next data byte */
monpjc 0:1be76329b246 1005 ucNextData = plvNextData->val[ --sNextData ];
monpjc 0:1be76329b246 1006 ucNextMask = 1;
monpjc 0:1be76329b246 1007 }
monpjc 0:1be76329b246 1008
monpjc 0:1be76329b246 1009 /* Set or clear the data bit according to the next data */
monpjc 0:1be76329b246 1010 if ( ucNextData & ucNextMask )
monpjc 0:1be76329b246 1011 {
monpjc 0:1be76329b246 1012 ucTdi |= ucTdiMask; /* Set bit */
monpjc 0:1be76329b246 1013 }
monpjc 0:1be76329b246 1014 else
monpjc 0:1be76329b246 1015 {
monpjc 0:1be76329b246 1016 ucTdi &= ( ~ucTdiMask ); /* Clear bit */
monpjc 0:1be76329b246 1017 }
monpjc 0:1be76329b246 1018
monpjc 0:1be76329b246 1019 /* Update the next data */
monpjc 0:1be76329b246 1020 ucNextMask <<= 1;
monpjc 0:1be76329b246 1021 }
monpjc 0:1be76329b246 1022 ucTdiMask <<= 1;
monpjc 0:1be76329b246 1023 ucDataMask >>= 1;
monpjc 0:1be76329b246 1024 }
monpjc 0:1be76329b246 1025
monpjc 0:1be76329b246 1026 /* Update the TDI value */
monpjc 0:1be76329b246 1027 plvTdi->val[ i ] = ucTdi;
monpjc 0:1be76329b246 1028 }
monpjc 0:1be76329b246 1029 }
monpjc 0:1be76329b246 1030 }
monpjc 0:1be76329b246 1031 #endif /* XSVF_SUPPORT_COMPRESSION */
monpjc 0:1be76329b246 1032
monpjc 0:1be76329b246 1033 /*============================================================================
monpjc 0:1be76329b246 1034 * XSVF Command Functions (type = TXsvfDoCmdFuncPtr)
monpjc 0:1be76329b246 1035 * These functions update pXsvfInfo->iErrorCode only on an error.
monpjc 0:1be76329b246 1036 * Otherwise, the error code is left alone.
monpjc 0:1be76329b246 1037 * The function returns the error code from the function.
monpjc 0:1be76329b246 1038 ============================================================================*/
monpjc 0:1be76329b246 1039
monpjc 0:1be76329b246 1040 /*****************************************************************************
monpjc 0:1be76329b246 1041 * Function: xsvfDoIllegalCmd
monpjc 0:1be76329b246 1042 * Description: Function place holder for illegal/unsupported commands.
monpjc 0:1be76329b246 1043 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1044 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1045 *****************************************************************************/
monpjc 0:1be76329b246 1046 int xsvfDoIllegalCmd( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1047 {
monpjc 0:1be76329b246 1048 XSVFDBG_PRINTF2( 0, "ERROR: Encountered unsupported command #%d (%s)\n",
monpjc 0:1be76329b246 1049 ((unsigned int)(pXsvfInfo->ucCommand)),
monpjc 0:1be76329b246 1050 ((pXsvfInfo->ucCommand < XLASTCMD)
monpjc 0:1be76329b246 1051 ? (xsvf_pzCommandName[pXsvfInfo->ucCommand])
monpjc 0:1be76329b246 1052 : "Unknown") );
monpjc 0:1be76329b246 1053 pXsvfInfo->iErrorCode = XSVF_ERROR_ILLEGALCMD;
monpjc 0:1be76329b246 1054 return( pXsvfInfo->iErrorCode );
monpjc 0:1be76329b246 1055 }
monpjc 0:1be76329b246 1056
monpjc 0:1be76329b246 1057 /*****************************************************************************
monpjc 0:1be76329b246 1058 * Function: xsvfDoXCOMPLETE
monpjc 0:1be76329b246 1059 * Description: XCOMPLETE (no parameters)
monpjc 0:1be76329b246 1060 * Update complete status for XSVF player.
monpjc 0:1be76329b246 1061 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1062 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1063 *****************************************************************************/
monpjc 0:1be76329b246 1064 int xsvfDoXCOMPLETE( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1065 {
monpjc 0:1be76329b246 1066 pXsvfInfo->ucComplete = 1;
monpjc 0:1be76329b246 1067 return( XSVF_ERROR_NONE );
monpjc 0:1be76329b246 1068 }
monpjc 0:1be76329b246 1069
monpjc 0:1be76329b246 1070 /*****************************************************************************
monpjc 0:1be76329b246 1071 * Function: xsvfDoXTDOMASK
monpjc 0:1be76329b246 1072 * Description: XTDOMASK <lenVal.TdoMask[XSDRSIZE]>
monpjc 0:1be76329b246 1073 * Prespecify the TDO compare mask.
monpjc 0:1be76329b246 1074 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1075 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1076 *****************************************************************************/
monpjc 0:1be76329b246 1077 int xsvfDoXTDOMASK( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1078 {
monpjc 0:1be76329b246 1079 readVal( &(pXsvfInfo->lvTdoMask), pXsvfInfo->sShiftLengthBytes );
monpjc 0:1be76329b246 1080 XSVFDBG_PRINTF( 4, " TDO Mask = ");
monpjc 0:1be76329b246 1081 XSVFDBG_PRINTLENVAL( 4, &(pXsvfInfo->lvTdoMask) );
monpjc 0:1be76329b246 1082 XSVFDBG_PRINTF( 4, "\n");
monpjc 0:1be76329b246 1083 return( XSVF_ERROR_NONE );
monpjc 0:1be76329b246 1084 }
monpjc 0:1be76329b246 1085
monpjc 0:1be76329b246 1086 /*****************************************************************************
monpjc 0:1be76329b246 1087 * Function: xsvfDoXSIR
monpjc 0:1be76329b246 1088 * Description: XSIR <(byte)shiftlen> <lenVal.TDI[shiftlen]>
monpjc 0:1be76329b246 1089 * Get the instruction and shift the instruction into the TAP.
monpjc 0:1be76329b246 1090 * If prespecified XRUNTEST!=0, goto RUNTEST and wait after
monpjc 0:1be76329b246 1091 * the shift for XRUNTEST usec.
monpjc 0:1be76329b246 1092 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1093 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1094 *****************************************************************************/
monpjc 0:1be76329b246 1095 int xsvfDoXSIR( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1096 {
monpjc 0:1be76329b246 1097 unsigned char ucShiftIrBits;
monpjc 0:1be76329b246 1098 short sShiftIrBytes;
monpjc 0:1be76329b246 1099 int iErrorCode;
monpjc 0:1be76329b246 1100
monpjc 0:1be76329b246 1101 /* Get the shift length and store */
monpjc 0:1be76329b246 1102 readByte( &ucShiftIrBits );
monpjc 0:1be76329b246 1103 sShiftIrBytes = xsvfGetAsNumBytes( ucShiftIrBits );
monpjc 0:1be76329b246 1104 XSVFDBG_PRINTF1( 3, " XSIR length = %d\n",
monpjc 0:1be76329b246 1105 ((unsigned int)ucShiftIrBits) );
monpjc 0:1be76329b246 1106
monpjc 0:1be76329b246 1107 if ( sShiftIrBytes > MAX_LEN )
monpjc 0:1be76329b246 1108 {
monpjc 0:1be76329b246 1109 iErrorCode = XSVF_ERROR_DATAOVERFLOW;
monpjc 0:1be76329b246 1110 }
monpjc 0:1be76329b246 1111 else
monpjc 0:1be76329b246 1112 {
monpjc 0:1be76329b246 1113 /* Get and store instruction to shift in */
monpjc 0:1be76329b246 1114 readVal( &(pXsvfInfo->lvTdi), xsvfGetAsNumBytes( ucShiftIrBits ) );
monpjc 0:1be76329b246 1115
monpjc 0:1be76329b246 1116 /* Shift the data */
monpjc 0:1be76329b246 1117 iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState), XTAPSTATE_SHIFTIR,
monpjc 0:1be76329b246 1118 ucShiftIrBits, &(pXsvfInfo->lvTdi),
monpjc 0:1be76329b246 1119 /*plvTdoCaptured*/0, /*plvTdoExpected*/0,
monpjc 0:1be76329b246 1120 /*plvTdoMask*/0, pXsvfInfo->ucEndIR,
monpjc 0:1be76329b246 1121 pXsvfInfo->lRunTestTime, /*ucMaxRepeat*/0 );
monpjc 0:1be76329b246 1122 }
monpjc 0:1be76329b246 1123
monpjc 0:1be76329b246 1124 if ( iErrorCode != XSVF_ERROR_NONE )
monpjc 0:1be76329b246 1125 {
monpjc 0:1be76329b246 1126 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1127 }
monpjc 0:1be76329b246 1128 return( iErrorCode );
monpjc 0:1be76329b246 1129 }
monpjc 0:1be76329b246 1130
monpjc 0:1be76329b246 1131 /*****************************************************************************
monpjc 0:1be76329b246 1132 * Function: xsvfDoXSIR2
monpjc 0:1be76329b246 1133 * Description: XSIR <(2-byte)shiftlen> <lenVal.TDI[shiftlen]>
monpjc 0:1be76329b246 1134 * Get the instruction and shift the instruction into the TAP.
monpjc 0:1be76329b246 1135 * If prespecified XRUNTEST!=0, goto RUNTEST and wait after
monpjc 0:1be76329b246 1136 * the shift for XRUNTEST usec.
monpjc 0:1be76329b246 1137 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1138 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1139 *****************************************************************************/
monpjc 0:1be76329b246 1140 int xsvfDoXSIR2( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1141 {
monpjc 0:1be76329b246 1142 long lShiftIrBits;
monpjc 0:1be76329b246 1143 short sShiftIrBytes;
monpjc 0:1be76329b246 1144 int iErrorCode;
monpjc 0:1be76329b246 1145
monpjc 0:1be76329b246 1146 /* Get the shift length and store */
monpjc 0:1be76329b246 1147 readVal( &(pXsvfInfo->lvTdi), 2 );
monpjc 0:1be76329b246 1148 lShiftIrBits = value( &(pXsvfInfo->lvTdi) );
monpjc 0:1be76329b246 1149 sShiftIrBytes = xsvfGetAsNumBytes( lShiftIrBits );
monpjc 0:1be76329b246 1150 XSVFDBG_PRINTF1( 3, " XSIR2 length = %d\n", lShiftIrBits);
monpjc 0:1be76329b246 1151
monpjc 0:1be76329b246 1152 if ( sShiftIrBytes > MAX_LEN )
monpjc 0:1be76329b246 1153 {
monpjc 0:1be76329b246 1154 iErrorCode = XSVF_ERROR_DATAOVERFLOW;
monpjc 0:1be76329b246 1155 }
monpjc 0:1be76329b246 1156 else
monpjc 0:1be76329b246 1157 {
monpjc 0:1be76329b246 1158 /* Get and store instruction to shift in */
monpjc 0:1be76329b246 1159 readVal( &(pXsvfInfo->lvTdi), xsvfGetAsNumBytes( lShiftIrBits ) );
monpjc 0:1be76329b246 1160
monpjc 0:1be76329b246 1161 /* Shift the data */
monpjc 0:1be76329b246 1162 iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState), XTAPSTATE_SHIFTIR,
monpjc 0:1be76329b246 1163 lShiftIrBits, &(pXsvfInfo->lvTdi),
monpjc 0:1be76329b246 1164 /*plvTdoCaptured*/0, /*plvTdoExpected*/0,
monpjc 0:1be76329b246 1165 /*plvTdoMask*/0, pXsvfInfo->ucEndIR,
monpjc 0:1be76329b246 1166 pXsvfInfo->lRunTestTime, /*ucMaxRepeat*/0 );
monpjc 0:1be76329b246 1167 }
monpjc 0:1be76329b246 1168
monpjc 0:1be76329b246 1169 if ( iErrorCode != XSVF_ERROR_NONE )
monpjc 0:1be76329b246 1170 {
monpjc 0:1be76329b246 1171 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1172 }
monpjc 0:1be76329b246 1173 return( iErrorCode );
monpjc 0:1be76329b246 1174 }
monpjc 0:1be76329b246 1175
monpjc 0:1be76329b246 1176 /*****************************************************************************
monpjc 0:1be76329b246 1177 * Function: xsvfDoXSDR
monpjc 0:1be76329b246 1178 * Description: XSDR <lenVal.TDI[XSDRSIZE]>
monpjc 0:1be76329b246 1179 * Shift the given TDI data into the JTAG scan chain.
monpjc 0:1be76329b246 1180 * Compare the captured TDO with the expected TDO from the
monpjc 0:1be76329b246 1181 * previous XSDRTDO command using the previously specified
monpjc 0:1be76329b246 1182 * XTDOMASK.
monpjc 0:1be76329b246 1183 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1184 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1185 *****************************************************************************/
monpjc 0:1be76329b246 1186 int xsvfDoXSDR( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1187 {
monpjc 0:1be76329b246 1188 int iErrorCode;
monpjc 0:1be76329b246 1189 readVal( &(pXsvfInfo->lvTdi), pXsvfInfo->sShiftLengthBytes );
monpjc 0:1be76329b246 1190 /* use TDOExpected from last XSDRTDO instruction */
monpjc 0:1be76329b246 1191 iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState), XTAPSTATE_SHIFTDR,
monpjc 0:1be76329b246 1192 pXsvfInfo->lShiftLengthBits, &(pXsvfInfo->lvTdi),
monpjc 0:1be76329b246 1193 &(pXsvfInfo->lvTdoCaptured),
monpjc 0:1be76329b246 1194 &(pXsvfInfo->lvTdoExpected),
monpjc 0:1be76329b246 1195 &(pXsvfInfo->lvTdoMask), pXsvfInfo->ucEndDR,
monpjc 0:1be76329b246 1196 pXsvfInfo->lRunTestTime, pXsvfInfo->ucMaxRepeat );
monpjc 0:1be76329b246 1197 if ( iErrorCode != XSVF_ERROR_NONE )
monpjc 0:1be76329b246 1198 {
monpjc 0:1be76329b246 1199 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1200 }
monpjc 0:1be76329b246 1201 return( iErrorCode );
monpjc 0:1be76329b246 1202 }
monpjc 0:1be76329b246 1203
monpjc 0:1be76329b246 1204 /*****************************************************************************
monpjc 0:1be76329b246 1205 * Function: xsvfDoXRUNTEST
monpjc 0:1be76329b246 1206 * Description: XRUNTEST <uint32>
monpjc 0:1be76329b246 1207 * Prespecify the XRUNTEST wait time for shift operations.
monpjc 0:1be76329b246 1208 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1209 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1210 *****************************************************************************/
monpjc 0:1be76329b246 1211 int xsvfDoXRUNTEST( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1212 {
monpjc 0:1be76329b246 1213 readVal( &(pXsvfInfo->lvTdi), 4 );
monpjc 0:1be76329b246 1214 pXsvfInfo->lRunTestTime = value( &(pXsvfInfo->lvTdi) );
monpjc 0:1be76329b246 1215 XSVFDBG_PRINTF1( 3, " XRUNTEST = %ld\n", pXsvfInfo->lRunTestTime );
monpjc 0:1be76329b246 1216 return( XSVF_ERROR_NONE );
monpjc 0:1be76329b246 1217 }
monpjc 0:1be76329b246 1218
monpjc 0:1be76329b246 1219 /*****************************************************************************
monpjc 0:1be76329b246 1220 * Function: xsvfDoXREPEAT
monpjc 0:1be76329b246 1221 * Description: XREPEAT <byte>
monpjc 0:1be76329b246 1222 * Prespecify the maximum number of XC9500/XL retries.
monpjc 0:1be76329b246 1223 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1224 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1225 *****************************************************************************/
monpjc 0:1be76329b246 1226 int xsvfDoXREPEAT( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1227 {
monpjc 0:1be76329b246 1228 readByte( &(pXsvfInfo->ucMaxRepeat) );
monpjc 0:1be76329b246 1229 XSVFDBG_PRINTF1( 3, " XREPEAT = %d\n",
monpjc 0:1be76329b246 1230 ((unsigned int)(pXsvfInfo->ucMaxRepeat)) );
monpjc 0:1be76329b246 1231 return( XSVF_ERROR_NONE );
monpjc 0:1be76329b246 1232 }
monpjc 0:1be76329b246 1233
monpjc 0:1be76329b246 1234 /*****************************************************************************
monpjc 0:1be76329b246 1235 * Function: xsvfDoXSDRSIZE
monpjc 0:1be76329b246 1236 * Description: XSDRSIZE <uint32>
monpjc 0:1be76329b246 1237 * Prespecify the XRUNTEST wait time for shift operations.
monpjc 0:1be76329b246 1238 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1239 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1240 *****************************************************************************/
monpjc 0:1be76329b246 1241 int xsvfDoXSDRSIZE( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1242 {
monpjc 0:1be76329b246 1243 int iErrorCode;
monpjc 0:1be76329b246 1244 iErrorCode = XSVF_ERROR_NONE;
monpjc 0:1be76329b246 1245 readVal( &(pXsvfInfo->lvTdi), 4 );
monpjc 0:1be76329b246 1246 pXsvfInfo->lShiftLengthBits = value( &(pXsvfInfo->lvTdi) );
monpjc 0:1be76329b246 1247 pXsvfInfo->sShiftLengthBytes= xsvfGetAsNumBytes( pXsvfInfo->lShiftLengthBits );
monpjc 0:1be76329b246 1248 XSVFDBG_PRINTF1( 3, " XSDRSIZE = %ld\n", pXsvfInfo->lShiftLengthBits );
monpjc 0:1be76329b246 1249 if ( pXsvfInfo->sShiftLengthBytes > MAX_LEN )
monpjc 0:1be76329b246 1250 {
monpjc 0:1be76329b246 1251 iErrorCode = XSVF_ERROR_DATAOVERFLOW;
monpjc 0:1be76329b246 1252 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1253 }
monpjc 0:1be76329b246 1254 return( iErrorCode );
monpjc 0:1be76329b246 1255 }
monpjc 0:1be76329b246 1256
monpjc 0:1be76329b246 1257 /*****************************************************************************
monpjc 0:1be76329b246 1258 * Function: xsvfDoXSDRTDO
monpjc 0:1be76329b246 1259 * Description: XSDRTDO <lenVal.TDI[XSDRSIZE]> <lenVal.TDO[XSDRSIZE]>
monpjc 0:1be76329b246 1260 * Get the TDI and expected TDO values. Then, shift.
monpjc 0:1be76329b246 1261 * Compare the expected TDO with the captured TDO using the
monpjc 0:1be76329b246 1262 * prespecified XTDOMASK.
monpjc 0:1be76329b246 1263 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1264 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1265 *****************************************************************************/
monpjc 0:1be76329b246 1266 int xsvfDoXSDRTDO( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1267 {
monpjc 0:1be76329b246 1268 int iErrorCode;
monpjc 0:1be76329b246 1269 iErrorCode = xsvfBasicXSDRTDO( &(pXsvfInfo->ucTapState),
monpjc 0:1be76329b246 1270 pXsvfInfo->lShiftLengthBits,
monpjc 0:1be76329b246 1271 pXsvfInfo->sShiftLengthBytes,
monpjc 0:1be76329b246 1272 &(pXsvfInfo->lvTdi),
monpjc 0:1be76329b246 1273 &(pXsvfInfo->lvTdoCaptured),
monpjc 0:1be76329b246 1274 &(pXsvfInfo->lvTdoExpected),
monpjc 0:1be76329b246 1275 &(pXsvfInfo->lvTdoMask),
monpjc 0:1be76329b246 1276 pXsvfInfo->ucEndDR,
monpjc 0:1be76329b246 1277 pXsvfInfo->lRunTestTime,
monpjc 0:1be76329b246 1278 pXsvfInfo->ucMaxRepeat );
monpjc 0:1be76329b246 1279 if ( iErrorCode != XSVF_ERROR_NONE )
monpjc 0:1be76329b246 1280 {
monpjc 0:1be76329b246 1281 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1282 }
monpjc 0:1be76329b246 1283 return( iErrorCode );
monpjc 0:1be76329b246 1284 }
monpjc 0:1be76329b246 1285
monpjc 0:1be76329b246 1286 /*****************************************************************************
monpjc 0:1be76329b246 1287 * Function: xsvfDoXSETSDRMASKS
monpjc 0:1be76329b246 1288 * Description: XSETSDRMASKS <lenVal.AddressMask[XSDRSIZE]>
monpjc 0:1be76329b246 1289 * <lenVal.DataMask[XSDRSIZE]>
monpjc 0:1be76329b246 1290 * Get the prespecified address and data mask for the XSDRINC
monpjc 0:1be76329b246 1291 * command.
monpjc 0:1be76329b246 1292 * Used for xc9500/xl compressed XSVF data.
monpjc 0:1be76329b246 1293 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1294 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1295 *****************************************************************************/
monpjc 0:1be76329b246 1296 #ifdef XSVF_SUPPORT_COMPRESSION
monpjc 0:1be76329b246 1297 int xsvfDoXSETSDRMASKS( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1298 {
monpjc 0:1be76329b246 1299 /* read the addressMask */
monpjc 0:1be76329b246 1300 readVal( &(pXsvfInfo->lvAddressMask), pXsvfInfo->sShiftLengthBytes );
monpjc 0:1be76329b246 1301 /* read the dataMask */
monpjc 0:1be76329b246 1302 readVal( &(pXsvfInfo->lvDataMask), pXsvfInfo->sShiftLengthBytes );
monpjc 0:1be76329b246 1303
monpjc 0:1be76329b246 1304 XSVFDBG_PRINTF( 4, " Address Mask = " );
monpjc 0:1be76329b246 1305 XSVFDBG_PRINTLENVAL( 4, &(pXsvfInfo->lvAddressMask) );
monpjc 0:1be76329b246 1306 XSVFDBG_PRINTF( 4, "\n" );
monpjc 0:1be76329b246 1307 XSVFDBG_PRINTF( 4, " Data Mask = " );
monpjc 0:1be76329b246 1308 XSVFDBG_PRINTLENVAL( 4, &(pXsvfInfo->lvDataMask) );
monpjc 0:1be76329b246 1309 XSVFDBG_PRINTF( 4, "\n" );
monpjc 0:1be76329b246 1310
monpjc 0:1be76329b246 1311 return( XSVF_ERROR_NONE );
monpjc 0:1be76329b246 1312 }
monpjc 0:1be76329b246 1313 #endif /* XSVF_SUPPORT_COMPRESSION */
monpjc 0:1be76329b246 1314
monpjc 0:1be76329b246 1315 /*****************************************************************************
monpjc 0:1be76329b246 1316 * Function: xsvfDoXSDRINC
monpjc 0:1be76329b246 1317 * Description: XSDRINC <lenVal.firstTDI[XSDRSIZE]> <byte(numTimes)>
monpjc 0:1be76329b246 1318 * <lenVal.data[XSETSDRMASKS.dataMask.len]> ...
monpjc 0:1be76329b246 1319 * Get the XSDRINC parameters and execute the XSDRINC command.
monpjc 0:1be76329b246 1320 * XSDRINC starts by loading the first TDI shift value.
monpjc 0:1be76329b246 1321 * Then, for numTimes, XSDRINC gets the next piece of data,
monpjc 0:1be76329b246 1322 * replaces the bits from the starting TDI as defined by the
monpjc 0:1be76329b246 1323 * XSETSDRMASKS.dataMask, adds the address mask from
monpjc 0:1be76329b246 1324 * XSETSDRMASKS.addressMask, shifts the new TDI value,
monpjc 0:1be76329b246 1325 * and compares the TDO to the expected TDO from the previous
monpjc 0:1be76329b246 1326 * XSDRTDO command using the XTDOMASK.
monpjc 0:1be76329b246 1327 * Used for xc9500/xl compressed XSVF data.
monpjc 0:1be76329b246 1328 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1329 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1330 *****************************************************************************/
monpjc 0:1be76329b246 1331 #ifdef XSVF_SUPPORT_COMPRESSION
monpjc 0:1be76329b246 1332 int xsvfDoXSDRINC( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1333 {
monpjc 0:1be76329b246 1334 int iErrorCode;
monpjc 0:1be76329b246 1335 int iDataMaskLen;
monpjc 0:1be76329b246 1336 unsigned char ucDataMask;
monpjc 0:1be76329b246 1337 unsigned char ucNumTimes;
monpjc 0:1be76329b246 1338 unsigned char i;
monpjc 0:1be76329b246 1339
monpjc 0:1be76329b246 1340 readVal( &(pXsvfInfo->lvTdi), pXsvfInfo->sShiftLengthBytes );
monpjc 0:1be76329b246 1341 iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState), XTAPSTATE_SHIFTDR,
monpjc 0:1be76329b246 1342 pXsvfInfo->lShiftLengthBits,
monpjc 0:1be76329b246 1343 &(pXsvfInfo->lvTdi), &(pXsvfInfo->lvTdoCaptured),
monpjc 0:1be76329b246 1344 &(pXsvfInfo->lvTdoExpected),
monpjc 0:1be76329b246 1345 &(pXsvfInfo->lvTdoMask), pXsvfInfo->ucEndDR,
monpjc 0:1be76329b246 1346 pXsvfInfo->lRunTestTime, pXsvfInfo->ucMaxRepeat );
monpjc 0:1be76329b246 1347 if ( !iErrorCode )
monpjc 0:1be76329b246 1348 {
monpjc 0:1be76329b246 1349 /* Calculate number of data mask bits */
monpjc 0:1be76329b246 1350 iDataMaskLen = 0;
monpjc 0:1be76329b246 1351 for ( i = 0; i < pXsvfInfo->lvDataMask.len; ++i )
monpjc 0:1be76329b246 1352 {
monpjc 0:1be76329b246 1353 ucDataMask = pXsvfInfo->lvDataMask.val[ i ];
monpjc 0:1be76329b246 1354 while ( ucDataMask )
monpjc 0:1be76329b246 1355 {
monpjc 0:1be76329b246 1356 iDataMaskLen += ( ucDataMask & 1 );
monpjc 0:1be76329b246 1357 ucDataMask >>= 1;
monpjc 0:1be76329b246 1358 }
monpjc 0:1be76329b246 1359 }
monpjc 0:1be76329b246 1360
monpjc 0:1be76329b246 1361 /* Get the number of data pieces, i.e. number of times to shift */
monpjc 0:1be76329b246 1362 readByte( &ucNumTimes );
monpjc 0:1be76329b246 1363
monpjc 0:1be76329b246 1364 /* For numTimes, get data, fix TDI, and shift */
monpjc 0:1be76329b246 1365 for ( i = 0; !iErrorCode && ( i < ucNumTimes ); ++i )
monpjc 0:1be76329b246 1366 {
monpjc 0:1be76329b246 1367 readVal( &(pXsvfInfo->lvNextData),
monpjc 0:1be76329b246 1368 xsvfGetAsNumBytes( iDataMaskLen ) );
monpjc 0:1be76329b246 1369 xsvfDoSDRMasking( &(pXsvfInfo->lvTdi),
monpjc 0:1be76329b246 1370 &(pXsvfInfo->lvNextData),
monpjc 0:1be76329b246 1371 &(pXsvfInfo->lvAddressMask),
monpjc 0:1be76329b246 1372 &(pXsvfInfo->lvDataMask) );
monpjc 0:1be76329b246 1373 iErrorCode = xsvfShift( &(pXsvfInfo->ucTapState),
monpjc 0:1be76329b246 1374 XTAPSTATE_SHIFTDR,
monpjc 0:1be76329b246 1375 pXsvfInfo->lShiftLengthBits,
monpjc 0:1be76329b246 1376 &(pXsvfInfo->lvTdi),
monpjc 0:1be76329b246 1377 &(pXsvfInfo->lvTdoCaptured),
monpjc 0:1be76329b246 1378 &(pXsvfInfo->lvTdoExpected),
monpjc 0:1be76329b246 1379 &(pXsvfInfo->lvTdoMask),
monpjc 0:1be76329b246 1380 pXsvfInfo->ucEndDR,
monpjc 0:1be76329b246 1381 pXsvfInfo->lRunTestTime,
monpjc 0:1be76329b246 1382 pXsvfInfo->ucMaxRepeat );
monpjc 0:1be76329b246 1383 }
monpjc 0:1be76329b246 1384 }
monpjc 0:1be76329b246 1385 if ( iErrorCode != XSVF_ERROR_NONE )
monpjc 0:1be76329b246 1386 {
monpjc 0:1be76329b246 1387 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1388 }
monpjc 0:1be76329b246 1389 return( iErrorCode );
monpjc 0:1be76329b246 1390 }
monpjc 0:1be76329b246 1391 #endif /* XSVF_SUPPORT_COMPRESSION */
monpjc 0:1be76329b246 1392
monpjc 0:1be76329b246 1393 /*****************************************************************************
monpjc 0:1be76329b246 1394 * Function: xsvfDoXSDRBCE
monpjc 0:1be76329b246 1395 * Description: XSDRB/XSDRC/XSDRE <lenVal.TDI[XSDRSIZE]>
monpjc 0:1be76329b246 1396 * If not already in SHIFTDR, goto SHIFTDR.
monpjc 0:1be76329b246 1397 * Shift the given TDI data into the JTAG scan chain.
monpjc 0:1be76329b246 1398 * Ignore TDO.
monpjc 0:1be76329b246 1399 * If cmd==XSDRE, then goto ENDDR. Otherwise, stay in ShiftDR.
monpjc 0:1be76329b246 1400 * XSDRB, XSDRC, and XSDRE are the same implementation.
monpjc 0:1be76329b246 1401 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1402 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1403 *****************************************************************************/
monpjc 0:1be76329b246 1404 int xsvfDoXSDRBCE( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1405 {
monpjc 0:1be76329b246 1406 unsigned char ucEndDR;
monpjc 0:1be76329b246 1407 int iErrorCode;
monpjc 0:1be76329b246 1408 ucEndDR = (unsigned char)(( pXsvfInfo->ucCommand == XSDRE ) ?
monpjc 0:1be76329b246 1409 pXsvfInfo->ucEndDR : XTAPSTATE_SHIFTDR);
monpjc 0:1be76329b246 1410 iErrorCode = xsvfBasicXSDRTDO( &(pXsvfInfo->ucTapState),
monpjc 0:1be76329b246 1411 pXsvfInfo->lShiftLengthBits,
monpjc 0:1be76329b246 1412 pXsvfInfo->sShiftLengthBytes,
monpjc 0:1be76329b246 1413 &(pXsvfInfo->lvTdi),
monpjc 0:1be76329b246 1414 /*plvTdoCaptured*/0, /*plvTdoExpected*/0,
monpjc 0:1be76329b246 1415 /*plvTdoMask*/0, ucEndDR,
monpjc 0:1be76329b246 1416 /*lRunTestTime*/0, /*ucMaxRepeat*/0 );
monpjc 0:1be76329b246 1417 if ( iErrorCode != XSVF_ERROR_NONE )
monpjc 0:1be76329b246 1418 {
monpjc 0:1be76329b246 1419 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1420 }
monpjc 0:1be76329b246 1421 return( iErrorCode );
monpjc 0:1be76329b246 1422 }
monpjc 0:1be76329b246 1423
monpjc 0:1be76329b246 1424 /*****************************************************************************
monpjc 0:1be76329b246 1425 * Function: xsvfDoXSDRTDOBCE
monpjc 0:1be76329b246 1426 * Description: XSDRB/XSDRC/XSDRE <lenVal.TDI[XSDRSIZE]> <lenVal.TDO[XSDRSIZE]>
monpjc 0:1be76329b246 1427 * If not already in SHIFTDR, goto SHIFTDR.
monpjc 0:1be76329b246 1428 * Shift the given TDI data into the JTAG scan chain.
monpjc 0:1be76329b246 1429 * Compare TDO, but do NOT use XTDOMASK.
monpjc 0:1be76329b246 1430 * If cmd==XSDRTDOE, then goto ENDDR. Otherwise, stay in ShiftDR.
monpjc 0:1be76329b246 1431 * XSDRTDOB, XSDRTDOC, and XSDRTDOE are the same implementation.
monpjc 0:1be76329b246 1432 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1433 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1434 *****************************************************************************/
monpjc 0:1be76329b246 1435 int xsvfDoXSDRTDOBCE( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1436 {
monpjc 0:1be76329b246 1437 unsigned char ucEndDR;
monpjc 0:1be76329b246 1438 int iErrorCode;
monpjc 0:1be76329b246 1439 ucEndDR = (unsigned char)(( pXsvfInfo->ucCommand == XSDRTDOE ) ?
monpjc 0:1be76329b246 1440 pXsvfInfo->ucEndDR : XTAPSTATE_SHIFTDR);
monpjc 0:1be76329b246 1441 iErrorCode = xsvfBasicXSDRTDO( &(pXsvfInfo->ucTapState),
monpjc 0:1be76329b246 1442 pXsvfInfo->lShiftLengthBits,
monpjc 0:1be76329b246 1443 pXsvfInfo->sShiftLengthBytes,
monpjc 0:1be76329b246 1444 &(pXsvfInfo->lvTdi),
monpjc 0:1be76329b246 1445 &(pXsvfInfo->lvTdoCaptured),
monpjc 0:1be76329b246 1446 &(pXsvfInfo->lvTdoExpected),
monpjc 0:1be76329b246 1447 /*plvTdoMask*/0, ucEndDR,
monpjc 0:1be76329b246 1448 /*lRunTestTime*/0, /*ucMaxRepeat*/0 );
monpjc 0:1be76329b246 1449 if ( iErrorCode != XSVF_ERROR_NONE )
monpjc 0:1be76329b246 1450 {
monpjc 0:1be76329b246 1451 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1452 }
monpjc 0:1be76329b246 1453 return( iErrorCode );
monpjc 0:1be76329b246 1454 }
monpjc 0:1be76329b246 1455
monpjc 0:1be76329b246 1456 /*****************************************************************************
monpjc 0:1be76329b246 1457 * Function: xsvfDoXSTATE
monpjc 0:1be76329b246 1458 * Description: XSTATE <byte>
monpjc 0:1be76329b246 1459 * <byte> == XTAPSTATE;
monpjc 0:1be76329b246 1460 * Get the state parameter and transition the TAP to that state.
monpjc 0:1be76329b246 1461 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1462 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1463 *****************************************************************************/
monpjc 0:1be76329b246 1464 int xsvfDoXSTATE( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1465 {
monpjc 0:1be76329b246 1466 unsigned char ucNextState;
monpjc 0:1be76329b246 1467 int iErrorCode;
monpjc 0:1be76329b246 1468 readByte( &ucNextState );
monpjc 0:1be76329b246 1469 iErrorCode = xsvfGotoTapState( &(pXsvfInfo->ucTapState), ucNextState );
monpjc 0:1be76329b246 1470 if ( iErrorCode != XSVF_ERROR_NONE )
monpjc 0:1be76329b246 1471 {
monpjc 0:1be76329b246 1472 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1473 }
monpjc 0:1be76329b246 1474 return( iErrorCode );
monpjc 0:1be76329b246 1475 }
monpjc 0:1be76329b246 1476
monpjc 0:1be76329b246 1477 /*****************************************************************************
monpjc 0:1be76329b246 1478 * Function: xsvfDoXENDXR
monpjc 0:1be76329b246 1479 * Description: XENDIR/XENDDR <byte>
monpjc 0:1be76329b246 1480 * <byte>: 0 = RUNTEST; 1 = PAUSE.
monpjc 0:1be76329b246 1481 * Get the prespecified XENDIR or XENDDR.
monpjc 0:1be76329b246 1482 * Both XENDIR and XENDDR use the same implementation.
monpjc 0:1be76329b246 1483 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1484 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1485 *****************************************************************************/
monpjc 0:1be76329b246 1486 int xsvfDoXENDXR( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1487 {
monpjc 0:1be76329b246 1488 int iErrorCode;
monpjc 0:1be76329b246 1489 unsigned char ucEndState;
monpjc 0:1be76329b246 1490
monpjc 0:1be76329b246 1491 iErrorCode = XSVF_ERROR_NONE;
monpjc 0:1be76329b246 1492 readByte( &ucEndState );
monpjc 0:1be76329b246 1493 if ( ( ucEndState != XENDXR_RUNTEST ) && ( ucEndState != XENDXR_PAUSE ) )
monpjc 0:1be76329b246 1494 {
monpjc 0:1be76329b246 1495 iErrorCode = XSVF_ERROR_ILLEGALSTATE;
monpjc 0:1be76329b246 1496 }
monpjc 0:1be76329b246 1497 else
monpjc 0:1be76329b246 1498 {
monpjc 0:1be76329b246 1499
monpjc 0:1be76329b246 1500 if ( pXsvfInfo->ucCommand == XENDIR )
monpjc 0:1be76329b246 1501 {
monpjc 0:1be76329b246 1502 if ( ucEndState == XENDXR_RUNTEST )
monpjc 0:1be76329b246 1503 {
monpjc 0:1be76329b246 1504 pXsvfInfo->ucEndIR = XTAPSTATE_RUNTEST;
monpjc 0:1be76329b246 1505 }
monpjc 0:1be76329b246 1506 else
monpjc 0:1be76329b246 1507 {
monpjc 0:1be76329b246 1508 pXsvfInfo->ucEndIR = XTAPSTATE_PAUSEIR;
monpjc 0:1be76329b246 1509 }
monpjc 0:1be76329b246 1510 XSVFDBG_PRINTF1( 3, " ENDIR State = %s\n",
monpjc 0:1be76329b246 1511 xsvf_pzTapState[ pXsvfInfo->ucEndIR ] );
monpjc 0:1be76329b246 1512 }
monpjc 0:1be76329b246 1513 else /* XENDDR */
monpjc 0:1be76329b246 1514 {
monpjc 0:1be76329b246 1515 if ( ucEndState == XENDXR_RUNTEST )
monpjc 0:1be76329b246 1516 {
monpjc 0:1be76329b246 1517 pXsvfInfo->ucEndDR = XTAPSTATE_RUNTEST;
monpjc 0:1be76329b246 1518 }
monpjc 0:1be76329b246 1519 else
monpjc 0:1be76329b246 1520 {
monpjc 0:1be76329b246 1521 pXsvfInfo->ucEndDR = XTAPSTATE_PAUSEDR;
monpjc 0:1be76329b246 1522 }
monpjc 0:1be76329b246 1523 XSVFDBG_PRINTF1( 3, " ENDDR State = %s\n",
monpjc 0:1be76329b246 1524 xsvf_pzTapState[ pXsvfInfo->ucEndDR ] );
monpjc 0:1be76329b246 1525 }
monpjc 0:1be76329b246 1526 }
monpjc 0:1be76329b246 1527
monpjc 0:1be76329b246 1528 if ( iErrorCode != XSVF_ERROR_NONE )
monpjc 0:1be76329b246 1529 {
monpjc 0:1be76329b246 1530 pXsvfInfo->iErrorCode = iErrorCode;
monpjc 0:1be76329b246 1531 }
monpjc 0:1be76329b246 1532 return( iErrorCode );
monpjc 0:1be76329b246 1533 }
monpjc 0:1be76329b246 1534
monpjc 0:1be76329b246 1535 /*****************************************************************************
monpjc 0:1be76329b246 1536 * Function: xsvfDoXCOMMENT
monpjc 0:1be76329b246 1537 * Description: XCOMMENT <text string ending in \0>
monpjc 0:1be76329b246 1538 * <text string ending in \0> == text comment;
monpjc 0:1be76329b246 1539 * Arbitrary comment embedded in the XSVF.
monpjc 0:1be76329b246 1540 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1541 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1542 *****************************************************************************/
monpjc 0:1be76329b246 1543 int xsvfDoXCOMMENT( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1544 {
monpjc 0:1be76329b246 1545 /* Use the comment for debugging */
monpjc 0:1be76329b246 1546 /* Otherwise, read through the comment to the end '\0' and ignore */
monpjc 0:1be76329b246 1547 //unsigned char ucText;
monpjc 0:1be76329b246 1548 /*
monpjc 0:1be76329b246 1549 if ( xsvf_iDebugLevel > 0 )
monpjc 0:1be76329b246 1550 {
monpjc 0:1be76329b246 1551 putchar( ' ' );
monpjc 0:1be76329b246 1552 }
monpjc 0:1be76329b246 1553
monpjc 0:1be76329b246 1554 do
monpjc 0:1be76329b246 1555 {
monpjc 0:1be76329b246 1556 readByte( &ucText );
monpjc 0:1be76329b246 1557 if ( xsvf_iDebugLevel > 0 )
monpjc 0:1be76329b246 1558 {
monpjc 0:1be76329b246 1559 putchar( ucText ? ucText : '\n' );
monpjc 0:1be76329b246 1560 }
monpjc 0:1be76329b246 1561 } while ( ucText );
monpjc 0:1be76329b246 1562 */
monpjc 0:1be76329b246 1563 pXsvfInfo->iErrorCode = XSVF_ERROR_NONE;
monpjc 0:1be76329b246 1564
monpjc 0:1be76329b246 1565 return( pXsvfInfo->iErrorCode );
monpjc 0:1be76329b246 1566 }
monpjc 0:1be76329b246 1567
monpjc 0:1be76329b246 1568 /*****************************************************************************
monpjc 0:1be76329b246 1569 * Function: xsvfDoXWAIT
monpjc 0:1be76329b246 1570 * Description: XWAIT <wait_state> <end_state> <wait_time>
monpjc 0:1be76329b246 1571 * If not already in <wait_state>, then go to <wait_state>.
monpjc 0:1be76329b246 1572 * Wait in <wait_state> for <wait_time> microseconds.
monpjc 0:1be76329b246 1573 * Finally, if not already in <end_state>, then goto <end_state>.
monpjc 0:1be76329b246 1574 * Parameters: pXsvfInfo - XSVF information pointer.
monpjc 0:1be76329b246 1575 * Returns: int - 0 = success; non-zero = error.
monpjc 0:1be76329b246 1576 *****************************************************************************/
monpjc 0:1be76329b246 1577 int xsvfDoXWAIT( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1578 {
monpjc 0:1be76329b246 1579 unsigned char ucWaitState;
monpjc 0:1be76329b246 1580 unsigned char ucEndState;
monpjc 0:1be76329b246 1581 long lWaitTime;
monpjc 0:1be76329b246 1582
monpjc 0:1be76329b246 1583 /* Get Parameters */
monpjc 0:1be76329b246 1584 /* <wait_state> */
monpjc 0:1be76329b246 1585 readVal( &(pXsvfInfo->lvTdi), 1 );
monpjc 0:1be76329b246 1586 ucWaitState = pXsvfInfo->lvTdi.val[0];
monpjc 0:1be76329b246 1587
monpjc 0:1be76329b246 1588 /* <end_state> */
monpjc 0:1be76329b246 1589 readVal( &(pXsvfInfo->lvTdi), 1 );
monpjc 0:1be76329b246 1590 ucEndState = pXsvfInfo->lvTdi.val[0];
monpjc 0:1be76329b246 1591
monpjc 0:1be76329b246 1592 /* <wait_time> */
monpjc 0:1be76329b246 1593 readVal( &(pXsvfInfo->lvTdi), 4 );
monpjc 0:1be76329b246 1594 lWaitTime = value( &(pXsvfInfo->lvTdi) );
monpjc 0:1be76329b246 1595 XSVFDBG_PRINTF2( 3, " XWAIT: state = %s; time = %ld\n",
monpjc 0:1be76329b246 1596 xsvf_pzTapState[ ucWaitState ], lWaitTime );
monpjc 0:1be76329b246 1597
monpjc 0:1be76329b246 1598 /* If not already in <wait_state>, go to <wait_state> */
monpjc 0:1be76329b246 1599 if ( pXsvfInfo->ucTapState != ucWaitState )
monpjc 0:1be76329b246 1600 {
monpjc 0:1be76329b246 1601 xsvfGotoTapState( &(pXsvfInfo->ucTapState), ucWaitState );
monpjc 0:1be76329b246 1602 }
monpjc 0:1be76329b246 1603
monpjc 0:1be76329b246 1604 /* Wait for <wait_time> microseconds */
monpjc 0:1be76329b246 1605 waitTime( lWaitTime );
monpjc 0:1be76329b246 1606
monpjc 0:1be76329b246 1607 /* If not already in <end_state>, go to <end_state> */
monpjc 0:1be76329b246 1608 if ( pXsvfInfo->ucTapState != ucEndState )
monpjc 0:1be76329b246 1609 {
monpjc 0:1be76329b246 1610 xsvfGotoTapState( &(pXsvfInfo->ucTapState), ucEndState );
monpjc 0:1be76329b246 1611 }
monpjc 0:1be76329b246 1612
monpjc 0:1be76329b246 1613 return( XSVF_ERROR_NONE );
monpjc 0:1be76329b246 1614 }
monpjc 0:1be76329b246 1615
monpjc 0:1be76329b246 1616
monpjc 0:1be76329b246 1617 /*============================================================================
monpjc 0:1be76329b246 1618 * Execution Control Functions
monpjc 0:1be76329b246 1619 ============================================================================*/
monpjc 0:1be76329b246 1620
monpjc 0:1be76329b246 1621 /*****************************************************************************
monpjc 0:1be76329b246 1622 * Function: xsvfInitialize
monpjc 0:1be76329b246 1623 * Description: Initialize the xsvf player.
monpjc 0:1be76329b246 1624 * Call this before running the player to initialize the data
monpjc 0:1be76329b246 1625 * in the SXsvfInfo struct.
monpjc 0:1be76329b246 1626 * xsvfCleanup is called to clean up the data in SXsvfInfo
monpjc 0:1be76329b246 1627 * after the XSVF is played.
monpjc 0:1be76329b246 1628 * Parameters: pXsvfInfo - ptr to the XSVF information.
monpjc 0:1be76329b246 1629 * Returns: int - 0 = success; otherwise error.
monpjc 0:1be76329b246 1630 *****************************************************************************/
monpjc 0:1be76329b246 1631 int xsvfInitialize( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1632 {
monpjc 0:1be76329b246 1633 /* Initialize values */
monpjc 0:1be76329b246 1634 pXsvfInfo->iErrorCode = xsvfInfoInit( pXsvfInfo );
monpjc 0:1be76329b246 1635
monpjc 0:1be76329b246 1636 if ( !pXsvfInfo->iErrorCode )
monpjc 0:1be76329b246 1637 {
monpjc 0:1be76329b246 1638 /* Initialize the TAPs */
monpjc 0:1be76329b246 1639 pXsvfInfo->iErrorCode = xsvfGotoTapState( &(pXsvfInfo->ucTapState),
monpjc 0:1be76329b246 1640 XTAPSTATE_RESET );
monpjc 0:1be76329b246 1641 }
monpjc 0:1be76329b246 1642
monpjc 0:1be76329b246 1643 return( pXsvfInfo->iErrorCode );
monpjc 0:1be76329b246 1644 }
monpjc 0:1be76329b246 1645
monpjc 0:1be76329b246 1646 /*****************************************************************************
monpjc 0:1be76329b246 1647 * Function: xsvfRun
monpjc 0:1be76329b246 1648 * Description: Run the xsvf player for a single command and return.
monpjc 0:1be76329b246 1649 * First, call xsvfInitialize.
monpjc 0:1be76329b246 1650 * Then, repeatedly call this function until an error is detected
monpjc 0:1be76329b246 1651 * or until the pXsvfInfo->ucComplete variable is non-zero.
monpjc 0:1be76329b246 1652 * Finally, call xsvfCleanup to cleanup any remnants.
monpjc 0:1be76329b246 1653 * Parameters: pXsvfInfo - ptr to the XSVF information.
monpjc 0:1be76329b246 1654 * Returns: int - 0 = success; otherwise error.
monpjc 0:1be76329b246 1655 *****************************************************************************/
monpjc 0:1be76329b246 1656 int xsvfRun( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1657 {
monpjc 0:1be76329b246 1658 /* Process the XSVF commands */
monpjc 0:1be76329b246 1659 if ( (!pXsvfInfo->iErrorCode) && (!pXsvfInfo->ucComplete) )
monpjc 0:1be76329b246 1660 {
monpjc 0:1be76329b246 1661 /* read 1 byte for the instruction */
monpjc 0:1be76329b246 1662 readByte( &(pXsvfInfo->ucCommand) );
monpjc 0:1be76329b246 1663 ++(pXsvfInfo->lCommandCount);
monpjc 0:1be76329b246 1664
monpjc 0:1be76329b246 1665 if ( pXsvfInfo->ucCommand < XLASTCMD )
monpjc 0:1be76329b246 1666 {
monpjc 0:1be76329b246 1667 /* Execute the command. Func sets error code. */
monpjc 0:1be76329b246 1668 XSVFDBG_PRINTF1( 2, " %s\n",
monpjc 0:1be76329b246 1669 xsvf_pzCommandName[pXsvfInfo->ucCommand] );
monpjc 0:1be76329b246 1670 /* If your compiler cannot take this form,
monpjc 0:1be76329b246 1671 then convert to a switch statement */
monpjc 0:1be76329b246 1672 xsvf_pfDoCmd[ pXsvfInfo->ucCommand ]( pXsvfInfo );
monpjc 0:1be76329b246 1673 }
monpjc 0:1be76329b246 1674 else
monpjc 0:1be76329b246 1675 {
monpjc 0:1be76329b246 1676 /* Illegal command value. Func sets error code. */
monpjc 0:1be76329b246 1677 xsvfDoIllegalCmd( pXsvfInfo );
monpjc 0:1be76329b246 1678 }
monpjc 0:1be76329b246 1679 }
monpjc 0:1be76329b246 1680
monpjc 0:1be76329b246 1681 return( pXsvfInfo->iErrorCode );
monpjc 0:1be76329b246 1682 }
monpjc 0:1be76329b246 1683
monpjc 0:1be76329b246 1684 /*****************************************************************************
monpjc 0:1be76329b246 1685 * Function: xsvfCleanup
monpjc 0:1be76329b246 1686 * Description: cleanup remnants of the xsvf player.
monpjc 0:1be76329b246 1687 * Parameters: pXsvfInfo - ptr to the XSVF information.
monpjc 0:1be76329b246 1688 * Returns: void.
monpjc 0:1be76329b246 1689 *****************************************************************************/
monpjc 0:1be76329b246 1690 void xsvfCleanup( SXsvfInfo* pXsvfInfo )
monpjc 0:1be76329b246 1691 {
monpjc 0:1be76329b246 1692 xsvfInfoCleanup( pXsvfInfo );
monpjc 0:1be76329b246 1693 }
monpjc 0:1be76329b246 1694
monpjc 0:1be76329b246 1695
monpjc 0:1be76329b246 1696 /*============================================================================
monpjc 0:1be76329b246 1697 * xsvfExecute() - The primary entry point to the XSVF player
monpjc 0:1be76329b246 1698 ============================================================================*/
monpjc 0:1be76329b246 1699
monpjc 0:1be76329b246 1700 /*****************************************************************************
monpjc 0:1be76329b246 1701 * Function: xsvfExecute
monpjc 0:1be76329b246 1702 * Description: Process, interpret, and apply the XSVF commands.
monpjc 0:1be76329b246 1703 * See port.c:readByte for source of XSVF data.
monpjc 0:1be76329b246 1704 * Parameters: none.
monpjc 0:1be76329b246 1705 * Returns: int - Legacy result values: 1 == success; 0 == failed.
monpjc 0:1be76329b246 1706 *****************************************************************************/
monpjc 0:1be76329b246 1707 int xsvfExecute()
monpjc 0:1be76329b246 1708 {
monpjc 0:1be76329b246 1709 SXsvfInfo xsvfInfo;
monpjc 0:1be76329b246 1710
monpjc 0:1be76329b246 1711 pc.printf("=========================\n");
monpjc 0:1be76329b246 1712
monpjc 0:1be76329b246 1713 xsvfInitialize( &xsvfInfo );
monpjc 0:1be76329b246 1714
monpjc 0:1be76329b246 1715 pc.printf("init complete\n");
monpjc 0:1be76329b246 1716
monpjc 0:1be76329b246 1717 while ( !xsvfInfo.iErrorCode && (!xsvfInfo.ucComplete) )
monpjc 0:1be76329b246 1718 {
monpjc 0:1be76329b246 1719 xsvfRun( &xsvfInfo );
monpjc 0:1be76329b246 1720 pc.printf("loop>\n");
monpjc 0:1be76329b246 1721 }
monpjc 0:1be76329b246 1722
monpjc 0:1be76329b246 1723 if ( xsvfInfo.iErrorCode )
monpjc 0:1be76329b246 1724 {
monpjc 0:1be76329b246 1725 XSVFDBG_PRINTF1( 0, "%s\n", xsvf_pzErrorName[
monpjc 0:1be76329b246 1726 ( xsvfInfo.iErrorCode < XSVF_ERROR_LAST )
monpjc 0:1be76329b246 1727 ? xsvfInfo.iErrorCode : XSVF_ERROR_UNKNOWN ] );
monpjc 0:1be76329b246 1728 XSVFDBG_PRINTF2( 0, "ERROR at or near XSVF command #%ld. See line #%ld in the XSVF ASCII file.\n",
monpjc 0:1be76329b246 1729 xsvfInfo.lCommandCount, xsvfInfo.lCommandCount );
monpjc 0:1be76329b246 1730 }
monpjc 0:1be76329b246 1731 else
monpjc 0:1be76329b246 1732 {
monpjc 0:1be76329b246 1733 XSVFDBG_PRINTF( 0, "SUCCESS - Completed XSVF execution.\n" );
monpjc 0:1be76329b246 1734 }
monpjc 0:1be76329b246 1735
monpjc 0:1be76329b246 1736 xsvfCleanup( &xsvfInfo );
monpjc 0:1be76329b246 1737
monpjc 0:1be76329b246 1738 return( XSVF_ERRORCODE(xsvfInfo.iErrorCode) );
monpjc 0:1be76329b246 1739 }
monpjc 0:1be76329b246 1740
monpjc 0:1be76329b246 1741