/* tidEMload.c - "Emergency" JTAG loading via VME for the TID */ #include #include #include #ifdef VXWORKS #include "vxCompat.h" #else #include "jvme.h" #endif #include "tsLib.h" extern volatile struct TS_A24RegStruct *TSp; void EMload(char *filename); #ifndef VXWORKS int main(int argc, char *argv[]) { int stat; char *filename; printf("\nTS Emergency JTAG Loading via VME\n"); printf("----------------------------\n"); if(argc<2) { filename = "tids.svf"; } else { filename = argv[1]; } printf("\n svg filename to be used = %s\n",filename); stat = vmeOpenDefaultWindows(); if(stat != OK) goto CLOSE; stat = tsInit((5<<19),2,0); /* if(stat != OK) */ /* goto CLOSE; */ printf("Press to emergency load the JTAG to the TS via VME.\n"); getchar(); EMload(filename); CLOSE: vmeCloseDefaultWindows(); return OK; } #endif #ifdef VXWORKS void cpuDelay(unsigned long delays) { unsigned long time_0, time_1, time, diff; time_0 = sysTimeBaseLGet(); do { time_1 = sysTimeBaseLGet(); time = sysTimeBaseLGet(); // printf("Time base: %x , next call: %x , second call: %x \n",time_0,time_1, time); diff = time-time_0; } while (diff eJTAGLoad,1); /* *laddr = 1; */ } vmeWrite32(&TSp->eJTAGLoad,0); /* *laddr = 0; */ } else if (jtagType == 1) // JTAG instruction shift { // Shift_IR header: vmeWrite32(&TSp->eJTAGLoad,0); vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,0); vmeWrite32(&TSp->eJTAGLoad,0); /* *laddr = 0; */ /* *laddr = 1; */ /* *laddr = 1; */ /* *laddr = 0; */ /* *laddr = 0; */ for (iloop =0; iloop > ibit )<<1) &0x2; if (iloop == numBits -1) shData = shData +1; //set the TMS high for last bit to exit Shift_IR vmeWrite32(&TSp->eJTAGLoad, shData); /* *laddr = shData; */ } // shift _IR tail vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,0); /* *laddr = 1; // update instruction register */ /* *laddr = 0; // back to the Run_test/Idle */ } else if (jtagType == 2) // JTAG data shift { //shift_DR header vmeWrite32(&TSp->eJTAGLoad,0); vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,0); vmeWrite32(&TSp->eJTAGLoad,0); /* *laddr = 0; */ /* *laddr = 1; */ /* *laddr = 0; */ /* *laddr = 0; */ for (iloop =0; iloop > ibit )<<1) &0x2; if (iloop == numBits -1) shData = shData +1; //set the TMS high for last bit to exit Shift_DR vmeWrite32(&TSp->eJTAGLoad, shData); /* *laddr = shData; */ } // shift _DR tail vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,0); /* *laddr = 1; // update Data_Register */ /* *laddr = 0; // back to the Run_test/Idle */ } else if (jtagType == 3) // JTAG instruction shift, stop at IR-PAUSE state, though, it started from IDLE { // Shift_IR header: vmeWrite32(&TSp->eJTAGLoad,0); vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,0); vmeWrite32(&TSp->eJTAGLoad,0); /* *laddr = 0; */ /* *laddr = 1; */ /* *laddr = 1; */ /* *laddr = 0; */ /* *laddr = 0; */ for (iloop =0; iloop > ibit )<<1) &0x2; if (iloop == numBits -1) shData = shData +1; //set the TMS high for last bit to exit Shift_IR vmeWrite32(&TSp->eJTAGLoad, shData); /* *laddr = shData; */ } // shift _IR tail vmeWrite32(&TSp->eJTAGLoad,0); vmeWrite32(&TSp->eJTAGLoad,0); /* *laddr = 0; // update instruction register */ /* *laddr = 0; // back to the Run_test/Idle */ } else if (jtagType == 4) // JTAG data shift, start from IR-PAUSE, end at IDLE { //shift_DR header vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,0); vmeWrite32(&TSp->eJTAGLoad,0); /* *laddr = 1; //to EXIT2_IR */ /* *laddr = 1; //to UPDATE_IR */ /* *laddr = 1; //to SELECT-DR_SCAN */ /* *laddr = 0; */ /* *laddr = 0; */ for (iloop =0; iloop > ibit )<<1) &0x2; if (iloop == numBits -1) shData = shData +1; //set the TMS high for last bit to exit Shift_DR vmeWrite32(&TSp->eJTAGLoad, shData); /* *laddr = shData; */ } // shift _DR tail vmeWrite32(&TSp->eJTAGLoad,1); vmeWrite32(&TSp->eJTAGLoad,0); /* *laddr = 1; // update Data_Register */ /* *laddr = 0; // back to the Run_test/Idle */ } else { printf( "\n JTAG type %d unrecognized \n",jtagType); } // printf (" \n Emergency command executed \n"); } void Parse(char *buf,int *Count,char **Word) { *Word = buf; *Count = 0; while(*buf != '\0') { while ((*buf==' ') || (*buf=='\t') || (*buf=='\n') || (*buf=='"')) *(buf++)='\0'; if ((*buf != '\n') && (*buf != '\0')) { Word[(*Count)++] = buf; } while ((*buf!=' ')&&(*buf!='\0')&&(*buf!='\n')&&(*buf!='\t')&&(*buf!='"')) { buf++; } } *buf = '\0'; } void EMload(char *filename) { unsigned long ShiftData[64], lineRead; unsigned int jtagType, jtagBit, iloop; FILE *svfFile; int byteRead; char bufRead[1024],bufRead2[256]; unsigned int sndData[256]; char *Word[16], *lastn; unsigned int nbits, nbytes, extrType, i, Count, nWords, nlines; //A24 Address modifier redefined #ifdef VXWORKS sysTempeSetAM(2,0x19); #else vmeSetA24AM(0x19); #endif printf("%s: A24 memory map is set to AM = 0x19 \n",__FUNCTION__); //open the file: svfFile = fopen(filename,"r"); if(svfFile==NULL) { perror("fopen"); printf("%s: ERROR: Unable to open file %s\n",__FUNCTION__,filename); return; } printf("\n File is open \n"); //PROM JTAG reset/Idle Emergency(0,0,ShiftData); printf("%s: Emergency PROM JTAG reset IDLE \n",__FUNCTION__); taskDelay(1); //Another PROM JTAG reset/Idle Emergency(0,0,ShiftData); printf("%s: Emergency PROM JTAG reset IDLE \n",__FUNCTION__); taskDelay(1); //initialization extrType = 0; lineRead=0; // for (nlines=0; nlines<200; nlines++) while (fgets(bufRead,256,svfFile) != NULL) { lineRead +=1; if (lineRead%1000 ==0) printf(" Lines read: %d out of 787000 \n",(int)lineRead); // fgets(bufRead,256,svfFile); if (((bufRead[0] == '/')&&(bufRead[1] == '/')) || (bufRead[0] == '!')) { // printf(" comment lines: %c%c \n",bufRead[0],bufRead[1]); } else { if (strrchr(bufRead,';') ==0) { do { lastn =strrchr(bufRead,'\n'); if (lastn !=0) lastn[0]='\0'; if (fgets(bufRead2,256,svfFile) != NULL) { strcat(bufRead,bufRead2); } else { printf("\n \n !!! End of file Reached !!! \n \n"); return; } } while (strrchr(bufRead,';') == 0); //do while loop } //end of if // begin to parse the data bufRead Parse(bufRead,&Count,&(Word[0])); if (strcmp(Word[0],"SDR") == 0) { sscanf(Word[1],"%d",&nbits); nbytes = (nbits-1)/8+1; if (strcmp(Word[2],"TDI") == 0) { for (i=0; i