Commit 533fca2e authored by Fabio Ravera's avatar Fabio Ravera
Browse files

Merge branch 'Dev_HybridTests_PS' into 'Dev'

Synchronizing hybrid test system branch (Attempt#0)

See merge request cms_tk_ph2/Ph2_ACF!256
parents a0e37788 3c6095dd
......@@ -12,6 +12,7 @@ logs/*
*.raw
Results/
Results/**
ResultsGUI/*
MonitorResults/**
RunNumbers.dat
*.log
......@@ -27,4 +28,12 @@ settings/connections_186.xml
consoledump.log
src/test.cc
build/
rundir*
\ No newline at end of file
rundir*
ReadRootFile.py
core.*
FEH_PS*/
*.cc
*.bin
.vscode/*
*.py
*.txt
......@@ -67,7 +67,7 @@ class Cic : public Chip
uint8_t getEdgeSelect() { return fEdgeSel; }
protected:
uint8_t fDriveStrength{3}; // drive strength 1-5
uint8_t fDriveStrength{5}; // drive strength 1-5
uint8_t fEdgeSel{0}; // 0 - positive edge, 1 - negative edge
};
} // namespace Ph2_HwDescription
......
......@@ -50,6 +50,10 @@ class SSA : public ReadoutChip
return true;
else if(dacName.find("ThresholdTrim") != std::string::npos)
return true;
if(dacName.find("GAINTRIMMING_S", 0, 12) != std::string::npos)
return true;
else if(dacName.find("GainTrim") != std::string::npos)
return true;
else
return false;
}
......@@ -59,6 +63,10 @@ class SSA : public ReadoutChip
return 5;
else if(dacName.find("ThresholdTrim") != std::string::npos)
return 5;
if(dacName.find("GAINTRIMMING_S", 0, 12) != std::string::npos)
return 4;
else if(dacName.find("GainTrim") != std::string::npos)
return 4;
else
return 8;
}
......
......@@ -23,8 +23,6 @@ ChipInterface::ChipInterface(const BeBoardFWMap& pBoardMap) : fBoardMap(pBoardMa
#endif
}
ChipInterface::~ChipInterface() {}
void ChipInterface::output()
{
#ifdef COUNT_FLAG
......
......@@ -24,7 +24,13 @@ class ChannelContainer;
namespace Ph2_HwInterface
{
using BeBoardFWMap = std::map<uint16_t, BeBoardFWInterface*>; /*!< Map of Board connected */
// #ifdef __TCUSB__
// #ifdef __ROH_USB__
// using TestCardInterface = TCInterface<TC_PSROH>;
// #elif __SEH_USB__
// using TestCardInterface = TCInterface<TC_2SSEH>;
// #endif
// #endif
/*!
* \class ChipInterface
* \brief Class representing the User Interface to the Chip on different boards
......@@ -33,13 +39,20 @@ class ChipInterface
{
protected:
std::recursive_mutex fMutex;
BeBoardFWMap fBoardMap; /*!< Map of Board connected */
BeBoardFWInterface* fBoardFW; /*!< Board loaded */
uint16_t fPrevBoardIdentifier; /*!< Id of the previous board */
uint16_t fRegisterCount; /*!< Counter for the number of Registers written */
uint16_t fTransactionCount; /*!< Counter for the number of Transactions */
bool fWithlpGBT = false; /*!< lpGBT is used for configuration */
BeBoardFWMap fBoardMap; /*!< Map of Board connected */
BeBoardFWInterface* fBoardFW; /*!< Board loaded */
// #ifdef __TCUSB__
// #ifdef __ROH_USB__
// TCInterface<TC_PSROH>* fExternalController;
// #elif __SEH_USB__
// TCInterface<TC_2SSEH>* fExternalController;
// #endif
// #endif
uint16_t fPrevBoardIdentifier; /*!< Id of the previous board */
uint16_t fRegisterCount; /*!< Counter for the number of Registers written */
uint16_t fTransactionCount; /*!< Counter for the number of Transactions */
bool fWithlpGBT = false; /*!< lpGBT is used for configuration */
/*!
* \brief Set the board to talk with
......@@ -57,7 +70,7 @@ class ChipInterface
/*!
* \brief Destructor of the ChipInterface Class
*/
virtual ~ChipInterface();
virtual ~ChipInterface() {}
/*!
* \brief Configure the Chip with the Chip Config File
......
......@@ -52,7 +52,7 @@ std::string D19cDebugFWInterface::L1ADebug(uint8_t pWait_ms, bool pPrint)
}
return cBuffer;
}
std::vector<std::string> D19cDebugFWInterface::StubDebug(bool pWithTestPulse, uint8_t pNlines)
std::vector<std::string> D19cDebugFWInterface::StubDebug(bool pWithTestPulse, uint8_t pNlines, bool pPrint)
{
LOG(INFO) << BOLDBLUE << "D19cDebugFWInterface::StubDebug ...." << RESET;
......@@ -95,7 +95,7 @@ std::vector<std::string> D19cDebugFWInterface::StubDebug(bool pWithTestPulse, ui
cOutput_wSpace += *cIt + " ";
cOutput += *cIt;
}
LOG(INFO) << BOLDBLUE << "Line " << +cLine << " : " << cOutput_wSpace << RESET;
if(pPrint) LOG(INFO) << BOLDBLUE << "Line " << +cLine << " : " << cOutput_wSpace << RESET;
cLines.push_back(cOutput);
// cStrLength = cOutput.length();
cLine++;
......
......@@ -17,7 +17,7 @@ class D19cDebugFWInterface : public BeBoardFWInterface
~D19cDebugFWInterface();
public:
std::vector<std::string> StubDebug(bool pWithTestPulse = true, uint8_t pNlines = 6);
std::vector<std::string> StubDebug(bool pWithTestPulse = true, uint8_t pNlines = 6, bool pPrint = true);
std::string L1ADebug(uint8_t pWait_ms = 1, bool pPrint = true);
std::vector<std::string> ScopeStubLines(bool pWithTestPulse = true);
};
......
......@@ -74,7 +74,7 @@ void D19clpGBTInterface::SetConfigMode(bool pUseOpticalLink, bool pUseCPB, bool
LOG(INFO) << BOLDGREEN << "Using Serial Interface configuration mode" << RESET;
#ifdef __ROH_USB__
LOG(INFO) << BOLDBLUE << "Toggling Test Card" << RESET;
if(pToggleTC) fExternalInterface.getInterface().toggle_SCI2C();
if(pToggleTC && fExternalController != nullptr) fExternalController->getInterface().toggle_SCI2C();
#endif
fUseOpticalLink = true;
if(pUseCPB)
......
......@@ -11,10 +11,6 @@
#define D19clpGBTInterface_H
#include "lpGBTInterface.h"
#ifdef __TCUSB__
#include "USB_a.h"
#include "USB_libusb.h"
#endif
namespace Ph2_HwInterface
{
......@@ -23,6 +19,10 @@ class D19clpGBTInterface : public lpGBTInterface
public:
D19clpGBTInterface(const BeBoardFWMap& pBoardMap, bool pUseOpticalLink, bool pUseCPB) : lpGBTInterface(pBoardMap), fUseOpticalLink(pUseOpticalLink), fUseCPB(pUseCPB)
{
LOG(INFO) << BOLDRED << "Constructor D19clpGBTInterface" << RESET;
#ifdef __TCUSB__
iniitalizeExternalController();
#endif
// configure during constructor now when configuring chip
SetConfigMode(pUseOpticalLink, pUseCPB);
// configure CPB - do this here rather than in SystemController? Not sure
......@@ -37,7 +37,20 @@ class D19clpGBTInterface : public lpGBTInterface
// configure FW for all boards
for(auto cBoardMap: pBoardMap) { (cBoardMap.second)->ConfigureCPB(cCPBconfig); }
}
~D19clpGBTInterface() {}
~D19clpGBTInterface()
{
LOG(DEBUG) << BOLDRED << "Destructor D19clpGBTInterface" << RESET;
#ifdef __TCUSB__
#if defined(__ROH_USB__) || defined(__SEH_USB__)
if(fExternalController != nullptr)
{
LOG(INFO) << BOLDRED << "Deleting pointer to external controller for D19clpGBTInterface" << RESET;
delete fExternalController;
fExternalController = nullptr;
}
#endif
#endif
}
// ###################################
// # LpGBT register access functions #
......
This diff is collapsed.
......@@ -3,6 +3,8 @@
#define __ROHInterface_H__
#include "BeBoardFWInterface.h"
#include <boost/tokenizer.hpp>
#include <random>
namespace Ph2_HwInterface
{
......@@ -12,20 +14,41 @@ class DPInterface
public:
DPInterface();
~DPInterface();
void Configure(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint32_t pPattern);
void Configure(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint32_t pPattern, uint16_t pFrequency = 320);
// default config is for ps-feh data player
void Start(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pType = 0);
void Stop(Ph2_HwInterface::BeBoardFWInterface* pInterface);
//
void StartSyncPlaying(Ph2_HwInterface::BeBoardFWInterface* pInterface);
void StopSyncPlaying(Ph2_HwInterface::BeBoardFWInterface* pInterface);
//
void ResetFCMDBram(Ph2_HwInterface::BeBoardFWInterface* pInterface);
// default config is for ps-feh data player
bool IsRunning(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pType = 0);
void CheckNPatterns(Ph2_HwInterface::BeBoardFWInterface* pInterface);
bool IsRunning(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pType = 0);
void CheckNPatterns(Ph2_HwInterface::BeBoardFWInterface* pInterface);
void ConfigureLine(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint16_t pPattern, uint8_t pLine);
void ConfigureLineBRAM(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pLine, uint8_t pPattern, uint16_t pNumberOfClks);
void ConstPatternBRAMs(Ph2_HwInterface::BeBoardFWInterface* pInterface, std::vector<uint8_t> pPatterns, uint16_t pNumberOfClks);
bool ReadL1Data(Ph2_HwInterface::BeBoardFWInterface* pInterface);
uint16_t LoadL1Data(Ph2_HwInterface::BeBoardFWInterface* pInterface); // returns number of L1 triggers sent
uint16_t SendTriggers(Ph2_HwInterface::BeBoardFWInterface* pInterface);
void SetMaxNBx(uint16_t pNumberOfClks) { fMaxBx = pNumberOfClks; }
void CheckFcmdBRAM(Ph2_HwInterface::BeBoardFWInterface* pInterface);
void GenerateDummyData();
protected:
private:
bool fEmulatorRunning;
bool fEmulatorConfigured;
uint32_t fWait_us = 10;
std::vector<uint8_t> fFastCommands;
std::vector<std::vector<uint8_t>> fInputCICL1Data;
uint16_t fNTriggers;
uint16_t fMaxBx = 1000;
};
} // namespace Ph2_HwInterface
#endif
#endif
\ No newline at end of file
This diff is collapsed.
/*!
\file GbtInterface.h
\brief User Interface to the Cics
\version 1.0
*/
#ifndef __GbtInterface_H__
#define __GbtInterface_H__
#include "BeBoardFWInterface.h"
/*!
* \namespace Ph2_HwInterface
* \brief Namespace regrouping all the interfaces to the hardware
*/
// add break codes here
namespace Ph2_HwInterface
{
using SCAI2C = std::pair<uint32_t, uint32_t>;
/*!
* \class GbtInterface
* \brief Class representing the User Interface to the Cic on different boards
*/
class GbtInterface
{
public:
/*!
* \brief Constructor of the GbtInterface Class
* \param pBoardMap
*/
GbtInterface();
/*!
* \brief Destructor of the GbtInterface Class
*/
~GbtInterface();
// GBT specific functions
// Slow contron mux
void selectMux(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pLinkId, uint32_t cWait_ms = 100);
// SCA - enable I2C master interfaces, GPIO, ADC
uint8_t scaEnable(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint16_t cI2Cmaster = 0x00);
void scaConfigure(Ph2_HwInterface::BeBoardFWInterface* pInterface);
bool scaSetGPIO(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t cChannel, uint8_t cLevel);
uint8_t scaStatus(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pMaster);
// configure gpio [sca]
void scaConfigureGPIO(Ph2_HwInterface::BeBoardFWInterface* pInterface);
uint16_t readAdcChn(Ph2_HwInterface::BeBoardFWInterface* pInterface, std::string pValueToRead, bool pConvertRawReading = false);
uint32_t readAdcCalibration(Ph2_HwInterface::BeBoardFWInterface* pInterface);
float convertAdcReading(uint16_t pReading, std::string pValueToRead);
// GBTx configuration
void gbtxSelectEdgeTx(Ph2_HwInterface::BeBoardFWInterface* pInterface, bool pRising = true);
void gbtxSelectEdge(Ph2_HwInterface::BeBoardFWInterface* pInterface, bool pRising = true);
void gbtxSetPhase(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pPhase = 11);
void gbtxConfigureChargePumps(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pStrength = 0x04);
// set clocks
void gbtxSetClocks(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pFrequency = 3, uint8_t cDriveStrength = 0x0a, uint8_t cCoarsePhase = 0, uint8_t cFinePhase = 0);
// read clocks
void gbtxReadClocks(Ph2_HwInterface::BeBoardFWInterface* pInterface);
// reset clock plls
void gbtxResetPhaseShifterClocks(Ph2_HwInterface::BeBoardFWInterface* pInterface);
// configure e-links
// 0 -- disable, 1 -- 80 Mb/s , 2 -- 160 Mbps , 3 -- 320 Mbps
void gbtxConfigureTxMode(Ph2_HwInterface::BeBoardFWInterface* pInterface, std::vector<uint8_t> cGroups, uint8_t pDataRate = 0);
void gbtxConfigureTxClocks(Ph2_HwInterface::BeBoardFWInterface* pInterface, std::vector<uint8_t> cGroups, uint8_t pDataRate = 0);
void gbtxConfigureRxClocks(Ph2_HwInterface::BeBoardFWInterface* pInterface, std::vector<uint8_t> cGroups, uint8_t pDataRate = 0);
void gbtxEnableTxChannel(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pGroup, std::vector<uint8_t> pChannels);
void gbtxEnableRxChannel(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pGroup, std::vector<uint8_t> pChannels);
void gbtxConfigureLinks(Ph2_HwInterface::BeBoardFWInterface* pInterface);
void gbtxDisableAllLinks(Ph2_HwInterface::BeBoardFWInterface* pInterface);
void gbtxResetFrameAlignerDLL(Ph2_HwInterface::BeBoardFWInterface* pInterface, std::vector<uint8_t> pGroups);
void gbtxFrameAlignerDLL(Ph2_HwInterface::BeBoardFWInterface* pInterface, std::vector<uint8_t> pGroups, uint8_t pDLLcurrent = 11, uint8_t pLockMode = 7);
void gbtxConfigure(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pDLLcurrent = 11, uint8_t pDLLlockMode = 7);
void gbtxSelectTerminationRx(Ph2_HwInterface::BeBoardFWInterface* pInterface, bool pEnable = true);
void gbtxSetDriveStrength(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pStrength = 0xA);
void gbtxAutoAlign(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pHyridId = 0);
struct RegConfig
{
uint8_t fFeId = 0;
uint8_t fChipId = 0;
uint8_t fPage = 0;
uint8_t fRegisterAddress = 0;
uint8_t fRegisterValue = 0;
};
// read and write functions for CIC and CBC
uint8_t cbcGetPageRegister(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pFeId, uint8_t pChipId);
uint8_t cbcSetPage(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pFeId, uint8_t pChipId, uint8_t pPage);
uint32_t cbcRead(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pFeId, uint8_t pChipId, uint8_t pPage, uint8_t pRegisterAddress);
bool cbcWrite(Ph2_HwInterface::BeBoardFWInterface* pInterface,
uint8_t pFeId,
uint8_t pChipId,
uint8_t pPage,
uint8_t pRegisterAddress,
uint8_t pRegisterValue,
bool pReadBack = true,
bool pSetPage = false);
uint32_t cicRead(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pFeId, uint8_t pRegisterAddress);
bool cicWrite(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint8_t pFeId, uint8_t pRegisterAddress, uint8_t pRegisterValue, bool pReadBack = true);
// multi-register write
// bool cbcWrite(Ph2_HwInterface::BeBoardFWInterface* pInterface, const std::vector<uint32_t>& pVecSend);
bool i2cWrite(Ph2_HwInterface::BeBoardFWInterface* pInterface, const std::vector<uint32_t>& pVecSend, std::vector<uint32_t>& pReplies, bool pReadBack = true);
private:
// GBTX ec
void ecReset(Ph2_HwInterface::BeBoardFWInterface* pInterface);
uint32_t ecWrite(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint16_t pI2Cmaster, uint32_t pCommand, uint32_t pData = 0x00);
uint32_t ecWrite(BeBoardFWInterface* pInterface, uint16_t pI2Cmaster, const std::vector<std::pair<uint32_t, uint32_t>>& pCommands);
uint32_t ecRead(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint16_t pI2Cmaster, uint32_t pCommand, uint32_t pData = 0x00);
// GBTx ic
void icReset(Ph2_HwInterface::BeBoardFWInterface* pInterface);
void icWrite(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint32_t pAddress, uint32_t pData);
uint32_t icRead(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint32_t pAddress, uint32_t pNwords);
// Temp replacement for new CPB
uint8_t configI2C(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint16_t pMaster, uint8_t pNBytes = 2, uint8_t pSclMode = 0, int pFrequency = 1000);
uint32_t readI2C(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint16_t pMaster, uint8_t pSlave, uint8_t pNBytes);
uint8_t writeI2C(Ph2_HwInterface::BeBoardFWInterface* pInterface, uint16_t pMaster, uint8_t pSlave, uint32_t pData, uint8_t pNBytes);
// Thermistor readout conversion
float convAdcToTemp(float pAdcValue, std::string pThermistor);
protected:
uint8_t fGBTxAddress = 0x01;
uint16_t fSCAMaster = 0x11; // I2C serial masters 14 (0x11) and 15 (0x12) are used on the SEH v3.1
std::map<std::string, uint8_t> fScaAdcChnMap = {{"AMUX_L", 0}, {"AMUX_R", 30}, {"VMIN", 14}, {"VM1V5", 21}, {"VM2V5", 27}, {"VRSSI", 24}, {"EXT_TEMP", 25}, {"INT_TEMP", 31}};
std::map<std::string, std::pair<int, int>> fScaAdcVoltageDeviderMap = {{"AMUX_L", std::make_pair(0, 1)},
{"AMUX_R", std::make_pair(0, 1)},
{"VMIN", std::make_pair(91000, 4700)},
{"VM1V5", std::make_pair(100000, 110000)},
{"VM2V5", std::make_pair(100, 47)},
{"VRSSI", std::make_pair(0, 1)},
{"EXT_TEMP", std::make_pair(0, 10000)},
{"INT_TEMP", std::make_pair(0, 1)}};
std::map<std::string, std::tuple<int, int, int>> fNTCThermistorMap = {{"NCP15XM331J03RC", std::make_tuple(298, 330, 3500)}}; // tuple contains <refTemp, resistance at refTemp, BConstant>
};
} // namespace Ph2_HwInterface
#endif
......@@ -43,7 +43,6 @@ bool SSA2Interface::ConfigureChip(Chip* pSSA2, bool pVerifLoop, uint32_t pBlockS
this->WriteChipSingleReg(pSSA2, "mask_peri_A", 255, false);
this->WriteChipSingleReg(pSSA2, "mask_peri_D", 255, false);
LOG(INFO) << BOLDBLUE << "Configuring SSA2 " << RESET;
setBoard(pSSA2->getBeBoardId());
std::vector<uint32_t> cVec;
ChipRegMap cSSA2RegMap = pSSA2->getRegMap();
bool cWrite = true;
......@@ -442,6 +441,10 @@ bool SSA2Interface::WriteChipReg(Chip* pSSA2, const std::string& pRegName, uint1
// bool cEnableAnalogue = WriteChipSingleReg(pSSA2, "ENFLAGS", cRegValue, pVerifLoop);
// return cEnableAnalogue;
// }
else if(fAmuxMap.find(pRegName) != fAmuxMap.end())
{
return this->ConfigureAmux(pSSA2, pRegName);
}
else if(pRegName == "MonitorBandgap")
{
return this->ConfigureAmux(pSSA2, "Bandgap");
......@@ -530,10 +533,10 @@ bool SSA2Interface::WriteChipReg(Chip* pSSA2, const std::string& pRegName, uint1
cRegValue = this->ReadChipReg(pSSA2, "ENFLAGS_S1");
LOG(DEBUG) << BOLDBLUE << "[post-set sampling] StripControl1 set to 0x" << std::hex << cRegValue << std::dec << RESET;
// configure for injection with the strip register
uint8_t cMask = 1;
uint8_t cMask = 0;
uint8_t cPolarity = 0;
uint8_t cHitCounter = 0;
uint8_t cDigitalCalib = 1;
uint8_t cDigitalCalib = pValue;
uint8_t cAnalogCalib = 0;
uint8_t cEnFlags = (cAnalogCalib << 4 | cDigitalCalib << 3 | cHitCounter << 2 | cPolarity << 1 | cMask);
this->WriteChipSingleReg(pSSA2, "mask_strip", 0x1F, pVerifLoop);
......@@ -596,7 +599,7 @@ bool SSA2Interface::WriteChipReg(Chip* pSSA2, const std::string& pRegName, uint1
uint8_t cPolarity = 0;
uint8_t cHitCounter = 0;
uint8_t cDigitalCalib = 0;
uint8_t cAnalogCalib = 1;
uint8_t cAnalogCalib = pValue;
uint8_t cEnFlags = (cAnalogCalib << 4 | cDigitalCalib << 3 | cHitCounter << 2 | cPolarity << 1 | cMask);
this->WriteChipSingleReg(pSSA2, "mask_strip", 0x1F, pVerifLoop);
this->WriteChipSingleReg(pSSA2, "ENFLAGS", cEnFlags, false);
......@@ -657,7 +660,7 @@ bool SSA2Interface::WriteChipReg(Chip* pSSA2, const std::string& pRegName, uint1
uint8_t cPolarity = 0;
uint8_t cHitCounter = 1;
uint8_t cDigitalCalib = 0;
uint8_t cAnalogCalib = 1;
uint8_t cAnalogCalib = pValue;
uint8_t cEnFlags = (cAnalogCalib << 4 | cDigitalCalib << 3 | cHitCounter << 2 | cPolarity << 1 | cMask);
this->WriteChipSingleReg(pSSA2, "mask_strip", 0x1F, pVerifLoop);
this->WriteChipSingleReg(pSSA2, "ENFLAGS", cEnFlags, false);
......@@ -699,9 +702,61 @@ bool SSA2Interface::WriteChipReg(Chip* pSSA2, const std::string& pRegName, uint1
}
else if(pRegName == "DigitalAsync")
{
// digital injection, async , enable all strips
uint8_t cRegValue = (pValue << 3) | (1 << 2) | (1 << 0);
return WriteChipSingleReg(pSSA2, "ENFLAGS", cRegValue, pVerifLoop);
// // digital injection, async , enable all strips
// uint8_t cRegValue = (pValue << 3) | (1 << 2) | (1 << 0);
// return WriteChipSingleReg(pSSA2, "ENFLAGS", cRegValue, pVerifLoop);
uint8_t cReadoutMode = 0x1;
uint8_t cEdgeSel_T1 = 0x0;
// readout mode
this->WriteChipSingleReg(pSSA2, "mask_peri_D", 0x7, pVerifLoop);
uint16_t cRegValue = this->ReadChipReg(pSSA2, "control_1");
LOG(DEBUG) << BOLDBLUE << "[pre-write ReadoutMode] Control_1 set to 0x" << std::hex << cRegValue << std::dec << RESET;
this->WriteChipSingleReg(pSSA2, "control_1", cReadoutMode, false);
cRegValue = this->ReadChipReg(pSSA2, "control_1");
LOG(DEBUG) << BOLDBLUE << "Control_1 set to 0x" << std::hex << cRegValue << std::dec << RESET;
this->WriteChipSingleReg(pSSA2, "mask_peri_D", 0xFF, pVerifLoop);
// edge select
cRegValue = this->ReadChipReg(pSSA2, "control_1");
LOG(DEBUG) << BOLDBLUE << "[pre-write Edge] Control_1 set to 0x" << std::hex << cRegValue << std::dec << RESET;
this->WriteChipSingleReg(pSSA2, "mask_peri_D", (0x1 << 3), pVerifLoop);
this->WriteChipSingleReg(pSSA2, "control_1", (cEdgeSel_T1 << 3), false);
cRegValue = this->ReadChipReg(pSSA2, "control_1");
LOG(DEBUG) << BOLDBLUE << "Control_1 set to 0x" << std::hex << cRegValue << std::dec << RESET;
this->WriteChipSingleReg(pSSA2, "mask_peri_D", 0xFF, pVerifLoop);
uint8_t cDuration = 0x8;
cRegValue = this->ReadChipReg(pSSA2, "control_2");
LOG(DEBUG) << BOLDBLUE << "[pre-write Duration] Control_2 set to 0x" << std::hex << cRegValue << std::dec << RESET;
this->WriteChipSingleReg(pSSA2, "mask_peri_D", (0xF << 4), pVerifLoop);
this->WriteChipSingleReg(pSSA2, "control_2", (cDuration << 4), false);
cRegValue = this->ReadChipReg(pSSA2, "control_2");
LOG(DEBUG) << BOLDBLUE << "Control_2 set to 0x" << std::hex << cRegValue << std::dec << RESET;
this->WriteChipSingleReg(pSSA2, "mask_peri_D", 0xFF, pVerifLoop);
// sampling mode
uint8_t cSamplingMode = 0;
cRegValue = this->ReadChipReg(pSSA2, "ENFLAGS_S1");
LOG(DEBUG) << BOLDBLUE << "[pre-write] StripControl1 set to 0x" << std::hex << cRegValue << std::dec << RESET;
this->WriteChipSingleReg(pSSA2, "mask_strip", (0x3 << 5), pVerifLoop);
this->WriteChipSingleReg(pSSA2, "ENFLAGS", (cSamplingMode << 5), false);
this->WriteChipSingleReg(pSSA2, "mask_strip", 0xFF, pVerifLoop);
cRegValue = this->ReadChipReg(pSSA2, "ENFLAGS_S1");
LOG(DEBUG) << BOLDBLUE << "[post-set sampling] StripControl1 set to 0x" << std::hex << cRegValue << std::dec << RESET;
// configure for injection with the strip register
uint8_t cMask = 1;
uint8_t cPolarity = 0;
uint8_t cHitCounter = 1;
uint8_t cDigitalCalib = pValue;
uint8_t cAnalogCalib = 0;
uint8_t cEnFlags = (cAnalogCalib << 4 | cDigitalCalib << 3 | cHitCounter << 2 | cPolarity << 1 | cMask);
this->WriteChipSingleReg(pSSA2, "mask_strip", 0x1F, pVerifLoop);
this->WriteChipSingleReg(pSSA2, "ENFLAGS", cEnFlags, false);
bool cSuccess = this->WriteChipSingleReg(pSSA2, "mask_strip", 0xFF, pVerifLoop);
cRegValue = this->ReadChipReg(pSSA2, "ENFLAGS_S1");
LOG(DEBUG) << BOLDBLUE << "StripControl1 set to 0x" << std::hex << cRegValue << std::dec << RESET;
return cSuccess;
}
else if(pRegName == "DigitalSync")
{
......@@ -800,6 +855,16 @@ bool SSA2Interface::WriteChipReg(Chip* pSSA2, const std::string& pRegName, uint1
this->WriteChipSingleReg(pSSA2, "mask_peri_A", 0xFF, false);
return WriteChipSingleReg(pSSA2, "Bias_THDAC", (pValue), pVerifLoop);
}
else if(pRegName == "LateralRX_L_PhaseData")
{
this->WriteChipSingleReg(pSSA2, "mask_peri_D", 0x07, false); // 0b00000111
return this->WriteChipSingleReg(pSSA2, "LateralRX_sampling", (pValue), pVerifLoop);
}
else if(pRegName == "LateralRX_R_PhaseData")
{
this->WriteChipSingleReg(pSSA2, "mask_peri_D", 0x70, false); // 0b01110000
return this->WriteChipSingleReg(pSSA2, "LateralRX_sampling", (pValue), pVerifLoop);
}
else
{
return this->WriteChipSingleReg(pSSA2, pRegName, pValue, pVerifLoop);
......@@ -812,7 +877,7 @@ bool SSA2Interface::ConfigureAmux(Chip* pChip, const std::string& pRegister)
// first make sure amux is set to 0 to avoid shorts
// from SSA2 python methods
uint8_t cHighZValue = 0x00;
std::vector<std::string> cRegNames{"Bias_TEST_LSB", "Bias_TEST_MSB"};
std::vector<std::string> cRegNames{"Bias_TEST_lsb", "Bias_TEST_msb"};
for(auto cReg: cRegNames)
{
bool cSuccess = this->WriteChipSingleReg(pChip, cReg, cHighZValue);
......
......@@ -872,7 +872,8 @@ bool SSAInterface::WriteChipAllLocalReg(ReadoutChip* pChip, const std::string& d
bool cWrite = this->WriteChipReg(pChip, "THTRIMMING_ALL", cVals[0], false);
if(pVerifLoop)
{
auto cReadback = this->ReadChipReg(pChip, "TrimDAC_S100");
// THTRIMMING_S5
auto cReadback = this->ReadChipReg(pChip, "THTRIMMING_S100");
LOG(DEBUG) << BOLDMAGENTA << "Read-back a value of " << +cReadback << " from trim-dac register" << RESET;
return (cReadback == cVals[0]);
}
......
......@@ -12,7 +12,6 @@
#define __TCINTERFACE_H__
#pragma once
#include "USB_a.h"
#include "USB_libusb.h"
/*!
......@@ -25,29 +24,42 @@ template <class T>
class TCInterface
{
public:
TCInterface();
~TCInterface() { delete[] fPtr; }
TCInterface() { fPtr = new T(); }
TCInterface(const std::string pName)
{
std::cout << "Constructor TCInterface<" << pName << "> with string\n";
fPtr = new T();
fName = pName;
}
~TCInterface()
{
std::cout << "Destructor TCInterface<" << fName << ">\n";
if(fPtr != nullptr)
{
delete fPtr;
fPtr = nullptr;
}
}
// T* getInterface() const { return fPtr; }
T getInterface() const { return *fPtr; }
// user-defined copy assignment (copy-and-swap idiom)
// T& operator=(const T original) { *fPtr = *original.fPtr; return *this; }
// user defined assignment operator
TCInterface& operator=(const TCInterface& rhs)
T& operator=(const T& rhs)
{
*fPtr = *rhs.fPtr;