Xilinx jtag tool added.
[platform/kernel/u-boot.git] / board / esd / common / xilinx_jtag / ports.c
1 /*
2  * (C) Copyright 2003
3  * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 /*******************************************************/
25 /* file: ports.c                                       */
26 /* abstract:  This file contains the routines to       */
27 /*            output values on the JTAG ports, to read */
28 /*            the TDO bit, and to read a byte of data  */
29 /*            from the prom                            */
30 /*                                                     */
31 /*******************************************************/
32
33 #include <common.h>
34 #include <asm/processor.h>
35
36 #include "ports.h"
37
38 static unsigned long output = 0;
39 static int filepos = 0;
40 static int oldstate = 0;
41 static int newstate = 0;
42 static int readptr = 0;
43
44 extern long filesize;
45 extern const unsigned char fpgadata[];
46
47
48 /* if in debugging mode, then just set the variables */
49 void setPort(short p,short val)
50 {
51         if (p==TMS) {
52                 if (val) {
53                         output |= JTAG_TMS;
54                 } else {
55                         output &= ~JTAG_TMS;
56                 }
57         }
58         if (p==TDI) {
59                 if (val) {
60                         output |= JTAG_TDI;
61                 } else {
62                         output &= ~JTAG_TDI;
63                 }
64         }
65         if (p==TCK) {
66                 if (val) {
67                         output |= JTAG_TCK;
68                 } else {
69                         output &= ~JTAG_TCK;
70                 }
71                 out32(GPIO0_OR, output);
72         }
73 }
74
75
76 /* toggle tck LH */
77 void pulseClock(void)
78 {
79         setPort(TCK,0);  /* set the TCK port to low  */
80         setPort(TCK,1);  /* set the TCK port to high */
81 }
82
83
84 /* read in a byte of data from the prom */
85 void readByte(unsigned char *data)
86 {
87         /* pretend reading using a file */
88         *data = fpgadata[readptr++];
89         newstate = (100 * filepos++) / filesize;
90         if (newstate != oldstate) {
91                 printf("%4d\r\r\r\r", newstate);
92                 oldstate = newstate;
93         }
94 }
95
96 /* read the TDO bit from port */
97 unsigned char readTDOBit(void)
98 {
99         unsigned long inputs;
100
101         inputs = in32(GPIO0_IR);
102         if (inputs & JTAG_TDO)
103                 return 1;
104         else
105                 return 0;
106 }
107
108
109 /* Wait at least the specified number of microsec.                           */
110 /* Use a timer if possible; otherwise estimate the number of instructions    */
111 /* necessary to be run based on the microcontroller speed.  For this example */
112 /* we pulse the TCK port a number of times based on the processor speed.     */
113 void waitTime(long microsec)
114 {
115         udelay(microsec); /* esd */
116 }