192Flx::Card::read(
const uint32_t aAddr,
const uint32_t aNrWords, std::vector<uint32_t>& aValues)
198 flxcard_bar2_regs_t* bar2 = (flxcard_bar2_regs_t*)
mFlxCard.openBackDoor(2);
201 uint32_t lNrReads64b = (aNrWords + 1) / 2;
202 uint32_t lAddr = aAddr / 2;
204 for (uint32_t i(0); i < lNrReads64b; i++) {
206 bar2->IPBUS_READ_ADDRESS = lAddr + i;
208 uint64_t lDataWord = bar2->IPBUS_READ_DATA;
210 aValues.push_back(lDataWord & 0xffffffff);
211 if (2 * i + 1 < aNrWords)
212 aValues.push_back(lDataWord >> 32);
215 log(uhal::Debug(),
"Flx::Card::read, ", aNrWords,
" requested, ", aValues.size(),
" read");
220Flx::Card::write(
const uint32_t aAddr,
const std::vector<std::pair<const uint8_t*, size_t>>& aData)
226 flxcard_bar2_regs_t* bar2 = (flxcard_bar2_regs_t*)
mFlxCard.openBackDoor(2);
229 for (
size_t i = 0; i < aData.size(); i++)
230 lNrBytes += aData.at(i).second;
232 assert((lNrBytes % 4) == 0);
234 char* allocated = NULL;
235 posix_memalign((
void**)&allocated, 4096 , lNrBytes + 4096);
236 if (allocated == NULL) {
237 exception::FlxCommunicationError lExc;
238 log(lExc,
"Failed to allocate ", uhal::Integer(lNrBytes + 4096),
" bytes in File::write/2 function");
243 char* buffer = allocated;
244 size_t lNrBytesCopied = 0;
245 for (
size_t i = 0; i < aData.size(); i++) {
246 memcpy(buffer + lNrBytesCopied, aData.at(i).first, aData.at(i).second);
247 lNrBytesCopied += aData.at(i).second;
251 uint32_t lAddr = aAddr / 2;
253 while (lNrBytesCopied < lNrBytes) {
254 bar2->IPBUS_WRITE_ADDRESS = lAddr;
255 char* lSrcPtr = buffer + lNrBytesCopied;
256 if ((lNrBytes - lNrBytesCopied) >= 8) {
257 bar2->IPBUS_WRITE_DATA.DATA = *(uint64_t*)lSrcPtr;
259 }
else if ((lNrBytes - lNrBytesCopied) >= 4) {
260 bar2->IPBUS_WRITE_DATA.DATA = uint64_t(*(uint32_t*)lSrcPtr);
436 log(uhal::Debug(),
"flx client is opening device file ", uhal::Quote(
mDeviceFile.
getPath()));
437 std::vector<uint32_t> lValues;
440 "Read status info from addr 0 (",
441 uhal::Integer(lValues.at(0)),
443 uhal::Integer(lValues.at(1)),
445 uhal::Integer(lValues.at(2)),
447 uhal::Integer(lValues.at(3)),
449 PacketFmt((
const uint8_t*)lValues.data(), 4 * lValues.size()));
459 if (lValues.at(1) > 0xFFFF) {
460 exception::FlxInitialisationError lExc;
462 "Invalid page size, ",
463 uhal::Integer(lValues.at(1)),
464 ", reported in device file ",
470 exception::FlxInitialisationError lExc;
474 ", reported in device file ",
476 " is inconsistent with number of pages, ",
483 "flx client connected to device at ",
487 " pages, each of size ",
491 " should be filled next");
523 uhal::Integer(aBuffers->sendCounter() / 4),
524 "-word packet to page ",
529 const uint32_t lHeaderWord = (0x10000 | (((aBuffers->sendCounter() / 4) - 1) & 0xFFFF));
530 std::vector<std::pair<const uint8_t*, size_t>> lDataToWrite;
531 lDataToWrite.push_back(std::make_pair(
reinterpret_cast<const uint8_t*
>(&lHeaderWord),
sizeof lHeaderWord));
532 lDataToWrite.push_back(std::make_pair(aBuffers->getSendBuffer(), aBuffers->sendCounter()));
538 uhal::Integer((aBuffers->sendCounter() / 4) + 1),
539 " 32-bit words at address ",
552 SteadyClock_t::time_point lStartTime = SteadyClock_t::now();
555 uint32_t lHwPublishedPageCount = 0x0;
557 std::vector<uint32_t> lValues;
562 lHwPublishedPageCount = lValues.at(3);
567 "Read status info from addr 0 (",
568 uhal::Integer(lValues.at(0)),
570 uhal::Integer(lValues.at(1)),
572 uhal::Integer(lValues.at(2)),
574 uhal::Integer(lValues.at(3)),
576 PacketFmt((
const uint8_t*)lValues.data(), 4 * lValues.size()));
584 if (SteadyClock_t::now() - lStartTime > std::chrono::microseconds(getBoostTimeoutPeriod().total_microseconds())) {
585 exception::FlxTimeout lExc;
588 uhal::Integer(lPageIndexToRead),
600 ") : Trying to read page index ",
601 uhal::Integer(lPageIndexToRead),
604 "; published page count is ",
605 uhal::Integer(lHwPublishedPageCount),
620 uhal::Integer(lPageIndexToRead),
621 " (published count ",
622 uhal::Integer(lHwPublishedPageCount),
623 ", surpasses required, ",
630 std::shared_ptr<uhal::Buffers> lBuffers =
mReplyQueue.front();
633 uint32_t lNrWordsToRead(lBuffers->replyCounter() >> 2);
636 std::vector<uint32_t> lPageContents;
642 uhal::Integer(lNrWordsToRead),
643 " 32-bit words from address ",
644 uhal::Integer(4 + lPageIndexToRead * 4 *
mPageSize),
646 PacketFmt((
const uint8_t*)lPageContents.data(), 4 * lPageContents.size()));
649 const std::deque<std::pair<uint8_t*, uint32_t>>& lReplyBuffers(lBuffers->getReplyBuffer());
650 size_t lNrWordsInPacket = (lPageContents.at(0) >> 16) + (lPageContents.at(0) & 0xFFFF);
651 if (lNrWordsInPacket != (lBuffers->replyCounter() >> 2))
653 "Expected reply packet to contain ",
654 uhal::Integer(lBuffers->replyCounter() >> 2),
655 " words, but it actually contains ",
656 uhal::Integer(lNrWordsInPacket),
659 size_t lNrBytesCopied = 0;
660 for (std::deque<std::pair<uint8_t*, uint32_t>>::const_iterator lIt = lReplyBuffers.begin();
661 lIt != lReplyBuffers.end();
664 if (lNrBytesCopied >= 4 * lNrWordsInPacket)
667 size_t lNrBytesToCopy = std::min(lIt->second, uint32_t(4 * lNrWordsInPacket - lNrBytesCopied));
668 memcpy(lIt->first, &lPageContents.at(1 + (lNrBytesCopied / 4)), lNrBytesToCopy);
669 lNrBytesCopied += lNrBytesToCopy;
674 if (uhal::exception::exception* lExc =
675 ClientInterface::validate(lBuffers))
679 }
catch (uhal::exception::exception& aExc) {
682 "Exception caught during reply validation for flx device with URI ",
683 uhal::Quote(this->uri()),
685 uhal::Quote(aExc.what()));