vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / jtag / ports.c
bloba7554111f0bb1f9829e6c3aa1639096d71fb583c
1 /*******************************************************/
2 /* file: ports.c */
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 */
6 /* from the prom */
7 /* */
8 /*******************************************************/
9 #include "ports.h"
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;
24 #define DITO 200000
26 /*******************************************************/
27 /* Swap bytes on little endian systems */
29 short swap(short word) {
31 char l,r;
33 r = word & 0xFF;
34 l = word >> 8;
35 word = (r << 8) | (l & 0xFF);
37 return word;
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) {
46 if (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; }
53 else return;
54 } else {
55 if (p == TMS) { jtag |= JTAG_TMS_BAR;
56 jtag &= ~JTAG_TMS; }
57 else if (p == TDI) { jtag |= JTAG_TDI_BAR;
58 jtag &= ~JTAG_TDI; }
59 else if (p == TCK) { jtag |= JTAG_TCK_BAR;
60 jtag &= ~JTAG_TCK; }
61 else return;
63 if (jtagAddr) *jtagAddr = swap(jtag);
65 if ((dito++ % DITO) == 0) {
66 printf("\7.");
67 fflush(stdout);
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() {
83 unsigned short rback;
85 if (jtagAddr) rback = swap(*jtagAddr);
86 if (rback & JTAG_TDO)
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 */
96 usleep(microsec);
99 /*******************************************************/
100 /* Pulse the TCK clock */
102 void pulseClock() {
104 setPort(TCK,0); /* set the TCK port to low */
105 setPort(TCK,1); /* set the TCK port to high */