177int rpx::JtagDriver::xferRel(uint8_t* txb,
unsigned txBytes,
Header* phdr, uint8_t* rxb,
unsigned sizeBytes) {
178 Xid xid = getXid(getHdr(txb));
183 for (attempt = 0; attempt <= retry_; attempt++) {
185 if (this->done_)
break;
190 got = xfer(txb, txBytes, &hdBuf_[0], getWordSize(), rxb, sizeBytes);
191 hdr = getHdr(&hdBuf_[0]);
193 if ((e = getErr(hdr))) {
195 const char* msg = getMsg(e);
198 pos = snprintf(errb,
sizeof(errb),
"Got error response from server -- ");
201 snprintf(errb + pos,
sizeof(errb) - pos,
"%s", msg);
203 snprintf(errb + pos,
sizeof(errb) - pos,
"error %d", e);
207 if (xid == XID_ANY || xid == getXid(hdr)) {
220uint64_t rpx::JtagDriver::query() {
224 setHdr(&txBuf_[0], mkQuery());
226 xferRel(&txBuf_[0], getWordSize(), &hdr,
nullptr, 0);
227 wordSize_ = wordSize(hdr);
229 if (wordSize_ <
sizeof(hdr)) {
230 log_->debug(
"Encountered an error. Please ensure the board is powered up.\n");
232 "Received invalid word size. Please ensure the board is powered up.\n"));
235 memDepth_ = memDepth(hdr);
236 periodNs_ = cvtPerNs(hdr);
238 log_->debug(
"Query result: wordSize %" PRId32
", memDepth %" PRId32
", period %l" PRId32
"ns\n",
241 static_cast<uint64_t
>(periodNs_));
248 if ((siz = (2 * memDepth_ + 1) * wordSize_) > bufSz_) {
250 txBuf_.reserve(bufSz_);
253 return memDepth_ * wordSize_;
268void rpx::JtagDriver::sendVectors(uint64_t bits, uint8_t* tms, uint8_t* tdi, uint8_t* tdo) {
269 unsigned wsz = getWordSize();
270 uint64_t bytesCeil = (bits + 8 - 1) / 8;
271 unsigned wholeWords = bytesCeil / wsz;
272 unsigned wholeWordBytes = wholeWords * wsz;
273 unsigned wordCeilBytes = ((bytesCeil + wsz - 1) / wsz) * wsz;
275 unsigned bytesLeft = bytesCeil - wholeWordBytes;
276 unsigned bytesTot = wsz + 2 * wordCeilBytes;
280 log_->debug(
"sendVec -- bits %l" PRId32
", bytes %l" PRId32
", bytesTot %" PRId32
"\n", bits, bytesCeil, bytesTot);
282 setHdr(&txBuf_[0], mkShift(bits));
285 wp = &txBuf_[0] + wsz;
288 for (idx = 0; idx < wholeWordBytes; idx += wsz) {
289 memcpy(wp, &tms[idx], wsz);
291 memcpy(wp, &tdi[idx], wsz);
295 memcpy(wp, &tms[idx], bytesLeft);
296 memcpy(wp + wsz, &tdi[idx], bytesLeft);
298 xferRel(&txBuf_[0], bytesTot,
nullptr, tdo, bytesCeil);