/*******************************************************/ /* 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 "stdio.h" /*#include "prgispx.h"*/ #include /* for rtems types. eg. for uint32_t that Read_timer returns */ #include /* for benchmark_timer_read( ) 4.9.1 */ #include "ports.h" extern FILE *in; extern int BoardId; #define DATA_OFFSET (unsigned short) 0 #define STATUS_OFFSET (unsigned short) 1 #define CONTROL_OFFSET (unsigned short) 2 #define IPSBAR (0x40000000) /* Default base address for the Edgeport and the Chip Select Module */ #define PORTTDP (IPSBAR+0x00100038) /* General Purpose Input Port TD */ #define PORTTD (IPSBAR+0x00100010) /* General Purpose IO Port TD */ volatile unsigned char *jtagportout = (unsigned char *)PORTTD; volatile unsigned char *jtagportin = (unsigned char *)PORTTDP; static unsigned long out_word; /*BYTE *xsvf_data=0;*/ void setPort(short p,short val) { volatile unsigned long value; /* 0 => Input TDO 1 => Output TDI 2 => Output TMS 3 => Output TCK */ if (p==TMS) out_word = ((out_word & 0x0AL) | (unsigned char) val << 2); if (p==TDI) out_word = ((out_word & 0x0CL) | (unsigned char) val << 1); if (p==TCK) { out_word = ((out_word & 0x06L) | (unsigned char) val << 3); value = out_word & 0x0EL; /* printf("Out Word 0x%1.1X \n",value); */ *jtagportout = value; } } /* 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 file */ void readByte(unsigned char *data) { fscanf(in,"%c",data); /**data=*xsvf_data++;*/ } /* read the TDO bit from port */ unsigned char readTDOBit() { volatile unsigned int value; value = *jtagportin ; /* printf("In Word 0x%1.1X \n",value); */ if ((value & 0x1) == 0) return( (unsigned char) 0 ); else return( (unsigned char) 1 ); } /* 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) { #ifdef NEVER_DONE /* 10/3/2008 new way */ unsigned start = benchmark_timer_read(); while (benchmark_timer_read() - start < microsec ) ; #endif static long tckCyclesPerMicrosec = 2; long tckCycles = microsec * tckCyclesPerMicrosec; long i; /* printf("MicroSec %5d\n",microsec);*/ /* For systems with TCK rates >= 1 MHz; This implementation is fine. */ for ( i = 0; i < tckCycles; ++i ) { pulseClock(); } } void toggle(long times) { long i; for (i = 0; i