Read next pending reply packet from appropriate page of FPGA-to-host device file, and validate contents.
356{
358 SteadyClock_t::time_point lStartTime = SteadyClock_t::now();
359
361 {
362 uint32_t lHwPublishedPageCount = 0x0;
363
364 std::vector<uint32_t> lValues;
365 while ( true ) {
366
369 lHwPublishedPageCount = lValues.at(3);
370 log (uhal::Debug(),
"Read status info from addr 0 (", Integer(lValues.at(0)),
", ", Integer(lValues.at(1)),
", ", Integer(lValues.at(2)),
", ", Integer(lValues.at(3)),
"): ", PacketFmt((
const uint8_t*)lValues.data(), 4 * lValues.size()));
371
374 break;
375 }
376
377
378 if (SteadyClock_t::now() - lStartTime > std::chrono::microseconds(getBoostTimeoutPeriod().total_microseconds())) {
379 exception::Axi4LiteTimeout lExc;
381 throw lExc;
382 }
383
384 log(uhal::Debug(),
"Axi4Lite client ", uhal::Quote(
id()),
" (URI: ", uhal::Quote(
uri()),
") : Trying to read page index ", Integer(lPageIndexToRead),
" = count ", Integer(
mReadReplyPageCount+1),
"; published page count is ", Integer(lHwPublishedPageCount),
"; sleeping for ",
mSleepDuration.count(),
"us");
387 lValues.clear();
388 }
389
390 log(uhal::Info(),
"Axi4Lite client ", uhal::Quote(
id()),
" (URI: ", uhal::Quote(
uri()),
") : Reading page ", Integer(lPageIndexToRead),
" (published count ", Integer(lHwPublishedPageCount),
", surpasses required, ", Integer(
mReadReplyPageCount + 1),
")");
391
392 }
394
395
396 std::shared_ptr<uhal::Buffers> lBuffers =
mReplyQueue.front();
398
399 uint32_t lNrWordsToRead(lBuffers->replyCounter() >> 2);
400 lNrWordsToRead += 1;
401
402 std::vector<uint32_t> lPageContents;
405 lGuard.unlock();
406 log (uhal::Debug(),
"Read " , Integer(lNrWordsToRead),
" 32-bit words from address " , Integer(4 + lPageIndexToRead * 4 *
mPageSize),
" ... ", PacketFmt((
const uint8_t*)lPageContents.data(), 4 * lPageContents.size()));
407
408
409 const std::deque< std::pair< uint8_t* , uint32_t > >& lReplyBuffers ( lBuffers->getReplyBuffer() );
410 size_t lNrWordsInPacket = (lPageContents.at(0) >> 16) + (lPageContents.at(0) & 0xFFFF);
411 if (lNrWordsInPacket != (lBuffers->replyCounter() >> 2))
412 log (uhal::Warning(),
"Expected reply packet to contain ", Integer(lBuffers->replyCounter() >> 2),
" words, but it actually contains ", Integer(lNrWordsInPacket),
" words");
413
414 size_t lNrBytesCopied = 0;
415 for (const auto& lBuffer: lReplyBuffers)
416 {
417
418 if ( lNrBytesCopied >= 4*lNrWordsInPacket)
419 break;
420
421 size_t lNrBytesToCopy = std::min( lBuffer.second , uint32_t(4*lNrWordsInPacket - lNrBytesCopied) );
422 memcpy ( lBuffer.first, &lPageContents.at(1 + (lNrBytesCopied / 4)), lNrBytesToCopy );
423 lNrBytesCopied += lNrBytesToCopy;
424 }
425
426
427
428 uhal::exception::exception* lExc = NULL;
429 try
430 {
431 lExc = ClientInterface::validate ( lBuffers );
432 }
433 catch ( uhal::exception::exception& aExc )
434 {
435 uhal::exception::ValidationError lExc2;
436 log ( lExc2 ,
"Exception caught during reply validation for Axi4Lite device with URI " , uhal::Quote ( this->
uri() ) ,
"; what returned: " , uhal::Quote ( aExc.what() ) );
437 throw lExc2;
438 }
439
440 if (lExc != NULL)
441 lExc->throwAsDerivedType();
442}