Read next pending reply packet from appropriate page of FPGA-to-host device file, and validate contents.
470{
472 SteadyClock_t::time_point lStartTime = SteadyClock_t::now();
473
475 {
476 uint32_t lHwPublishedPageCount = 0x0;
477
478 std::vector<uint32_t> lValues;
479 while ( true ) {
481
483 lHwPublishedPageCount = lValues.at(3);
484
485 log (uhal::Debug(),
"Read status info from addr 0 (", uhal::Integer(lValues.at(0)),
", ", uhal::Integer(lValues.at(1)),
", ", uhal::Integer(lValues.at(2)),
", ", uhal::Integer(lValues.at(3)),
"): ", PacketFmt((
const uint8_t*)lValues.data(), 4 * lValues.size()));
486
489 break;
490 }
491
492
493 if (SteadyClock_t::now() - lStartTime > std::chrono::microseconds(getBoostTimeoutPeriod().total_microseconds())) {
494 exception::FlxTimeout lExc;
496 throw lExc;
497 }
498
499 log(uhal::Debug(),
"flx client ", uhal::Quote(
id()),
" (URI: ", uhal::Quote(
uri()),
") : Trying to read page index ", uhal::Integer(lPageIndexToRead),
" = count ", uhal::Integer(
mReadReplyPageCount+1),
"; published page count is ", uhal::Integer(lHwPublishedPageCount),
"; sleeping for ",
mSleepDuration.count(),
"us");
502 lValues.clear();
503 }
504
505 log(uhal::Info(),
"flx client ", uhal::Quote(
id()),
" (URI: ", uhal::Quote(
uri()),
") : Reading page ", uhal::Integer(lPageIndexToRead),
" (published count ", uhal::Integer(lHwPublishedPageCount),
", surpasses required, ", uhal::Integer(
mReadReplyPageCount + 1),
")");
506 }
508
509
510 std::shared_ptr<uhal::Buffers> lBuffers =
mReplyQueue.front();
512
513 uint32_t lNrWordsToRead(lBuffers->replyCounter() >> 2);
514 lNrWordsToRead += 1;
515
516 std::vector<uint32_t> lPageContents;
519 lGuard.unlock();
520 log (uhal::Debug(),
"Read " , uhal::Integer(lNrWordsToRead),
" 32-bit words from address " , uhal::Integer(4 + lPageIndexToRead * 4 *
mPageSize),
" ... ", PacketFmt((
const uint8_t*)lPageContents.data(), 4 * lPageContents.size()));
521
522
523 const std::deque< std::pair< uint8_t* , uint32_t > >& lReplyBuffers ( lBuffers->getReplyBuffer() );
524 size_t lNrWordsInPacket = (lPageContents.at(0) >> 16) + (lPageContents.at(0) & 0xFFFF);
525 if (lNrWordsInPacket != (lBuffers->replyCounter() >> 2))
526 log (uhal::Warning(),
"Expected reply packet to contain ", uhal::Integer(lBuffers->replyCounter() >> 2),
" words, but it actually contains ", uhal::Integer(lNrWordsInPacket),
" words");
527
528 size_t lNrBytesCopied = 0;
529 for ( std::deque< std::pair< uint8_t* , uint32_t > >::const_iterator lIt = lReplyBuffers.begin() ; lIt != lReplyBuffers.end() ; ++lIt )
530 {
531
532 if ( lNrBytesCopied >= 4*lNrWordsInPacket)
533 break;
534
535 size_t lNrBytesToCopy = std::min( lIt->second , uint32_t(4*lNrWordsInPacket - lNrBytesCopied) );
536 memcpy ( lIt->first, &lPageContents.at(1 + (lNrBytesCopied / 4)), lNrBytesToCopy );
537 lNrBytesCopied += lNrBytesToCopy;
538 }
539
540
541
542 try
543 {
544 if ( uhal::exception::exception* lExc = ClientInterface::validate ( lBuffers ) )
545 {
547 }
548 }
549 catch ( uhal::exception::exception& aExc )
550 {
552 log ( *
mAsynchronousException ,
"Exception caught during reply validation for flx device with URI " , uhal::Quote ( this->
uri() ) ,
"; what returned: " , uhal::Quote ( aExc.what() ) );
553 }
554
556 {
558 }
559}