?? vme2hex.c
字號:
/****************************************************************************
vme2hex.c
Convert an VME File Into ispHEX Array.
Lattice Semiconductor Corp. Copyright 1996-2003
vme2hex.exe comprises of two modules:
vme2hex.c The front end of converting a binary file to HEX file.
hex_core.c The ispVM(tm) is reduced to be an VME file parser.
V1.01 Howard Tang 11/19/96 Change count from unsigned int to long int.
V1.02 Howard Tang 11/25/96 Correct size of buffer.
Fix the output file name to be istream.hex
V1.03 Howard Tang 6/23/97 Fix the large(>64K bytes) .isp file problem.
V7.00 Howard Tang 9/16/98 Update to support ispSTREAM with Token files
for ispCODE V7.0.
File type code is 0xFF.
Howard Tang 10/5/98 Remove the buffer[] array from the istream.hex
for SLIM ispSTREAM. Only one byte of working
memory is needed.
V8.0 Howard Tang 3/19/00 Add support to ispVM Embedded files.
use ispVM(tm) to parse the entire VME file
for breaking up the file into multiple blocks
V9.0 Howard Tang 10/22/01 Add support to multiple device SVF file.
V10.0 tnt 03/13/02 Supports VME 2.0. Understands looping constructs
and keywords: CRC, CRCMASK, READ, and READMASK.
* 4/28/03 Update to v10.1. v10.1 supports Continue If Fail (USERCODE *
* Verification). *
********************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "VMOpcode.h"
FILE *fpr;
extern unsigned short tdodata; /*shift out data from device and compare*/
extern unsigned short maskdata; /*mask data exist or not*/
extern unsigned short tdidata;
extern unsigned short hdrdata;
extern unsigned short tdrdata;
extern unsigned short hirdata;
extern unsigned short tirdata;
extern unsigned short heapdata;
/*2/15/02 tnt added to support 1532*/
extern unsigned short crcdata;
extern unsigned short cmaskdata;
extern unsigned short DataType; /*holds the data type of the current row*/
extern unsigned short dmaskdata;
/*prototype */
extern char ispVMCode(void);
short int main(short int argc, char *argv[])
{
FILE *fpw,*fp;
char *ptr,
filename[300],
str[300];
int i;
unsigned char data;
unsigned char CompressFlag = 0x00;
/* V1.03 unsigned short*/
long int temp, temp1; /*V1.02 Add temp1*/
short int vmeArrays = 0;
long int ByteCount = VMEHEXMAX;
long int count = 0L; /*V1.01 the byte size of the ispSTREAM file*/
printf("\n Lattice Semiconductor Corp.\n");
printf("\n ispVM Embedded File to HEX String Converter V10.1 Copyright 2000-2004\n");
if ((argc < 2) ||(argc > 3))
{
printf("\nUsage: vme2hex [drive:][path]vme_filename [option]\n");
printf("Example: vme2hex my_file.vme\n");
printf("\n");
printf("vme_filename The VME File Created By svf2vme.exe \n");
exit(1);
}
if ((fpr = fopen(argv[1], "rb")) == NULL)
{
printf("\n%s File not found!\n", argv[1]);
exit(1);
}
strcpy(str, argv[1]);
ptr = strchr(str, '.');
if (ptr)
*ptr = '\0';
sprintf(filename, "%s.vme", str);
strcpy(str, argv[1]);
if (stricmp(str, filename))
{
printf("\nFile %s Is Not An ispVM Embedded File\n", str);
exit(1);
}
strcpy(str, argv[1]);
ptr = strchr(str, '.');
if (ptr)
*ptr = '\0';
/* sprintf(filename, "%s.hex", str); */
sprintf(filename, "vme_file.h"); /*V1.02 fix the output file name*/
if ((fpw = fopen(filename, "w")) == NULL)
{
printf("\n%s File not found!\n", filename);
exit(1);
}
data = fgetc(fpr);
/*Check the ispSTREAM file type*/
count = 1;
if (data == 0x00)
fprintf(fpw, "\n/*SLIM ispSTREAM File on ISP programming.*/");
else if (data == '_')
fprintf(fpw, "\n/*ispVM Embedded File for ispVM*/");
else if (data == 0x01)
fprintf(fpw, "\n/*SLIM ispSTREAM File on ispJTAG programming.*/");
else if (data == 0x02)
fprintf(fpw, "\n/*Super SLIM ispSTREAM File on ISP programming.*/");
else if (data == 0x03)
fprintf(fpw, "\n/*Super SLIM ispSTREAM File on ispJTAG programming.*/");
else if (data == 0x0F)
fprintf(fpw, "\n/*ispSTREAM File on ISP programming.*/");
else if (data == 0xF0)
fprintf(fpw, "\n/*ispSTREAM File on ispJTAG programming.*/");
else if (data == 0x0A)
fprintf(fpw, "\n/*super ispSTREAM File on ISP programming.*/");
else if (data == 0x0B)
fprintf(fpw, "\n/*super ispSTREAM File on ispJTAG programming.*/");
else if (data == 0xFF) /*V1.04*/
fprintf(fpw, "\n/*ispSTREAM File with Tokens for ispCODE V7.0.*/\n");
else
{
printf("nFailed: The File (%s) is not Valid for ispCODE or ispVM.\n", argv[1]);
fclose(fpr);
exit(1);
}
/*Read the header information*/
if (data == '_')
{
} /*ispVM Embedded*/
else if (data < 0xFF) /*V1.07*/
{
if (((char)data >= 0x00) &&((char)data <= 0x04))
temp =fgetc(fpr);
else if ((data == 0x0F) ||(data == 0xF0))
temp = fgetc(fpr) + 1;
else temp = fgetc(fpr) + 1;
/*ChainLength*/
count++;
fprintf(fpw, "\n/*The number of devices in the chain is %d.*/", temp);
/*ErasePulse*/
temp = fgetc(fpr) * 0x100;
temp += fgetc(fpr);
count += 2;
fprintf(fpw, "\n/*The bulk erase time is %d mS.*/", temp);
/*ProgramPulse*/
fprintf(fpw, "\n/*The row programming time is %d mS.*/", fgetc(fpr));
/*RowLength*/
temp = fgetc(fpr) * 0x100;
temp += fgetc(fpr);
count += 2;
if (((char)data >= 0x00) &&((char)data <= 0x04))
temp &= 0x0FFF; /*Mask out the control bits*/
fprintf(fpw, "\n/*The number of rows for programming is %d.*/", temp);
/*DataSize*/
temp1 = fgetc(fpr) * 0x100; /*V1.02*/
temp1 += fgetc(fpr); /*V1.02*/
count += 2;
fprintf(fpw, "\n/*The combined length of the data registers %d.*/", temp1);
temp = fgetc(fpr) * 0x100;
temp += fgetc(fpr);
count += 2;
if (((char)data >= 0x00) &&((char)data <= 0x04))
{
/*IDStreamLength*/
fprintf(fpw, "\n/*The combined length of all the ID registers %d.*/", temp);
}
else /* if ((data == 0x0F) ||(data == 0xF0))
*/
{
/*EraseRowEnd*/
fprintf(fpw, "\n/*The location where bulk erase verify end is %d.*/", temp);
temp = 0; /*V1.02*/
}
if (data > 0x03) /*7.0 buffer[] array is not needed for V7.0 SLIM ispSTREAM*/
{
if (temp1 >= temp) /*V1.02 allocate sufficient memory to process ID string
or Data string*/
fprintf(fpw, "\nunsigned char buffer[%d]; /*allocate memory to process the data*/\n", temp1/8 + 1);
else
fprintf(fpw, "\nunsigned char buffer[%d]; /*allocate memory to process the data*/\n", temp/8 + 1);
}
fprintf(fpw, "\n");
} /*V1.04*/
if (data == 0xFF) /*7.00 Token base ispSTREAM found*/
{
fgetc(fpr); /*discard the MEM token*/
temp = fgetc(fpr) * 0x100;
temp += fgetc(fpr);
count += 3;
fprintf(fpw, "\nunsigned char MaskData[%d]; /*memory to hold mask data*/\n", temp);
fprintf(fpw, "\nunsigned char InData[%d]; /*memory to hold input data*/\n", temp);
fprintf(fpw, "\nunsigned char OutData[%d]; /*memory to hold output data*/\n", temp);
}
else if (data == '_')
{
/*ispVM embedded*/
for (i = 0; i < 7; i++)
fgetc(fpr); /*skipp __VME1.0*/
CompressFlag = fgetc(fpr);
if (CompressFlag == 0xf1)
DataType |= COMPRESS;
else if (CompressFlag == 0xf2)
DataType &= ~COMPRESS;
ispVMCode();
count=0;
fclose(fpr);
/*restore the pointer to the beginning of the file*/
fpr = fopen(argv[1], "rb");
do
{
fgetc(fpr);
count++; /*count all the bytes till the end*/
}while (!feof(fpr));
if(maskdata)
fprintf(fpw, "\nunsigned char MaskBuf[%d]; /*memory to hold mask data*/\n", maskdata/8+1);
else
fprintf(fpw, "\nunsigned char *MaskBuf=NULL; /*memory to hold mask data*/\n");
if(tdidata)
fprintf(fpw, "\nunsigned char TdiBuf[%d]; /*memory to hold input data*/\n", tdidata/8+1);
else
fprintf(fpw, "\nunsigned char *TdiBuf=NULL; /*memory to hold output data*/\n");
if(tdodata)
fprintf(fpw, "\nunsigned char TdoBuf[%d]; /*memory to hold output data*/\n", tdodata/8+1);
else
fprintf(fpw, "\nunsigned char *TdoBuf=NULL; /*memory to hold output data*/\n");
if(hdrdata)
fprintf(fpw, "\nunsigned char HdrBuf[%d]; /*memory to hold output data*/\n", hdrdata/8+1);
else
fprintf(fpw, "\nunsigned char *HdrBuf=NULL; /*memory to hold output data*/\n");
if(tdrdata)
fprintf(fpw, "\nunsigned char TdrBuf[%d]; /*memory to hold output data*/\n", tdrdata/8+1);
else
fprintf(fpw, "\nunsigned char *TdrBuf=NULL; /*memory to hold output data*/\n");
if(hirdata)
fprintf(fpw, "\nunsigned char HirBuf[%d]; /*memory to hold output data*/\n", hirdata/8+1);
else
fprintf(fpw, "\nunsigned char *HirBuf=NULL; /*memory to hold output data*/\n");
if(tirdata)
fprintf(fpw, "\nunsigned char TirBuf[%d]; /*memory to hold output data*/\n", tirdata/8+1);
else
fprintf(fpw, "\nunsigned char *TirBuf=NULL; /*memory to hold output data*/\n");
if(heapdata)
fprintf(fpw, "\nunsigned char HeapBuf[%d]; /*memory to hold heap data*/\n", heapdata);
else
fprintf(fpw, "\nunsigned char *HeapBuf=NULL; /*memory to hold heap data*/\n");
if (crcdata)
fprintf(fpw, "\nunsigned char CRCBuf[%d]; /*memory to hold CRC data*/\n", crcdata/8 + 1);
else
fprintf(fpw, "\nunsigned char *CRCBuf=NULL; /*memory to hold CRC data*/\n");
if (cmaskdata)
fprintf(fpw, "\nunsigned char CMASKBuf[%d]; /*memory to hold CMASK data*/\n", cmaskdata/8 + 1);
else
fprintf(fpw, "\nunsigned char *CMASKBuf=NULL; /*memory to hold CMASK data*/\n");
if (dmaskdata)
fprintf(fpw, "\nunsigned char DMASKBuf[%d]; /*memory to hold DMASK data*/\n", dmaskdata/8 + 1);
else
fprintf(fpw, "\nunsigned char *DMASKBuf=NULL; /*memory to hold DMASK data*/\n");
fclose(fpr);
}
/*restore the pinter to the beginning of the file*/
fpr = fopen(argv[1], "rb");
if (data == '_'){
if(count%VMEHEXMAX)
vmeArrays = (short int)(count/VMEHEXMAX +1);
else
vmeArrays = count/VMEHEXMAX;
}
else
fprintf(fpw, "unsigned char ispstream[%ld] = {\n", count); /*v1.01*/
for(i=1;i<=vmeArrays;i++){
if((count - VMEHEXMAX)>0){
ByteCount = VMEHEXMAX;
count -= VMEHEXMAX;
}
else
ByteCount = count;
sprintf(filename, "vme%d.c",i);
if ((fp = fopen(filename, "w")) == NULL)
{
printf("\n%s File not found!\n", filename);
exit(1);
}
fprintf(fpw, "\nextern unsigned char vme%d[%ldL];\n", i,ByteCount);
fprintf(fp, "\nunsigned char vme%d[%ldL] = {\n", i,ByteCount);
if(ByteCount == count)
ByteCount -= 1;
for (temp = 1; temp < (ByteCount); temp++)
{
fprintf(fp, "0x%02X, ", fgetc(fpr));
if (temp%15 == 0)
fprintf(fp, "\n"); /*make the file more readable*/
}
fprintf(fp, "0x%02X", fgetc(fpr));
fprintf(fp, "};\n");
fclose(fp);
}
if (data == '_'){
fprintf(fpw, "\nshort int vmearrays = %d;\n",vmeArrays);
fprintf(fpw, "unsigned char *vmeArray[%d] = {",vmeArrays);
for(i=1;i<= vmeArrays;i++){
if(i== vmeArrays)
fprintf(fpw, "vme%d",i);
else
fprintf(fpw, "vme%d, ",i);
}
fprintf(fpw, "};\n");
}
fclose(fpw);
fclose(fpr);
if (data == '_'){
printf("\nispVM Embedded Files Generated:\n");
for(i=1;i<=vmeArrays;i++){
sprintf(filename, "vme%d.c",i);
printf("\t-%s\n",filename);
}
sprintf(filename, "vme_file.h");
printf("\t-%s\n",filename);
}
else
printf("\nispHEX File (%s) Generated.\n", filename);
return (0);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -