120 const std::vector<std::pair<const uint8_t*, size_t> >& aData) {
121 if (mBar ==
nullptr) open();
124 for (
size_t i = 0; i < aData.size(); i++) lNrBytes += aData.at(i).second;
126 assert((lNrBytes % 4) == 0);
127 size_t lNrWords = lNrBytes/4;
129 createBuffer(lNrBytes);
132 for (
size_t i = 0; i < aData.size(); ++i) {
133 for (
size_t j = 0; j < aData.at(i).second; ++j) {
134 mBuffer[k] = aData.at(i).first[j];
139 auto mBuffer32b =
reinterpret_cast<const uint32_t*
>(mBuffer);
141 for (
size_t i(0); i<lNrWords; ++i) {
142 mBar[aAddr + i] = htole32(mBuffer32b[i]);
358 SteadyClock_t::time_point lStartTime = SteadyClock_t::now();
362 uint32_t lHwPublishedPageCount = 0x0;
364 std::vector<uint32_t> lValues;
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()));
378 if (SteadyClock_t::now() - lStartTime > std::chrono::microseconds(getBoostTimeoutPeriod().total_microseconds())) {
379 exception::Axi4LiteTimeout lExc;
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");
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),
")");
396 std::shared_ptr<uhal::Buffers> lBuffers =
mReplyQueue.front();
399 uint32_t lNrWordsToRead(lBuffers->replyCounter() >> 2);
402 std::vector<uint32_t> lPageContents;
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()));
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");
414 size_t lNrBytesCopied = 0;
415 for (
const auto& lBuffer: lReplyBuffers)
418 if ( lNrBytesCopied >= 4*lNrWordsInPacket)
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;
428 uhal::exception::exception* lExc = NULL;
431 lExc = ClientInterface::validate ( lBuffers );
433 catch ( uhal::exception::exception& aExc )
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() ) );
441 lExc->throwAsDerivedType();