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 <atomic>
24#include <cstdint>
25#include <cstdio>
26#include <memory>
27#include <vector>
28
29#include "rogue/GeneralError.h"
30#include "rogue/Logging.h"
31
32namespace rogue {
33namespace protocols {
34namespace xilinx {
61 protected:
62 // TCP port number (2542 is the Vivado default; 0 = kernel-assigned)
63 uint16_t port_;
64
65 // occasionally drop a packet for testing (when enabled)
66 bool drEn_;
67 std::atomic<bool> done_;
68 unsigned drop_;
69
70 typedef uint32_t Header;
71 typedef uint8_t Xid;
72
73 static const Xid XID_ANY = 0;
74
75 // Log
76 std::shared_ptr<rogue::Logging> log_;
77
78 private:
79 unsigned wordSize_;
80 unsigned memDepth_;
81
82 std::vector<uint8_t> txBuf_;
83 std::vector<uint8_t> hdBuf_;
84
85 unsigned bufSz_;
86 unsigned retry_;
87
88 Xid xid_;
89
90 uint32_t periodNs_;
91
92 Header newXid();
93
94 Header mkQuery();
95 Header mkShift(unsigned len);
96
97 virtual void setHdr(uint8_t* buf, Header hdr);
98
99 protected:
100 static Header getHdr(const uint8_t* buf);
101
102 static const Header PVERS = 0x00000000;
103 static const Header CMD_Q = 0x00000000;
104 static const Header CMD_S = 0x10000000;
105 static const Header CMD_E = 0x20000000;
106
107 static const Header CMD_MASK = 0x30000000;
108 static const unsigned ERR_SHIFT = 0;
109 static const Header ERR_MASK = 0x000000ff;
110
111 static const unsigned XID_SHIFT = 20;
112 static const unsigned LEN_SHIFT = 0;
113 static const Header LEN_MASK = 0x000fffff;
114
115 static const unsigned ERR_BAD_VERSION = 1;
116 static const unsigned ERR_BAD_COMMAND = 2;
117 static const unsigned ERR_TRUNCATED = 3;
118 static const unsigned ERR_NOT_PRESENT = 4;
119
120 static Xid getXid(Header x);
121 static uint32_t getCmd(Header x);
122 static unsigned getErr(Header x);
123 static uint64_t getLen(Header x);
124
125 // returns error message or nullptr (unknown error)
126 static const char* getMsg(unsigned error);
127
128 // extract from message header
129 unsigned wordSize(Header reply);
130 unsigned memDepth(Header reply);
131 uint32_t cvtPerNs(Header reply);
132
133 static int isLE() {
134 static const union {
135 uint8_t c[2];
136 uint16_t s;
137 } u = {.s = 1};
138 return !!u.c[0];
139 }
140
141 static const uint32_t UNKNOWN_PERIOD = 0;
142
143 static double REF_FREQ_HZ() {
144 return 200.0E6;
145 }
146
147 // obtain (current/cached) parameters; these may
148 // depend on values provided by the transport-level driver
149 virtual unsigned getWordSize();
150 virtual unsigned getMemDepth();
151 virtual uint32_t getPeriodNs();
152
153 public:
167 static std::shared_ptr<rogue::protocols::xilinx::JtagDriver> create(uint16_t port);
168
170 static void setup_python();
171
181 explicit JtagDriver(uint16_t port);
182
184 virtual ~JtagDriver() = default;
185
192 virtual void init();
193
210 virtual int xfer(uint8_t*, unsigned, uint8_t*, unsigned, uint8_t*, unsigned) {
211 return 0;
212 }
213
229 virtual int xferRel(uint8_t* txb, unsigned txBytes, Header* phdr, uint8_t* rxb, unsigned sizeBytes);
230
240 virtual uint64_t query();
241
252 virtual uint64_t getMaxVectorSize() {
253 return 0;
254 }
255
267 virtual uint32_t setPeriodNs(uint32_t newPeriod);
268
282 virtual void sendVectors(uint64_t numBits, uint8_t* tms, uint8_t* tdi, uint8_t* tdo);
283
289 virtual void dumpInfo(FILE* f = stdout);
290
296 bool isDone() {
297 return this->done_.load(std::memory_order_acquire);
298 }
299};
300
302inline unsigned hdBufMax() {
303 return 16;
304}
305
306// Convenience
307typedef std::shared_ptr<rogue::protocols::xilinx::JtagDriver> JtagDriverPtr;
308} // namespace xilinx
309} // namespace protocols
310} // namespace rogue
311
312#endif
Base transport driver for the AxisToJtag firmware protocol.
Definition JtagDriver.h:60
std::shared_ptr< rogue::Logging > log_
Definition JtagDriver.h:76
static const unsigned XID_SHIFT
Definition JtagDriver.h:111
virtual uint64_t getMaxVectorSize()
Returns transport-supported maximum vector size in bytes.
Definition JtagDriver.h:252
static const unsigned ERR_NOT_PRESENT
Definition JtagDriver.h:118
virtual ~JtagDriver()=default
Virtual destructor for safe polymorphic deletion.
static const uint32_t UNKNOWN_PERIOD
Definition JtagDriver.h:141
static const unsigned ERR_BAD_COMMAND
Definition JtagDriver.h:116
static const unsigned ERR_BAD_VERSION
Definition JtagDriver.h:115
bool isDone()
Returns completion/shutdown flag.
Definition JtagDriver.h:296
static Header getHdr(const uint8_t *buf)
static const char * getMsg(unsigned error)
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:117
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:112
static const unsigned ERR_SHIFT
Definition JtagDriver.h:108
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)
virtual int xfer(uint8_t *, unsigned, uint8_t *, unsigned, uint8_t *, unsigned)
Transport-level transfer primitive implemented by subclass.
Definition JtagDriver.h:210
static unsigned getErr(Header x)
virtual void init()
Performs post-construction initialization.
unsigned hdBufMax()
Maximum temporary header buffer size in bytes.
Definition JtagDriver.h:302
std::shared_ptr< rogue::protocols::xilinx::JtagDriver > JtagDriverPtr
Definition JtagDriver.h:307