1 #include "otsdaq-mu2e-crv/FEInterfaces/ROCCosmicRayVetoInterface.h"
2 #include "otsdaq-mu2e-crv/FEInterfaces/ROC_Registers.h"
4 #include "otsdaq/Macros/InterfacePluginMacros.h"
9 #define __MF_SUBJECT__ "FE-ROCCosmicRayVetoInterface"
12 ROCCosmicRayVetoInterface::ROCCosmicRayVetoInterface(
13 const std::string& rocUID,
14 const ConfigurationTree& theXDAQContextConfigTree,
15 const std::string& theConfigurationPath)
16 : ROCCoreVInterface(rocUID, theXDAQContextConfigTree, theConfigurationPath)
20 __COUT_INFO__ <<
"ROCCosmicRayVetoInterface instantiated with link: "
21 << (int)linkID_ <<
" and EventWindowDelayOffset = " << delay_ << __E__;
23 registerFEMacroFunction(
25 static_cast<FEVInterface::frontEndMacroFunction_t
>(
26 &ROCCosmicRayVetoInterface::DoTheCRV_Dance),
27 std::vector<std::string>{
"Which Step"},
28 std::vector<std::string>{
32 registerFEMacroFunction(
"Get Firmware Version",
33 static_cast<FEVInterface::frontEndMacroFunction_t
>(
34 &ROCCosmicRayVetoInterface::GetFirmwareVersion),
35 std::vector<std::string>{},
36 std::vector<std::string>{
"version",
"git hash"},
39 registerFEMacroFunction(
"Get Test Counter",
40 static_cast<FEVInterface::frontEndMacroFunction_t
>(
41 &ROCCosmicRayVetoInterface::GetTestCounter),
42 std::vector<std::string>{},
43 std::vector<std::string>{
"counter"},
46 registerFEMacroFunction(
"Set Test Counter",
47 static_cast<FEVInterface::frontEndMacroFunction_t
>(
48 &ROCCosmicRayVetoInterface::SetTestCounter),
49 std::vector<std::string>{
"Set Counter (Default: 0)"},
50 std::vector<std::string>{},
53 registerFEMacroFunction(
"Reset uC",
54 static_cast<FEVInterface::frontEndMacroFunction_t
>(
55 &ROCCosmicRayVetoInterface::HardReset),
56 std::vector<std::string>{},
57 std::vector<std::string>{},
60 registerFEMacroFunction(
"Configure ROC",
61 static_cast<FEVInterface::frontEndMacroFunction_t
>(
62 &ROCCosmicRayVetoInterface::RocConfigure),
63 std::vector<std::string>{
"send GR packages (Default: true)"},
64 std::vector<std::string>{},
67 registerFEMacroFunction(
"Reset TX and Counters",
68 static_cast<FEVInterface::frontEndMacroFunction_t
>(
69 &ROCCosmicRayVetoInterface::SoftReset),
70 std::vector<std::string>{},
71 std::vector<std::string>{},
74 registerFEMacroFunction(
"Get Status",
75 static_cast<FEVInterface::frontEndMacroFunction_t
>(
76 &ROCCosmicRayVetoInterface::GetStatus),
77 std::vector<std::string>{},
78 std::vector<std::string>{
79 "version",
"git hash",
80 "CR",
"Send GR",
"Loopback Mode",
"PLL lock",
"Active Ports",
"Uptime",
"Link Errors Loss",
"Link Errors CRC",
81 "Test Cnt",
"Marker Decoded Cnt",
"Marker Delayed Cnt",
"Heartbeat Rx Cnt",
"Heartbeat Tx Cnt",
"DR Cnt",
"Injection Cnt",
"Loopback Markers (fiber) Cnt",
82 "Last Event Length (12.5ns)",
"Injection Length (12.5ns)",
"Injection Timestamp"
86 registerFEMacroFunction(
"Read Fiber Rx",
87 static_cast<FEVInterface::frontEndMacroFunction_t
>(
88 &ROCCosmicRayVetoInterface::FiberRx),
89 std::vector<std::string>{
"number of packages (Default: 10)"},
90 std::vector<std::string>{
"buffer"},
93 registerFEMacroFunction(
"Read Fiber Tx",
94 static_cast<FEVInterface::frontEndMacroFunction_t
>(
95 &ROCCosmicRayVetoInterface::FiberTx),
96 std::vector<std::string>{
"number of packages (Default: 10)"},
97 std::vector<std::string>{
"buffer"},
100 registerFEMacroFunction(
"Set Loopback Mode",
101 static_cast<FEVInterface::frontEndMacroFunction_t
>(
102 &ROCCosmicRayVetoInterface::SetLoopbackMode),
103 std::vector<std::string>{
"loopback mode (Default: 0)"},
104 std::vector<std::string>{},
110 ROCCosmicRayVetoInterface::~ROCCosmicRayVetoInterface(
void)
114 __COUT__ << FEVInterface::interfaceUID_ <<
" Destructor" << __E__;
137 void ROCCosmicRayVetoInterface::writeEmulatorRegister(uint16_t address,
138 uint16_t data_to_write)
140 __FE_COUT__ <<
"Calling write ROC Emulator register: link number " << std::dec
141 << (int)linkID_ <<
", address = " << address
142 <<
", write data = " << data_to_write << __E__;
148 uint16_t ROCCosmicRayVetoInterface::readEmulatorRegister(uint16_t address)
150 __FE_COUT__ <<
"Calling read ROC Emulator register: link number " << std::dec
151 << (int)linkID_ <<
", address = " << address << __E__;
180 void ROCCosmicRayVetoInterface::configure(
void)
try
182 __COUT_INFO__ <<
".... do nothing for CRV ROC yet ... " << __E__;
186 catch(
const std::runtime_error& e)
188 __FE_COUT__ <<
"Error caught: " << e.what() << __E__;
193 __FE_SS__ <<
"Unknown error caught. Check printouts!" << __E__;
194 __FE_COUT__ << ss.str();
199 void ROCCosmicRayVetoInterface::halt(
void) {}
202 void ROCCosmicRayVetoInterface::pause(
void) {}
205 void ROCCosmicRayVetoInterface::resume(
void) {}
208 void ROCCosmicRayVetoInterface::start(std::string)
213 void ROCCosmicRayVetoInterface::stop(
void) {}
216 bool ROCCosmicRayVetoInterface::running(
void) {
return false; }
219 void ROCCosmicRayVetoInterface::DoTheCRV_Dance(__ARGS__)
222 __FE_COUT__ <<
"Hello" << __E__;
223 __SET_ARG_OUT__(
"Random Result",0xA4);
227 void ROCCosmicRayVetoInterface::GetFirmwareVersion(__ARGS__)
229 __SET_ARG_OUT__(
"version", this->readRegister(ROCLib::ROC_Register::Version));
230 __SET_ARG_OUT__(
"git hash",
231 (this->readRegister(ROCLib::ROC_Register::GitHashHigh) << 16) +
232 this->readRegister(ROCLib::ROC_Register::GitHashLow)
236 void ROCCosmicRayVetoInterface::GetTestCounter(__ARGS__)
238 __SET_ARG_OUT__(
"counter", this->readRegister(ROCLib::ROC_Register::TestCounter));
241 void ROCCosmicRayVetoInterface::SetTestCounter(__ARGS__)
243 uint16_t value = __GET_ARG_IN__(
"Set Counter (Default: 0)", uint16_t, 0);
244 this->writeRegister(ROCLib::ROC_Register::TestCounter, value);
247 void ROCCosmicRayVetoInterface::Reset() {
248 this->writeRegister(ROCLib::ROC_Register::Reset, 0x1);
250 void ROCCosmicRayVetoInterface::HardReset(__ARGS__) { Reset(); }
252 void ROCCosmicRayVetoInterface::ResetTxBuffers() {
253 this->writeRegister(ROCLib::ROC_Register::GTP_CRC, 0x1);
254 this->writeRegister(ROCLib::ROC_Register::CRS, 0x300);
256 void ROCCosmicRayVetoInterface::SoftReset(__ARGS__)
261 void ROCCosmicRayVetoInterface::RocConfigure(
bool gr) {
263 this->writeRegister(ROCLib::ROC_Register::PLLStat, 0x0);
265 this->writeRegister(ROCLib::ROC_Register::PLLMuxHigh, 0x12);
266 this->writeRegister(ROCLib::ROC_Register::PLLMuxHLow, 0x12);
269 this->writeRegister(ROCLib::ROC_Register::CR, 0x20);
272 this->writeRegister(ROCLib::ROC_Register::Data_Broadcast|ROCLib::ROC_Register::Data_CRC, 0xA8);
278 for (
int i = 0; i < 3; ++i) {
279 this->writeRegister(ROCLib::ROC_Register_Data[i]|ROCLib::ROC_Register::Data_DDR_WriteHigh,0x0);
280 this->writeRegister(ROCLib::ROC_Register_Data[i]|ROCLib::ROC_Register::Data_DDR_WriteHigh,0x0);
281 this->writeRegister(ROCLib::ROC_Register_Data[i]|ROCLib::ROC_Register::Data_DDR_ReadHigh, 0x0);
282 this->writeRegister(ROCLib::ROC_Register_Data[i]|ROCLib::ROC_Register::Data_DDR_ReadLow, 0x0);
286 this->writeRegister(ROCLib::ROC_Register::TRIG, 0x1);
289 if(gr) this->writeRegister(ROCLib::ROC_Register::sendGR, 0x1);
290 else this->writeRegister(ROCLib::ROC_Register::sendGR, 0x0);
293 void ROCCosmicRayVetoInterface::RocConfigure(__ARGS__)
295 bool gr = __GET_ARG_IN__(
"send GR packages (Default: true)",
bool,
true);
299 void ROCCosmicRayVetoInterface::GetStatus(__ARGS__)
301 __SET_ARG_OUT__(
"version", this->readRegister(ROCLib::ROC_Register::Version));
302 __SET_ARG_OUT__(
"git hash",
303 ((this->readRegister(ROCLib::ROC_Register::GitHashHigh) << 16) +
304 this->readRegister(ROCLib::ROC_Register::GitHashLow)) & 0xffffffff
306 __SET_ARG_OUT__(
"CR", this->readRegister(ROCLib::ROC_Register::CR));
307 __SET_ARG_OUT__(
"Send GR", this->readRegister(ROCLib::ROC_Register::sendGR) & 0x1);
308 __SET_ARG_OUT__(
"Loopback Mode", this->readRegister(ROCLib::ROC_Register::LoopbackMode));
309 __SET_ARG_OUT__(
"PLL lock", ((this->readRegister(ROCLib::ROC_Register::PLLStat)) >> 4) & 0x1 );
310 __SET_ARG_OUT__(
"Active Ports",
311 (this->readRegister(ROCLib::ROC_Register::ActivePortsHigh) << 16) +
312 this->readRegister(ROCLib::ROC_Register::ActivePortsLow));
313 __SET_ARG_OUT__(
"Uptime",
314 (this->readRegister(ROCLib::ROC_Register::UpTimeHigh) << 16) +
315 this->readRegister(ROCLib::ROC_Register::UpTimeLow));
316 __SET_ARG_OUT__(
"Link Errors Loss", this->readRegister(ROCLib::ROC_Register::LinkErrors) & 0xff);
317 __SET_ARG_OUT__(
"Link Errors CRC", this->readRegister(ROCLib::ROC_Register::LinkErrors) >> 12);
320 __SET_ARG_OUT__(
"Test Cnt", this->readRegister(ROCLib::ROC_Register::TestCounter));
321 __SET_ARG_OUT__(
"Marker Decoded Cnt", this->readRegister(ROCLib::ROC_Register::MarkerCnt) & 0xff);
322 __SET_ARG_OUT__(
"Marker Delayed Cnt", (this->readRegister(ROCLib::ROC_Register::MarkerCnt) >> 8));
323 __SET_ARG_OUT__(
"Heartbeat Rx Cnt", this->readRegister(ROCLib::ROC_Register::HeartBeat) & 0xff);
324 __SET_ARG_OUT__(
"Heartbeat Tx Cnt", this->readRegister(ROCLib::ROC_Register::HeartBeat) >> 8);
325 __SET_ARG_OUT__(
"DR Cnt",
326 (this->readRegister(ROCLib::ROC_Register::DRCntHigh) << 16) +
327 this->readRegister(ROCLib::ROC_Register::DRCnLow));
328 __SET_ARG_OUT__(
"Injection Cnt", this->readRegister(ROCLib::ROC_Register::InjectionCnt));
329 __SET_ARG_OUT__(
"Loopback Markers (fiber) Cnt", this->readRegister(ROCLib::ROC_Register::LoopbackMarkerCnt));
332 __SET_ARG_OUT__(
"Last Event Length (12.5ns)", this->readRegister(ROCLib::ROC_Register::LastEventLength));
333 __SET_ARG_OUT__(
"Injection Length (12.5ns)", this->readRegister(ROCLib::ROC_Register::InjectionLength));
334 __SET_ARG_OUT__(
"Injection Timestamp", this->readRegister(ROCLib::ROC_Register::InjectionTS));
338 void ROCCosmicRayVetoInterface::FiberRx(__ARGS__) {
339 int n = __GET_ARG_IN__(
"number of packages (Default: 10)",
int, 10);
343 for(
int i = 0; i < n; ++i) {
344 for(
int k = 0; k < 10; ++k) {
345 o << std::hex << std::setfill(
'0') << std::setw(4) << this->readRegister(ROCLib::ROC_Register::GTPRxRead) <<
" ";
349 __SET_ARG_OUT__(
"buffer", o.str());
352 void ROCCosmicRayVetoInterface::FiberTx(__ARGS__) {
353 int n = __GET_ARG_IN__(
"number of packages (Default: 10)",
int, 10);
357 for(
int i = 0; i < n; ++i) {
358 for(
int k = 0; k < 10; ++k) {
359 o << std::hex << std::setfill(
'0') << std::setw(4) << this->readRegister(ROCLib::ROC_Register::GTPTxRead) <<
" ";
363 __SET_ARG_OUT__(
"buffer", o.str());
366 void ROCCosmicRayVetoInterface::SetLoopbackMode(__ARGS__) {
367 int16_t mode = __GET_ARG_IN__(
"loopback mode (Default: 0)", int16_t, 0);
368 this->writeRegister(ROCLib::ROC_Register::LoopbackMode, mode);