📄 ispvm_ui.c
字号:
if ( HDRData != NULL ) {
free( HDRData );
HDRData = NULL;
}
HDRData = ( unsigned char * ) malloc( usSize / 8 + 2 );
break;
case TDR:
if ( TDRData != NULL ) {
free( TDRData );
TDRData = NULL;
}
TDRData = ( unsigned char * ) malloc( usSize / 8 + 2 );
break;
case HEAP:
if ( pucHeapMemory != NULL ) {
free( pucHeapMemory );
pucHeapMemory = NULL;
}
pucHeapMemory = ( unsigned char * ) malloc( usSize + 2 );
break;
/* 05/27/03 Nguyen added to support Dynamic IO */
case DMASK:
if ( OutDMaskData != NULL ) {
if ( usPreviousSize == usSize ) { /*already allocated*/
break;
}
else {
free( OutDMaskData );
OutDMaskData = NULL;
}
}
OutDMaskData = ( unsigned char * ) malloc( usSize / 8 + 2 );
usPreviousSize = usSize;
break;
default:
return;
}
}
/***************************************************************************
ispVMFreeMem
Input:
None
Any memory array found to be other than NULL, memory is to be free for
proper closure of the program.
****************************************************************************/
char ispVMFreeMem(void)
{
if ( pucHeapMemory != NULL ) {
free( pucHeapMemory );
pucHeapMemory = NULL;
}
if ( OutMaskData != NULL ) {
free( OutMaskData );
OutMaskData = NULL;
}
if ( InData != NULL ) {
free( InData );
InData = NULL;
}
if ( OutData != NULL ) {
free( OutData );
OutData = NULL;
}
if ( HIRData != NULL ) {
free( HIRData );
HIRData = NULL;
}
if ( TIRData != NULL ) {
free( TIRData );
TIRData = NULL;
}
if ( HDRData != NULL ) {
free( HDRData );
HDRData = NULL;
}
if ( TDRData != NULL ) {
free( TDRData );
TDRData = NULL;
}
/* 05/27/03 Nguyen added to support Dynamic IO */
if ( OutDMaskData != NULL ) {
free( OutDMaskData );
OutDMaskData = NULL;
}
return ( 0 );
}
/****************************************************************************
The Entry Point Of ispVM
process the given VME file which has algorithm and data included.
8/29/01 ht change the VME file version from 1.0 to 1.1
*****************************************************************************/
char ispVM( char * a_pszFilename )
{
char szHeader[] = { "__VME2.0" };
char cRetCode;
char cIndex;
char CompressFlag = 0x00;
if ( ( fptrVME = fopen( a_pszFilename, "rb" ) ) == NULL ) {
return -2;
}
for ( cIndex = 0; cIndex < 8; cIndex++ ) {
if ( GetByte() != szHeader[ cIndex ] ) {
return -3;
}
}
/*8/23/01 ht clear all flags to begin*/
usDataType = 0x0000;
usFlowControl = 0x0000;
CompressFlag = GetByte();
if( CompressFlag == ( char ) 0xf1 ) {
usDataType |= COMPRESS;
}
else if( CompressFlag == ( char ) 0xf2 ) {
usDataType &= ~COMPRESS;
}
else {
return -3;
}
ispVMStart(); /*enable Lattice Cable*/
/*force the chain to Test-Logic/Reset*/
cRetCode = ispVMCode();
ispVMEnd(); /*reset the chain to Test-Logic/Reset*/
/*disable Lattice Cable*/
fclose( fptrVME );
return ( cRetCode );
}
/*************************************************************
* *
* error_handler *
* *
* rcode - error code *
* *
* *
* This procedure return the address of the message string *
* for the corresponding error code. *
* *
*************************************************************/
void error_handler( short a_siRetCode, char * pszMessage )
{
char * pszErrorMessage[] = { "pass",
"verification fail",
"can't find the file",
"wrong file type",
"file error",
"option error" };
strcpy( pszMessage, pszErrorMessage[ -a_siRetCode ] );
}
/*************************************************************
* *
* MAIN *
* *
*************************************************************/
short main( int argc, char * argv[] )
{
unsigned short iCommandLineIndex;
short siRetCode = 0;
char szExtension[ 5 ] = { 0 };
printf( " Lattice Semiconductor Corp.\n" );
printf( "\n ispVME(tm) V10.1.1 Copyright 1998-2004.\n" );
printf( "\nFor daisy chain programming of all in-system programmable devices\n\n" );
if ( argc < 2 ) {
printf( "\nUsage: vme [option] vme_file [vme_file]\n" );
printf( "Example: vme -t 10 vme_file1.vme vme_file2.vme\n" );
printf( "option -t: Increase delay time by percent\n" );
printf( " -t 25 \n" );
printf( " example: Increase delay time by 25 percent \n" );
printf( "\n\n");
exit( 1 );
}
siRetCode = Check_Cable_Power();
if ( siRetCode == CABLE_NOT_DETECT ) {
printf( "Error: download cable not detected\n\n" );
exit( 1 );
}
if ( siRetCode == POWER_OFF ) {
printf( "Error: the power is not on\n\n" );
exit( 1 );
}
/* Parse command line arguments, count the number of VME files */
for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) {
strcpy( szCommandLineArg, argv[ iCommandLineIndex ] );
strcpy( szExtension, &szCommandLineArg[ strlen( szCommandLineArg ) - 4 ] );
strlwr( szExtension );
if ( !strcmp( strlwr( szCommandLineArg ), "-t" ) && ( iCommandLineIndex == 1 ) ) {
if ( ++iCommandLineIndex >= argc ) {
printf( "Error: delay value not given\n\n" );
exit( -5 );
}
delayPercent = atoi( argv[ iCommandLineIndex ] );
if ( delayPercent == 0 ) {
printf( "Error: delay value must be a number greater than zero\n\n" );
exit( -5 );
}
}
else if ( !strcmp( strlwr( szCommandLineArg ), "-t" ) && ( iCommandLineIndex != 1 ) ) {
printf( "Error: delay option -t must be the first argument\n\n" );
exit( 1 );
}
else if ( strcmp( szExtension, ".vme" ) ) {
printf( "Error: VME files must end with the extension *.vme\n\n" );
exit( 1 );
}
}
siRetCode = 0;
for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) { /* Process all VME files sequentially */
strcpy( szCommandLineArg, argv[ iCommandLineIndex ] );
if ( !strcmp( strlwr( szCommandLineArg ), "-t" ) && ( iCommandLineIndex == 1 ) ) {
++iCommandLineIndex;
}
else {
printf( "Processing virtual machine file (%s)......\n\n", szCommandLineArg );
siRetCode = ispVM( szCommandLineArg );
ispVMFreeMem();
if ( siRetCode < 0 ) {
break;
}
}
}
if ( siRetCode < 0 ) {
error_handler( siRetCode, szCommandLineArg );
printf( "Failed due to %s\n\n", szCommandLineArg );
printf( "+=======+\n" );
printf( "| FAIL! |\n" );
printf( "+=======+\n\n" );
}
else {
printf( "+=======+\n" );
printf( "| PASS! |\n" );
printf( "+=======+\n\n" );
}
exit( siRetCode );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -