Read next pending reply packet from appropriate page of FPGA-to-host device file, and validate contents.
444{
446 SteadyClock_t::time_point lStartTime = SteadyClock_t::now();
447
449 uint32_t lHwPublishedPageCount = 0x0;
450
451 std::vector<uint32_t> lValues;
452 while (true) {
453
456 lHwPublishedPageCount = lValues.at(3);
458 "Read status info from addr 0 (",
459 Integer(lValues.at(0)),
460 ", ",
461 Integer(lValues.at(1)),
462 ", ",
463 Integer(lValues.at(2)),
464 ", ",
465 Integer(lValues.at(3)),
466 "): ",
467 PacketFmt((const uint8_t*)lValues.data(), 4 * lValues.size()));
468
471 break;
472 }
473
474
475 if (SteadyClock_t::now() - lStartTime > std::chrono::microseconds(getBoostTimeoutPeriod().total_microseconds())) {
476 exception::Axi4LiteTimeout lExc;
478 "Next page (index ",
479 Integer(lPageIndexToRead),
480 " count ",
482 ") of Axi4Lite device '" +
mMappedFile.
getPath() +
"' is not ready after timeout period");
483 throw lExc;
484 }
485
487 "Axi4Lite client ",
488 uhal::Quote(id()),
489 " (URI: ",
491 ") : Trying to read page index ",
492 Integer(lPageIndexToRead),
493 " = count ",
495 "; published page count is ",
496 Integer(lHwPublishedPageCount),
497 "; sleeping for ",
499 "us");
502 lValues.clear();
503 }
504
506 "Axi4Lite client ",
507 uhal::Quote(id()),
508 " (URI: ",
510 ") : Reading page ",
511 Integer(lPageIndexToRead),
512 " (published count ",
513 Integer(lHwPublishedPageCount),
514 ", surpasses required, ",
516 ")");
517 }
519
520
521 std::shared_ptr<uhal::Buffers> lBuffers =
mReplyQueue.front();
523
524 uint32_t lNrWordsToRead(lBuffers->replyCounter() >> 2);
525 lNrWordsToRead += 1;
526
527 std::vector<uint32_t> lPageContents;
530 lGuard.unlock();
532 "Read ",
533 Integer(lNrWordsToRead),
534 " 32-bit words from address ",
535 Integer(4 + lPageIndexToRead * 4 *
mPageSize),
536 " ... ",
537 PacketFmt((
const uint8_t*)lPageContents.data(), 4 * lPageContents.size()));
538
539
540 const std::deque<std::pair<uint8_t*, uint32_t>>& lReplyBuffers(lBuffers->getReplyBuffer());
541 size_t lNrWordsInPacket = (lPageContents.at(0) >> 16) + (lPageContents.at(0) & 0xFFFF);
542 if (lNrWordsInPacket != (lBuffers->replyCounter() >> 2))
544 "Expected reply packet to contain ",
545 Integer(lBuffers->replyCounter() >> 2),
546 " words, but it actually contains ",
547 Integer(lNrWordsInPacket),
548 " words");
549
550 size_t lNrBytesCopied = 0;
551 for (const auto& lBuffer : lReplyBuffers) {
552
553 if (lNrBytesCopied >= 4 * lNrWordsInPacket)
554 break;
555
556 size_t lNrBytesToCopy = std::min(lBuffer.second, uint32_t(4 * lNrWordsInPacket - lNrBytesCopied));
557 memcpy(lBuffer.first, &lPageContents.at(1 + (lNrBytesCopied / 4)), lNrBytesToCopy);
558 lNrBytesCopied += lNrBytesToCopy;
559 }
560
561
562 uhal::exception::exception* lExc = NULL;
563 try {
564 lExc = ClientInterface::validate(lBuffers);
565 } catch (uhal::exception::exception& aExc) {
566 uhal::exception::ValidationError lExc2;
568 "Exception caught during reply validation for Axi4Lite device with URI ",
569 uhal::Quote(this->
uri()),
570 "; what returned: ",
571 uhal::Quote(aExc.what()));
572 throw lExc2;
573 }
574
575 if (lExc != NULL)
576 lExc->throwAsDerivedType();
577}
PacketFmt(const uint8_t *const, const size_t)