Skip to content

Commit 7a9588f

Browse files
committed
Add external CRORC error-checking
1 parent 7710bdb commit 7a9588f

File tree

1 file changed

+55
-17
lines changed

1 file changed

+55
-17
lines changed

src/CommandLineUtilities/ProgramDmaBench.cxx

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -833,11 +833,51 @@ class ProgramDmaBench: public Program
833833
}
834834

835835
bool checkErrorsCrorcExternal(uintptr_t pageAddress, size_t pageSize, int64_t eventNumber, int linkId)
836-
{ // TODO: Update for new RDH
837-
uint32_t dataCounter = 0; //always start at 0 for CRUs Internal loopbacks
838-
uint32_t packetCounter = mPacketCounters[linkId] + 1;
836+
{
837+
// TODO: Clean this up
838+
// DataFormat is the same as the CRU
839+
const auto memBytes = Cru::DataFormat::getEventSize(reinterpret_cast<const char*>(pageAddress));
840+
if (memBytes < 40 || memBytes > pageSize) {
841+
mErrorCount++;
842+
if (mErrorCount < MAX_RECORDED_ERRORS) {
843+
mErrorStream <<
844+
b::format("[RDHERR]\tevent:%1% l:%2% payloadBytes:%3% size:%4% words out of ranger\n")
845+
% eventNumber % linkId % memBytes % pageSize;
846+
}
847+
return true;
848+
}
839849

840-
auto page = reinterpret_cast<const volatile uint32_t*>(pageAddress);
850+
uint32_t packetCounter = Cru::DataFormat::getPacketCounter(reinterpret_cast<const char*>(pageAddress));
851+
852+
if (mPacketCounters[linkId] == PACKET_COUNTER_INITIAL_VALUE) {
853+
mErrorStream <<
854+
b::format("resync packet counter for e%d l:%d packet_cnt:%x mpacket_cnt:%x, le:%d \n") % eventNumber % linkId % packetCounter %
855+
mPacketCounters[linkId] % mEventCounters[linkId];
856+
mPacketCounters[linkId] = packetCounter;
857+
} else if (((mPacketCounters[linkId] + 1) % (mMaxRdhPacketCounter + 1)) != packetCounter) {
858+
mErrorCount++;
859+
if (mErrorCount < MAX_RECORDED_ERRORS) {
860+
mErrorStream <<
861+
b::format("[RDHERR]\tevent:%1% l:%2% packet_cnt:%3% mpacket_cnt:%4% unexpected packet counter\n")
862+
% eventNumber % linkId % packetCounter % mPacketCounters[linkId];
863+
}
864+
return true;
865+
} else {
866+
mPacketCounters[linkId] = packetCounter;
867+
}
868+
869+
//TODO: fast check
870+
/*
871+
if (mFastCheckEnabled) {
872+
return false;
873+
}
874+
*/
875+
876+
// Every page starts from a clean slate
877+
uint32_t dataCounter = 0;
878+
879+
// Skip the RDH
880+
auto page = reinterpret_cast<const volatile uint32_t*>(pageAddress + Cru::DataFormat::getHeaderSize());
841881

842882
bool foundError = false;
843883
auto checkValue = [&](uint32_t i, uint32_t expectedValue, uint32_t actualValue) {
@@ -848,21 +888,16 @@ class ProgramDmaBench: public Program
848888
};
849889

850890
uint32_t offset = dataCounter;
851-
size_t pageSize32 = pageSize/sizeof(uint32_t); //Addressable size of dma page
852-
853-
if (page[0] != packetCounter) {
854-
mErrorStream <<
855-
b::format("[RDHERR]\tevent:%1% l:%2% packet_cnt:%3% lpacket_cnt%4% mpacket_cnt:%5% unexpected packet counter\n")
856-
% eventNumber % linkId % page[0] % packetCounter % mPacketCounters[linkId];
857-
}
891+
size_t pageSize32 = (memBytes - Cru::DataFormat::getHeaderSize())/sizeof(uint32_t); //Addressable size of dma page (after RDH)
858892

859-
for (size_t i=1; i < pageSize32; i++) { //iterate through sp
893+
for (size_t i=0; i < pageSize32; i++) { //iterate through dmaPage
894+
if (i == (pageSize32 - 1)) { //skip the DTSW at the end of the page
895+
continue;
896+
}
860897
checkValue(i, offset, page[i]);
861898
offset = (offset+1) % (0x100000000);
862899
}
863900

864-
mPacketCounters[linkId] = (mPacketCounters[linkId] + 1) % (0x100000000);
865-
866901
return foundError;
867902
}
868903

@@ -885,9 +920,12 @@ class ProgramDmaBench: public Program
885920
size_t pageSize32 = pageSize/sizeof(uint32_t); //Addressable size of dma page
886921

887922
if (page[0] != packetCounter) {
888-
mErrorStream <<
889-
b::format("[RDHERR]\tevent:%1% l:%2% packet_cnt:%3% lpacket_cnt%4% mpacket_cnt:%5% unexpected packet counter\n")
890-
% eventNumber % linkId % page[0] % packetCounter % mPacketCounters[linkId];
923+
mErrorCount++;
924+
if (mErrorCount < MAX_RECORDED_ERRORS) {
925+
mErrorStream <<
926+
b::format("[RDHERR]\tevent:%1% l:%2% packet_cnt:%3% lpacket_cnt%4% mpacket_cnt:%5% unexpected packet counter\n")
927+
% eventNumber % linkId % page[0] % packetCounter % mPacketCounters[linkId];
928+
}
891929
}
892930

893931
for (size_t i=1; i < pageSize32; i++) { //iterate through sp

0 commit comments

Comments
 (0)