トランジスタ技術2011年9月号「mbed30分クッキング」のプログラムです。

Dependencies:   mbed TextLCD SDFileSystem

Committer:
shintamainjp
Date:
Mon Aug 08 10:33:50 2011 +0000
Revision:
0:42e9eb506e88
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shintamainjp 0:42e9eb506e88 1 /*******************************************************/
shintamainjp 0:42e9eb506e88 2 /* file: ports.c */
shintamainjp 0:42e9eb506e88 3 /* abstract: This file contains the routines to */
shintamainjp 0:42e9eb506e88 4 /* output values on the JTAG ports, to read */
shintamainjp 0:42e9eb506e88 5 /* the TDO bit, and to read a byte of data */
shintamainjp 0:42e9eb506e88 6 /* from the prom */
shintamainjp 0:42e9eb506e88 7 /* Revisions: */
shintamainjp 0:42e9eb506e88 8 /* 12/01/2008: Same code as before (original v5.01). */
shintamainjp 0:42e9eb506e88 9 /* Updated comments to clarify instructions.*/
shintamainjp 0:42e9eb506e88 10 /* Add print in setPort for xapp058_example.exe.*/
shintamainjp 0:42e9eb506e88 11 /*******************************************************/
shintamainjp 0:42e9eb506e88 12 #include "ports.h"
shintamainjp 0:42e9eb506e88 13 #include "mbed.h"
shintamainjp 0:42e9eb506e88 14
shintamainjp 0:42e9eb506e88 15 typedef struct work {
shintamainjp 0:42e9eb506e88 16 FILE *fp;
shintamainjp 0:42e9eb506e88 17 int done;
shintamainjp 0:42e9eb506e88 18 int total;
shintamainjp 0:42e9eb506e88 19 void (*cbfunc_progress)(int done, int total);
shintamainjp 0:42e9eb506e88 20 void (*cbfunc_waittime)(int microsec);
shintamainjp 0:42e9eb506e88 21 } work_t;
shintamainjp 0:42e9eb506e88 22
shintamainjp 0:42e9eb506e88 23 work_t work;
shintamainjp 0:42e9eb506e88 24 DigitalOut g_iTCK(p15); /* For mbed */
shintamainjp 0:42e9eb506e88 25 DigitalOut g_iTMS(p16); /* For mbed */
shintamainjp 0:42e9eb506e88 26 DigitalOut g_iTDI(p17); /* For mbed */
shintamainjp 0:42e9eb506e88 27 DigitalIn g_iTDO(p18); /* For mbed */
shintamainjp 0:42e9eb506e88 28
shintamainjp 0:42e9eb506e88 29 void initPort(FILE *fp, void (*cbfunc_progress)(int done, int total), void (*cbfunc_waittime)(int microsec)) {
shintamainjp 0:42e9eb506e88 30 work.fp = fp;
shintamainjp 0:42e9eb506e88 31 fseek(fp, 0, SEEK_END);
shintamainjp 0:42e9eb506e88 32 work.total = ftell(fp);
shintamainjp 0:42e9eb506e88 33 work.done = 0;
shintamainjp 0:42e9eb506e88 34 fseek(fp, 0, SEEK_SET);
shintamainjp 0:42e9eb506e88 35 work.cbfunc_progress = cbfunc_progress;
shintamainjp 0:42e9eb506e88 36 work.cbfunc_waittime = cbfunc_waittime;
shintamainjp 0:42e9eb506e88 37 }
shintamainjp 0:42e9eb506e88 38
shintamainjp 0:42e9eb506e88 39 /* setPort: Implement to set the named JTAG signal (p) to the new value (v).*/
shintamainjp 0:42e9eb506e88 40 /* if in debugging mode, then just set the variables */
shintamainjp 0:42e9eb506e88 41 void setPort(short p,short val) {
shintamainjp 0:42e9eb506e88 42 /*
shintamainjp 0:42e9eb506e88 43 * Modified for mbed.
shintamainjp 0:42e9eb506e88 44 */
shintamainjp 0:42e9eb506e88 45 /* Printing code for the xapp058_example.exe. You must set the specified
shintamainjp 0:42e9eb506e88 46 JTAG signal (p) to the new value (v). See the above, old Win95 code
shintamainjp 0:42e9eb506e88 47 as an implementation example. */
shintamainjp 0:42e9eb506e88 48 if (p == TCK) {
shintamainjp 0:42e9eb506e88 49 g_iTCK = val;
shintamainjp 0:42e9eb506e88 50 // printf( "TCK = %d; TMS = %d; TDI = %d\n", g_iTCK.read(), g_iTMS.read(), g_iTDI.read() );
shintamainjp 0:42e9eb506e88 51 return;
shintamainjp 0:42e9eb506e88 52 }
shintamainjp 0:42e9eb506e88 53 if (p == TMS) {
shintamainjp 0:42e9eb506e88 54 g_iTMS = val;
shintamainjp 0:42e9eb506e88 55 return;
shintamainjp 0:42e9eb506e88 56 }
shintamainjp 0:42e9eb506e88 57 if (p == TDI) {
shintamainjp 0:42e9eb506e88 58 g_iTDI = val;
shintamainjp 0:42e9eb506e88 59 return;
shintamainjp 0:42e9eb506e88 60 }
shintamainjp 0:42e9eb506e88 61 }
shintamainjp 0:42e9eb506e88 62
shintamainjp 0:42e9eb506e88 63 /* toggle tck LH. No need to modify this code. It is output via setPort. */
shintamainjp 0:42e9eb506e88 64 void pulseClock() {
shintamainjp 0:42e9eb506e88 65 setPort(TCK,0); /* set the TCK port to low */
shintamainjp 0:42e9eb506e88 66 setPort(TCK,1); /* set the TCK port to high */
shintamainjp 0:42e9eb506e88 67 }
shintamainjp 0:42e9eb506e88 68
shintamainjp 0:42e9eb506e88 69 /* readByte: Implement to source the next byte from your XSVF file location */
shintamainjp 0:42e9eb506e88 70 /* read in a byte of data from the prom */
shintamainjp 0:42e9eb506e88 71 void readByte(unsigned char *data) {
shintamainjp 0:42e9eb506e88 72 /*
shintamainjp 0:42e9eb506e88 73 * Modified for mbed.
shintamainjp 0:42e9eb506e88 74 */
shintamainjp 0:42e9eb506e88 75 *data = (unsigned char)fgetc( work.fp );
shintamainjp 0:42e9eb506e88 76
shintamainjp 0:42e9eb506e88 77 work.done++;
shintamainjp 0:42e9eb506e88 78 if (work.cbfunc_progress != NULL) {
shintamainjp 0:42e9eb506e88 79 work.cbfunc_progress(work.done, work.total);
shintamainjp 0:42e9eb506e88 80 }
shintamainjp 0:42e9eb506e88 81 }
shintamainjp 0:42e9eb506e88 82
shintamainjp 0:42e9eb506e88 83 /* readTDOBit: Implement to return the current value of the JTAG TDO signal.*/
shintamainjp 0:42e9eb506e88 84 /* read the TDO bit from port */
shintamainjp 0:42e9eb506e88 85 unsigned char readTDOBit() {
shintamainjp 0:42e9eb506e88 86 /*
shintamainjp 0:42e9eb506e88 87 * Modified for mbed.
shintamainjp 0:42e9eb506e88 88 */
shintamainjp 0:42e9eb506e88 89 return( (unsigned char) g_iTDO );
shintamainjp 0:42e9eb506e88 90 }
shintamainjp 0:42e9eb506e88 91
shintamainjp 0:42e9eb506e88 92 /* waitTime: Implement as follows: */
shintamainjp 0:42e9eb506e88 93 /* REQUIRED: This function must consume/wait at least the specified number */
shintamainjp 0:42e9eb506e88 94 /* of microsec, interpreting microsec as a number of microseconds.*/
shintamainjp 0:42e9eb506e88 95 /* REQUIRED FOR SPARTAN/VIRTEX FPGAs and indirect flash programming: */
shintamainjp 0:42e9eb506e88 96 /* This function must pulse TCK for at least microsec times, */
shintamainjp 0:42e9eb506e88 97 /* interpreting microsec as an integer value. */
shintamainjp 0:42e9eb506e88 98 /* RECOMMENDED IMPLEMENTATION: Pulse TCK at least microsec times AND */
shintamainjp 0:42e9eb506e88 99 /* continue pulsing TCK until the microsec wait */
shintamainjp 0:42e9eb506e88 100 /* requirement is also satisfied. */
shintamainjp 0:42e9eb506e88 101 void waitTime(long microsec) {
shintamainjp 0:42e9eb506e88 102 /*
shintamainjp 0:42e9eb506e88 103 * Modified for mbed.
shintamainjp 0:42e9eb506e88 104 */
shintamainjp 0:42e9eb506e88 105
shintamainjp 0:42e9eb506e88 106 static long tckCyclesPerMicrosec = 2; /* must be at least 1 */
shintamainjp 0:42e9eb506e88 107 long tckCycles = microsec * tckCyclesPerMicrosec;
shintamainjp 0:42e9eb506e88 108 long i;
shintamainjp 0:42e9eb506e88 109
shintamainjp 0:42e9eb506e88 110 if (work.cbfunc_waittime != NULL) {
shintamainjp 0:42e9eb506e88 111 work.cbfunc_waittime(microsec);
shintamainjp 0:42e9eb506e88 112 }
shintamainjp 0:42e9eb506e88 113
shintamainjp 0:42e9eb506e88 114 /* This implementation is highly recommended!!! */
shintamainjp 0:42e9eb506e88 115 /* This implementation requires you to tune the tckCyclesPerMicrosec
shintamainjp 0:42e9eb506e88 116 variable (above) to match the performance of your embedded system
shintamainjp 0:42e9eb506e88 117 in order to satisfy the microsec wait time requirement. */
shintamainjp 0:42e9eb506e88 118 for ( i = 0; i < tckCycles; ++i ) {
shintamainjp 0:42e9eb506e88 119 pulseClock();
shintamainjp 0:42e9eb506e88 120 }
shintamainjp 0:42e9eb506e88 121 }