Root/Software/xc3sprog/debug.cpp

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

Archive Download this file

Branches:
master



interactive