/*******************************************************/ /* 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 "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. 2009/04/09 dayle The story: the Xilinx has "microsec". It is real. The problem is happening that RTEMS is seeing "microsec" and responding much slower. So one fix is to change tckCyclesPerMicrosec from 2 to 1. This does reduce the programming time from the order of 1 hour to 1/2 hour. Better is to replace the loop with pulseClock to be a call to rtems wait a given number of ticks/microsec. */ void waitTime(long microsec) { /*static long tckCyclesPerMicrosec = 2;*/ static long tckCyclesPerMicrosec = 1; /* 4/9/9 change. rtems4.9.1 ok, but slower */ long tckCycles = microsec * tckCyclesPerMicrosec; long i; /*printf("MicroSec %5ld\n",microsec);*/ /* For systems with TCK rates >= 1 MHz; This implementation is fine. */ for ( i = 0; i < tckCycles; ++i ) { pulseClock(); } /* Alternative to pulseClock() for loop http://www.rtems.com/onlinedocs/releases/rtemsdocs-4.9.1/share/rtems/html/c_user/c_user00082.html Included by rtems.h. How long is a tick? rtems_status_code rtems_task_wake_after( rtems_interval ticks); */ /*rtems_task_wake_after( 1 ); 2011/03/14 dayle changed from 100 -> 1 this wrote 141750 bytes, then wrote error on the verify, reporting capture as all zeros. Therefore, go back to pulseClock */ } void toggle(long times) { long i; for (i = 0; i