Paul Clarke
/
JTAG_Programmer_copy
Currently Non-working JTAG programmer
ports.c@0:a23e8a7c9275, 2012-06-28 (annotated)
- Committer:
- monpjc
- Date:
- Thu Jun 28 13:36:55 2012 +0000
- Revision:
- 0:a23e8a7c9275
new
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
monpjc | 0:a23e8a7c9275 | 1 | /*******************************************************/ |
monpjc | 0:a23e8a7c9275 | 2 | /* file: ports.c */ |
monpjc | 0:a23e8a7c9275 | 3 | /* abstract: This file contains the routines to */ |
monpjc | 0:a23e8a7c9275 | 4 | /* output values on the JTAG ports, to read */ |
monpjc | 0:a23e8a7c9275 | 5 | /* the TDO bit, and to read a byte of data */ |
monpjc | 0:a23e8a7c9275 | 6 | /* from the prom */ |
monpjc | 0:a23e8a7c9275 | 7 | /* Revisions: */ |
monpjc | 0:a23e8a7c9275 | 8 | /* 12/01/2008: Same code as before (original v5.01). */ |
monpjc | 0:a23e8a7c9275 | 9 | /* Updated comments to clarify instructions.*/ |
monpjc | 0:a23e8a7c9275 | 10 | /* Add print in setPort for xapp058_example.exe.*/ |
monpjc | 0:a23e8a7c9275 | 11 | /*******************************************************/ |
monpjc | 0:a23e8a7c9275 | 12 | #include "ports.h" |
monpjc | 0:a23e8a7c9275 | 13 | /*#include "prgispx.h"*/ |
monpjc | 0:a23e8a7c9275 | 14 | #include "mbed.h" |
monpjc | 0:a23e8a7c9275 | 15 | DigitalOut TMS_pin(p5); |
monpjc | 0:a23e8a7c9275 | 16 | DigitalOut TDI_pin(p6); |
monpjc | 0:a23e8a7c9275 | 17 | DigitalOut TCK_pin(p7); |
monpjc | 0:a23e8a7c9275 | 18 | DigitalIn TDO_pin(p8); |
monpjc | 0:a23e8a7c9275 | 19 | |
monpjc | 0:a23e8a7c9275 | 20 | extern FILE *fp; |
monpjc | 0:a23e8a7c9275 | 21 | static int g_iTCK = 0; /* For xapp058_example .exe */ |
monpjc | 0:a23e8a7c9275 | 22 | static int g_iTMS = 0; /* For xapp058_example .exe */ |
monpjc | 0:a23e8a7c9275 | 23 | static int g_iTDI = 0; /* For xapp058_example .exe */ |
monpjc | 0:a23e8a7c9275 | 24 | |
monpjc | 0:a23e8a7c9275 | 25 | /*BYTE *xsvf_data=0;*/ |
monpjc | 0:a23e8a7c9275 | 26 | |
monpjc | 0:a23e8a7c9275 | 27 | |
monpjc | 0:a23e8a7c9275 | 28 | /* setPort: Implement to set the named JTAG signal (p) to the new value (v).*/ |
monpjc | 0:a23e8a7c9275 | 29 | /* if in debugging mode, then just set the variables */ |
monpjc | 0:a23e8a7c9275 | 30 | void setPort(short p,short val) |
monpjc | 0:a23e8a7c9275 | 31 | { |
monpjc | 0:a23e8a7c9275 | 32 | /* Printing code for the xapp058_example.exe. You must set the specified |
monpjc | 0:a23e8a7c9275 | 33 | JTAG signal (p) to the new value (v). See the above, old Win95 code |
monpjc | 0:a23e8a7c9275 | 34 | as an implementation example. */ |
monpjc | 0:a23e8a7c9275 | 35 | if (p==TMS) |
monpjc | 0:a23e8a7c9275 | 36 | { |
monpjc | 0:a23e8a7c9275 | 37 | g_iTMS = val; |
monpjc | 0:a23e8a7c9275 | 38 | TMS_pin = val; |
monpjc | 0:a23e8a7c9275 | 39 | } |
monpjc | 0:a23e8a7c9275 | 40 | if (p==TDI) |
monpjc | 0:a23e8a7c9275 | 41 | { |
monpjc | 0:a23e8a7c9275 | 42 | g_iTDI = val; |
monpjc | 0:a23e8a7c9275 | 43 | TDI_pin = val; |
monpjc | 0:a23e8a7c9275 | 44 | } |
monpjc | 0:a23e8a7c9275 | 45 | if (p==TCK) |
monpjc | 0:a23e8a7c9275 | 46 | { |
monpjc | 0:a23e8a7c9275 | 47 | g_iTCK = val; |
monpjc | 0:a23e8a7c9275 | 48 | TCK_pin = val; |
monpjc | 0:a23e8a7c9275 | 49 | printf( "TCK = %d; TMS = %d; TDI = %d\n", g_iTCK, g_iTMS, g_iTDI ); |
monpjc | 0:a23e8a7c9275 | 50 | } |
monpjc | 0:a23e8a7c9275 | 51 | } |
monpjc | 0:a23e8a7c9275 | 52 | |
monpjc | 0:a23e8a7c9275 | 53 | |
monpjc | 0:a23e8a7c9275 | 54 | /* toggle tck LH. No need to modify this code. It is output via setPort. */ |
monpjc | 0:a23e8a7c9275 | 55 | void pulseClock() |
monpjc | 0:a23e8a7c9275 | 56 | { |
monpjc | 0:a23e8a7c9275 | 57 | setPort(TCK,0); /* set the TCK port to low */ |
monpjc | 0:a23e8a7c9275 | 58 | setPort(TCK,1); /* set the TCK port to high */ |
monpjc | 0:a23e8a7c9275 | 59 | } |
monpjc | 0:a23e8a7c9275 | 60 | |
monpjc | 0:a23e8a7c9275 | 61 | |
monpjc | 0:a23e8a7c9275 | 62 | /* readByte: Implement to source the next byte from your XSVF file location */ |
monpjc | 0:a23e8a7c9275 | 63 | /* read in a byte of data from the prom */ |
monpjc | 0:a23e8a7c9275 | 64 | void readByte(unsigned char *data) |
monpjc | 0:a23e8a7c9275 | 65 | { |
monpjc | 0:a23e8a7c9275 | 66 | /* pretend reading using a file */ |
monpjc | 0:a23e8a7c9275 | 67 | *data = (unsigned char)fgetc( fp ); |
monpjc | 0:a23e8a7c9275 | 68 | |
monpjc | 0:a23e8a7c9275 | 69 | } |
monpjc | 0:a23e8a7c9275 | 70 | |
monpjc | 0:a23e8a7c9275 | 71 | /* readTDOBit: Implement to return the current value of the JTAG TDO signal.*/ |
monpjc | 0:a23e8a7c9275 | 72 | /* read the TDO bit from port */ |
monpjc | 0:a23e8a7c9275 | 73 | unsigned char readTDOBit() |
monpjc | 0:a23e8a7c9275 | 74 | { |
monpjc | 0:a23e8a7c9275 | 75 | /* You must return the current value of the JTAG TDO signal. */ |
monpjc | 0:a23e8a7c9275 | 76 | return( (unsigned char) TDO_pin ); |
monpjc | 0:a23e8a7c9275 | 77 | } |
monpjc | 0:a23e8a7c9275 | 78 | |
monpjc | 0:a23e8a7c9275 | 79 | /* waitTime: Implement as follows: */ |
monpjc | 0:a23e8a7c9275 | 80 | /* REQUIRED: This function must consume/wait at least the specified number */ |
monpjc | 0:a23e8a7c9275 | 81 | /* of microsec, interpreting microsec as a number of microseconds.*/ |
monpjc | 0:a23e8a7c9275 | 82 | /* REQUIRED FOR SPARTAN/VIRTEX FPGAs and indirect flash programming: */ |
monpjc | 0:a23e8a7c9275 | 83 | /* This function must pulse TCK for at least microsec times, */ |
monpjc | 0:a23e8a7c9275 | 84 | /* interpreting microsec as an integer value. */ |
monpjc | 0:a23e8a7c9275 | 85 | /* RECOMMENDED IMPLEMENTATION: Pulse TCK at least microsec times AND */ |
monpjc | 0:a23e8a7c9275 | 86 | /* continue pulsing TCK until the microsec wait */ |
monpjc | 0:a23e8a7c9275 | 87 | /* requirement is also satisfied. */ |
monpjc | 0:a23e8a7c9275 | 88 | void waitTime(long microsec) |
monpjc | 0:a23e8a7c9275 | 89 | { |
monpjc | 0:a23e8a7c9275 | 90 | wait(microsec); |
monpjc | 0:a23e8a7c9275 | 91 | } |