1 #include "otsdaq-mu2e/FEInterfaces/DTCFrontEndInterface.h"
2 #include "otsdaq/Macros/BinaryStringMacros.h"
3 #include "otsdaq/Macros/InterfacePluginMacros.h"
4 #include "otsdaq/PluginMakers/MakeInterface.h"
9 #define __MF_SUBJECT__ "DTCFrontEndInterface"
11 std::string RunDataFN =
"";
12 std::fstream DataFile;
14 bool artdaqMode_ =
true;
16 DTCFrontEndInterface::DTCFrontEndInterface(
17 const std::string& interfaceUID,
18 const ConfigurationTree& theXDAQContextConfigTree,
19 const std::string& interfaceConfigurationPath)
21 interfaceUID, theXDAQContextConfigTree, interfaceConfigurationPath)
25 __FE_COUT__ <<
"instantiate DTC... " << interfaceUID <<
" "
26 << theXDAQContextConfigTree <<
" " << interfaceConfigurationPath << __E__;
32 emulate_cfo_ = getSelfNode().getNode(
"EmulateCFO").getValue<
bool>();
52 __FE_COUT__ <<
"Emulator DTC mode starting up..." << __E__;
62 unsigned dtc_class_roc_mask = 0;
65 std::vector<std::pair<std::string, ConfigurationTree>> rocChildren =
66 Configurable::getSelfNode().getNode(
"LinkToROCGroupTable").getChildren();
70 for(
auto& roc : rocChildren)
72 __FE_COUT__ <<
"roc uid " << roc.first << __E__;
73 bool enabled = roc.second.getNode(
"Status").getValue<
bool>();
74 __FE_COUT__ <<
"roc enable " << enabled << __E__;
78 int linkID = roc.second.getNode(
"linkID").getValue<
int>();
79 roc_mask_ |= (0x1 << linkID);
81 (0x1 << (linkID * 4));
86 __FE_COUT__ <<
"DTC roc_mask_ = 0x" << std::hex << roc_mask_ << std::dec << __E__;
87 __FE_COUT__ <<
"roc_mask to instantiate DTC class = 0x" << std::hex
88 << dtc_class_roc_mask << std::dec << __E__;
93 std::string expectedDesignVersion =
"";
94 auto mode = DTCLib::DTC_SimMode_NoCFO;
96 __COUT__ <<
"DTC arguments..." << std::endl;
98 __COUTV__(dtc_class_roc_mask);
99 __COUTV__(expectedDesignVersion);
100 __COUT__ <<
"END END DTC arguments..." << std::endl;
102 thisDTC_ =
new DTCLib::DTC(mode, dtc_, dtc_class_roc_mask, expectedDesignVersion);
104 if(emulate_cfo_ == 1)
134 dtc_location_in_chain_ =
135 getSelfNode().getNode(
"LocationInChain").getValue<
unsigned int>();
139 std::vector<std::pair<std::string, ConfigurationTree>> rocChildren =
140 Configurable::getSelfNode().getNode(
"LinkToROCGroupTable").getChildren();
142 int dtcHwEmulateROCmask = 0;
143 for(
auto& roc : rocChildren)
145 bool enabled = roc.second.getNode(
"EmulateInDTCHardware").getValue<
bool>();
149 int linkID = roc.second.getNode(
"linkID").getValue<
int>();
150 __FE_COUT__ <<
"roc uid '" << roc.first <<
"' at link=" << linkID
151 <<
" is DTC-hardware emulated!" << __E__;
152 dtcHwEmulateROCmask |= (1 << linkID);
156 __FE_COUT__ <<
"Writing DTC-hardware emulation mask: 0x" << std::hex
157 << dtcHwEmulateROCmask << std::dec << __E__;
158 registerWrite(0x9110, dtcHwEmulateROCmask);
159 __FE_COUT__ <<
"End check for DTC-hardware emulated ROCs." << __E__;
163 __MCOUT_INFO__(
"DTCFrontEndInterface instantiated with name: "
164 << device_name_ <<
" dtc_location_in_chain_ = "
165 << dtc_location_in_chain_ <<
" talking to /dev/mu2e" << dtc_ << __E__);
169 DTCFrontEndInterface::~DTCFrontEndInterface(
void)
179 __FE_COUT__ <<
"Destructed." << __E__;
183 void DTCFrontEndInterface::configureSlowControls(
void)
185 __FE_COUT__ <<
"Configuring slow controls..." << __E__;
188 FEVInterface::configureSlowControls();
190 __FE_COUT__ <<
"DTC '" << getInterfaceUID()
191 <<
"' slow controls channel count (BEFORE considering ROCs): "
192 << mapOfSlowControlsChannels_.size() << __E__;
194 mapOfROCSlowControlsChannels_.clear();
197 ConfigurationTree ROCLink =
198 Configurable::getSelfNode().getNode(
"LinkToROCGroupTable");
199 if(!ROCLink.isDisconnected())
201 std::vector<std::pair<std::string, ConfigurationTree>> rocChildren =
202 ROCLink.getChildren();
204 unsigned int initialChannelCount;
206 for(
auto& rocChildPair : rocChildren)
208 initialChannelCount = mapOfROCSlowControlsChannels_.size();
210 FEVInterface::addSlowControlsChannels(
211 rocChildPair.second.getNode(
"LinkToSlowControlsChannelTable"),
212 "/" + rocChildPair.first ,
213 &mapOfROCSlowControlsChannels_);
215 __FE_COUT__ <<
"ROC '" << getInterfaceUID() <<
"/" << rocChildPair.first
216 <<
"' slow controls channel count: "
217 << mapOfROCSlowControlsChannels_.size() - initialChannelCount
224 __FE_COUT__ <<
"ROC link disconnected, assuming no ROCs" << __E__;
226 __FE_COUT__ <<
"DTC '" << getInterfaceUID()
227 <<
"' slow controls channel count (AFTER considering ROCs): "
228 << mapOfSlowControlsChannels_.size() +
229 mapOfROCSlowControlsChannels_.size()
232 __FE_COUT__ <<
"Done configuring slow controls." << __E__;
238 void DTCFrontEndInterface::resetSlowControlsChannelIterator(
void)
241 FEVInterface::resetSlowControlsChannelIterator();
243 currentChannelIsInROC_ =
false;
248 FESlowControlsChannel* DTCFrontEndInterface::getNextSlowControlsChannel(
void)
251 if(slowControlsChannelsIterator_ == mapOfSlowControlsChannels_.end())
253 slowControlsChannelsIterator_ = mapOfROCSlowControlsChannels_.begin();
254 currentChannelIsInROC_ =
true;
258 if(slowControlsChannelsIterator_ == mapOfROCSlowControlsChannels_.end())
261 if(currentChannelIsInROC_)
263 std::vector<std::string> uidParts;
264 StringMacros::getVectorFromString(
265 slowControlsChannelsIterator_->second.interfaceUID_,
268 if(uidParts.size() != 2)
270 __FE_SS__ <<
"Illegal ROC slow controls channel name '"
271 << slowControlsChannelsIterator_->second.interfaceUID_
272 <<
".' Format should be DTC/ROC." << __E__;
274 currentChannelROCUID_ =
278 (slowControlsChannelsIterator_++)->second);
283 unsigned int DTCFrontEndInterface::getSlowControlsChannelCount(
void)
285 return mapOfSlowControlsChannels_.size() + mapOfROCSlowControlsChannels_.size();
290 void DTCFrontEndInterface::getSlowControlsValue(FESlowControlsChannel& channel,
291 std::string& readValue)
293 __FE_COUTV__(currentChannelIsInROC_);
294 __FE_COUTV__(currentChannelROCUID_);
295 __FE_COUTV__(universalDataSize_);
296 if(!currentChannelIsInROC_)
298 readValue.resize(universalDataSize_);
299 universalRead(channel.getUniversalAddress(), &readValue[0]);
303 auto rocIt = rocs_.find(currentChannelROCUID_);
304 if(rocIt == rocs_.end())
306 __FE_SS__ <<
"ROC UID '" << currentChannelROCUID_
307 <<
"' was not found in ROC map." << __E__;
308 ss <<
"Here are the existing ROCs: ";
310 for(
auto& rocPair : rocs_)
312 ss <<
", " << rocPair.first;
321 readValue.resize(universalDataSize_);
322 *((uint16_t*)(&readValue[0])) =
323 rocIt->second->readRegister(*((uint16_t*)channel.getUniversalAddress()));
326 __FE_COUTV__(readValue.size());
330 void DTCFrontEndInterface::registerFEMacros(
void)
332 mapOfFEMacroFunctions_.clear();
335 registerFEMacroFunction(
337 static_cast<FEVInterface::frontEndMacroFunction_t>(
338 &DTCFrontEndInterface::WriteROCBlock),
339 std::vector<std::string>{
"rocLinkIndex",
"block",
"address",
"writeData"},
340 std::vector<std::string>{},
343 registerFEMacroFunction(
"ROC_MultipleRead",
344 static_cast<FEVInterface::frontEndMacroFunction_t>(
345 &DTCFrontEndInterface::ReadROCBlock),
346 std::vector<std::string>{
"rocLinkIndex",
"numberOfWords",
"address",
"incrementAddress"},
347 std::vector<std::string>{
"readData"},
350 registerFEMacroFunction(
"ROC_ReadBlock",
351 static_cast<FEVInterface::frontEndMacroFunction_t>(
352 &DTCFrontEndInterface::BlockReadROC),
353 std::vector<std::string>{
"rocLinkIndex",
"block",
"address"},
354 std::vector<std::string>{
"readData"},
359 registerFEMacroFunction(
361 static_cast<FEVInterface::frontEndMacroFunction_t>(
362 &DTCFrontEndInterface::WriteROC),
363 std::vector<std::string>{
"rocLinkIndex",
"address",
"writeData"},
364 std::vector<std::string>{},
367 registerFEMacroFunction(
369 static_cast<FEVInterface::frontEndMacroFunction_t>(
370 &DTCFrontEndInterface::ReadROC),
371 std::vector<std::string>{
"rocLinkIndex",
"address"},
372 std::vector<std::string>{
"readData"},
375 registerFEMacroFunction(
"DTC_Reset",
376 static_cast<FEVInterface::frontEndMacroFunction_t>(
377 &DTCFrontEndInterface::DTCReset),
378 std::vector<std::string>{},
379 std::vector<std::string>{},
382 registerFEMacroFunction(
"DTC_HighRate_DCS_Check",
383 static_cast<FEVInterface::frontEndMacroFunction_t>(
384 &DTCFrontEndInterface::DTCHighRateDCSCheck),
385 std::vector<std::string>{
"rocLinkIndex",
"loops",
"baseAddress",
386 "correctRegisterValue0",
"correctRegisterValue1"},
387 std::vector<std::string>{},
390 registerFEMacroFunction(
"DTC_HighRate_DCS_Block_Check",
391 static_cast<FEVInterface::frontEndMacroFunction_t>(
392 &DTCFrontEndInterface::DTCHighRateBlockCheck),
393 std::vector<std::string>{
"rocLinkIndex",
"loops",
"baseAddress",
394 "correctRegisterValue0",
"correctRegisterValue1"},
395 std::vector<std::string>{},
398 registerFEMacroFunction(
"DTC_SendHeartbeatAndDataRequest",
399 static_cast<FEVInterface::frontEndMacroFunction_t>(
400 &DTCFrontEndInterface::DTCSendHeartbeatAndDataRequest),
401 std::vector<std::string>{
"numberOfRequests",
"timestampStart"},
402 std::vector<std::string>{
"readData"},
407 __FE_COUT__ <<
"Getting children ROC FEMacros..." << __E__;
408 rocFEMacroMap_.clear();
409 for(
auto& roc : rocs_)
411 auto feMacros = roc.second->getMapOfFEMacroFunctions();
412 for(
auto& feMacro:feMacros)
414 __FE_COUT__ << roc.first <<
"::" << feMacro.first << __E__;
417 std::string macroName =
419 std::to_string(roc.second->getLinkID()) +
420 "_" + roc.first +
"_" +
422 __FE_COUTV__(macroName);
424 std::vector<std::string> inputArgs,outputArgs;
428 for(
auto& inArg: feMacro.second.namesOfInputArguments_)
429 inputArgs.push_back(inArg);
430 for(
auto& outArg: feMacro.second.namesOfOutputArguments_)
431 outputArgs.push_back(outArg);
433 __FE_COUTV__(StringMacros::vectorToString(inputArgs));
434 __FE_COUTV__(StringMacros::vectorToString(outputArgs));
436 rocFEMacroMap_.emplace(std::make_pair(macroName,
437 std::make_pair(roc.first,feMacro.first)));
439 registerFEMacroFunction(macroName,
440 static_cast<FEVInterface::frontEndMacroFunction_t>(
441 &DTCFrontEndInterface::RunROCFEMacro),
454 void DTCFrontEndInterface::createROCs(
void)
458 std::vector<std::pair<std::string, ConfigurationTree>> rocChildren =
459 Configurable::getSelfNode().getNode(
"LinkToROCGroupTable").getChildren();
462 for(
auto& roc : rocChildren)
463 if(roc.second.getNode(
"Status").getValue<
bool>())
466 <<
"ROC Plugin Name: "
467 << roc.second.getNode(
"ROCInterfacePluginName").getValue<std::string>()
469 __FE_COUT__ <<
"ROC Name: " << roc.first << std::endl;
473 __COUTV__(theXDAQContextConfigTree_.getValueAsString());
475 roc.second.getNode(
"ROCInterfacePluginName").getValue<std::string>());
481 std::unique_ptr<FEVInterface> tmpVFE = makeInterface(
482 roc.second.getNode(
"ROCInterfacePluginName").getValue<std::string>(),
484 theXDAQContextConfigTree_,
485 (theConfigurationPath_ +
"/LinkToROCGroupTable/" + roc.first));
489 tmpVFE->parentSupervisor_ = parentSupervisor_;
497 __COUTV__(tmpRoc.emulatorMode_);
498 tmpRoc.emulatorMode_ = emulatorMode_;
499 __COUTV__(tmpRoc.emulatorMode_);
503 __FE_COUT__ <<
"Creating ROC in emulator mode..." << __E__;
519 __COUT__ <<
"Starting ROC emulator thread..." << __E__;
520 ROCCoreVInterface::emulatorThread(rocEmulator);
546 tmpRoc.thisDTC_ = thisDTC_;
549 rocs_.emplace(std::pair<std::string, std::unique_ptr<ROCCoreVInterface>>(
550 roc.first, &tmpRoc));
554 __COUTV__(rocs_[roc.first]->emulatorMode_);
556 catch(
const cet::exception& e)
558 __SS__ <<
"Failed to instantiate plugin named '" << roc.first
560 << roc.second.getNode(
"ROCInterfacePluginName")
561 .getValue<std::string>()
562 <<
"' due to the following error: \n"
563 << e.what() << __E__;
564 __FE_COUT_ERR__ << ss.str();
565 __MOUT_ERR__ << ss.str();
568 catch(
const std::bad_cast& e)
570 __SS__ <<
"Cast to ROCCoreVInterface failed! Verify the plugin inherits "
571 "from ROCCoreVInterface."
573 ss <<
"Failed to instantiate plugin named '" << roc.first <<
"' of type '"
574 << roc.second.getNode(
"ROCInterfacePluginName").getValue<std::string>()
575 <<
"' due to the following error: \n"
576 << e.what() << __E__;
578 __FE_COUT_ERR__ << ss.str();
579 __MOUT_ERR__ << ss.str();
585 __FE_COUT__ <<
"Done creating " << rocs_.size() <<
" ROC(s)" << std::endl;
590 void DTCFrontEndInterface::readStatus(
void)
592 __FE_COUT__ << device_name_ <<
" firmware version (0x9004) = 0x" << std::hex
593 << registerRead(0x9004) << __E__;
597 __FE_COUT__ << device_name_ <<
" temperature = " << readTemperature() <<
" degC"
600 __FE_COUT__ << device_name_ <<
" SERDES reset........ (0x9118) = 0x" << std::hex
601 << registerRead(0x9118) << __E__;
602 __FE_COUT__ << device_name_ <<
" SERDES disparity err (0x911c) = 0x" << std::hex
603 << registerRead(0x9118) << __E__;
604 __FE_COUT__ << device_name_ <<
" SERDES unlock error. (0x9124) = 0x" << std::hex
605 << registerRead(0x9124) << __E__;
606 __FE_COUT__ << device_name_ <<
" PLL locked.......... (0x9128) = 0x" << std::hex
607 << registerRead(0x9128) << __E__;
608 __FE_COUT__ << device_name_ <<
" SERDES Rx status.... (0x9134) = 0x" << std::hex
609 << registerRead(0x9134) << __E__;
610 __FE_COUT__ << device_name_ <<
" SERDES reset done... (0x9138) = 0x" << std::hex
611 << registerRead(0x9138) << __E__;
612 __FE_COUT__ << device_name_ <<
" link status......... (0x9140) = 0x" << std::hex
613 << registerRead(0x9140) << __E__;
614 __FE_COUT__ << device_name_ <<
" SERDES ref clk freq. (0x915c) = 0x" << std::hex
615 << registerRead(0x915c) <<
" = " << std::dec << registerRead(0x915c)
617 __FE_COUT__ << device_name_ <<
" control............. (0x9100) = 0x" << std::hex
618 << registerRead(0x9100) << __E__;
619 __FE_COUT__ << __E__;
625 int DTCFrontEndInterface::getROCLinkStatus(
int ROC_link)
627 int overall_link_status = registerRead(0x9140);
629 int ROC_link_status = (overall_link_status >> ROC_link) & 0x1;
631 return ROC_link_status;
634 int DTCFrontEndInterface::getCFOLinkStatus()
636 int overall_link_status = registerRead(0x9140);
638 int CFO_link_status = (overall_link_status >> 6) & 0x1;
640 return CFO_link_status;
643 int DTCFrontEndInterface::checkLinkStatus()
647 for(
int i = 0; i < 8; i++)
654 ROCs_OK &= getROCLinkStatus(i);
658 if((getCFOLinkStatus() == 1) && ROCs_OK == 1)
678 bool DTCFrontEndInterface::ROCActive(
unsigned ROC_link)
683 if(((roc_mask_ >> ROC_link) & 0x01) == 1)
694 void DTCFrontEndInterface::configure(
void)
try
696 __FE_COUTV__(getIterationIndex());
697 __FE_COUTV__(getSubIterationIndex());
701 __FE_COUT__ <<
"Emulator DTC configuring... # of ROCs = " << rocs_.size()
703 for(
auto& roc : rocs_)
704 roc.second->configure();
707 __FE_COUT__ <<
"DTC configuring... # of ROCs = " << rocs_.size() << __E__;
714 const int number_of_system_configs =
718 const int reset_fpga = 1;
719 const bool config_clock = configure_clock_;
720 const bool config_jitter_attenuator = configure_clock_;
721 const int reset_rx = 0;
723 const int number_of_dtc_config_steps = 7;
725 const int max_number_of_tries = 3;
727 int number_of_total_config_steps =
728 number_of_system_configs * number_of_dtc_config_steps;
730 int config_step = getIterationIndex();
731 int config_substep = getSubIterationIndex();
733 if(number_of_system_configs > 0)
735 if(config_step >= number_of_total_config_steps)
740 if(config_substep > 0 && config_substep < max_number_of_tries)
743 const int number_of_link_checks = 10;
747 for(
int i = 0; i < number_of_link_checks; i++)
749 if(checkLinkStatus() == 1)
752 __FE_COUT__ << device_name_ <<
" Link Status is OK = 0x" << std::hex
753 << registerRead(0x9140) << std::dec << __E__;
755 indicateIterationWork();
759 else if(getCFOLinkStatus() == 0)
763 __FE_COUT__ << device_name_ <<
" CFO Link Status is bad = 0x" << std::hex
764 << registerRead(0x9140) << std::dec << __E__;
767 indicateIterationWork();
775 __FE_COUT__ <<
"Waiting for DTC Link Status = 0x" << std::hex
776 << registerRead(0x9140) << std::dec << __E__;
781 indicateSubIterationWork();
784 else if(config_substep > max_number_of_tries)
788 __FE_COUT__ <<
"Links still bad = 0x" << std::hex << registerRead(0x9140)
789 << std::dec <<
"... continue" << __E__;
790 indicateIterationWork();
797 if((config_step % number_of_dtc_config_steps) == 0)
799 if(reset_fpga == 1 && config_step < number_of_dtc_config_steps)
803 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_
804 <<
" reset FPGA...");
806 int dataInReg = registerRead(0x9100);
807 int dataToWrite = dataInReg | 0x80000000;
808 registerWrite(0x9100, dataToWrite);
811 __MCOUT_INFO__(
"............. firmware version "
812 << std::hex << registerRead(0x9004) << std::dec << __E__);
817 else if((config_step % number_of_dtc_config_steps) == 1)
819 if((config_clock == 1 || emulate_cfo_ == 1) &&
820 config_step < number_of_dtc_config_steps)
824 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_
825 <<
" reset clock..." << __E__);
827 __FE_COUT__ <<
"DTC - set crystal frequency to 156.25 MHz" << __E__;
828 registerWrite(0x915c, 0x09502F90);
831 registerWrite(0x9168, 0x5d870100);
832 registerWrite(0x916c, 0x00000001);
836 int targetFrequency = 200000000;
845 DTCLib::DTC_OscillatorType_Timing;
847 __FE_COUT__ <<
"DTC - set oscillator frequency to " << std::dec
848 << targetFrequency <<
" MHz" << __E__;
850 thisDTC_->SetNewOscillatorFrequency(oscillator, targetFrequency);
859 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_
860 <<
" do NOT reset clock..." << __E__);
863 else if((config_step % number_of_dtc_config_steps) == 2)
867 if((config_jitter_attenuator == 1 || emulate_cfo_ == 1) &&
868 config_step < number_of_dtc_config_steps)
870 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_
871 <<
" configure Jitter Attenuator..." << __E__);
873 configureJitterAttenuator();
879 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_
880 <<
" do NOT configure Jitter Attenuator..." << __E__);
883 else if((config_step % number_of_dtc_config_steps) == 3)
888 if(emulate_cfo_ == 1)
890 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_
891 <<
" enable CFO emulation and internal clock");
892 int dataInReg = registerRead(0x9100);
894 dataInReg | 0x40808404;
895 registerWrite(0x9100, dataToWrite);
897 __FE_COUT__ <<
"....... CFO emulation: turn off Event Windows" << __E__;
898 registerWrite(0x91f0, 0x1000);
900 __FE_COUT__ <<
"....... CFO emulation: turn off 40MHz marker interval"
902 registerWrite(0x91f4, 0x00000000);
904 __FE_COUT__ <<
"....... CFO emulation: enable heartbeats" << __E__;
905 registerWrite(0x91a8, 0x15000);
909 int dataInReg = registerRead(0x9100);
913 registerWrite(0x9100, dataToWrite);
919 __FE_COUT__ <<
"DTC reset CFO link CPLL" << __E__;
920 registerWrite(0x9118, 0x00004000);
921 registerWrite(0x9118, 0x00000000);
925 __FE_COUT__ <<
"DTC reset CFO link RX" << __E__;
926 registerWrite(0x9118, 0x00400000);
927 registerWrite(0x9118, 0x00000000);
933 __FE_COUT__ <<
"DTC do NOT reset PLL and CFO RX" << __E__;
942 else if((config_step % number_of_dtc_config_steps) == 4)
944 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_
945 <<
" wait for links..." << __E__);
953 if(emulate_cfo_ == 1)
955 __FE_COUT__ <<
"DTC reset ROC link SERDES CPLLs" << __E__;
956 registerWrite(0x9118, 0x00003f00);
957 registerWrite(0x9118, 0x00000000);
961 __FE_COUT__ <<
"DTC reset ROC link SERDES TX" << __E__;
962 registerWrite(0x9118, 0x3f000000);
963 registerWrite(0x9118, 0x00000000);
974 indicateSubIterationWork();
979 else if((config_step % number_of_dtc_config_steps) == 5)
981 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_
982 <<
" enable markers, Tx, Rx" << __E__);
986 int data_to_write = (roc_mask_ << 8) | roc_mask_;
987 __FE_COUT__ <<
"DTC enable markers - enabled ROC links 0x" << std::hex
988 << data_to_write << std::dec << __E__;
989 registerWrite(0x91f8, data_to_write);
991 data_to_write = 0x4040 | (roc_mask_ << 8) | roc_mask_;
992 __FE_COUT__ <<
"DTC enable tx and rx - CFO and enabled ROC links 0x" << std::hex
993 << data_to_write << std::dec << __E__;
994 registerWrite(0x9114, data_to_write);
997 __FE_COUT__ <<
"DTC set CFO link output loopback mode ENABLE" << __E__;
999 int dataInReg = registerRead(0x9100);
1000 int dataToWrite = dataInReg & 0xefffffff;
1001 registerWrite(0x9100, dataToWrite);
1003 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_ <<
" configure ROCs"
1006 bool doConfigureROCs =
false;
1009 doConfigureROCs = Configurable::getSelfNode()
1010 .getNode(
"EnableROCConfigureStep")
1017 for(
auto& roc : rocs_)
1018 roc.second->configure();
1022 else if((config_step % number_of_dtc_config_steps) == 6)
1024 if(emulate_cfo_ == 1)
1026 __MCOUT_INFO__(
"Step " << config_step
1027 <<
": CFO emulation enable Event start characters "
1028 "and event window interval"
1031 __FE_COUT__ <<
"CFO emulation: set Event Window interval" << __E__;
1035 registerWrite(0x91f0, 0x00000000);
1038 __FE_COUT__ <<
"CFO emulation: set 40MHz marker interval" << __E__;
1040 registerWrite(0x91f4, 0x00000000);
1043 __FE_COUT__ <<
"CFO emulation: set heartbeat interval " << __E__;
1045 registerWrite(0x91a8, 0x00000000);
1048 __MCOUT_INFO__(
"Step " << config_step <<
": " << device_name_ <<
" configured"
1051 if(checkLinkStatus() == 1)
1053 __MCOUT_INFO__(device_name_ <<
" links OK 0x" << std::hex
1054 << registerRead(0x9140) << std::dec << __E__);
1059 if(number_of_system_configs < 0)
1064 else if(config_step > max_number_of_tries)
1066 __MCOUT_INFO__(device_name_ <<
" links not OK 0x" << std::hex
1067 << registerRead(0x9140) << std::dec << __E__);
1072 __MCOUT_INFO__(device_name_ <<
" links not OK 0x" << std::hex
1073 << registerRead(0x9140) << std::dec << __E__);
1079 indicateIterationWork();
1085 catch(
const std::runtime_error& e)
1087 __FE_SS__ <<
"Error caught: " << e.what() << __E__;
1092 __FE_SS__ <<
"Unknown error caught. Check the printouts!" << __E__;
1097 void DTCFrontEndInterface::halt(
void)
1099 __FE_COUT__ <<
"Halting..." << __E__;
1101 for(
auto& roc : rocs_)
1108 __FE_COUT__ <<
"Halted." << __E__;
1115 void DTCFrontEndInterface::pause(
void)
1117 __FE_COUT__ <<
"Pausing..." << __E__;
1118 for(
auto& roc : rocs_)
1120 roc.second->pause();
1126 __FE_COUT__ <<
"Paused." << __E__;
1130 void DTCFrontEndInterface::resume(
void)
1132 __FE_COUT__ <<
"Resuming..." << __E__;
1133 for(
auto& roc : rocs_)
1135 roc.second->resume();
1141 __FE_COUT__ <<
"Resumed." << __E__;
1145 void DTCFrontEndInterface::start(std::string runNumber)
1149 __FE_COUT__ <<
"Emulator DTC starting... # of ROCs = " << rocs_.size()
1151 for(
auto& roc : rocs_) {
1152 __FE_COUT__ <<
"Starting ROC ";
1153 roc.second->start(runNumber);
1154 __FE_COUT__ <<
"Done starting ROC";}
1163 __FE_COUT__ <<
" Trying to get the FEWRITE_RUNFILE info";
1164 FEWriteFile = std::atoi(std::getenv(
"FEWRITE_RUNFILE"));
1165 __FE_COUT__ <<
"FEWriteFile is " << FEWriteFile;
1168 char* dataPath(std::getenv(
"OTSDAQ_DATA"));
1169 RunDataFN = std::string(dataPath) +
"/RunData_" + runNumber +
".dat";
1171 __FE_COUT__ <<
"Run data FN is: "<< RunDataFN;
1172 if (!DataFile.is_open()) {
1173 DataFile.open (RunDataFN, std::ios::out | std::ios::app);
1175 if (DataFile.fail()) {
1176 __FE_COUT__ <<
"FAILED to open data file RunData" << RunDataFN;
1181 __FE_COUT__ <<
"opened data file RunData" << RunDataFN;
1188 __FE_COUT__ <<
"Emulator DTC starting..." << __E__;
1193 int numberOfLoopbacks =
1194 getConfigurationManager()
1195 ->getNode(
"/Mu2eGlobalsTable/SyncDemoConfig/NumberOfLoopbacks")
1196 .getValue<
unsigned int>();
1198 __FE_COUTV__(numberOfLoopbacks);
1200 int stopIndex = getIterationIndex();
1202 if(numberOfLoopbacks == 0)
1204 for(
auto& roc : rocs_)
1206 roc.second->start(runNumber);
1211 const int numberOfChains = 1;
1212 int link[numberOfChains] = {0};
1214 const int numberOfDTCsPerChain = 1;
1216 const int numberOfROCsPerDTC = 1;
1227 int totalNumberOfMeasurements =
1228 numberOfChains * numberOfDTCsPerChain * numberOfROCsPerDTC;
1230 int loopbackIndex = getIterationIndex();
1232 if(loopbackIndex == 0)
1234 initial_9100_ = registerRead(0x9100);
1235 initial_9114_ = registerRead(0x9114);
1236 indicateIterationWork();
1240 if(loopbackIndex > totalNumberOfMeasurements)
1242 __MCOUT_INFO__(device_name_ <<
" loopback DONE" << __E__);
1244 if(checkLinkStatus() == 1)
1256 for(
auto& roc : rocs_)
1258 __MCOUT_INFO__(
".... ROC" << roc.second->getLinkID() <<
"-DTC link lost "
1259 << roc.second->readDTCLinkLossCounter()
1263 registerWrite(0x9100, initial_9100_);
1264 registerWrite(0x9114, initial_9114_);
1272 unsigned int activeROC = (loopbackIndex - 1) % numberOfROCsPerDTC;
1276 for(
int nDTC = 0; nDTC < numberOfDTCsPerChain; nDTC++)
1278 if((loopbackIndex - 1) >= (nDTC * numberOfROCsPerDTC) &&
1279 (loopbackIndex - 1) < ((nDTC + 1) * numberOfROCsPerDTC))
1290 if(activeDTC == dtc_location_in_chain_)
1292 __FE_COUT__ <<
"DTC" << activeDTC <<
"loopback mode ENABLE" << __E__;
1293 int dataInReg = registerRead(0x9100);
1294 int dataToWrite = dataInReg & 0xefffffff;
1295 registerWrite(0x9100, dataToWrite);
1301 __FE_COUT__ <<
"active DTC = " << activeDTC
1302 <<
" is NOT this DTC = " << dtc_location_in_chain_
1303 <<
"... pass signal through" << __E__;
1305 int dataInReg = registerRead(0x9100);
1306 int dataToWrite = dataInReg | 0x10000000;
1307 registerWrite(0x9100, dataToWrite);
1312 (0x101 << activeROC);
1313 __FE_COUT__ <<
"enable ROC " << activeROC <<
" --> 0x" << std::hex << ROCToEnable
1314 << std::dec << __E__;
1316 registerWrite(0x9114, ROCToEnable);
1318 indicateIterationWork();
1322 for(
auto& roc : rocs_)
1324 if(roc.second->getLinkID() == activeROC)
1326 __FE_COUT__ <<
"... ROC realign link... " << __E__;
1327 roc.second->writeRegister(22, 0);
1328 roc.second->writeRegister(22, 1);
1332 indicateIterationWork();
1337 void DTCFrontEndInterface::stop(
void)
1341 __FE_COUT__ <<
"Stopping in artdaqmode" << __E__;
1347 __FE_COUT__ <<
"Emulator DTC stopping... # of ROCs = " << rocs_.size()
1349 for(
auto& roc : rocs_)
1355 if (DataFile.is_open()) {
1357 __FE_COUT__ <<
"closed data file";
1363 __FE_COUT__ <<
"Emulator DTC stopping..." << __E__;
1367 int numberOfCAPTANPulses =
1368 getConfigurationManager()
1369 ->getNode(
"/Mu2eGlobalsTable/SyncDemoConfig/NumberOfCAPTANPulses")
1370 .getValue<
unsigned int>();
1372 __FE_COUTV__(numberOfCAPTANPulses);
1374 int stopIndex = getIterationIndex();
1376 if(numberOfCAPTANPulses == 0)
1378 for(
auto& roc : rocs_)
1388 for(
auto& roc : rocs_)
1391 roc.second->writeRegister(22, 0);
1392 roc.second->writeRegister(22, 1);
1394 std::stringstream filename;
1395 filename <<
"/home/mu2edaq/sync_demo/ots/" << device_name_ <<
"_ROC"
1396 << roc.second->getLinkID() <<
"data.txt";
1397 std::string filenamestring = filename.str();
1398 datafile_[i].open(filenamestring);
1403 if(stopIndex > numberOfCAPTANPulses)
1406 for(
auto& roc : rocs_)
1408 __MCOUT_INFO__(
".... ROC" << roc.second->getLinkID() <<
"-DTC link lost "
1409 << roc.second->readDTCLinkLossCounter()
1411 datafile_[i].close();
1418 __FE_COUT__ <<
"Entering read timestamp loop..." << __E__;
1419 for(
auto& roc : rocs_)
1421 int timestamp_data = roc.second->readTimestamp();
1423 __FE_COUT__ <<
"Read " << stopIndex <<
" -> " << device_name_ <<
" timestamp "
1424 << timestamp_data << __E__;
1426 datafile_[i] << stopIndex <<
" " << timestamp_data << std::endl;
1430 indicateIterationWork();
1436 bool DTCFrontEndInterface::running(
void)
1439 __FE_COUT__ <<
"Running in artdaqmode" << __E__;
1444 __FE_COUT__ <<
"Emulator DTC running... # of ROCs = " << rocs_.size()
1446 bool stillRunning =
false;
1447 for(
auto& roc : rocs_)
1448 stillRunning = stillRunning || roc.second->running();
1450 return stillRunning;
1456 std::time_t current_time;
1457 bool incrementTimestamp =
true;
1459 uint32_t cfodelay = 10000;
1461 int requestsAhead = 0;
1462 unsigned int number = -1;
1463 unsigned int timestampStart = 0;
1465 auto device = thisDTC_->GetDevice();
1466 auto initTime = device->GetDeviceTime();
1467 device->ResetDeviceTime();
1468 auto afterInit = std::chrono::steady_clock::now();
1471 if(emulate_cfo_ == 1)
1473 registerWrite(0x9100, 0x40008404);
1480 registerWrite(0x91BC, 0x10);
1485 registerWrite(0x91f4, 0x0);
1489 registerWrite(0x9158, 0x1);
1492 bool useCFOEmulator =
true;
1493 uint16_t debugPacketCount = 0;
1494 auto debugType = DTCLib::DTC_DebugType_SpecialSequence;
1495 bool stickyDebugType =
true;
1497 bool asyncRR =
false;
1498 bool forceNoDebugMode =
true;
1500 DTCLib::DTCSoftwareCFO* EmulatedCFO_ =
1501 new DTCLib::DTCSoftwareCFO(thisDTC_,
1510 EmulatedCFO_->SendRequestsForRange(
1512 DTCLib::DTC_Timestamp(static_cast<uint64_t>(timestampStart)),
1517 auto readoutRequestTime = device->GetDeviceTime();
1518 device->ResetDeviceTime();
1519 auto afterRequests = std::chrono::steady_clock::now();
1523 while(WorkLoop::continueWorkLoop_)
1525 for(
auto& roc : rocs_)
1527 roc.second->running();
1531 unsigned quietCount = 20;
1534 std::stringstream ostr;
1539 mu2e_databuff_t* buffer;
1541 __FE_COUT__ <<
"util - before read for DAQ in running";
1542 auto sts = device->read_data(
1543 DTC_DMA_Engine_DAQ, reinterpret_cast<void**>(&buffer), tmo_ms);
1544 __FE_COUT__ <<
"util - after read for DAQ in running " <<
" sts=" << sts
1545 <<
", buffer=" << (
void*)buffer;
1549 void* readPtr = &buffer[0];
1550 auto bufSize =
static_cast<uint16_t
>(*
static_cast<uint64_t*
>(readPtr));
1551 readPtr =
static_cast<uint8_t*
>(readPtr) + 8;
1553 __FE_COUT__ <<
"Buffer reports DMA size of " << std::dec << bufSize
1554 <<
" bytes. Device driver reports read of " << sts <<
" bytes,"
1557 __FE_COUT__ <<
"util - bufSize is " << bufSize;
1558 outputStream.write(static_cast<char*>(readPtr), sts - 8);
1559 auto maxLine =
static_cast<unsigned>(ceil((sts - 8) / 16.0));
1560 __FE_COUT__ <<
"maxLine " << maxLine;
1561 for(
unsigned line = 0; line < maxLine; ++line)
1563 ostr <<
"0x" << std::hex << std::setw(5) << std::setfill(
'0') << line
1565 for(
unsigned byte = 0; byte < 8; ++byte)
1567 if(line * 16 + 2 * byte < sts - 8u)
1570 reinterpret_cast<uint16_t*
>(buffer)[4 + line * 8 + byte];
1571 ostr << std::setw(4) << static_cast<int>(thisWord) <<
" ";
1581 __FE_COUT__ <<
"writing to DataFile";
1583 __FE_COUT__ <<
" something bad happened when writing to datafile? \n";
1584 if (!DataFile.is_open())
1585 __FE_COUT__ <<
"trying to write to the data file but it isnt open. \n";
1586 DataFile << ostr.str();
1591 if(maxLine > quietCount * 2 && quiet && line == (quietCount - 1))
1593 line =
static_cast<unsigned>(ceil((sts - 8) / 16.0)) -
1598 device->read_release(DTC_DMA_Engine_DAQ, 1);
1603 DataFile << ostr.str();
1608 delete EmulatedCFO_;
1617 void DTCFrontEndInterface::ReadROC(__ARGS__)
1619 __FE_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1620 __FE_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1621 for(
auto& argIn : argsIn)
1622 __FE_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1624 DTCLib::DTC_Link_ID rocLinkIndex =
1625 DTCLib::DTC_Link_ID(__GET_ARG_IN__(
"rocLinkIndex", uint8_t));
1626 uint8_t address = __GET_ARG_IN__(
"address", uint8_t);
1627 __FE_COUTV__(rocLinkIndex);
1628 __FE_COUTV__((
unsigned int)address);
1633 uint16_t readData = -999;
1635 for(
auto& roc : rocs_)
1637 __FE_COUT__ <<
"Found link ID " << roc.second->getLinkID() <<
" looking for "
1638 << rocLinkIndex << __E__;
1640 if(rocLinkIndex == roc.second->getLinkID())
1642 readData = roc.second->readRegister(address);
1647 char readDataStr[100];
1648 sprintf(readDataStr,
"0x%X",readData);
1649 __SET_ARG_OUT__(
"readData",readDataStr);
1653 __FE_COUT__ <<
"readData"
1654 <<
": " << std::hex << readData << std::dec << __E__;
1655 __FE_COUT__ <<
"End of Data";
1660 __FE_SS__ <<
"ROC link ID " << rocLinkIndex <<
" not found!" << __E__;
1669 void DTCFrontEndInterface::WriteROC(__ARGS__)
1671 __FE_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1672 __FE_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1673 for(
auto& argIn : argsIn)
1674 __FE_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1676 DTCLib::DTC_Link_ID rocLinkIndex =
1677 DTCLib::DTC_Link_ID(__GET_ARG_IN__(
"rocLinkIndex", uint8_t));
1678 uint8_t address = __GET_ARG_IN__(
"address", uint8_t);
1679 uint16_t writeData = __GET_ARG_IN__(
"writeData", uint16_t);
1681 __FE_COUTV__(rocLinkIndex);
1682 __FE_COUTV__((
unsigned int)address);
1683 __FE_COUTV__(writeData);
1685 __FE_COUT__ <<
"ROCs size = " << rocs_.size() << __E__;
1687 for(
auto& roc : rocs_)
1689 __FE_COUT__ <<
"Found link ID " << roc.second->getLinkID() <<
" looking for "
1690 << rocLinkIndex << __E__;
1692 if(rocLinkIndex == roc.second->getLinkID())
1694 roc.second->writeRegister(address, writeData);
1696 for(
auto& argOut : argsOut)
1697 __FE_COUT__ << argOut.first <<
": " << argOut.second << __E__;
1703 __FE_SS__ <<
"ROC link ID " << rocLinkIndex <<
" not found!" << __E__;
1708 void DTCFrontEndInterface::WriteROCBlock(__ARGS__)
1710 __FE_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1711 __FE_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1712 for(
auto& argIn : argsIn)
1713 __FE_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1717 __FE_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1718 __FE_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1720 for(
auto& argIn : argsIn)
1721 __FE_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1723 DTCLib::DTC_Link_ID rocLinkIndex =
1724 DTCLib::DTC_Link_ID(__GET_ARG_IN__(
"rocLinkIndex", uint8_t));
1725 uint8_t address = __GET_ARG_IN__(
"address", uint8_t);
1726 uint16_t writeData = __GET_ARG_IN__(
"writeData", uint16_t);
1727 uint8_t block = __GET_ARG_IN__(
"block", uint8_t);
1728 __FE_COUTV__(rocLinkIndex);
1729 __FE_COUT__ <<
"block = " << std::dec << (
unsigned int)block << __E__;
1730 __FE_COUT__ <<
"address = 0x" << std::hex << (
unsigned int)address << std::dec
1732 __FE_COUT__ <<
"writeData = 0x" << std::hex << writeData << std::dec << __E__;
1734 bool acknowledge_request =
false;
1736 thisDTC_->WriteExtROCRegister(
1737 rocLinkIndex, block, address, writeData, acknowledge_request);
1739 for(
auto& argOut : argsOut)
1740 __FE_COUT__ << argOut.first <<
": " << argOut.second << __E__;
1744 void DTCFrontEndInterface::BlockReadROC(__ARGS__)
1746 __FE_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1747 __FE_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1748 for(
auto& argIn : argsIn)
1749 __FE_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1751 DTCLib::DTC_Link_ID rocLinkIndex =
1752 DTCLib::DTC_Link_ID(__GET_ARG_IN__(
"rocLinkIndex", uint8_t));
1753 uint8_t address = __GET_ARG_IN__(
"address", uint8_t);
1754 uint8_t block = __GET_ARG_IN__(
"block", uint8_t);
1755 __FE_COUTV__(rocLinkIndex);
1756 __FE_COUT__ <<
"block = " << std::dec << (
unsigned int)block << __E__;
1757 __FE_COUT__ <<
"address = 0x" << std::hex << (
unsigned int)address << std::dec
1760 bool acknowledge_request =
false;
1762 for(
auto& roc : rocs_)
1764 __FE_COUT__ <<
"At ROC link ID " << roc.second->getLinkID() <<
", looking for "
1765 << rocLinkIndex << __E__;
1767 if(rocLinkIndex == roc.second->getLinkID())
1771 readData = thisDTC_->ReadExtROCRegister(rocLinkIndex, block, address);
1773 std::string readDataString =
"";
1774 readDataString = BinaryStringMacros::binaryNumberToHexString(readData);
1778 __SET_ARG_OUT__(
"readData", readDataString);
1781 __FE_COUT__ <<
"readData"
1782 <<
": " << readDataString << __E__;
1787 __FE_SS__ <<
"ROC link ID " << rocLinkIndex <<
" not found!" << __E__;
1792 void DTCFrontEndInterface::ReadROCBlock(__ARGS__)
1794 __FE_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1795 __FE_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1796 for(
auto& argIn : argsIn)
1797 __FE_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1800 __FE_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
1801 __FE_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
1803 for(
auto& argIn : argsIn)
1804 __FE_COUT__ << argIn.first <<
": " << argIn.second << __E__;
1806 DTCLib::DTC_Link_ID rocLinkIndex =
1807 DTCLib::DTC_Link_ID(__GET_ARG_IN__(
"rocLinkIndex", uint8_t));
1808 uint16_t address = __GET_ARG_IN__(
"address", uint16_t);
1809 uint16_t wordCount = __GET_ARG_IN__(
"numberOfWords", uint16_t);
1810 bool incrementAddress = __GET_ARG_IN__(
"incrementAddress",
bool);
1812 __FE_COUTV__(rocLinkIndex);
1813 __FE_COUT__ <<
"address = 0x" << std::hex << (
unsigned int)address << std::dec
1815 __FE_COUT__ <<
"numberOfWords = " << std::dec << (
unsigned int)wordCount << __E__;
1816 __FE_COUTV__(incrementAddress);
1818 for(
auto& roc : rocs_)
1820 __FE_COUT__ <<
"At ROC link ID " << roc.second->getLinkID() <<
", looking for "
1821 << rocLinkIndex << __E__;
1823 if(rocLinkIndex == roc.second->getLinkID())
1825 std::vector<uint16_t> readData;
1827 roc.second->readBlock(readData, address, wordCount, incrementAddress);
1829 std::string readDataString =
"";
1832 for(
const auto& data : readData)
1835 readDataString +=
", ";
1838 readDataString += BinaryStringMacros::binaryNumberToHexString(data);
1843 __SET_ARG_OUT__(
"readData", readDataString);
1846 __FE_COUT__ <<
"readData"
1847 <<
": " << readDataString << __E__;
1852 __FE_SS__ <<
"ROC link ID " << rocLinkIndex <<
" not found!" << __E__;
1858 void DTCFrontEndInterface::DTCHighRateBlockCheck(__ARGS__)
1860 unsigned int linkIndex = __GET_ARG_IN__(
"rocLinkIndex",
unsigned int);
1861 unsigned int loops = __GET_ARG_IN__(
"loops",
unsigned int);
1862 unsigned int baseAddress = __GET_ARG_IN__(
"baseAddress",
unsigned int);
1863 unsigned int correctRegisterValue0 =
1864 __GET_ARG_IN__(
"correctRegisterValue0",
unsigned int);
1865 unsigned int correctRegisterValue1 =
1866 __GET_ARG_IN__(
"correctRegisterValue1",
unsigned int);
1868 __FE_COUTV__(linkIndex);
1869 __FE_COUTV__(loops);
1870 __FE_COUTV__(baseAddress);
1871 __FE_COUTV__(correctRegisterValue0);
1872 __FE_COUTV__(correctRegisterValue1);
1874 for(
auto& roc : rocs_)
1875 if(roc.second->getLinkID() == linkIndex)
1877 roc.second->highRateBlockCheck(
1878 loops, baseAddress, correctRegisterValue0, correctRegisterValue1);
1882 __FE_SS__ <<
"Error! Could not find ROC at link index " << linkIndex << __E__;
1888 void DTCFrontEndInterface::DTCHighRateDCSCheck(__ARGS__)
1890 unsigned int linkIndex = __GET_ARG_IN__(
"rocLinkIndex",
unsigned int);
1891 unsigned int loops = __GET_ARG_IN__(
"loops",
unsigned int);
1892 unsigned int baseAddress = __GET_ARG_IN__(
"baseAddress",
unsigned int);
1893 unsigned int correctRegisterValue0 =
1894 __GET_ARG_IN__(
"correctRegisterValue0",
unsigned int);
1895 unsigned int correctRegisterValue1 =
1896 __GET_ARG_IN__(
"correctRegisterValue1",
unsigned int);
1898 __FE_COUTV__(linkIndex);
1899 __FE_COUTV__(loops);
1900 __FE_COUTV__(baseAddress);
1901 __FE_COUTV__(correctRegisterValue0);
1902 __FE_COUTV__(correctRegisterValue1);
1904 for(
auto& roc : rocs_)
1905 if(roc.second->getLinkID() == linkIndex)
1907 roc.second->highRateCheck(
1908 loops, baseAddress, correctRegisterValue0, correctRegisterValue1);
1912 __FE_SS__ <<
"Error! Could not find ROC at link index " << linkIndex << __E__;
1918 void DTCFrontEndInterface::DTCSendHeartbeatAndDataRequest(__ARGS__)
1920 unsigned int number = __GET_ARG_IN__(
"numberOfRequests",
unsigned int);
1921 unsigned int timestampStart = __GET_ARG_IN__(
"timestampStart",
unsigned int);
1925 bool incrementTimestamp =
true;
1926 uint32_t cfodelay = 10000;
1928 int requestsAhead = 0;
1930 __FE_COUTV__(number);
1931 __FE_COUTV__(timestampStart);
1933 auto device = thisDTC_->GetDevice();
1935 auto initTime = device->GetDeviceTime();
1936 device->ResetDeviceTime();
1937 auto afterInit = std::chrono::steady_clock::now();
1939 if(emulate_cfo_ == 1)
1941 registerWrite(0x9100, 0x40008404);
1948 registerWrite(0x91BC, 0x10);
1953 registerWrite(0x91f4, 0x0);
1957 registerWrite(0x9158, 0x1);
1960 bool useCFOEmulator =
true;
1961 uint16_t debugPacketCount = 0;
1962 auto debugType = DTCLib::DTC_DebugType_SpecialSequence;
1963 bool stickyDebugType =
true;
1965 bool asyncRR =
false;
1966 bool forceNoDebugMode =
true;
1978 DTCLib::DTCSoftwareCFO* EmulatedCFO_ =
1979 new DTCLib::DTCSoftwareCFO(thisDTC_,
1996 EmulatedCFO_->SendRequestsForRange(
1998 DTCLib::DTC_Timestamp(static_cast<uint64_t>(timestampStart)),
2006 auto readoutRequestTime = device->GetDeviceTime();
2007 device->ResetDeviceTime();
2008 auto afterRequests = std::chrono::steady_clock::now();
2011 unsigned quietCount = 20;
2014 std::stringstream ostr;
2017 for(
unsigned ii = 0; ii < number; ++ii)
2019 __FE_COUT__ <<
"Buffer Read " << std::dec << ii << std::endl;
2020 mu2e_databuff_t* buffer;
2022 __FE_COUT__ <<
"util - before read for DAQ - ii=" << ii;
2023 auto sts = device->read_data(
2024 DTC_DMA_Engine_DAQ, reinterpret_cast<void**>(&buffer), tmo_ms);
2025 __FE_COUT__ <<
"util - after read for DAQ - ii=" << ii <<
", sts=" << sts
2026 <<
", buffer=" << (
void*)buffer;
2030 void* readPtr = &buffer[0];
2031 auto bufSize =
static_cast<uint16_t
>(*
static_cast<uint64_t*
>(readPtr));
2032 readPtr =
static_cast<uint8_t*
>(readPtr) + 8;
2034 std::cout <<
"Buffer reports DMA size of " << std::dec << bufSize
2035 <<
" bytes. Device driver reports read of " << sts <<
" bytes,"
2038 std::cout <<
"util - bufSize is " << bufSize;
2042 outputStream.write(static_cast<char*>(readPtr), sts - 8);
2044 auto maxLine =
static_cast<unsigned>(ceil((sts - 8) / 16.0));
2045 std::cout <<
"maxLine " << maxLine;
2046 for(
unsigned line = 0; line < maxLine; ++line)
2048 ostr <<
"0x" << std::hex << std::setw(5) << std::setfill(
'0') << line
2050 for(
unsigned byte = 0; byte < 8; ++byte)
2052 if(line * 16 + 2 * byte < sts - 8u)
2055 reinterpret_cast<uint16_t*
>(buffer)[4 + line * 8 + byte];
2056 ostr << std::setw(4) << static_cast<int>(thisWord) <<
" ";
2063 __FE_COUT__ << ostr.str();
2065 if(maxLine > quietCount * 2 && quiet && line == (quietCount - 1))
2067 line =
static_cast<unsigned>(ceil((sts - 8) / 16.0)) -
2072 device->read_release(DTC_DMA_Engine_DAQ, 1);
2077 __SET_ARG_OUT__(
"readData", ostr.str());
2079 __FE_COUT__ << ostr.str();
2081 delete EmulatedCFO_;
2087 __FE_SS__ <<
"Error! DTC must be in CFOEmulate mode" << __E__;
2095 void DTCFrontEndInterface::DTCReset(__ARGS__) { DTCReset(); }
2098 void DTCFrontEndInterface::DTCReset()
2101 char* address =
new char[universalAddressSize_]{
2103 char* data =
new char[universalDataSize_]{
2105 uint64_t macroAddress;
2107 std::map<std::string , uint64_t >
2111 macroAddress = 0x9100;
2112 memcpy(address, ¯oAddress, 8);
2113 macroData = 0xa0000000;
2114 memcpy(data, ¯oData, 8);
2115 universalWrite(address, data);
2118 macroAddress = 0x9118;
2119 memcpy(address, ¯oAddress, 8);
2120 macroData = 0x0000003f;
2121 memcpy(data, ¯oData, 8);
2122 universalWrite(address, data);
2125 macroAddress = 0x9100;
2126 memcpy(address, ¯oAddress, 8);
2127 macroData = 0x00000000;
2128 memcpy(data, ¯oData, 8);
2129 universalWrite(address, data);
2132 macroAddress = 0x9100;
2133 memcpy(address, ¯oAddress, 8);
2134 macroData = 0x10000000;
2135 memcpy(data, ¯oData, 8);
2136 universalWrite(address, data);
2139 macroAddress = 0x9100;
2140 memcpy(address, ¯oAddress, 8);
2141 macroData = 0x30000000;
2142 memcpy(data, ¯oData, 8);
2143 universalWrite(address, data);
2146 macroAddress = 0x9100;
2147 memcpy(address, ¯oAddress, 8);
2148 macroData = 0x10000000;
2149 memcpy(data, ¯oData, 8);
2150 universalWrite(address, data);
2153 macroAddress = 0x9118;
2154 memcpy(address, ¯oAddress, 8);
2155 macroData = 0x00000000;
2156 memcpy(data, ¯oData, 8);
2157 universalWrite(address, data);
2165 void DTCFrontEndInterface::RunROCFEMacro(__ARGS__)
2173 auto feMacroIt = rocFEMacroMap_.find(feMacroStruct.feMacroName_);
2174 if(feMacroIt == rocFEMacroMap_.end())
2176 __FE_SS__ <<
"Fatal error - ROC FE Macro name '" << feMacroStruct.feMacroName_
2177 <<
"' not found in DTC's map!" << __E__;
2181 const std::string& rocUID = feMacroIt->second.first;
2182 const std::string& rocFEMacroName = feMacroIt->second.second;
2184 __FE_COUTV__(rocUID);
2185 __FE_COUTV__(rocFEMacroName);
2187 auto rocIt = rocs_.find(rocUID);
2188 if(rocIt == rocs_.end())
2190 __FE_SS__ <<
"Fatal error - ROC name '" << rocUID <<
"' not found in DTC's map!"
2195 rocIt->second->runSelfFrontEndMacro(rocFEMacroName, argsIn, argsOut);