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

📄 slim_vme.c

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

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

/*************************************************************
*                                                            *
* EXTERNAL FUNCTIONS                                         *
*                                                            *
*************************************************************/

extern unsigned char GetByte( int a_iCurrentIndex, char a_cAlgo );
extern short ispProcessVME();
extern void EnableHardware();
extern void DisableHardware();

#ifdef VME_WINDOWS
extern int Check_Cable_Power();
#endif

/*************************************************************
*                                                            *
* EXTERNAL VARIABLES                                         *
*                                                            *
*************************************************************/

extern xdata const int g_iDataSize;
extern int g_iMovingAlgoIndex;
extern int g_iMovingDataIndex;
extern unsigned short g_usDataType;

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

const char szHeader[] = { "_SVME1.1" };

/*************************************************************
*                                                            *
* ISPVMENTRYPOINT                                            *
*                                                            *
* INPUT:                                                     *
*     a_pszAlgoFile: this is the name of the algorithm file. *
*                                                            *
*     a_pszDataFile: this is the name of the data file.      *
*     Note that this argument may be empty if the algorithm  *
*     does not require a data file.                          *
*                                                            *
* RETURN:                                                    *
*     The return value will be a negative number if an error *
*     occurred, or 0 if everything was successful            *
*                                                            *
* DESCRIPTION:                                               *
*     This function opens the file pointers to the algo and  *
*     data file.  It intializes global variables to their    *
*     default values and enters the processor.               *
*                                                            *
*************************************************************/

short int ispEntryPoint()
{
	short int siRetCode = 0;
	char cIndex;

	if ( g_iDataSize ) {
		if ( GetByte( g_iMovingDataIndex++, 0 ) ) {
			g_usDataType |= COMPRESS;
		}
	}

	/*************************************************************
	*                                                            *
	* Check the vme version.                                     *
	*                                                            *
	*************************************************************/

	for ( cIndex = 0; cIndex < 8; cIndex++ ) {
		if ( GetByte( g_iMovingAlgoIndex++, 1 ) != szHeader[ cIndex ] ) {
			return ERR_WRONG_VERSION;
		}
	}

	/*************************************************************
	*                                                            *
	* Start the hardware.                                        *
	*                                                            *
	*************************************************************/

    EnableHardware();
                         
	/*************************************************************
	*                                                            *
	* Begin processing algorithm and data file.                  *
	*                                                            *
	*************************************************************/

	siRetCode = ispProcessVME();

	/*************************************************************
	*                                                            *
	* Stop the hardware.                                         *
	*                                                            *
	*************************************************************/

    DisableHardware();

	/*************************************************************
	*                                                            *
	* Return the return code.                                    *
	*                                                            *
	*************************************************************/

	return ( siRetCode );
}

/*************************************************************
*                                                            *
* ERROR_HANDLER                                              *
*                                                            *
* INPUT:                                                     *
*     a_siRetCode: this is the error code reported by the    *
*     processor.                                             *
*                                                            *
*     a_pszMessage: this will store the return message.      *
*                                                            *
* RETURN:                                                    *
*     None.                                                  *
*                                                            *
* DESCRIPTION:                                               *
*     This function assigns an error message based on the    *
*     error reported by the processor.  The program should   *
*     display the error message prior to exiting.            *
*                                                            *
*************************************************************/

#ifdef VME_WINDOWS
void error_handler( short int a_siRetCode, char * a_pszMessage )
{
	switch( a_siRetCode ) {
	case ERR_VERIFY_FAIL:
		strcpy( a_pszMessage, "VERIFY FAIL" );
		break;
	case ERR_FIND_ALGO_FILE:
		strcpy( a_pszMessage, "CANNOT FIND ALGO FILE" );
		break;
	case ERR_FIND_DATA_FILE:
		strcpy( a_pszMessage, "CANNOT FIND DATA FILE" );
		break;
	case ERR_WRONG_VERSION:
		strcpy( a_pszMessage, "WRONG FILE TYPE/VERSION" );
		break;
	case ERR_ALGO_FILE_ERROR:
		strcpy( a_pszMessage, "ALGO FILE ERROR" );
		break;
	case ERR_DATA_FILE_ERROR:
		strcpy( a_pszMessage, "DATA FILE ERROR" );
		break;
	case ERR_OUT_OF_MEMORY:
		strcpy( a_pszMessage, "OUT OF MEMORY" );
		break;
	default:
		strcpy( a_pszMessage, "UNKNOWN ERROR" );
		break;
	}
}
#endif /* VME_WINDOWS */

/*************************************************************
*                                                            *
* MAIN                                                       *
*                                                            *
*************************************************************/

short int main()
{
	/*************************************************************
	*                                                            *
	* LOCAL VARIABLES:                                           *
	*     siRetCode: this variable holds the return.             *
	*                                                            *
	*************************************************************/

	short int siRetCode = 0; 

#ifdef VME_WINDOWS
	char szErrorMessage[ 50 ] = { 0 };
	time_t startTime;
	time_t endTime;
	short int siTime = 0;

	printf( "                 Lattice Semiconductor Corp.\n" );
	printf( "          Slim ispVME(tm) EPROM 1.1 Copyright 2004.\n\n" );

	siRetCode = Check_Cable_Power();
	if ( siRetCode == CABLE_NOT_DETECT ) {
		printf( "Error: download cable not detected\n\n" );
		return( 1 );
	}
	if ( siRetCode == POWER_OFF ) {
		printf( "Error: the power is not on\n\n" );
		return( 1 );
	}
	
	time( &startTime );
#endif /* VME_WINDOWS */

	/*************************************************************
	*                                                            *
	* Pass in the command line arguments to the entry point.     *
	*                                                            *
	*************************************************************/

	siRetCode = ispEntryPoint();

#ifdef VME_WINDOWS
	time( &endTime );

	/*************************************************************
	*                                                            *
	* Check the return code and report appropriate message       *
	*                                                            *
	*************************************************************/

	if ( siRetCode < 0 ) {
		error_handler( siRetCode, szErrorMessage );
        printf( "\nProcessing failure: %s\n\n", szErrorMessage );
        printf( "+=======+\n" );
        printf( "| FAIL! |\n" );
        printf( "+=======+\n\n" );
	} 
	else {
		printf( "\n+=======+\n" );
        printf( "| PASS! |\n" );
        printf( "+=======+\n\n" );
		siTime = endTime - startTime;
		printf( "Processing time: %d\n\n", siTime );
	}
#endif /* VME_WINDOWS */
	
	return( siRetCode );
} 

⌨️ 快捷键说明

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