Root/Software/xc3sprog/detectchain.cpp

1/* JTAG chain detection
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
22#include "iodebug.h"
23#include "jtag.h"
24#include "devicedb.h"
25#include "jtag_bus.h"
26
27#define MEMDEV "/dev/mem"
28#define CPLD_PHY_BASE PXA_CS2_PHYS
29
30#define DEVICEDB "/usr/share/xc3sprog/devlist.txt"
31
32int main(int argc, char **args)
33{
34  JTAGBus io(MEMDEV,CPLD_PHY_BASE);
35  
36  if(io.checkError()){
37    fprintf(stderr,"Can map physical address into virtual space! or can not open '%s'.\n",MEMDEV);
38    return 1;
39  }
40
41  Jtag jtag(&io);
42  int num=jtag.getChain();
43  DeviceDB db(DEVICEDB);
44  int dblast=0;
45  for(int i=0; i<num; i++){
46    unsigned long id=jtag.getDeviceID(i);
47    int length=db.loadDevice(id);
48    printf("IDCODE: 0x%08x\t",id);
49    if(length>0){
50      jtag.setDeviceIRLength(i,length);
51      printf("Desc: %s\tIR length: %d\n",db.getDeviceDescription(dblast),length);
52      dblast++;
53    }
54    else{
55      printf("not found in '%s'.\n",DEVICEDB);
56    }
57  }
58  return 0;
59}
60

Archive Download this file

Branches:
master



interactive