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
20
21 #include <stdio.h>
22
23 #include "iobase.h"
24 #include "ioparport.h"
25 #include "iodebug.h"
26
27
28 using namespace std;
29
30 void testPP();
31 void testDebug();
32 void printBit(unsigned char *data, int bit);
33 void getSwitches(IOBase *io);
34 void getID(IOBase *io);
35
main(int argc,char ** args)36 int main(int argc, char**args)
37 {
38 testPP();
39 return 0;
40 }
41
testDebug()42 void testDebug()
43 {
44 IOBase *io;
45 io=new IODebug();
46 unsigned char tdi[]={0x3a,0xa3};
47 unsigned char tdo[10];
48 io->setTapState(IOBase::SHIFT_DR);
49 io->shiftTDITDO(tdi,tdo,16,false);
50 for(int i=0; i<2; i++)printf("TDO %02x\n",tdo[i]);
51 delete io;
52 }
53
testPP()54 void testPP()
55 {
56 IOBase *io;
57 io=new IOParport("/dev/parport0");
58 unsigned char tdi[]={0,0,0,0,0,0,0,0};
59 unsigned char tdo[100];
60 io->setTapState(IOBase::SHIFT_DR);
61 io->shiftTDITDO(tdi,tdo,64);
62 for(int i=0; i<8; i++)printf("TDO %02x\n",tdo[i]);
63 printf("\n");
64 getSwitches(io);
65 getID(io);
66 delete io;
67 }
68
printBit1(bool val)69 void printBit1(bool val)
70 {
71 if(val)printf("|=| ");
72 else printf("| | ");
73 }
74
getID(IOBase * io)75 void getID(IOBase *io)
76 {
77 unsigned char tdo[100];
78 unsigned char tdi[]={0x09,0xff};
79 io->setTapState(IOBase::SHIFT_IR);
80 io->shiftTDI(tdi,14);
81 io->setTapState(IOBase::RUN_TEST_IDLE);
82 io->setTapState(IOBase::SHIFT_DR);
83 io->shiftTDO(tdo,64);
84 for(int i=0; i<8; i++)printf("TDO %02x\n",tdo[i]);
85 printf("\n");
86 }
87
getSwitches(IOBase * io)88 void getSwitches(IOBase *io)
89 {
90 unsigned char tdo[100];
91 unsigned char tdi[]={0x01,0xff};
92 io->setTapState(IOBase::SHIFT_IR);
93 io->shiftTDI(tdi,14);
94 io->setTapState(IOBase::SHIFT_DR);
95 io->shiftTDO(tdo,600);
96 int swi[]={25,45,56,59,73,86,93,90};
97 for(int i=7; i>=0; i--){
98 int bit=swi[i];
99 bool val=(tdo[bit/8]>>(bit%8))&1;
100 printBit1(val);
101 }
102 printf("\n");
103 for(int i=7; i>=0; i--){
104 int bit=swi[i];
105 bool val=(tdo[bit/8]>>(bit%8))&1;
106 printBit1(!val);
107 }
108 printf("\n\n");
109 }
110
printBit(unsigned char * data,int bit)111 void printBit(unsigned char *data, int bit)
112 {
113 printf("bit %d = %d\n",bit,(data[bit/8]>>(bit%8))&1);
114 }
115
116
117