178int rpx::JtagDriver::xferRel(uint8_t* txb,
unsigned txBytes,
Header* phdr, uint8_t* rxb,
unsigned sizeBytes) {
179 Xid xid = getXid(getHdr(txb));
182 for (
unsigned attempt = 0; attempt <= retry_; attempt++) {
184 if (this->done_.load(std::memory_order_acquire))
break;
189 got = xfer(txb, txBytes, &hdBuf_[0], getWordSize(), rxb, sizeBytes);
190 hdr = getHdr(&hdBuf_[0]);
192 unsigned e = getErr(hdr);
195 const char* msg = getMsg(e);
197 int pos = snprintf(errb,
sizeof(errb),
"Got error response from server -- ");
198 if (pos < 0) pos = 0;
199 if (
static_cast<size_t>(pos) >=
sizeof(errb)) pos =
static_cast<int>(
sizeof(errb) - 1);
200 size_t remaining =
sizeof(errb) -
static_cast<size_t>(pos);
203 snprintf(errb + pos, remaining,
"%s", msg);
205 snprintf(errb + pos, remaining,
"error %u", e);
209 if (xid == XID_ANY || xid == getXid(hdr)) {
217 if (!this->done_.load(std::memory_order_acquire))
223uint64_t rpx::JtagDriver::query() {
226 setHdr(&txBuf_[0], mkQuery());
228 xferRel(&txBuf_[0], getWordSize(), &hdr,
nullptr, 0);
229 wordSize_ = wordSize(hdr);
231 if (
static_cast<size_t>(wordSize_) <
sizeof(hdr)) {
232 log_->debug(
"Encountered an error. Please ensure the board is powered up.\n");
234 "Received invalid word size. Please ensure the board is powered up.\n"));
237 memDepth_ = memDepth(hdr);
238 periodNs_ = cvtPerNs(hdr);
240 log_->debug(
"Query result: wordSize %u, memDepth %u, period %" PRIu32
" ns\n",
250 uint64_t siz64 = (2ULL *
static_cast<uint64_t
>(memDepth_) + 1) *
static_cast<uint64_t
>(wordSize_);
251 if (siz64 > UINT_MAX)
253 unsigned siz =
static_cast<unsigned>(siz64);
256 txBuf_.resize(bufSz_);
259 return static_cast<uint64_t
>(memDepth_) *
static_cast<uint64_t
>(wordSize_);
274void rpx::JtagDriver::sendVectors(uint64_t bits, uint8_t* tms, uint8_t* tdi, uint8_t* tdo) {
275 if (bits == 0 || bits > LEN_MASK + 1)
277 "bit count %" PRIu64
" out of range [1, %u]", bits,
static_cast<unsigned>(LEN_MASK + 1)));
279 unsigned wsz = getWordSize();
280 uint64_t bytesCeil = (bits + 7) / 8;
281 unsigned wholeWords =
static_cast<unsigned>(bytesCeil / wsz);
282 unsigned wholeWordBytes = wholeWords * wsz;
283 unsigned wordCeilBytes =
static_cast<unsigned>(((bytesCeil + wsz - 1) / wsz) * wsz);
284 unsigned bytesLeft =
static_cast<unsigned>(bytesCeil - wholeWordBytes);
285 unsigned bytesTot = wsz + 2 * wordCeilBytes;
287 if (bytesTot > bufSz_)
289 "bytesTot %u exceeds buffer size %u", bytesTot, bufSz_));
291 log_->debug(
"sendVec -- bits %" PRIu64
", bytes %" PRIu64
", bytesTot %u\n", bits, bytesCeil, bytesTot);
293 setHdr(&txBuf_[0], mkShift(
static_cast<unsigned>(bits)));
296 uint8_t* wp = &txBuf_[0] + wsz;
300 for (idx = 0; idx < wholeWordBytes; idx += wsz) {
301 memcpy(wp, &tms[idx], wsz);
303 memcpy(wp, &tdi[idx], wsz);
307 memcpy(wp, &tms[idx], bytesLeft);
308 memcpy(wp + wsz, &tdi[idx], bytesLeft);
310 xferRel(&txBuf_[0], bytesTot,
nullptr, tdo,
static_cast<unsigned>(bytesCeil));