1 /* JTAG routines
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 #ifndef JTAG_H
22 #define JTAG_H
23 
24 #include <vector>
25 
26 #include "iobase.h"
27 
28 typedef unsigned char byte;
29 
30 class Jtag
31 {
32  private:
33   static const int MAXNUMDEVICES=1000;
34  protected:
35   struct chainParam_t
36   {
37     byte idcode[4]; // Store IDCODE
38     //byte bypass[4]; // The bypass instruction. Most instruction register lengths are a lot less than 32 bits.
39     int irlen; // instruction register length.
40   };
41   std::vector<chainParam_t> devices;
42   IOBase *io;
43   int numDevices;
44   IOBase::tapState_t postDRState;
45   IOBase::tapState_t postIRState;
46   int deviceIndex;
47   FILE *logfile;
48   bool shiftDRincomplete;
49  public:
50   Jtag(IOBase *iob);
51   int getChain(); // Shift IDCODEs from devices
setPostDRState(IOBase::tapState_t s)52   inline void setPostDRState(IOBase::tapState_t s){postDRState=s;}
setPostIRState(IOBase::tapState_t s)53   inline void setPostIRState(IOBase::tapState_t s){postIRState=s;}
54   int setDeviceIRLength(int dev, int len);
getDeviceID(int dev)55   inline byte *getDeviceID(int dev){
56     if(dev>=devices.size())return 0;
57     return devices[dev].idcode;
58   }
59   int selectDevice(int dev);
60   void shiftDR(const byte *tdi, byte *tdo, int length, int align=0, bool exit=true);// Some devices use TCK for aligning data, for example, Xilinx FPGAs for configuration data.
61   void shiftIR(const byte *tdi, byte *tdo=0); // No length argumant required as IR length specified in chainParam_t
62 };
63 
64 #endif //JTAG_H
65