1 /* JTAG debugging code
2
3 Copyright (C) 2004 Andrew Rogers
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Changes:
20 Dmitry Teytelman [dimtey@gmail.com] 14 Jun 2006 [applied 13 Aug 2006]:
21 Modified to support the changes in IOParport class.
22 */
23
24
25
26 #include <stdio.h>
27
28 #include "iobase.h"
29 #include "ioparport.h"
30 #include "iodebug.h"
31
32 using namespace std;
33
34 void testPP();
35 void testDebug();
36 void printBit(unsigned char *data, int bit);
37 void getSwitches(IOBase *io);
38 void getID(IOBase *io);
39
main(int argc,char ** args)40 int main(int argc, char**args)
41 {
42 testPP();
43 return 0;
44 }
45
testDebug()46 void testDebug()
47 {
48 IODebug io;
49
50 unsigned char tdi[]={0x3a,0xa3};
51 unsigned char tdo[10];
52 io.setTapState(IOBase::SHIFT_DR);
53 io.shiftTDITDO(tdi,tdo,16,false);
54 for(int i=0; i<2; i++)fprintf(stderr, "TDO %02x\n",tdo[i]);
55 }
56
testPP()57 void testPP()
58 {
59 IOParport io(0);
60
61 unsigned char tdi[]={0,0,0,0,0,0,0,0};
62 unsigned char tdo[100];
63 io.setTapState(IOBase::SHIFT_DR);
64 io.shiftTDITDO(tdi,tdo,64);
65 for(int i=0; i<8; i++)fprintf(stderr, "TDO %02x\n",tdo[i]);
66 fprintf(stderr, "\n");
67 getSwitches(&io);
68 getID(&io);
69 }
70
printBit1(bool val)71 void printBit1(bool val)
72 {
73 if(val)fprintf(stderr, "|=| ");
74 else fprintf(stderr, "| | ");
75 }
76
getID(IOBase * io)77 void getID(IOBase *io)
78 {
79 unsigned char tdo[100];
80 unsigned char tdi[]={0xfe,0x09};
81 io->setTapState(IOBase::SHIFT_IR);
82 io->shiftTDI(tdi,14);
83 io->setTapState(IOBase::RUN_TEST_IDLE);
84 io->setTapState(IOBase::SHIFT_DR);
85 io->shiftTDO(tdo,64);
86 for(int i=0; i<8; i++)fprintf(stderr, "TDO %02x\n",tdo[i]);
87 fprintf(stderr, "\n");
88 }
89
getSwitches(IOBase * io)90 void getSwitches(IOBase *io)
91 {
92 unsigned char tdo[100];
93 unsigned char tdi[]={0xff,0x01};
94 io->setTapState(IOBase::SHIFT_IR);
95 io->shiftTDI(tdi,14);
96 io->setTapState(IOBase::SHIFT_DR);
97 io->shiftTDO(tdo,600);
98 int swi[]={506,509,518,521,539,536,557,569};
99 for(int i=0; i<8; i++){
100 int bit=swi[i];
101 bool val=(tdo[bit/8]>>(bit%8))&1;
102 printBit1(val);
103 }
104 fprintf(stderr, "\n");
105 for(int i=0; i<8; i++){
106 int bit=swi[i];
107 bool val=(tdo[bit/8]>>(bit%8))&1;
108 printBit1(!val);
109 }
110 fprintf(stderr, "\n\n");
111 }
112
printBit(unsigned char * data,int bit)113 void printBit(unsigned char *data, int bit)
114 {
115 fprintf(stderr, "bit %d = %d\n",bit,(data[bit/8]>>(bit%8))&1);
116 }
117
118
119