📄 svf2vme.c
字号:
else {
rcode = bits;
}
}
}
/* If all fail and compress by key is the best */
if ( ( rcode < 3 ) && ( comprkey < bytecount - 1 ) && ( comprkey < bytes ) ) {
write( 0xFF );
write( ( unsigned char ) key );
xch = 0x00;
bits = 0;
cur_char = 0x00;
for ( i = 0; i < bytes; i++ ) {
cur_char = data_buf[ i ];
if ( cur_char == key ) {
bits++;
m = 0;
}
else {
xch |= 0x80 >> bits++;
m = 8;
}
k = 0;
do {
if ( bits > 7 ) {
write( xch );
bits = 0;
xch = 0x00;
}
if ( m ) {
xch |= ( ( cur_char << k ) & 0x80 ) >> bits;
bits++;
}
} while ( ++k < m );
if (bits > 7) {
write( xch );
bits = 0;
xch = 0x00;
}
}
if ( i % 8 ) {
write( xch );
bits = 0;
xch = 0x00;
}
/* Return back that it is all done */
*options = NoSave;
return 0x00;
}
if ( rcode == 0x00 ) {
*options = Store;
}
return ( rcode );
}
/************************************************************************
* *
* CharToHex() *
* converts ASCII letter, assumed to be a Hex digit to an integer *
* *
************************************************************************/
short int CharToHex( char hexNibbleChar )
{
int hexdigit;
if ( hexNibbleChar >= '0' && hexNibbleChar <= '9' ) {
hexdigit = hexNibbleChar - '0';
}
else if ( hexNibbleChar >= 'a' && hexNibbleChar <= 'f' ) {
hexdigit = hexNibbleChar - 'a' + 10;
}
else if ( hexNibbleChar >= 'A' && hexNibbleChar <='F' ) {
hexdigit = hexNibbleChar - 'A' +10;
}
else {
hexdigit = 0;
}
return hexdigit;
}
/************************************************************************
* *
* write() *
* write data to a file or to a port; *
* counts the number of bytes written if inside a repeat loop; *
* counts the number of total bytes in the VME file *
* *
* Token It is to distinguish between data or Token code. *
* Token code is not sent to the parallel port *
* 0=>it is pure data *
* 1=>it is a token *
* data the content of data to be written to a file. *
************************************************************************/
short int write(unsigned char data)
{
fputc(data, fpw);
if (inRepeat) {
heapsize++;
}
totalbytecount++;
return OK;
}
/************************************************************************
* *
* reverse() *
* swap the 4 bits Hex number *
* *
************************************************************************/
unsigned char reverse( unsigned char a_cDigit )
{
char cBitIndex;
unsigned char cCurChar = 0x00;
for ( cBitIndex = 0; cBitIndex < 4; cBitIndex++ ) {
if ( ( a_cDigit >> cBitIndex ) & 0x01 ) {
cCurChar |= 0x01 << ( 3 - cBitIndex );
}
}
return ( cCurChar );
}
/************************************************************************ *
* AllocateCFGMemory() *
* Allocate memory for chain structure *
* * Input: *
* Total of devices in chain *
* * Output: *
* 0 if false *
* *
************************************************************************/
int AllocateCFGMemory( int struct_size )
{
if ( cfgChain != NULL ) {
free( cfgChain );
}
cfgChain = NULL;
if ( ( cfgChain =( CFG * ) calloc( struct_size + 1, sizeof( CFG ) ) ) == NULL ) {
free( cfgChain );
printf( "\nOut of Memory!\n" );
return false;
}
return true;
}
/************************************************************************ *
* DeAllocateCFGMemory() *
* Deallocate memory used to store chain information *
* Input: *
* *
* Output: *
* *
* *
************************************************************************/
void DeAllocateCFGMemory()
{
if ( cfgChain != NULL ) {
free( cfgChain );
}
}
/************************************************************************
* *
* PrintHelp() *
* Print the useage menu on console *
* *
************************************************************************/
void PrintHelp(void)
{
printf( "Usage: svf2vme [ -help |\n" );
printf( " [ -full ]\n" );
printf( " [ -loop ]\n" );
printf( " -infile < input file path1 > [ -clock < frequency > ]\n" );
printf( " [ -vendor < altera | xilinx > ]\n" );
printf( " [ -verify_ues ]\n" );
printf( " [ -infile < input file path1 > [ -clock < frequency > ]\n" );
printf( " [ -vendor < altera | xilinx > ]\n" );
printf( " [ -verify_ues ] ]\n" );
printf( " [ -bypass < instruction register length > ]\n" );
printf( " [ -outfile < output file path > ]\n" );
printf( " ]\n" );
printf( "Example: \n" );
printf( " svf2vme -infile c:\\file.svf -clock 10K\n" );
printf( " svf2vme -infile c:\\file1.svf -clock 10M c:\\file2.svf -vendor altera\n" );
printf( " svf2vme -infile -bypass 8 c:\\file.svf -clock 10K -outfile c:\\file.vme \n" );
printf( "\n" );
printf( "See the readme.txt for more information. \n\n" );
}
/**************************************************************************
* MAIN *
* *
* 3/2/2000 Howard Tang support multiple svf files conversion: *
* example: svf2vme svf1.svf 6 svf2.svf ... *
* 5/31/2000 H. Tang V2.01 Add support to short form SVF and space or *
* no space between TDx and xMASK with ( and ). *
* 12/19/00 H. Tang V2.02 Read a new line if reaches end of line. *
* 01/02/01 H. Tang V2.03 Fix memory problem when splitting long SDR *
* 03/28/01 Nguyen V2.04 Accept \t as delimiter on strtok() calls. *
* The SVF files generated by ispVM 9.0.1 have *
* TAPs in it. *
* 04/26/01 H. Tang V3.00 Add support to multiple devices in a single *
* SVF file generated by ispVM 9.0.x *
* 08/28/01 H. Tang V9.00 change it to support VME V9.0 format. *
***************************************************************************/
int main( int argc, char *argv[] )
{
int iRetCode;
int iCommandLineIndex;
int iFullVMEOption = 0;
int iSVFCount = 0;
int iBypassCount = 0;
int iCurrentSVFCount = 0;
int iTemp = 0;
char * szTmp = NULL;
char szVMEFilename[ 1024 ] = { 0 };
char szCommandLineArg[1024] = { 0 };
char tmpname[ 1024 ] = { 0 };
char szErrorMessage[ 1024 ] = { 0 };
FILE * fptrVMEFile = NULL;
printf( " Lattice Semiconductor Corp.\n" );
printf( "\n ispSVF Compiler Version %s Copyright 1998-2004\n\n", VERSION_NUMBER );
if ( argc < 2 )
{
PrintHelp();
exit( ERR_COMMAND_LINE_SYNTAX );
}
/* Pre-process the command line arguments to count the number of SVF files and bypasses given */
for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) {
strcpy( szCommandLineArg, argv[ iCommandLineIndex ] );
if ( !stricmp( szCommandLineArg, "-infile" ) || !stricmp( szCommandLineArg, "-if" ) ) {
iSVFCount++;
}
else if ( !strcmp( szCommandLineArg, "-bypass" ) || !strcmp( szCommandLineArg, "-by" ) ) {
iBypassCount++;
}
}
if ( iSVFCount <= 0 ) {
sprintf( szErrorMessage, "Error: missing required argument -infile < input file >.\n\n" );
printf( "%s", szErrorMessage );
PrintHelp();
exit( ERR_COMMAND_LINE_SYNTAX );
}
iSVFCount += iBypassCount;
/* Allocate memory for chain setup */
iRetCode = AllocateCFGMemory( iSVFCount );
if ( !iRetCode ) {
sprintf( szErrorMessage, "Error: system out of memory.\n\n" );
printf( "%s", szErrorMessage );
exit( OUT_OF_MEMORY );
}
/* Initialize variables for looping */
PatternNumArray = ( int * ) calloc( iSVFCount, sizeof( int ) );
if ( !PatternNumArray ) {
sprintf( szErrorMessage, "Error: system out of memory.\n\n" );
printf( "%s", szErrorMessage );
exit( OUT_OF_MEMORY );
}
SDRValueArray = ( int ** ) calloc( iSVFCount, sizeof( int * ) );
if ( !SDRValueArray ) {
sprintf( szErrorMessage, "Error: system out of memory.\n\n" );
printf( "%s", szErrorMessage );
exit( OUT_OF_MEMORY );
}
Repeat = ( int ** ) calloc( iSVFCount, sizeof( int * ) );
if ( !Repeat ) {
sprintf( szErrorMessage, "Error: system out of memory.\n\n" );
printf( "%s", szErrorMessage );
exit( OUT_OF_MEMORY );
}
for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) {
strcpy( szCommandLineArg, argv[ iCommandLineIndex ] );
strlwr( szCommandLineArg );
if ( !strcmp( szCommandLineArg, "-help" ) || !strcmp( szCommandLineArg, "-h" ) ) {
PrintHelp();
exit( OK_SHOW_HELP );
}
else if ( !strcmp( szCommandLineArg, "-full" ) || !strcmp( szCommandLineArg, "-f" ) ) {
iFullVMEOption = 1;
}
else if ( !strcmp( szCommandLineArg, "-loop" ) || !strcmp( szCommandLineArg, "-l" ) ) {
iLoopVMEOption = 1;
}
else if ( !strcmp( szCommandLineArg, "-infile" ) || !strcmp( szCommandLineArg, "-if" ) ) {
iRetCode = GetSVFInformation( &iCommandLineIndex, &iCurrentSVFCount, argc, argv, szErrorMessage );
if ( iRetCode < 0 ) {
printf( "%s", szErrorMessage );
if ( iRetCode == ERR_COMMAND_LINE_SYNTAX ) {
PrintHelp();
}
exit( iRetCode );
}
}
else if ( !strcmp( szCommandLineArg, "-bypass" ) || !strcmp( szCommandLineArg, "-by" ) ) {
if ( ++iCommandLineIndex >= argc ) {
sprintf( szErrorMessage, "Error: missing bypass length.\n\n" );
printf( "%s", szErrorMessage );
exit( ERR_COMMAND_LINE_SYNTAX );
}
strcpy( szCommandLineArg, argv[ iCommandLineIndex ] );
for ( iTemp = 0; iTemp < strlen( szCommandLineArg ); iTemp++ ) {
if ( !isdigit( szCommandLineArg[ iTemp ] ) ) {
sprintf( szErrorMessage, "Error: bypass length %s is not a number.\n\n", szCommandLineArg );
printf( "%s", szErrorMessage );
exit( ERR_COMMAND_LINE_SYNTAX );
}
}
strcpy( cfgChain[ iCurrentSVFCount ].name, "JTAG" );
strcpy( cfgChain[ iCurrentSVFCount ].Svffile, "" );
cfgChain[ iCurrentSVFCount ].inst = atoi( szCommandLineArg );
strcpy( cfgChain[ iCurrentSVFCount ].Vendor, "lattice" );
strcpy( cfgChain[ iCurrentSVFCount ].Frequency, "1m" );
cfgChain[ iCurrentSVFCount ].iVerifyUES = 0;
iCurrentSVFCount++;
}
else if ( !strcmp( szCommandLineArg, "-outfile" ) || !strcmp( szCommandLineArg, "-of" ) ) {
if ( ++iCommandLineIndex >= argc ) {
sprintf( szErrorMessage, "Error: missing output file name.\n\n" );
printf( "%s", szErrorMessage );
exit( ERR_COMMAND_LINE_SYNTAX );
}
strcpy( szVMEFilename, argv[ iCommandLineIndex ] );
fptrVMEFile = fopen( szVMEFilename, "w" );
if ( fptrVMEFile == NULL ) {
sprintf( szErrorMessage, "Error: unable to write to output file %s\n\n", szVMEFilename );
printf( "%s", szErrorMessage );
exit( FILE_NOT_VALID );
}
remove( szVMEFilename );
}
else {
sprintf( szErrorMessage, "Error: %s is an unrecognized or misplaced argument.\n\n", szCommandLineArg );
printf( "%s", szErrorMessage );
PrintHelp();
exit( ERR_COMMAND_LINE_SYNTAX );
}
}
if ( szVMEFilename[0] == '\0' ) {
/* If no output file then use the name of the first SVF file */
for ( iTemp = 0; iTemp < iCurrentSVFCount; iTemp++ ) {
if ( !stricmp( cfgChain[ iTemp ].name, "SVF" ) ) {
break;
}
}
strcpy( szCommandLineArg, cfgChain[ iTemp ].Svffile );
szTmp = &szCommandLineArg[ strlen( szCommandLineArg ) - 4 ];
if ( szTmp ) {
*szTmp = '\0';
}
sprintf( szVMEFilename, "%s.vme", szCommandLineArg );
}
/* Create the temporary verify UES file if it has been selected */
for ( iTemp = 0; iTemp < iCurrentSVFCount; iTemp++ ) {
if ( cfgChain[ iTemp ].iVerifyUES == 1 ) {
iRetCode = CreateVerifyUESFile( cfgChain[ iTemp ].Svffile, szVMEFilename, szErrorMessage );
if ( iRetCode < OK ) {
printf( szErrorMessage );
exit( iRetCode );
}
else if ( iRetCode == MISSING_UES_COMMENTS ) {
sprintf( szErrorMessage, "Warning: svf file %s does not have USERCODE verification comments. ", cfgChain[ iTemp ].Svffile );
strcat( szErrorMessage, "Continue generating VME file without USERCODE verification option.\n\n" );
printf( szErrorMessage );
}
else if ( iRetCode == MISSING_IDCODE_COMMENTS ) {
sprintf( szErrorMessage, "Warning: svf fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -