1 /*******************************************************/
3 /* abstract: This file contains the routines to */
4 /* output values on the JTAG ports, to read */
5 /* the TDO bit, and to read a byte of data */
8 /*******************************************************/
11 #define JTAG_TDO 0x01 /* Data Out */
12 #define JTAG_TDO_BAR 0x10
14 #define JTAG_TDI 0x02 /* Data In */
15 #define JTAG_TDI_BAR 0x20
17 #define JTAG_TMS 0x04 /* Mode Select */
18 #define JTAG_TMS_BAR 0x40
20 #define JTAG_TCK 0x08 /* Clock */
21 #define JTAG_TCK_BAR 0x80
23 static unsigned long dito
= 0;
26 /*******************************************************/
27 /* Swap bytes on little endian systems */
29 short swap(short word
) {
35 word
= (r
<< 8) | (l
& 0xFF);
40 /*******************************************************/
41 /* Write one bit to selected Jtag bit */
42 /* p is the jtag port TMS, TDI or TCK */
43 /* val contains the bit value one or zero */
45 void setPort(short p
,short val
) {
47 if (p
== TMS
) { jtag
|= JTAG_TMS
;
48 jtag
&= ~JTAG_TMS_BAR
; }
49 else if (p
== TDI
) { jtag
|= JTAG_TDI
;
50 jtag
&= ~JTAG_TDI_BAR
; }
51 else if (p
== TCK
) { jtag
|= JTAG_TCK
;
52 jtag
&= ~JTAG_TCK_BAR
; }
55 if (p
== TMS
) { jtag
|= JTAG_TMS_BAR
;
57 else if (p
== TDI
) { jtag
|= JTAG_TDI_BAR
;
59 else if (p
== TCK
) { jtag
|= JTAG_TCK_BAR
;
63 if (jtagAddr
) *jtagAddr
= swap(jtag
);
65 if ((dito
++ % DITO
) == 0) {
71 /*******************************************************/
72 /* read in a byte of data from the input stream */
74 void readByte(unsigned char *data
) {
76 *data
= (unsigned char) fgetc(inp
);
79 /*******************************************************/
80 /* read the TDO bit from port */
82 unsigned char readTDOBit() {
85 if (jtagAddr
) rback
= swap(*jtagAddr
);
87 return (unsigned char) 1;
88 return (unsigned char) 0;
91 /*****************************************************************************/
92 /* Wait at least the specified number of microsec. */
94 void waitTime(long microsec
) {
95 setPort(TCK
,0); /* set the TCK port to low */
99 /*******************************************************/
100 /* Pulse the TCK clock */
104 setPort(TCK
,0); /* set the TCK port to low */
105 setPort(TCK
,1); /* set the TCK port to high */