/*******************************************************/ /* file: ports.c */ /* abstract: This file contains the routines to */ /* output values on the JTAG ports, to read */ /* the TDO bit, and to read a byte of data */ /* from the prom */ /* */ /*******************************************************/ #include "ports.h" #include "util.h" void setPort(short p,short val) { static char *str={"SetPort(12,12)"}; //itoa_q(p,str+8,2,16); //itoa_q(val,str+11,2,16); //printl(str);printl("\n"); switch(p) { case TMS: if(val) jtag_tms_on(); else jtag_tms_off(); break; case TDI: if(val) jtag_tdi_on(); else jtag_tdi_off(); break; case TCK: if(val) jtag_tck_off(); else jtag_tck_on(); break; } } /* toggle tck LH */ void pulseClock() { setPort(TCK,0); /* set the TCK port to low */ setPort(TCK,1); /* set the TCK port to high */ } /* read in a byte of data from the prom */ char *gjtag_fptr=0; void jtag_setFile(char* fptr) { gjtag_fptr = fptr; return 0; } void readByte(unsigned char *data) { *data=*gjtag_fptr++; } /* read the TDO bit from port */ unsigned char readTDOBit() { return jtag_tdo(); } /* Wait at least the specified number of microsec. */ /* Use a timer if possible; otherwise estimate the number of instructions */ /* necessary to be run based on the microcontroller speed. For this example */ /* we pulse the TCK port a number of times based on the processor speed. */ void waitTime(long microsec) { delay(microsec); #if 0 static long tckCyclesPerMicrosec = 1; long tckCycles = microsec * tckCyclesPerMicrosec; long i; /* For systems with TCK rates >= 1 MHz; This implementation is fine. */ for ( i = 0; i < tckCycles; ++i ) { pulseClock(); } #if 0 /* For systems with TCK rates << 1 MHz; Consider this implementation. */ if ( microsec >= 50L ) { /* Make sure TCK is low during wait for XC18V00/XCF00 */ /* Or, a running TCK implementation as shown above is an OK alternate */ setPort( TCK, 0 ); /* Use Windows Sleep(). Round up to the nearest millisec */ _sleep( ( microsec + 999L ) / 1000L ); } else /* Satisfy Virtex-II TCK cycles */ { for ( i = 0; i < microsec; ++i ) { pulseClock(); } } #endif #if 0 /* If Virtex-II support is not required, then this implementation is fine */ /* Make sure TCK is low during wait for XC18V00/XCF00 */ /* Or, a running TCK implementation as shown above is an OK alternate */ setPort( TCK, 0 ); /* Use Windows Sleep(). Round up to the nearest millisec */ _sleep( ( microsec + 999L ) / 1000L ); #endif #endif }