-
Notifications
You must be signed in to change notification settings - Fork 0
/
jtag.h
87 lines (73 loc) · 2.67 KB
/
jtag.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* JTAG routines
Copyright (C) 2004 Andrew Rogers
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Changes:
Dmitry Teytelman [dimtey@gmail.com] 14 Jun 2006 [applied 13 Aug 2006]:
Code cleanup for clean -Wall compile.
*/
#ifndef JTAG_H
#define JTAG_H
#include <stdio.h>
#include <vector>
#include "iobase.h"
#define MAXNUMDEVICES 1000
typedef unsigned char byte;
class Jtag
{
private:
// static const int MAXNUMDEVICES=1000;
protected:
struct chainParam_t
{
unsigned long idcode; // Store IDCODE
//byte bypass[4]; // The bypass instruction. Most instruction register lengths are a lot less than 32 bits.
int irlen; // instruction register length.
};
std::vector<chainParam_t> devices;
IOBase *io;
int numDevices;
IOBase::tapState_t postDRState;
IOBase::tapState_t postIRState;
int deviceIndex;
FILE *logfile;
bool shiftDRincomplete;
public:
Jtag(IOBase *iob);
int getChain(); // Shift IDCODEs from devices
inline void setPostDRState(IOBase::tapState_t s){postDRState=s;}
inline void setPostIRState(IOBase::tapState_t s){postIRState=s;}
void Usleep(unsigned int usec);
int setDeviceIRLength(int dev, int len);
unsigned long getDeviceID(unsigned int dev){
if(dev>=devices.size())return 0;
return devices[dev].idcode;
}
int selectDevice(int dev);
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.
void shiftIR(const byte *tdi, byte *tdo=0); // No length argumant required as IR length specified in chainParam_t
inline void longToByteArray(unsigned long l, byte *b){
b[0]=(byte)(l&0xff);
b[1]=(byte)((l>>8)&0xff);
b[2]=(byte)((l>>16)&0xff);
b[3]=(byte)((l>>24)&0xff);
}
inline void shortToByteArray(const unsigned short l, byte *b){
b[0]=(byte)(l&0xff);
b[1]=(byte)((l>>8)&0xff);
}
inline unsigned long byteArrayToLong(byte *b){
return ((unsigned long)b[3]<<24)+((unsigned long)b[2]<<16)+
((unsigned long)b[1]<<8)+(unsigned long)b[0];
}
};
#endif //JTAG_H