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

📄 slim_pro.c

📁 在对存储空间要求非常严格的嵌入式系统中用CPU下载CPLD的代码
💻 C
📖 第 1 页 / 共 4 页
字号:

#ifdef VME_DEBUG
			printf( "%d\n", g_siTailIR );
#endif /* VME_DEBUG */

			break;
		case HDR:
			g_siHeadDR = ispVMDataSize();

#ifdef VME_DEBUG
			printf( "%d\n", g_siHeadDR );
#endif /* VME_DEBUG */

			break;
		case TDR:
			g_siTailDR = ispVMDataSize();

#ifdef VME_DEBUG
			printf( "%d\n", g_siTailDR );
#endif /* VME_DEBUG */

			break;
		case BEGIN_REPEAT:
			/*************************************************************
			*                                                            *
			* Execute repeat loop.                                       *
			*                                                            *
			*************************************************************/

			uiDataSize = ispVMDataSize();

			switch ( GetByte( g_iMovingAlgoIndex++, 1 ) ) {
			case PROGRAM:
				/*************************************************************
				*                                                            *
				* Set the main data index to the moving data index.  This    *
				* allows the processor to remember the beginning of the      *
				* data.  Set the cProgram variable to true to indicate to    *
				* the verify flow later that a programming flow has been     *
				* completed so the moving data index must return to the      *
				* main data index.                                           *
				*                                                            *
				*************************************************************/
				g_iMainDataIndex = g_iMovingDataIndex;
				cProgram = 1;
				break;
			case VERIFY:
				/*************************************************************
				*                                                            *
				* If the static variable cProgram has been set, then return  *
				* the moving data index to the main data index because this  *
				* is a erase, program, verify operation.  If the programming *
				* flag is not set, then this is a verify only operation thus *
				* no need to return the moving data index.                   *
				*                                                            *
				*************************************************************/
				if ( cProgram ) {
					g_iMovingDataIndex = g_iMainDataIndex;
					cProgram = 0;
				}
				break;
			}

			/*************************************************************
			*                                                            *
			* Set the repeat index to the first byte in the repeat loop. *
			*                                                            *
			*************************************************************/

			g_iRepeatIndex = g_iMovingAlgoIndex;

			for ( ; uiDataSize > 0; uiDataSize-- ) {
				/*************************************************************
				*                                                            *
				* Initialize the current algorithm index to the beginning of *
				* the repeat index before each repeat loop.                  *
				*                                                            *
				*************************************************************/

				g_iMovingAlgoIndex = g_iRepeatIndex;

				/*************************************************************
				*                                                            *
				* Make recursive call.                                       *
				*                                                            *
				*************************************************************/

				siRetCode = ispProcessVME();
				if ( siRetCode < 0 ) {
					break;
				}
			}
			break;
		case END_REPEAT:
			/*************************************************************
			*                                                            *
			* Exit the current repeat frame.                             *
			*                                                            *
			*************************************************************/
			return siRetCode;
		case ENDVME:
			/*************************************************************
			*                                                            *
			* If the ENDVME token is found and g_iMovingAlgoIndex is     *
			* greater than or equal to g_iAlgoSize, then that indicates  *
			* the end of the chain.  If g_iMovingAlgoIndex is less than  *
			* g_iAlgoSize, then that indicates that there are still more *
			* devices to be processed.                                   *
			*                                                            *
			*************************************************************/
			if ( g_iMovingAlgoIndex >= g_iAlgoSize ) {
				return siRetCode;
			}
			break;
		default:
			/*************************************************************
			*                                                            *
			* Unrecognized opcode.  Return with file error.              *
			*                                                            *
			*************************************************************/
			return ERR_ALGO_FILE_ERROR;
		}
		
		if ( siRetCode < 0 ) {
			return siRetCode;
		}
	}
	
	return ERR_ALGO_FILE_ERROR;
}

/*************************************************************
*                                                            *
* ISPVMDATASIZE                                              *
*                                                            *
* INPUT:                                                     *
*     None.                                                  *
*                                                            *
* RETURN:                                                    *
*     This function returns a number indicating the size of  *
*     the instruction.                                       *
*                                                            *
* DESCRIPTION:                                               *
*     This function returns a number.  The number is the     *
*     value found in SVF commands such as SDR, SIR, HIR, and *
*     etc.  For example:                                     *
*               SDR 200 TDI(FFF..F);                         *
*     The return value would be 200.                         *
*                                                            *
*************************************************************/

unsigned int ispVMDataSize()
{
	unsigned int uiSize = 0;
	unsigned char ucCurrentByte = 0;
	unsigned char ucIndex = 0;
	
	while ( ( ucCurrentByte = GetByte( g_iMovingAlgoIndex++, 1 ) ) & 0x80 ) {
		uiSize |= ( ( unsigned int ) ( ucCurrentByte & 0x7F ) ) << ucIndex;
		ucIndex += 7;
	}
	uiSize |= ( ( unsigned int ) ( ucCurrentByte & 0x7F ) ) << ucIndex;
	return uiSize;
}

/*************************************************************
*                                                            *
* ISPVMSHIFTEXEC                                             *
*                                                            *
* INPUT:                                                     *
*     a_uiDataSize: this holds the size of the command.      *
*                                                            *
* RETURN:                                                    *
*     Returns 0 if passing, -1 if failing.                   *
*                                                            *
* DESCRIPTION:                                               *
*     This function handles the data in the SIR/SDR commands *
*     by either decompressing the data or setting the        *
*     respective indexes to point to the appropriate         *
*     location in the algo or data array.  Note that data    *
*     only comes after TDI, DTDI, TDO, DTDO, and MASK.       *
*                                                            *
*************************************************************/

short int ispVMShiftExec( unsigned int a_uiDataSize )
{
	unsigned char ucDataByte = 0;
	
	/*************************************************************
	*                                                            *
	* Reset the data type register.                              *
	*                                                            *
	*************************************************************/

	g_usDataType &= ~( TDI_DATA + TDO_DATA + MASK_DATA + DTDI_DATA + DTDO_DATA + COMPRESS_FRAME );

	/*************************************************************
	*                                                            *
	* Convert the size from bits to byte.                        *
	*                                                            *
	*************************************************************/

	if ( a_uiDataSize % 8 ) {
		a_uiDataSize = a_uiDataSize / 8 + 1;
	}
	else {
		a_uiDataSize = a_uiDataSize / 8;
	}
	
	/*************************************************************
	*                                                            *
	* Begin extracting the command.                              *
	*                                                            *
	*************************************************************/

	while ( ( ucDataByte = GetByte( g_iMovingAlgoIndex++, 1 ) ) != CONTINUE ) { 
		switch ( ucDataByte ) {
		case TDI:
			/*************************************************************
			*                                                            *
			* Set data type register to indicate TDI data and set TDI    *
			* index to the current algorithm location.                   *
			*                                                            *
			*************************************************************/
			g_usDataType |= TDI_DATA;
			g_iTDIIndex = g_iMovingAlgoIndex;
			g_iMovingAlgoIndex += a_uiDataSize;
			break;
		case DTDI:
			/*************************************************************
			*                                                            *
			* Set data type register to indicate DTDI data and check the *
			* next byte to make sure it's the DATA byte.  DTDI indicates *
			* that the data should be read from the data array, not the  *
			* algo array.                                                *
			*                                                            *
			*************************************************************/
			g_usDataType |= DTDI_DATA;
			if ( GetByte( g_iMovingAlgoIndex++, 1 ) != DATA ) {
				return ERR_ALGO_FILE_ERROR;
			}

			/*************************************************************
			*                                                            *
			* If the COMPRESS flag is set, read the next byte from the   *
			* data file array.  If the byte is true, then that indicates *
			* the frame was compressable.  Note that even though the     *
			* overall data file was compressed, certain frames may not   *
			* be compressable that is why this byte must be checked.     *
			*                                                            *
			*************************************************************/
			if ( g_usDataType & COMPRESS ) {
				if ( GetByte( g_iMovingDataIndex++, 0 ) ) {
					g_usDataType |= COMPRESS_FRAME;
				}
			}
			break;
		case TDO:
			/*************************************************************
			*                                                            *
			* Set data type register to indicate TDO data and set TDO    *
			* index to the current algorithm location.                   *
			*                                                            *
			*************************************************************/
			g_usDataType |= TDO_DATA;
			g_iTDOIndex = g_iMovingAlgoIndex;
			g_iMovingAlgoIndex += a_uiDataSize;
			break;
		case DTDO:
			/*************************************************************
			*                                                            *
			* Set data type register to indicate DTDO data and check the *
			* next byte to make sure it's the DATA byte.  DTDO indicates *
			* that the data should be read from the data array, not the  *
			* algo array.                                                *
			*                                                            *
			*************************************************************/
			g_usDataType |= DTDO_DATA;
			if ( GetByte( g_iMovingAlgoIndex++, 1 ) != DATA ) {
				return ERR_ALGO_FILE_ERROR;
			}

			/*************************************************************
			*                                                            *
			* If the COMPRESS flag is set, read the next byte from the   *
			* data file array.  If the byte is true, then that indicates *
			* the frame was compressable.  Note that even though the     *
			* overall data file was compressed, certain frames may not   *
			* be compressable that is why this byte must be checked.     *
			*                                                            *
			*************************************************************/
			if ( g_usDataType & COMPRESS ) {
				if ( GetByte( g_iMovingDataIndex++, 0 ) ) {
					g_usDataType |= COMPRESS_FRAME;
				}

⌨️ 快捷键说明

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