rogue
Loading...
Searching...
No Matches
JtagDriver.h
Go to the documentation of this file.
1
18#ifndef __ROGUE_PROTOCOLS_XILINX_JTAG_DRIVER_H__
19#define __ROGUE_PROTOCOLS_XILINX_JTAG_DRIVER_H__
20
21#include "rogue/Directives.h"
22
23#include <inttypes.h>
24#include <stdint.h>
25#include <unistd.h>
26
27#include <cerrno>
28#include <cstdio>
29#include <cstring>
30#include <exception>
31#include <memory>
32#include <stdexcept>
33#include <vector>
34
35#include "rogue/GeneralError.h"
36#include "rogue/Logging.h"
37
38using std::vector;
39
40namespace rogue {
41namespace protocols {
42namespace xilinx {
69 protected:
70 // Remote port number
71 uint16_t port_;
72
73 // occasionally drop a packet for testing (when enabled)
74 bool drEn_;
75 bool done_;
76 unsigned drop_;
77
78 typedef uint32_t Header;
79 typedef uint8_t Xid;
80
81 static const Xid XID_ANY = 0;
82
83 // Log
84 std::shared_ptr<rogue::Logging> log_;
85
86 private:
87 unsigned wordSize_;
88 unsigned memDepth_;
89
90 vector<uint8_t> txBuf_;
91 vector<uint8_t> hdBuf_;
92
93 unsigned bufSz_;
94 unsigned retry_;
95
96 Xid xid_;
97
98 uint32_t periodNs_;
99
100 Header newXid();
101
102 Header mkQuery();
103 Header mkShift(unsigned len);
104
105 virtual void setHdr(uint8_t* buf, Header hdr);
106
107 protected:
108 static Header getHdr(uint8_t* buf);
109
110 static const Header PVERS = 0x00000000;
111 static const Header CMD_Q = 0x00000000;
112 static const Header CMD_S = 0x10000000;
113 static const Header CMD_E = 0x20000000;
114
115 static const Header CMD_MASK = 0x30000000;
116 static const unsigned ERR_SHIFT = 0;
117 static const Header ERR_MASK = 0x000000ff;
118
119 static const unsigned XID_SHIFT = 20;
120 static const unsigned LEN_SHIFT = 0;
121 static const Header LEN_MASK = 0x000fffff;
122
123 static const unsigned ERR_BAD_VERSION = 1;
124 static const unsigned ERR_BAD_COMMAND = 2;
125 static const unsigned ERR_TRUNCATED = 3;
126 static const unsigned ERR_NOT_PRESENT = 4;
127
128 static Xid getXid(Header x);
129 static uint32_t getCmd(Header x);
130 static unsigned getErr(Header x);
131 static uint64_t getLen(Header x);
132
133 // returns error message or NULL (unknown error)
134 static const char* getMsg(unsigned error);
135
136 // extract from message header
137 unsigned wordSize(Header reply);
138 unsigned memDepth(Header reply);
139 uint32_t cvtPerNs(Header reply);
140
141 static int isLE() {
142 static const union {
143 uint8_t c[2];
144 uint16_t s;
145 } u = {.s = 1};
146 return !!u.c[0];
147 }
148
149 static const uint32_t UNKNOWN_PERIOD = 0;
150
151 static double REF_FREQ_HZ() {
152 return 200.0E6;
153 }
154
155 // obtain (current/cached) parameters; these may
156 // depend on values provided by the transport-level driver
157 virtual unsigned getWordSize();
158 virtual unsigned getMemDepth();
159 virtual uint32_t getPeriodNs();
160
161 public:
175 static std::shared_ptr<rogue::protocols::xilinx::JtagDriver> create(uint16_t port);
176
178 static void setup_python();
179
189 explicit JtagDriver(uint16_t port);
190
197 virtual void init();
198
215 virtual int xfer(uint8_t* txb, unsigned txBytes, uint8_t* hdbuf, unsigned hsize, uint8_t* rxb, unsigned size) {
216 return 0;
217 }
218
234 virtual int xferRel(uint8_t* txb, unsigned txBytes, Header* phdr, uint8_t* rxb, unsigned sizeBytes);
235
245 virtual uint64_t query();
246
257 virtual uint64_t getMaxVectorSize() {
258 return 0;
259 }
260
272 virtual uint32_t setPeriodNs(uint32_t newPeriod);
273
287 virtual void sendVectors(uint64_t numBits, uint8_t* tms, uint8_t* tdi, uint8_t* tdo);
288
294 virtual void dumpInfo(FILE* f = stdout);
295
301 bool isDone() {
302 return this->done_;
303 }
304};
305
307static unsigned hdBufMax() {
308 return 16;
309}
310
311// Convenience
312typedef std::shared_ptr<rogue::protocols::xilinx::JtagDriver> JtagDriverPtr;
313} // namespace xilinx
314} // namespace protocols
315} // namespace rogue
316
317#endif
Base transport driver for the AxisToJtag firmware protocol.
Definition JtagDriver.h:68
std::shared_ptr< rogue::Logging > log_
Definition JtagDriver.h:84
static const unsigned XID_SHIFT
Definition JtagDriver.h:119
virtual uint64_t getMaxVectorSize()
Returns transport-supported maximum vector size in bytes.
Definition JtagDriver.h:257
static const unsigned ERR_NOT_PRESENT
Definition JtagDriver.h:126
static const uint32_t UNKNOWN_PERIOD
Definition JtagDriver.h:149
static const unsigned ERR_BAD_COMMAND
Definition JtagDriver.h:124
static const unsigned ERR_BAD_VERSION
Definition JtagDriver.h:123
bool isDone()
Returns completion/shutdown flag.
Definition JtagDriver.h:301
static const char * getMsg(unsigned error)
static Header getHdr(uint8_t *buf)
virtual int xfer(uint8_t *txb, unsigned txBytes, uint8_t *hdbuf, unsigned hsize, uint8_t *rxb, unsigned size)
Transport-level transfer primitive implemented by subclass.
Definition JtagDriver.h:215
virtual void sendVectors(uint64_t numBits, uint8_t *tms, uint8_t *tdi, uint8_t *tdo)
Sends JTAG TMS/TDI vectors and receives TDO.
static uint64_t getLen(Header x)
static const unsigned ERR_TRUNCATED
Definition JtagDriver.h:125
virtual void dumpInfo(FILE *f=stdout)
Dumps cached driver/target information.
virtual uint64_t query()
Queries target capabilities and caches protocol parameters.
static void setup_python()
Registers Python bindings for this class.
virtual uint32_t setPeriodNs(uint32_t newPeriod)
Requests update of TCK period.
static std::shared_ptr< rogue::protocols::xilinx::JtagDriver > create(uint16_t port)
Creates a JTAG driver instance.
static const unsigned LEN_SHIFT
Definition JtagDriver.h:120
static const unsigned ERR_SHIFT
Definition JtagDriver.h:116
virtual int xferRel(uint8_t *txb, unsigned txBytes, Header *phdr, uint8_t *rxb, unsigned sizeBytes)
Executes transfer with retry and protocol validation.
static uint32_t getCmd(Header x)
static unsigned getErr(Header x)
virtual void init()
Performs post-construction initialization.
static unsigned hdBufMax()
Maximum temporary header buffer size in bytes.
Definition JtagDriver.h:307
std::shared_ptr< rogue::protocols::xilinx::JtagDriver > JtagDriverPtr
Definition JtagDriver.h:312