⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slim_pro.c

📁 在对存储空间要求非常严格的嵌入式系统中用CPU下载CPLD的代码
💻 C
📖 第 1 页 / 共 4 页
字号:
			}
			break;
		case MASK:
			/*************************************************************
			*                                                            *
			* Set data type register to indicate MASK data.  Set MASK    *
			* location index to current algorithm array position.        *
			*                                                            *
			*************************************************************/
			g_usDataType |= MASK_DATA;
			g_iMASKIndex = g_iMovingAlgoIndex;
			g_iMovingAlgoIndex += a_uiDataSize;
			break;
		default:
			/*************************************************************
			*                                                            *
			* Unrecognized or misplaced opcode.  Return error.           *
			*                                                            *
			*************************************************************/
			return ERR_ALGO_FILE_ERROR;
		}
	}  
	
	/*************************************************************
	*                                                            *
	* Reached the end of the instruction.  Return passing.       *
	*                                                            *
	*************************************************************/

	return 0;
}

/*************************************************************
*                                                            *
* ISPVMSHIFT                                                 *
*                                                            *
* INPUT:                                                     *
*     a_cCommand: this argument specifies either the SIR or  *
*     SDR command.                                           *
*                                                            *
* RETURN:                                                    *
*     The return value indicates whether the SIR/SDR was     *
*     processed successfully or not.  A return value equal   *
*     to or greater than 0 is passing, and less than 0 is    *
*     failing.                                               *
*                                                            *
* DESCRIPTION:                                               *
*     This function is the entry point to execute an SIR or  *
*     SDR command to the device.                             *
*                                                            *
*************************************************************/

short int ispVMShift( char a_cCommand )
{
	short int siRetCode = 0;
	unsigned int uiDataSize = ispVMDataSize();

#ifdef VME_DEBUG
	printf( "%d\n", uiDataSize );
#endif /* VME_DEBUG */
	
	/*************************************************************
	*                                                            *
	* Clear any existing SIR/SDR instructions from the data type *
	* register.                                                  *
	*                                                            *
	*************************************************************/
	
	g_usDataType &= ~( SIR_DATA + SDR_DATA );

	/*************************************************************
	*                                                            *
	* Move state machine to appropriate state depending on the   *
	* command.  Issue bypass if needed.                          *
	*                                                            *
	*************************************************************/

	switch ( a_cCommand ) {
	case SIR:
		/*************************************************************
		*                                                            *
		* Set the data type register to indicate that it's executing *
		* an SIR instruction.  Move state machine to IRPAUSE,        *
		* SHIFTIR.  If header instruction register exists, then      *
		* issue bypass.                                              *
		*                                                            *
		*************************************************************/
		g_usDataType |= SIR_DATA;
		ispVMStateMachine( IRPAUSE );
		ispVMStateMachine( SHIFTIR );
		if ( g_siHeadIR > 0 ){ 
			ispVMBypass( g_siHeadIR );
			sclock();
		}
		break;
	case SDR:
		/*************************************************************
		*                                                            *
		* Set the data type register to indicate that it's executing *
		* an SDR instruction.  Move state machine to DRPAUSE,        *
		* SHIFTDR.  If header data register exists, then issue       *
		* bypass.                                                    *
		*                                                            *
		*************************************************************/
		g_usDataType |= SDR_DATA;
		ispVMStateMachine( DRPAUSE );
		ispVMStateMachine( SHIFTDR );
		if ( g_siHeadDR > 0 ){
			ispVMBypass( g_siHeadDR );
			sclock();
		}
		break;
	}
	
	/*************************************************************
	*                                                            *
	* Set the appropriate index locations.  If error then return *
	* error code immediately.                                    *
	*                                                            *
	*************************************************************/

	siRetCode = ispVMShiftExec( uiDataSize );
	
	if ( siRetCode < 0 ) {
		return siRetCode;
	}

	/*************************************************************
	*                                                            *
	* Execute the command to the device.  If TDO exists, then    *
	* read from the device and verify.  Else only TDI exists     *
	* which must send data to the device only.                   *
	*                                                            *
	*************************************************************/

	if ( ( g_usDataType & TDO_DATA ) || ( g_usDataType & DTDO_DATA ) ) {
		siRetCode = ispVMRead( uiDataSize );
		/*************************************************************
		*                                                            *
		* A frame of data has just been read and verified.  If the   *
		* DTDO_DATA flag is set, then check to make sure the next    *
		* byte in the data array, which is the last byte of the      *
		* frame, is the END_FRAME byte.                              *
		*                                                            *
		*************************************************************/
		if ( g_usDataType & DTDO_DATA ) {
			if ( GetByte( g_iMovingDataIndex++, 0 ) != END_FRAME ) {
				siRetCode = ERR_DATA_FILE_ERROR;
			}
		}
	}
	else {
		ispVMSend( uiDataSize );
		/*************************************************************
		*                                                            *
		* A frame of data has just been sent.  If the DTDI_DATA flag *
		* is set, then check to make sure the next byte in the data  *
		* array, which is the last byte of the frame, is the         *
		* END_FRAME byte.                                            *
		*                                                            *
		*************************************************************/
		if ( g_usDataType & DTDI_DATA ) {
			if ( GetByte( g_iMovingDataIndex++, 0 ) != END_FRAME ) {
				siRetCode = ERR_DATA_FILE_ERROR;
			}
		}
	}
	
	/*************************************************************
	*                                                            *
	* Bypass trailer if it exists.  Move state machine to        *
	* ENDIR/ENDDR state.                                         *
	*                                                            *
	*************************************************************/

	switch ( a_cCommand ) {
	case SIR:
		if ( g_siTailIR > 0 ) {
			sclock();
			ispVMBypass( g_siTailIR );
		}
		ispVMStateMachine( g_cEndIR );
		break;
    case SDR:  
		if ( g_siTailDR > 0 ) {
			sclock();
			ispVMBypass( g_siTailDR );
		}
		ispVMStateMachine( g_cEndDR );
		break;
	}
	
	return siRetCode;
}

/*************************************************************
*                                                            *
* GETBYTE                                                    *
*                                                            *
* INPUT:                                                     *
*     a_iCurrentIndex: the current index to access.          *
*                                                            *
*     a_cAlgo: 1 if the return byte is to be retrieved from  *
*     the algorithm array, 0 if the byte is to be retrieved  *
*     from the data array.                                   *
*                                                            *
* RETURN:                                                    *
*     This function returns a byte of data from either the   *
*     algorithm or data array.  It returns -1 if out of      *
*     bounds.                                                *
*                                                            *
*************************************************************/

unsigned char GetByte( int a_iCurrentIndex, char a_cAlgo )
{
	unsigned char ucData = 0;
	
	if ( a_cAlgo ) { 
		/*************************************************************
		*                                                            *
		* If the current index is still within range, then return    *
		* the next byte.  If it is out of range, then return -1.     *
		*                                                            *
		*************************************************************/
		if ( a_iCurrentIndex >= g_iAlgoSize ) {
			return ( unsigned char ) 0xFF;
		}
		ucData = g_pucAlgoArray[ a_iCurrentIndex ];
	}
	else {
		/*************************************************************
		*                                                            *
		* If the current index is still within range, then return    *
		* the next byte.  If it is out of range, then return -1.     *
		*                                                            *
		*************************************************************/
		if ( a_iCurrentIndex >= g_iDataSize ) {
			return ( unsigned char ) 0xFF;
		}
		ucData = g_pucDataArray[ a_iCurrentIndex ];
	}

	return ucData;
}

/*************************************************************
*                                                            *
* SCLOCK                                                     *
*                                                            *
* INPUT:                                                     *
*     None.                                                  *
*                                                            *
* RETURN:                                                    *
*     None.                                                  *
*                                                            *
* DESCRIPTION:                                               *
*     This function applies a HLL pulse to TCK.              *
*                                                            *
*************************************************************/

void sclock()
{
	/*************************************************************
	*                                                            *
	* Set TCK to HIGH, LOW, LOW.                                 *
	*                                                            *
	*************************************************************/

	writePort( pinTCK, 0x01 );
	writePort( pinTCK, 0x00 );
	writePort( pinTCK, 0x00 );
}

/*************************************************************
*                                                            *
* ISPVMREAD                                                  *
*                                                            *
* INPUT:                                                     *
*     a_uiDataSize: this argument is the size of the         *
*     command.                                               *
*                                                            *
* RETURN:                                                    *
*     The return value is 0 if passing, and -1 if failing.   *
*                                                            *
* DESCRIPTION:                                               *
*     This function reads a data stream from the device and  *
*     compares it to the expected TDO.                       *
*                                                            *
*************************************************************/

short int ispVMRead( unsigned int a_uiDataSize )
{
	unsigned int uiIndex = 0;
	unsigned short usErrorCount = 0;
	unsigned char ucTDOByte = 0;

⌨️ 快捷键说明

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