📄 svf2vme.c
字号:
headers[3].value += chain[i].inst;
}
for (i = 0; i < 4; i++) {
write(headers[i].types);
/* 11/08/01 fix the single device SVF file map into chain problem*/
/* TDI (00000); is added to fix the problem*/
if (headers[i].value) {
write((unsigned char)(headers[i].value));
write(TDI);
if (headers[i].value%8)
temp=headers[i].value/8+1;
else
temp = headers[i].value/8;
if ((headers[i].types==HIR)||(headers[i].types==TIR))
xchar = 0xFF;
else
xchar = 0x00;
for (j=0; j<temp; j++)
write(xchar);
/* continue is written because the header and trailer */
/* for one chip may also possibly be written with continue, */
/* thus preserving symmetry */
write(CONTINUE);
}
else {
write(0x00);
}
}
}
/************************************************************************
* The SVF execution loop *
*************************************************************************/
SVF_string = NULL;
while ( ( rcode == 0 ) && ( ( rcode = Token( " \n" ) ) == 0 ) ) {
/* Extracts the SDR, SIR, RUNTEST, etc... Instruction */
for ( i = 0; i < ScanTokenMax; i++ ) {
if ( stricmp( scanTokens[ i ].text, SVF_string ) == 0 ) {
break;
}
}
if ( i >= ScanTokenMax ) {
return FILE_ERROR;
}
opcode = scanTokens[ i ].token;
switch (opcode){
case SDR:
rcode = ScanCom(1, options);
break;
case SIR:
rcode = ScanCom(0, options);
break;
case STATE:
rcode = STATECom();
break;
case RUNTEST:
rcode = RUNTESTCom();
break;
case TRST:
rcode = Token(" ");
break; /*throw it away*/
case ENDIR:
rcode = Token( " " );
write( opcode );
for ( j = 0; j < StableStateMax; j++ ) {
if ( !stricmp( SVF_string, stableStates[ j ].text ) ) {
break;
}
}
if ( j == StableStateMax ) {
write( IRPAUSE );
}
else {
write( ( char ) j );
CurEndIR = j;
}
break;
case ENDDR:
rcode = Token(" ");
write(opcode);
for (j = 0; j < StableStateMax; j++)
if (stricmp(SVF_string,
stableStates[j].text) == 0)
break;
if (j == StableStateMax)
write(DRPAUSE);
else {write((char)j); CurEndDR = j;}
break;
case REPEAT:
write(HEAP);
write(SECUREHEAP);
globalBitArrayCounter = 0;
if (numBitArray != NULL) {
free (numBitArray);
numBitArray = NULL;
}
arrayCounter = 0;
rcode = Token(" ");
write(opcode);
scan_len = atol(SVF_string);
ConvNumber( scan_len );
allocateFlag = 1;
inRepeat = 1;
heapsize = 0;
break;
case ENDLOOP:
write(opcode);
inRepeat = 0;
heapSizeArray[numOfRepeats] = heapsize;
numOfRepeats++;
break;
case LEFTPAREN: /* REPEAT data */
if ( !iLoopVMEOption ) {
return FILE_ERROR;
}
if ( arrayCounter < globalBitArrayCounter ) {
if ( ( dataptr = ( unsigned char * ) malloc( numBitArray[ arrayCounter ] / 8 + 2 ) ) == NULL ) {
return OUT_OF_MEMORY;
}
filler = 0;
ConvertFromHexString( numBitArray[ arrayCounter ], dataptr, &filler, 1, 0 );
convertToispSTREAM( numBitArray[ arrayCounter ], dataptr, options + 1, 1 );
arrayCounter++;
}
if ( arrayCounter >= globalBitArrayCounter ){
arrayCounter = 0;
}
if (dataptr != NULL) {
free(dataptr);
dataptr = NULL;
}
break;
case HDR:
case HIR:
case TIR:
case TDR:
if(chips > 1){
rcode = Token(";");
break;
}
rcode = Token(" ");
write(opcode); /*got the header type*/
scan_len = atol( SVF_string );
if ( scan_len == 0 ){
ConvNumber( scan_len );
}
else {/*non-zero header*/
if ( scan_len > ( long int ) ScanMax ) /*can't be larger than 64000*/
return FILE_ERROR;
rcode = TDIToken( scan_len, 3, 0 ); /* turn off compression */
} /* for header and trailers */
break; /* because compress is off */
case FREQUENCY: /* for chips > 1 */
rcode = FREQUENCYCom();
break;
case ENDDATA:
break; /* found; */
case TDI:
rcode = Token(")");
break;
case VUES:
/* Write Continue If Fail opcode */
write( opcode );
break;
default:
return FILE_ERROR;
}
}
if (scanNodes[0].mask != NULL){
free(scanNodes[0].mask);
scanNodes[0].mask = NULL;
}
if (scanNodes[1].mask != NULL){
free(scanNodes[1].mask);
scanNodes[1].mask = NULL;
}
for (i = 0; i < 4; i++){
if (scanNodes[i].tdi != NULL){
free(scanNodes[i].tdi);
scanNodes[i].tdi = NULL;
}
}
fclose(fp);
}
else if (stricmp(chain[device].name, "JTAG") == 0)
{
}
else return FILE_ERROR;
}
/*8/28/01 ht added to support flow control*/
if (options&0x02)
{write(SETFLOW),
ConvNumber(GO_NOGO);
}
write(ENDVME);
fclose(fpw);
/* parse VME file to add heapsizes */
if (numOfRepeats) {
rcode = InsertHeapSize(heapSizeArray, numOfRepeats, vmefilename);
}
if (numBitArray != NULL) {
free (numBitArray);
numBitArray = NULL;
}
if (heapSizeArray != NULL) {
free (heapSizeArray);
heapSizeArray = NULL;
}
return rcode;
}
/************************************************************************
*
* ExeSTATECommand()
* execute a subset of the SVF STATE command
*
* SVF STATE command sends the TAP to the selected *stable* state.
* The stable state are RESET, IDLE, IRPAUSE, DRPAUSE.
* 9/28/00 ht added support to multiple transistion among stable states.
* example: STATE RESET IDLE; It is translated into
* STATE RESET;
* STATE IDLE;
*
*************************************************************************/
short int STATECom()
{
short int i, rcode;
rcode = Token(" ");
while ( ( rcode == 0 ) && ( SVF_string[ 0 ] != ';' ) ) {
for ( i = 0; i < StableStateMax; i++ ) {
if ( stricmp( SVF_string, stableStates[ i ].text ) == 0) {
break;
}
}
if ( i == StableStateMax ) {
rcode = FILE_ERROR;
break;
}
else {
write( STATE );
write( ( char ) i );
}
rcode = Token(" ");
}
return rcode;
}
/************************************************************************
* *
* ExeRUNTESTCommand() *
* *
* The time is expressed in 16 bits integer in uS or mS. *
* 03/02/00 Howard Tang Break RUNTEST up into STATE, TCK and WAIT opcode *
* *
************************************************************************/
short int RUNTESTCom()
{
short int i, rcode, elements;
long int test_time_read = 0;
float float_time = 0;
float fDelayTime = 0, fFrequency = 0;
static default_state = IDLE;
rcode = 0;
elements = -1;
write(STATE);
if ( frequency == 0 ) {
frequency = 1000L; /*default frequency to 1MHZ */
}
while ( ( elements < 3 ) && ( ( rcode = Token(" ") ) == 0 ) ) {
switch ( elements ) {
case 2:
if ( stricmp( SVF_string, "MAXIMUM" ) == 0 ) {
/*throw away MAXIMUM*/
for ( i = 0; i < 3; i++ ) {
rcode = Token( " " );
}
}
else if ( ( stricmp( SVF_string, "ENDSTATE" ) == 0 ) || ( SVF_string[ 0 ] == ';' ) ) {
}
else {
elements = 0; /*found min time in SEC, throw out TCK*/
}
default:
break;
}
switch ( ++elements ) {
case 0:
/*first element is a STATE*/
for ( i = 0; i < StableStateMax; i++ ) {
if ( stricmp( SVF_string, stableStates[ i ].text ) == 0 ) {
break;
}
}
if ( i < StableStateMax ) {
write( ( char ) i ); /*it is a STATE */
default_state = i; /*keep it for next RUNTEST */
}
else {
write( ( char ) default_state ); /*it is a number, so use default*/
++elements; /*flag element 1 is found*/
}
if ( elements == 0 ) {
break; /*STATE found*/
}
case 1: /*element 1 is a number*/
if ( ( strchr( SVF_string, 'E' ) != NULL ) || ( strchr( SVF_string, 'e' ) != NULL ) ) {
float_time = ( float ) atof( SVF_string );
}
else {
test_time_read = atoi( SVF_string );
}
break;
case 2: /*element 2 is either TCK or SEC*/
if ( 0 == stricmp( SVF_string, "TCK" ) ) {
/* 1/19/04 If TCK count is greater than 1000, then write only 3 TCKs and convert it to delay */
if ( test_time_read > 1000 ) {
write( TCK );
ConvNumber( 3 );
/* 1/21/04 fFrequency expresses the frequency of TCK in terms of Hz */
fFrequency = 1 / ( ( float ) frequency * 1000 );
/* 1/21/04 Convert TCK into delay based on the frequency of TCK */
fDelayTime = ( float ) test_time_read * fFrequency;
/* 1/21/04 Convert delay from seconds to microseconds */
fDelayTime *= 1000000;
/* 1/26/04 If delay is greater than 1000 microseconds, then encode
the MSB to 1. */
if ( fDelayTime > 1000 ) {
fDelayTime = ( float ) ( fDelayTime / 1000 );
/* 1/26/04 The delay time must be split over several delays if it
exceeds the range of signed short integers, which is 32767. */
while ( fDelayTime > 32767 ) {
write( WAIT );
/* 1/26/04 Encode MSB to 1. VME processor will handle the decoding
by turning off the MSB and multiplying it by 1000. */
ConvNumber( 32767 + 0x8000 );
fDelayTime -= 32767;
}
fDelayTime += 0x8000;
}
write( WAIT );
ConvNumber( fDelayTime );
}
else {
write( TCK );
ConvNumber( test_time_read );
}
}
else if ( 0 == stricmp( SVF_string, "SEC" ) ) {
/* 1/21/04 Convert delay time to microseconds */
fDelayTime = float_time * 1000000;
/* 1/26/04 If delay is greater than 1000 microseconds, then encode
the MSB to 1. */
if ( fDelayTime > 1000 ) {
fDelayTime = ( float ) ( fDelayTime / 1000 );
/* 1/26/04 The delay time must be split over several delays if it
exceeds the range of signed short integers, which is 32767. */
while ( fDelayTime > 32767 ) {
write( WAIT );
/* 1/26/04 Encode MSB to 1. VME processor will handle the decoding
by turning off the MSB and multiplying it by 1000. */
ConvNumber( 32767 + 0x8000 );
fDelayTime -= 32767;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -