Commit bbe7baca authored by Sarah Seif El Nasr's avatar Sarah Seif El Nasr
Browse files

DEBUG - DO NOT USE - added method to keep track of number of CPB writes and reads per chip/lpGBT

parent 198ce9b7
......@@ -87,6 +87,8 @@ class Cbc : public ReadoutChip
else
return 8;
}
};
} // namespace Ph2_HwDescription
......
......@@ -163,12 +163,31 @@ class Chip : public FrontEndDescription
//std::cout << "\t\t\t Value is 0x" << std::hex << getReg(pReg) << std::dec << " Mask is 0x" << std::hex << cRegMask << std::dec << " value is " << +cValue << "\n";
return cValue;
}
// update write count
void updateWriteCount(uint32_t fIncrement=1 ){ fI2CWrites+= fIncrement ; }
void updateReadCount(uint32_t fIncrement=1){ fI2Reads+= fIncrement ; }
void updateRBMismatchCount(uint32_t fIncrement=1){ fI2CReadMismatches+= fIncrement ; }
void updateRegWriteCount(uint32_t fIncrement=1){ fRegWrites+= fIncrement ; }
void updateRegReadCount(uint32_t fIncrement=1){ fRegReads+= fIncrement ; }
uint32_t getWriteCount(){ return fI2CWrites;}
uint32_t getReadCount(){ return fI2Reads;}
uint32_t getRBMismatchCount(){ return fI2CReadMismatches;}
uint32_t getRegWriteCount(){ return fRegWrites;}
uint32_t getRegReadCount(){ return fRegReads;}
protected:
uint8_t fChipId;
uint16_t fMaxRegValue;
uint16_t fClockFrequency;
ChipRegMap fRegMap;
CommentMap fCommentMap;
private:
uint32_t fI2CWrites=0;
uint32_t fI2Reads=0;
uint32_t fI2CReadMismatches=0;
uint32_t fRegWrites=0;
uint32_t fRegReads=0;
};
/*!
......
......@@ -64,12 +64,22 @@ class lpGBT : public Chip
uint8_t getRxHSLPolarity() { return fRxHSLPolarity; }
uint8_t getTxHSLPolarity() { return fTxHSLPolarity; }
void updateWriteCount(uint8_t pMasterId, uint32_t fIncrement=1 ){ fI2CWrites[pMasterId]+= fIncrement ; }
void updateReadCount(uint8_t pMasterId, uint32_t fIncrement=1){ fI2CReads[pMasterId]+= fIncrement ; }
uint32_t getWriteCount(uint8_t pMasterId){ return fI2CWrites[pMasterId];}
uint32_t getReadCount(uint8_t pMasterId){ return fI2CReads[pMasterId];}
private:
bool phaseRxAligned; // @TMP@
std::string configFileName;
std::vector<uint8_t> fClocks, fRxGroups, fRxChannels, fTxGroups, fTxChannels;
uint16_t fClocksFrequency, fRxDataRate, fTxDataRate;
uint8_t fRxHSLPolarity, fTxHSLPolarity;
// number of write transactions - one element per master
std::vector<uint32_t> fI2CWrites{0,0,0};
// number of read transactions - one element per master
std::vector<uint32_t> fI2CReads{0,0,0};
};
} // namespace Ph2_HwDescription
......
......@@ -328,6 +328,10 @@ class BeBoardFWInterface : public RegManager
fCPBConfig.fMaxAttempts = pConfig.fMaxAttempts;
fCPBConfig.fI2CFrequency = pConfig.fI2CFrequency;
}
// return functions for internal I2C reads and writes
uint32_t getWriteCount(){ return fI2CWriteCount;}
uint32_t getReadCount(){ return fI2CReadCount;}
uint32_t getRBMismatchCount(){ return fI2CReadMismatches;}
protected:
uint32_t fBlockSize{0};
......@@ -350,6 +354,12 @@ class BeBoardFWInterface : public RegManager
return pMismatchedWriteVector;
}
protected :
// I2C write and read count
uint32_t fI2CWriteCount{0};
uint32_t fI2CReadCount{0};
uint32_t fI2CReadMismatches{0};
};
} // namespace Ph2_HwInterface
......
......@@ -334,7 +334,9 @@ uint16_t CbcInterface::readErrorRegister(ReadoutChip* pCbc)
{
bool cVerifLoop = true;
bool cSuccess = ConfigurePage(pCbc, cRegItem.fPage, cVerifLoop);
if(cSuccess) cErrorReg = fBoardFW->ReadFERegister(pCbc, cRegItem.fAddress);
if(cSuccess){
cErrorReg = fBoardFW->ReadFERegister(pCbc, cRegItem.fAddress);
}
}
return cErrorReg;
}
......@@ -829,7 +831,9 @@ uint8_t CbcInterface::ReadChipSingleReg(Chip* pCbc, const std::string& pRegNode)
{
bool cVerifLoop = true;
bool cSuccess = ( pRegNode == "FeCtrl&TrgLat2" ) ? true : ConfigurePage(pCbc, cRegItem.fPage, cVerifLoop);
if(cSuccess) cValue = fBoardFW->ReadFERegister(pCbc, cRegItem.fAddress);
if(cSuccess){
cValue = fBoardFW->ReadFERegister(pCbc, cRegItem.fAddress);
}
}
pCbc->setReg(pRegNode, cValue);
......
......@@ -621,7 +621,7 @@ void D19cFWInterface::configureLink(const BeBoard* pBoard)
if(cSCAenabled == 1) LOG(INFO) << BOLDBLUE << "SCA enabled successfully." << RESET;
cGBTx.scaConfigureGPIO(this);
// configure GBTx
bool cRisingEdge = false;
bool cRisingEdge = true;
// cGBTx.gbtxResetPhaseShifterClocks(this);
cGBTx.gbtxConfigureChargePumps(this);
cGBTx.gbtxResetPhaseShifterClocks(this);
......@@ -5718,7 +5718,7 @@ bool D19cFWInterface::I2CWrite(uint8_t pLinkId, uint8_t pMasterId, uint8_t pSlav
std::this_thread::sleep_for(std::chrono::microseconds(50));
std::vector<uint32_t> cReplyVector = ReadReplyCPB(10);
fI2Cstatus = cReplyVector[7] & 0xFF;
size_t cIter = 0, cMaxIter = fCPBConfig.fMaxAttempts;
size_t cIter = 0, cMaxIter = fCPBConfig.fMaxAttempts;
while(fI2Cstatus != 4 && cIter < cMaxIter && fCPBConfig.fReTry)
{
// // reset link
......@@ -5748,6 +5748,7 @@ bool D19cFWInterface::I2CWrite(uint8_t pLinkId, uint8_t pMasterId, uint8_t pSlav
fI2Cstatus = cReplyVector[7] & 0xFF;
cIter++;
}
fI2CWriteCount+= (1+cIter);
if(cIter == cMaxIter)
{
LOG(INFO) << BOLDRED << "[D19cFWInterface::I2CWrite] Iter#" << +cIter << " I2CM" << +pMasterId << " status indicates a failure 0x" << std::hex << +fI2Cstatus << std::dec
......@@ -5814,6 +5815,7 @@ uint8_t D19cFWInterface::I2CRead(uint8_t pLinkId, uint8_t pMasterId, uint8_t pSl
if(cIter == cMaxIter - 1) LOG(INFO) << BOLDRED << "[D19cFWInterface::I2CRead] : Corrupted CPB reply frame" << RESET;
cIter++;
};
fI2CReadCount += (1+cIter);
if(cIter == cMaxIter) throw std::runtime_error(std::string("[D19cFWInterface::I2CRead] : Corrupted CPB reply frame"));
return cReadBack;
}
......@@ -5849,7 +5851,18 @@ bool D19cFWInterface::WriteFERegister(Ph2_HwDescription::Chip* pChip, uint16_t p
cNbytes = 2;
cSlaveData = (pRegisterValue << 8) | (pRegisterAddress & 0xFF);
}
fI2CWriteCount=0;
fI2CReadMismatches=0;
bool cSuccess = I2CWrite(cLinkId, cMasterId, cChipAddress, cSlaveData, cNbytes);
pChip->updateWriteCount( fI2CWriteCount );
if( fI2CWriteCount != 1 ){
std::stringstream cOutput;
pChip->printChipType(cOutput);
LOG (INFO) << BOLDYELLOW << "\t\t... Pre-verfication - took " << +fI2CWriteCount
<< " I2C writes to succeed in writing " << +pRegisterValue << " on register " << +pRegisterAddress
<< " for " << cOutput.str() << "#" << +pChip->getId() << " on Hybrid#" << +pChip->getHybridId()
<< RESET;
}
if(pVerify && cSuccess)
{
uint8_t cReadBack = ReadFERegister(pChip, pRegisterAddress);
......@@ -5861,14 +5874,29 @@ bool D19cFWInterface::WriteFERegister(Ph2_HwDescription::Chip* pChip, uint16_t p
LOG(INFO) << BOLDRED << "I2C ReadBack Mismatch in hybrid " << +pChip->getHybridId() << " Chip " << +cChipId << " register 0x" << std::hex << +pRegisterAddress << std::dec
<< " asked to write 0x" << std::hex << +pRegisterValue << std::dec << " and read back 0x" << std::hex << +cReadBack << std::dec << RESET;
}
cSuccess = I2CWrite(cLinkId, cMasterId, cChipAddress, cSlaveData, cNbytes);
if(cSuccess) { cReadBack = ReadFERegister(pChip, pRegisterAddress); }
// dont re-write - just try and read again
cReadBack = ReadFERegister(pChip, pRegisterAddress);
fI2CReadMismatches++;
// this was repeating both the write and the read
//cSuccess = I2CWrite(cLinkId, cMasterId, cChipAddress, cSlaveData, cNbytes);
//if(cSuccess) { cReadBack = ReadFERegister(pChip, pRegisterAddress); }
cIter++;
}
if(cReadBack != pRegisterValue) { throw std::runtime_error(std::string("I2C readback mismatch")); }
}
else if(!cSuccess)
LOG(INFO) << BOLDRED << "I2C Write FAILED - I2C status is " << +fI2Cstatus << RESET;
if( fI2CReadMismatches != 0 ){
std::stringstream cOutput;
pChip->printChipType(cOutput);
LOG (INFO) << BOLDYELLOW << "\t\t\t ...Post-verfication - took " << +fI2CReadMismatches
<< "attempts to read-back written value from " << +pRegisterValue << " on register " << +pRegisterAddress
<< " for " << cOutput.str() << "#" << +pChip->getId() << " on Hybrid#" << +pChip->getHybridId()
<< RESET;
}
pChip->updateRBMismatchCount( fI2CReadMismatches );
pChip->updateRegWriteCount();
return cSuccess;
}
......@@ -5894,8 +5922,13 @@ uint8_t D19cFWInterface::ReadFERegister(Ph2_HwDescription::Chip* pChip, uint16_t
cSlaveData = (pRegisterAddress & 0xFF);
}
fI2CWriteCount=0;
I2CWrite(cLinkId, cMasterId, cChipAddress, cSlaveData, cNbytes);
pChip->updateWriteCount( fI2CWriteCount );
fI2CReadCount=0;
uint32_t cReadBack = I2CRead(cLinkId, cMasterId, cChipAddress, 1);
pChip->updateReadCount( fI2CReadCount );
pChip->updateRegReadCount();
return cReadBack;
}
......
......@@ -830,6 +830,7 @@ class D19cFWInterface : public BeBoardFWInterface
// fast command generic block
void ResetFCMDBram();
void ConfigureFCMDBram(std::vector<uint8_t> pFastCommands);
};
} // namespace Ph2_HwInterface
......
......@@ -32,7 +32,7 @@ bool D19clpGBTInterface::ConfigureChip(Ph2_HwDescription::Chip* pChip, bool pVer
cCPBconfig.fEnable = fUseCPB;
cCPBconfig.fI2CFrequency = 3;
cCPBconfig.fWait_us = 50; // TO-DO - make configurable from xml
cCPBconfig.fReTry = 1; // TO-DO - make configurable from xml
cCPBconfig.fReTry = 0; // TO-DO - make configurable from xml
cCPBconfig.fVerbose = 0; // TO-DO - make configurable from xml
cCPBconfig.fMaxAttempts = 1000; // TO-DO - make configurable from xml
fBoardFW->ConfigureCPB(cCPBconfig);
......
......@@ -155,7 +155,6 @@ class D19clpGBTInterface : public lpGBTInterface
if(fFeType == FrontEndType::OuterTrackerPS) return {fReset_LHS_CIC, fReset_LHS_MPA, fReset_LHS_SSA, fReset_RHS_CIC, fReset_RHS_MPA, fReset_RHS_SSA};
return {};
}
private:
// default clock configuration
lpGBTClockConfig fClkConfig;
......@@ -171,6 +170,11 @@ class D19clpGBTInterface : public lpGBTInterface
// reset
uint8_t fResetMinPeriod = 100; // ms was 100
// number of read transactions
uint8_t fI2CReads_M0 = 0 ;
uint8_t fI2CReads_M1 = 0 ;
uint8_t fI2CReads_M2 = 0 ;
// clocks
uint8_t fClock_RHS_Hybrid = 1;
uint8_t fClock_LHS_Hybrid = 11;
......
......@@ -270,6 +270,41 @@ class SystemController
void DecodeData(const Ph2_HwDescription::BeBoard* pBoard, const std::vector<uint32_t>& pData, uint32_t pNevents, BoardType pType);
double findValueInSettings(const std::string name, double defaultValue = 0.) const;
void PrintRegCount()
{
// print number of I2C transactions
for(auto cBoard: *fDetectorContainer)
{
for(auto cOpticalGroup: *cBoard)
{
auto& clpGBT = cOpticalGroup->flpGBT;
for(auto cHybrid: *cOpticalGroup)
{
LOG (INFO) << BOLDBLUE << "Hybrid#" << +cHybrid->getId() << RESET;
uint8_t cMasterId = (cHybrid->getId()%2 == 0 ) ? 2 : 0 ;
for(auto cChip: *cHybrid)
{
LOG (INFO) << BOLDMAGENTA << "\t\t..Chip#" << +cChip->getId()
<< " performed " << cChip->getWriteCount() << " CPB I2C writes and "
<< cChip->getReadCount() << " CPB I2C reads; "
<< " wrote " << cChip->getRegWriteCount() << " registers and read "
<< cChip->getRegReadCount() << " registers."
<< RESET;
if( clpGBT != nullptr )
{
clpGBT->updateWriteCount( cMasterId , cChip->getWriteCount() );
clpGBT->updateReadCount( cMasterId , cChip->getReadCount() );
}
}
if( clpGBT != nullptr )
{
LOG (INFO) << BOLDBLUE << "\tCPB I2C writes on Master" << +cMasterId << " : " << clpGBT->getWriteCount( cMasterId ) << RESET;
LOG (INFO) << BOLDBLUE << "\tCPB I2C reads on Master" << +cMasterId << " : " << clpGBT->getReadCount( cMasterId ) << RESET;
}
}
}
}
}
private:
void SetFuture(const Ph2_HwDescription::BeBoard* pBoard, const std::vector<uint32_t>& pData, uint32_t pNevents, BoardType pType);
......
......@@ -55,14 +55,14 @@
</Global>
<CBC_Files path="${PH2ACF_BASE_DIR}/settings/CbcFiles/" />
<CBC Id="4" configfile="CBC3_default.txt" />
<!-- <CBC Id="1" configfile="CBC3_default.txt" />
<CBC Id="0" configfile="CBC3_default.txt" />
<CBC Id="1" configfile="CBC3_default.txt" />
<CBC Id="2" configfile="CBC3_default.txt" />
<CBC Id="3" configfile="CBC3_default.txt" />
<CBC Id="4" configfile="CBC3_default.txt" />
<CBC Id="5" configfile="CBC3_default.txt" />
<CBC Id="6" configfile="CBC3_default.txt" />
<CBC Id="7" configfile="CBC3_default.txt" /> -->
<CBC Id="7" configfile="CBC3_default.txt" />
<CIC_Files path="${PH2ACF_BASE_DIR}/settings/CicFiles/" />
......@@ -79,14 +79,14 @@
</Global>
<CBC_Files path="${PH2ACF_BASE_DIR}/settings/CbcFiles/" />
<CBC Id="4" configfile="CBC3_default.txt" />
<!-- <CBC Id="1" configfile="CBC3_default.txt" />
<CBC Id="0" configfile="CBC3_default.txt" />
<CBC Id="1" configfile="CBC3_default.txt" />
<CBC Id="2" configfile="CBC3_default.txt" />
<CBC Id="3" configfile="CBC3_default.txt" />
<CBC Id="4" configfile="CBC3_default.txt" />
<CBC Id="5" configfile="CBC3_default.txt" />
<CBC Id="6" configfile="CBC3_default.txt" />
<CBC Id="7" configfile="CBC3_default.txt" /> -->
<CBC Id="7" configfile="CBC3_default.txt" />
<CIC_Files path="${PH2ACF_BASE_DIR}/settings/CicFiles/" />
......
......@@ -12,7 +12,7 @@
<!-- RHS -->
<OpticalGroup Id="0" FMCId="0" >
<GBT phaseTap="7" enable="1"/>
<GBT phaseTap="8" enable="1"/>
<Hybrid Id="0" Status="1" LinkId="0" >
<Global>
<Settings threshold="560" latency="200"/>
......@@ -35,7 +35,7 @@
<CIC_Files path="${PH2ACF_BASE_DIR}/settings/CicFiles/" />
<CIC2 Id="8" configfile="CIC2_default.txt" />
</Hybrid>
<Hybrid Id="1" Status="1" LinkId="0" >
<Hybrid Id="1" Status="0" LinkId="0" >
<Global>
<Settings threshold="560" latency="200"/>
<TestPulse enable="1" polarity="0" amplitude="0xE1" channelgroup="0" delay="0" groundothers="0"/>
......
......@@ -775,6 +775,7 @@ int main(int argc, char* argv[])
cShortFinder.waitForRunToBeCompleted();
cShortFinder.Stop();
}
cTool.PrintRegCount();
cTool.dumpConfigFiles();
cTool.SaveResults();
cTool.WriteRootFile();
......@@ -791,7 +792,6 @@ int main(int argc, char* argv[])
cGoodRuns.open("GoodRunNumbers.dat", std::fstream::app);
cGoodRuns << cRunNumber << "\n";
cGoodRuns.close();
#ifdef __POWERSUPPLY__
cPowerLog.open(cTool.getDirectoryName() + "/PowerLog.tab", std::ios::app);
const auto cStop = std::chrono::system_clock::now();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment