micro.c

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

C
1,848
字号
			--lNumBits;
			if ( iExitShift && !lNumBits )
			{
				/* Exit Shift-DR state */
				setPort( TMS, 1 );
			}

			/* Set the new TDI value */
			setPort( TDI, (short)(ucTdiByte & 1) );
			ucTdiByte   >>= 1;

			/* Set TCK low */
			setPort( TCK, 0 );

			if ( pucTdo )
			{
				/* Save the TDO value */
				ucTdoBit    = readTDOBit();
				ucTdoByte   |= ( ucTdoBit << i );
			}

			/* Set TCK high */
			setPort( TCK, 1 );
		}

		/* Save the TDO byte value */
		if ( pucTdo )
		{
			(*(--pucTdo))   = ucTdoByte;
		}
	}
}

/*****************************************************************************
 * Function:     xsvfShift
 * Description:  Goes to the given starting TAP state.
 *               Calls xsvfShiftOnly to shift in the given TDI data and
 *               optionally capture the TDO data.
 *               Compares the TDO captured data against the TDO expected
 *               data.
 *               If a data mismatch occurs, then executes the exception
 *               handling loop upto ucMaxRepeat times.
 * Parameters:   pucTapState     - Ptr to current TAP state.
 *               ucStartState    - Starting shift state: Shift-DR or Shift-IR.
 *               lNumBits        - number of bits to shift.
 *               plvTdi          - ptr to lenval for TDI data.
 *               plvTdoCaptured  - ptr to lenval for storing TDO data.
 *               plvTdoExpected  - ptr to expected TDO data.
 *               plvTdoMask      - ptr to TDO mask.
 *               ucEndState      - state in which to end the shift.
 *               lRunTestTime    - amount of time to wait after the shift.
 *               ucMaxRepeat     - Maximum number of retries on TDO mismatch.
 * Returns:      int             - 0 = success; otherwise TDO mismatch.
 * Notes:        XC9500XL-only Optimization:
 *               Skip the waitTime() if plvTdoMask->val[0:plvTdoMask->len-1]
 *               is NOT all zeros and sMatch==1.
 *****************************************************************************/
int xsvfShift( unsigned char*   pucTapState,
	       unsigned char    ucStartState,
	       long             lNumBits,
	       lenVal*          plvTdi,
	       lenVal*          plvTdoCaptured,
	       lenVal*          plvTdoExpected,
	       lenVal*          plvTdoMask,
	       unsigned char    ucEndState,
	       long             lRunTestTime,
	       unsigned char    ucMaxRepeat )
{
	int             iErrorCode;
	int             iMismatch;
	unsigned char   ucRepeat;
	int             iExitShift;

	iErrorCode  = XSVF_ERROR_NONE;
	iMismatch   = 0;
	ucRepeat    = 0;
	iExitShift  = ( ucStartState != ucEndState );

	XSVFDBG_PRINTF1( 3, "   Shift Length = %ld\n", lNumBits );
	XSVFDBG_PRINTF( 4, "    TDI          = ");
	XSVFDBG_PRINTLENVAL( 4, plvTdi );
	XSVFDBG_PRINTF( 4, "\n");
	XSVFDBG_PRINTF( 4, "    TDO Expected = ");
	XSVFDBG_PRINTLENVAL( 4, plvTdoExpected );
	XSVFDBG_PRINTF( 4, "\n");

	if ( !lNumBits )
	{
		/* Compatibility with XSVF2.00:  XSDR 0 = no shift, but wait in RTI */
		if ( lRunTestTime )
		{
			/* Wait for prespecified XRUNTEST time */
			xsvfGotoTapState( pucTapState, XTAPSTATE_RUNTEST );
			XSVFDBG_PRINTF1( 3, "   Wait = %ld usec\n", lRunTestTime );
			waitTime( lRunTestTime );
		}
	}
	else
	{
		do
		{
			/* Goto Shift-DR or Shift-IR */
			xsvfGotoTapState( pucTapState, ucStartState );

			/* Shift TDI and capture TDO */
			xsvfShiftOnly( lNumBits, plvTdi, plvTdoCaptured, iExitShift );

			if ( plvTdoExpected )
			{
				/* Compare TDO data to expected TDO data */
				iMismatch   = !EqualLenVal( plvTdoExpected,
							    plvTdoCaptured,
							    plvTdoMask );
			}

			if ( iExitShift )
			{
				/* Update TAP state:  Shift->Exit */
				++(*pucTapState);
				XSVFDBG_PRINTF1( 3, "   TAP State = %s\n",
						 xsvf_pzTapState[ *pucTapState ] );

				if ( iMismatch && lRunTestTime && ( ucRepeat < ucMaxRepeat ) )
				{
					XSVFDBG_PRINTF( 4, "    TDO Expected = ");
					XSVFDBG_PRINTLENVAL( 4, plvTdoExpected );
					XSVFDBG_PRINTF( 4, "\n");
					XSVFDBG_PRINTF( 4, "    TDO Captured = ");
					XSVFDBG_PRINTLENVAL( 4, plvTdoCaptured );
					XSVFDBG_PRINTF( 4, "\n");
					XSVFDBG_PRINTF( 4, "    TDO Mask     = ");
					XSVFDBG_PRINTLENVAL( 4, plvTdoMask );
					XSVFDBG_PRINTF( 4, "\n");
					XSVFDBG_PRINTF1( 3, "   Retry #%d\n", ( ucRepeat + 1 ) );
					/* Do exception handling retry - ShiftDR only */
					xsvfGotoTapState( pucTapState, XTAPSTATE_PAUSEDR );
					/* Shift 1 extra bit */
					xsvfGotoTapState( pucTapState, XTAPSTATE_SHIFTDR );
					/* Increment RUNTEST time by an additional 25% */
					lRunTestTime    += ( lRunTestTime >> 2 );
				}
				else
				{
					/* Do normal exit from Shift-XR */
					xsvfGotoTapState( pucTapState, ucEndState );
				}

				if ( lRunTestTime )
				{
					/* Wait for prespecified XRUNTEST time */
					xsvfGotoTapState( pucTapState, XTAPSTATE_RUNTEST );
					XSVFDBG_PRINTF1( 3, "   Wait = %ld usec\n", lRunTestTime );
					waitTime( lRunTestTime );
				}
			}
		} while ( iMismatch && ( ucRepeat++ < ucMaxRepeat ) );
	}

	if ( iMismatch )
	{
		XSVFDBG_PRINTF( 1, " TDO Expected = ");
		XSVFDBG_PRINTLENVAL( 1, plvTdoExpected );
		XSVFDBG_PRINTF( 1, "\n");
		XSVFDBG_PRINTF( 1, " TDO Captured = ");
		XSVFDBG_PRINTLENVAL( 1, plvTdoCaptured );
		XSVFDBG_PRINTF( 1, "\n");
		XSVFDBG_PRINTF( 1, " TDO Mask     = ");
		XSVFDBG_PRINTLENVAL( 1, plvTdoMask );
		XSVFDBG_PRINTF( 1, "\n");
		if ( ucMaxRepeat && ( ucRepeat > ucMaxRepeat ) )
		{
			iErrorCode  = XSVF_ERROR_MAXRETRIES;
		}
		else
		{
			iErrorCode  = XSVF_ERROR_TDOMISMATCH;
		}
	}

	return( iErrorCode );
}

/*****************************************************************************
 * Function:     xsvfBasicXSDRTDO
 * Description:  Get the XSDRTDO parameters and execute the XSDRTDO command.
 *               This is the common function for all XSDRTDO commands.
 * Parameters:   pucTapState         - Current TAP state.
 *               lShiftLengthBits    - number of bits to shift.
 *               sShiftLengthBytes   - number of bytes to read.
 *               plvTdi              - ptr to lenval for TDI data.
 *               lvTdoCaptured       - ptr to lenval for storing TDO data.
 *               iEndState           - state in which to end the shift.
 *               lRunTestTime        - amount of time to wait after the shift.
 *               ucMaxRepeat         - maximum xc9500/xl retries.
 * Returns:      int                 - 0 = success; otherwise TDO mismatch.
 *****************************************************************************/
int xsvfBasicXSDRTDO( unsigned char*    pucTapState,
		      long              lShiftLengthBits,
		      short             sShiftLengthBytes,
		      lenVal*           plvTdi,
		      lenVal*           plvTdoCaptured,
		      lenVal*           plvTdoExpected,
		      lenVal*           plvTdoMask,
		      unsigned char     ucEndState,
		      long              lRunTestTime,
		      unsigned char     ucMaxRepeat )
{
	readVal( plvTdi, sShiftLengthBytes );
	if ( plvTdoExpected )
	{
		readVal( plvTdoExpected, sShiftLengthBytes );
	}
	return( xsvfShift( pucTapState, XTAPSTATE_SHIFTDR, lShiftLengthBits,
			   plvTdi, plvTdoCaptured, plvTdoExpected, plvTdoMask,
			   ucEndState, lRunTestTime, ucMaxRepeat ) );
}

/*****************************************************************************
 * Function:     xsvfDoSDRMasking
 * Description:  Update the data value with the next XSDRINC data and address.
 * Example:      dataVal=0x01ff, nextData=0xab, addressMask=0x0100,
 *               dataMask=0x00ff, should set dataVal to 0x02ab
 * Parameters:   plvTdi          - The current TDI value.
 *               plvNextData     - the next data value.
 *               plvAddressMask  - the address mask.
 *               plvDataMask     - the data mask.
 * Returns:      void.
 *****************************************************************************/
#ifdef  XSVF_SUPPORT_COMPRESSION
void xsvfDoSDRMasking( lenVal*  plvTdi,
		       lenVal*  plvNextData,
		       lenVal*  plvAddressMask,
		       lenVal*  plvDataMask )
{
	int             i;
	unsigned char   ucTdi;
	unsigned char   ucTdiMask;
	unsigned char   ucDataMask;
	unsigned char   ucNextData;
	unsigned char   ucNextMask;
	short           sNextData;

	/* add the address Mask to dataVal and return as a new dataVal */
	addVal( plvTdi, plvTdi, plvAddressMask );

	ucNextData  = 0;
	ucNextMask  = 0;
	sNextData   = plvNextData->len;
	for ( i = plvDataMask->len - 1; i >= 0; --i )
	{
		/* Go through data mask in reverse order looking for mask (1) bits */
		ucDataMask  = plvDataMask->val[ i ];
		if ( ucDataMask )
		{
			/* Retrieve the corresponding TDI byte value */
			ucTdi       = plvTdi->val[ i ];

			/* For each bit in the data mask byte, look for 1's */
			ucTdiMask   = 1;
			while ( ucDataMask )
			{
				if ( ucDataMask & 1 )
				{
					if ( !ucNextMask )
					{
						/* Get the next data byte */
						ucNextData  = plvNextData->val[ --sNextData ];
						ucNextMask  = 1;
					}

					/* Set or clear the data bit according to the next data */
					if ( ucNextData & ucNextMask )
					{
						ucTdi   |= ucTdiMask;       /* Set bit */
					}
					else
					{
						ucTdi   &= ( ~ucTdiMask );  /* Clear bit */
					}

					/* Update the next data */
					ucNextMask  <<= 1;
				}
				ucTdiMask   <<= 1;
				ucDataMask  >>= 1;
			}

			/* Update the TDI value */
			plvTdi->val[ i ]    = ucTdi;
		}
	}
}
#endif  /* XSVF_SUPPORT_COMPRESSION */

/*============================================================================
 * XSVF Command Functions (type = TXsvfDoCmdFuncPtr)
 * These functions update pXsvfInfo->iErrorCode only on an error.
 * Otherwise, the error code is left alone.
 * The function returns the error code from the function.
 ============================================================================*/

/*****************************************************************************
 * Function:     xsvfDoIllegalCmd
 * Description:  Function place holder for illegal/unsupported commands.
 * Parameters:   pXsvfInfo   - XSVF information pointer.
 * Returns:      int         - 0 = success;  non-zero = error.
 *****************************************************************************/
int xsvfDoIllegalCmd( SXsvfInfo* pXsvfInfo )
{
	XSVFDBG_PRINTF2( 0, "ERROR:  Encountered unsupported command #%d (%s)\n",
			 ((unsigned int)(pXsvfInfo->ucCommand)),
			 ((pXsvfInfo->ucCommand < XLASTCMD)
			  ? (xsvf_pzCommandName[pXsvfInfo->ucCommand])
			  : "Unknown") );
	pXsvfInfo->iErrorCode   = XSVF_ERROR_ILLEGALCMD;
	return( pXsvfInfo->iErrorCode );
}

/*****************************************************************************
 * Function:     xsvfDoXCOMPLETE
 * Description:  XCOMPLETE (no parameters)
 *               Update complete status for XSVF player.
 * Parameters:   pXsvfInfo   - XSVF information pointer.
 * Returns:      int         - 0 = success;  non-zero = error.
 *****************************************************************************/
int xsvfDoXCOMPLETE( SXsvfInfo* pXsvfInfo )
{
	pXsvfInfo->ucComplete   = 1;
	return( XSVF_ERROR_NONE );
}

/*****************************************************************************
 * Function:     xsvfDoXTDOMASK
 * Description:  XTDOMASK <lenVal.TdoMask[XSDRSIZE]>
 *               Prespecify the TDO compare mask.
 * Parameters:   pXsvfInfo   - XSVF information pointer.
 * Returns:      int         - 0 = success;  non-zero = error.
 *****************************************************************************/
int xsvfDoXTDOMASK( SXsvfInfo* pXsvfInfo )
{
	readVal( &(pXsvfInfo->lvTdoMask), pXsvfInfo->sShiftLengthBytes );
	XSVFDBG_PRINTF( 4, "    TDO Mask     = ");
	XSVFDBG_PRINTLENVAL( 4, &(pXsvfInfo->lvTdoMask) );
	XSVFDBG_PRINTF( 4, "\n");
	return( XSVF_ERROR_NONE );
}

/*****************************************************************************
 * Function:     xsvfDoXSIR
 * Description:  XSIR <(byte)shiftlen> <lenVal.TDI[shiftlen]>
 *               Get the instruction and shift the instruction into the TAP.
 *               If prespecified XRUNTEST!=0, goto RUNTEST and wait after
 *               the shift for XRUNTEST usec.
 * Parameters:   pXsvfInfo   - XSVF information pointer.
 * Returns:      int         - 0 = success;  non-zero = error.
 *****************************************************************************/
int xsvfDoXSIR( SXsvfInfo* pXsvfInfo )
{
	unsigned char   ucShiftIrBits;
	short           sShiftIrBytes;
	int             iErrorCode;

	/* Get the shift length and store */
	readByte( &ucShiftIrBits );
	sShiftIrBytes   = xsvfGetAsNumBytes( ucShiftIrBits );
	XSVFDBG_PRINTF1( 3, "   XSIR length = %d\n",
			 ((unsigned int)ucShiftIrBits) );

	if ( sShiftIrBytes > MAX_LEN )
	{

⌨️ 快捷键说明

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