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

📄 slim_pro.c

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

#ifdef VME_WINDOWS
#include <windows.h>
#include <mmsystem.h>
#include <time.h>
#include <conio.h>
#include "windriver.h"
#endif /* VME_WINDOWS */

#ifdef VME_DEBUG
#include "debug.h"
#include <stdio.h>
#endif /* VME_DEBUG */

/*************************************************************
*                                                            *
* PROTOTYPES                                                 *
*                                                            *
*************************************************************/

unsigned int ispVMDataSize();
short int ispVMShiftExec( unsigned int a_uiDataSize );
short int ispVMShift( char a_cCommand );
unsigned char GetByte( int a_iCurrentIndex, char a_cAlgo );
void ispVMStateMachine( char a_cNextState );
void ispVMClocks( unsigned int a_usClocks );
void ispVMBypass( unsigned int a_siLength );
void sclock();
short int ispVMRead( unsigned int a_uiDataSize );
void ispVMSend( unsigned int a_uiDataSize );

/*************************************************************
*                                                            *
* EXTERNAL FUNCTION                                          *
*                                                            *
*************************************************************/

extern void ispVMDelay( unsigned int a_usDelay );
extern unsigned char readPort();
extern void writePort( unsigned char a_ucPins, unsigned char a_ucValue );

/*************************************************************
*                                                            *
* GLOBAL VARIABLES                                           *
*                                                            *
*************************************************************/

unsigned short g_usDataType = 0x0000; /*** data type register used to hold information ***
									  **** about the algorithm and data ***/
unsigned char g_cEndDR = 0;		/*** used to hold the ENDDR state. ***/
unsigned char g_cEndIR = 0;		/*** used to hold the ENDIR state. ***/
short int g_siHeadDR = 0;		/*** used to hold the header data register ***/
short int g_siHeadIR = 0;		/*** used to hold the header instruction register ***/
short int g_siTailDR = 0;		/*** used to hold the trailer data register ***/
short int g_siTailIR = 0;		/*** used to hold the trailer instruction register ***/

int g_iMovingAlgoIndex = 0;	    /*** variable to hold the current index in the algo array ***/
int g_iMovingDataIndex = 0;		/*** variable to hold the current index in the data array ***/
int g_iMainDataIndex = 0;		/*** forward-only index used as a placed holder in the data array ***/
int g_iRepeatIndex = 0;		    /*** Used to point to the location of REPEAT data ***/
int g_iTDIIndex = 0;			/*** Used to point to the location of TDI data ***/
int g_iTDOIndex = 0;			/*** Used to point to the location of TDO data ***/
int g_iMASKIndex = 0;			/*** Used to point to the location of MASK data ***/
unsigned char g_ucCompressCounter = 0; /*** used to indicate how many times 0xFF is repeated ***/

short int g_siIspPins = 0x00;         /*** holds the current byte to be sent to the hardware ***/
char g_cCurrentJTAGState = 0;			/*** holds the current state of JTAG state machine ***/
xdata const struct iState {               /*** JTAG state machine transistion table ***/
	 unsigned char  CurState;		/*** From this state ***/
	 unsigned char  NextState;		/*** Step to this state ***/
	 unsigned char  Pattern;		/*** The pattern of TMS ***/
	 unsigned char  Pulses;			/*** The number of steps ***/
} iStates[ 20 ] = {
	{ DRPAUSE,	SHIFTDR,	0x80, 2 },
	{ IRPAUSE,	SHIFTIR,	0x80, 2 },
	{ SHIFTIR,	IRPAUSE,	0x80, 2 },
	{ SHIFTDR,	DRPAUSE,	0x80, 2 },
	{ DRPAUSE,	IDLE,		0xC0, 3 },
	{ IRPAUSE,	IDLE,		0xC0, 3 },
	{ RESET,	IDLE,		0x00, 1 },
	{ RESET,	DRPAUSE,	0x50, 5 },
	{ RESET,	IRPAUSE,	0x68, 6 },
	{ IDLE,		RESET,		0xE0, 3 },
	{ IDLE,		DRPAUSE,	0xA0, 4 },
	{ IDLE,		IRPAUSE,	0xD0, 5 },
	{ DRPAUSE,	RESET,		0xF8, 5 },
	{ DRPAUSE,	IRPAUSE,	0xF4, 7 },
	{ IRPAUSE,	RESET,		0xF8, 5 },
	{ IRPAUSE,	DRPAUSE,	0xE8, 6 },
	{ IRPAUSE,	SHIFTDR,	0xE0, 5 },
	{ SHIFTIR,	IDLE,		0xC0, 3 },
	{ SHIFTDR,	IDLE,		0xC0, 3 },
	{ RESET,	RESET,		0xFC, 6 }
};

#ifdef VME_WINDOWS
short int g_siOutPort = 0x0378;	/** Variable used in Windows only **/
short int g_siInPort = 0x0379;	/** Variable used in Windows only **/
#endif /* VME_WINDOWS */

/*************************************************************
*                                                            *
* EXTERNAL VARIABLES                                         *
*                                                            *
*     If the algorithm does not require the data, then       *
*     declare the variables g_pucDataArray and g_iDataSize   *
*     as local variables and set them to NULL and 0,         *
*     respectively.                                          *
*                                                            *
*     Example:                                               *
*          xdata unsigned char * g_pucDataArray = NULL;      *
*          xdata int g_iDataSize = 0;                        *
*                                                            *
*************************************************************/

extern xdata const unsigned char g_pucAlgoArray[];
extern xdata const unsigned char g_pucDataArray[];
extern xdata const int g_iAlgoSize;
extern xdata const int g_iDataSize;

/*************************************************************
*                                                            *
* ISPPROCESSVME                                              *
*                                                            *
* INPUT:                                                     *
*     None.                                                  *
*                                                            *
* RETURN:                                                    *
*     The return value indicates whether the vme 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 core of the embedded processor.   *
*     It extracts the VME file for the high-level tokens     *
*     such as SIR, SDR, STATE, etc, and calls the            *
*     appropriate functions to process them.                 *
*                                                            *
*************************************************************/

short int ispProcessVME()
{
	unsigned char ucOpcode = 0;
	short int siRetCode = 0;
	static char cProgram = 0;
	unsigned int uiDataSize = 0;

#ifdef VME_DEBUG
	short int iOpcodeIndex = 0;
#endif /* VME_DEBUG */
	
	/*************************************************************
	*                                                            *
	* Begin processing the vme algorithm and data files.         *
	*                                                            *
	*************************************************************/
	
	while ( ( ucOpcode = GetByte( g_iMovingAlgoIndex++, 1 ) ) != 0xFF ) {

#ifdef VME_DEBUG
		for ( iOpcodeIndex = 0; iOpcodeIndex < iOpcodeCount; iOpcodeIndex++ ) {
            if ( ispVMOpcodes[ iOpcodeIndex ].ucOpcode == ucOpcode ) {
				break;
			}
		}
		if ( iOpcodeIndex >= iOpcodeCount ) {
			printf( "\nInstruction: UNKNOWN\n" );
		}
		else {
			printf( "\nInstruction: %s ", ispVMOpcodes[ iOpcodeIndex ].a_pszText );
		}
#endif /* VME_DEBUG */

		/*************************************************************
		*                                                            *
		* This switch statement is the main switch that represents   *
		* the core of the embedded processor.                        *
		*                                                            *
		*************************************************************/
		
		switch ( ucOpcode ) {
		case STATE:
			/*************************************************************
			*                                                            *
			* Move the state.                                            *
			*                                                            *
			*************************************************************/	
			ispVMStateMachine( GetByte( g_iMovingAlgoIndex++, 1 ) );
			break;
		case SIR:
		case SDR:
			/*************************************************************
			*                                                            *
			* Execute SIR/SDR command.                                   *
			*                                                            *
			*************************************************************/
			siRetCode = ispVMShift( ucOpcode );
			break;
		case TCK:
			/*************************************************************
			*                                                            *
			* Pulse TCK signal the specified time.                       *
			*                                                            *
			*************************************************************/
			ispVMClocks( ispVMDataSize() );
			break;
		case WAIT:
			/*************************************************************
			*                                                            *
			* Issue delay in specified time.                             *
			*                                                            *
			*************************************************************/
			ispVMDelay( ispVMDataSize() );
			break;
		case ENDDR:
			/*************************************************************
			*                                                            *
			* Get the ENDDR state and store in global variable.          *
			*                                                            *
			*************************************************************/
			g_cEndDR = GetByte( g_iMovingAlgoIndex++, 1 );

#ifdef VME_DEBUG
			switch ( g_cEndDR ) {
			case RESET:
				printf( "RESET\n" );
				break;
			case IDLE:
				printf( "IDLE\n" );
				break;
			case IRPAUSE:
				printf( "IRPAUSE\n" );
				break;
			case DRPAUSE:
				printf( "DRPAUSE\n" );
				break;
			case SHIFTIR:
				printf( "SHIFTIR\n" );
				break;
			case SHIFTDR:
				printf( "SHIFTDR\n" );
				break;
			default:
				printf( "UNKNOWN\n" );
			}
#endif /* VME_DEBUG */

			break;
		case ENDIR:
			/*************************************************************
			*                                                            *
			* Get the ENDIR state and store in global variable.          *
			*                                                            *
			*************************************************************/
			g_cEndIR = GetByte( g_iMovingAlgoIndex++, 1 );
			
#ifdef VME_DEBUG
			switch ( g_cEndIR ) {
			case RESET:
				printf( "RESET\n" );
				break;
			case IDLE:
				printf( "IDLE\n" );
				break;
			case IRPAUSE:
				printf( "IRPAUSE\n" );
				break;
			case DRPAUSE:
				printf( "DRPAUSE\n" );
				break;
			case SHIFTIR:
				printf( "SHIFTIR\n" );
				break;
			case SHIFTDR:
				printf( "SHIFTDR\n" );
				break;
			default:
				printf( "UNKNOWN\n" );
			}
#endif /* VME_DEBUG */

			break;
		case HIR:
			g_siHeadIR = ispVMDataSize();

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

			break;
		case TIR:
			g_siTailIR = ispVMDataSize();

⌨️ 快捷键说明

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