9WIB::WIB(std::string
const & address, std::string
const & WIBAddressTable, std::string
const & FEMBAddressTable,
bool fullStart):
10 WIBBase(address,WIBAddressTable,FEMBAddressTable),DAQMode(UNKNOWN),FEMBStreamCount(4),FEMBCDACount(2),
11 ContinueOnFEMBRegReadError(false),ContinueOnFEMBSPIError(false),ContinueOnFEMBSyncError(true),
12 ContinueIfListOfFEMBClockPhasesDontSync(true){
27 Write(
"POWER.ENABLE.MASTER_BIAS",1);
47 Write(
"POWER.ENABLE.MASTER_BIAS",1);
55 BUException::WIB_FEATURE_NOT_SUPPORTED e;
56 e.Append(
"Automatic DAQLink configuration not supported with this firmware.\n");
61 std::string base(
"DAQ_LINK_");
63 base.append(
".CONTROL.");
64 printf(
"%s\n",base.c_str());
67 uint32_t enable_mask = 0;
72 Write(base+
"ENABLE_CDA_STREAM",enable_mask);
74 Write(base+
"ENABLE",0x1);
81 BUException::WIB_FEATURE_NOT_SUPPORTED e;
82 e.Append(
"Automatic DAQLink configuration not supported with this firmware.\n");
87 std::string base(
"DAQ_LINK_");
89 base.append(
".CONTROL.");
97 Write(base+
"ENABLE_CDA_STREAM",stream);
132 Write(
"SYSTEM.RESET",0xFF);
134 Write(
"POWER.ENABLE.MASTER_BIAS",0x1);
143 Write(
"SYSTEM.RESET.UDP_RESET",1);
144 }
catch(BUException::BAD_REPLY & e){
151 Write(
"SYSTEM.RESET.UDP_RESET",1);
152 }
catch(BUException::BAD_REPLY & e){
165 Write(
"DAQ.SI5342.RESET",1);
167 Write(
"DAQ.SI5342.RESET",0);
169 printf(
"Configuring SI5342 for FELIX\n");
177 Write(
"SYSTEM.RESET.EB_PLL_RESET",1);
181 Write(
"SYSTEM.RESET.DAQ_PATH_RESET",1);
186 Write(
"DTS.CMD_COUNT_RESET", 0xFFFFFFFF);
187 Write(
"DTS.CMD_COUNT_RESET", 0);
190 Write(
"DTS.CONVERT_CONTROL.HALT", 1);
191 Write(
"DTS.CONVERT_CONTROL.ENABLE", 0);
194 Write(
"POWER.ENABLE.MASTER_BIAS",1);
199 BUException::WIB_DAQMODE_UNKNOWN e;
203 BUException::WIB_BAD_ARGS e;
204 e.Append(
"localClock > 1; must be 0 (for DTS) or 1 (for local clock)\n");
208 BUException::WIB_BAD_ARGS e;
209 e.Append(
"PDTSsource > 1; must be 0 (for backplane) or 1 (for front panel)\n");
213 BUException::WIB_BAD_ARGS e;
214 e.Append(
"PDTS TGRP > 15; must be 0 to 15\n");
219 uint32_t slow_control_dnd =
Read(
"SYSTEM.SLOW_CONTROL_DND");
222 Write(
"SYSTEM.SLOW_CONTROL_DND",1);
225 for (
size_t iFEMB=1; iFEMB<=4; iFEMB++){
230 Write(
"DTS.CONVERT_CONTROL.HALT",1);
231 Write(
"DTS.CONVERT_CONTROL.ENABLE",0);
232 Write(
"DTS.CONVERT_CONTROL.START_SYNC",0);
236 printf(
"Configuring local clock\n");
242 Write(
"DTS.CONVERT_CONTROL.EN_FAKE",1);
243 Write(
"DTS.CONVERT_CONTROL.LOCAL_TIMESTAMP",1);
244 Write(
"FEMB_CNC.CNC_CLOCK_SELECT",1);
250 printf(
"Configuring DTS\n");
251 Write(
"DTS.PDTS_TGRP",PDTS_TGRP);
252 printf(
"Using timing group 0x%X\n",PDTS_TGRP);
255 Write(
"FEMB_CNC.CNC_CLOCK_SELECT",1);
258 Write(
"DTS.PDTS_ENABLE",1);
263 Write(
"FEMB1.DAQ.ENABLE",0);
264 Write(
"FEMB2.DAQ.ENABLE",0);
265 Write(
"FEMB3.DAQ.ENABLE",0);
266 Write(
"FEMB4.DAQ.ENABLE",0);
268 Write(
"SYSTEM.SLOW_CONTROL_DND",slow_control_dnd);
274 BUException::WIB_DAQMODE_UNKNOWN e;
278 BUException::WIB_BAD_ARGS e;
279 e.Append(
"localClock > 1; must be 0 (for DTS) or 1 (for local clock)\n");
283 BUException::WIB_BAD_ARGS e;
284 e.Append(
"PDTSsource > 1; must be 0 (for backplane) or 1 (for front panel)\n");
288 BUException::WIB_BAD_ARGS e;
289 e.Append(
"PDTS TGRP > 15; must be 0 to 15\n");
294 bool reset_check =
false;
297 printf(
"Checking if locked on local clock\n");
298 reset_check = ( (
Read(
"DTS.CONVERT_CONTROL.EN_FAKE") != 1)
299 || (
Read(
"DTS.CCONVERT_CONTROL.LOCAL_TIMESTAMP") != 1)
300 || (
Read(
"FEMB_CNC.CNC_CLOCK_SELECT") != 1)
302 || (
Read(
"DTS.SI5344.INPUT_SELECT") != 1)
303 || (
Read(
"DTS.SI5344.ENABLE") != 1) );
305 printf(
"Already in a good state\n");
308 printf(
"Need to reset for local clocking\n");
312 printf(
"Checking if locked on PDTS\n");
313 reset_check = ( (
Read(
"DTS.PDTS_TGRP") != PDTS_TGRP)
314 || (
Read(
"FEMB_CNC.CNC_CLOCK_SELECT") != 1)
315 || (
Read(
"DTS.PDTS_ENABLE") != 1)
316 || (
Read(
"DTS.CDS.LOL") != 0)
317 || (
Read(
"DTS.CDS.LOS") != 0)
324 printf(
"Already in a good state\n");
327 printf(
"Need to reset for PDTS\n");
335 (
Read(
"DAQ.SI5342.ENABLE") == 0)
336 || (
Read(
"DAQ.SI5342.INPUT_SELECT") != 1)
337 || (
Read(
"DAQ.SI5342.LOL") == 1)
338 || (
Read(
"DAQ.SI5342.LOS_XAXB") == 1)
339 || (
Read(
"DAQ.SI5342.LOS_2") == 1) ){
340 printf(
"Need to reset for SI5342\n");
344 printf(
"SI5342 in good state\n");
350 uint32_t slow_control_dnd =
Read(
"SYSTEM.SLOW_CONTROL_DND");
353 Write(
"SYSTEM.SLOW_CONTROL_DND",1);
355 for (
size_t iFEMB=1; iFEMB<=4; iFEMB++){
360 Write(
"DTS.CONVERT_CONTROL.HALT",1);
361 Write(
"DTS.CONVERT_CONTROL.ENABLE",0);
362 Write(
"DTS.CONVERT_CONTROL.START_SYNC",0);
366 printf(
"Configuring local clock\n");
372 Write(
"DTS.CONVERT_CONTROL.EN_FAKE",1);
373 Write(
"DTS.CONVERT_CONTROL.LOCAL_TIMESTAMP",1);
374 Write(
"FEMB_CNC.CNC_CLOCK_SELECT",1);
380 printf(
"Configuring DTS\n");
381 Write(
"DTS.PDTS_TGRP",PDTS_TGRP);
382 printf(
"Using timing group 0x%X\n",PDTS_TGRP);
385 Write(
"FEMB_CNC.CNC_CLOCK_SELECT",1);
388 Write(
"DTS.PDTS_ENABLE",1);
393 Write(
"SYSTEM.SLOW_CONTROL_DND",slow_control_dnd);
396 std::cout <<
"Resetting DAQ Links" << std::endl;
399 for (
size_t iLink=1; iLink <= nLinks; ++iLink){
400 std::cout << iLink << std::endl;
404 Write(
"FEMB1.DAQ.ENABLE",0);
405 Write(
"FEMB2.DAQ.ENABLE",0);
406 Write(
"FEMB3.DAQ.ENABLE",0);
407 Write(
"FEMB4.DAQ.ENABLE",0);
413 BUException::WIB_DAQMODE_UNKNOWN e;
421 uint32_t slow_control_dnd =
Read(
"SYSTEM.SLOW_CONTROL_DND");
422 Write(
"SYSTEM.SLOW_CONTROL_DND",1);
425 Write(
"FEMB_CNC.FEMB_STOP",1);
427 Write(
"SYSTEM.RESET.DAQ_PATH_RESET",1);
441 Write(
"FEMB1.DAQ.ENABLE",0xF);
442 Write(
"FEMB2.DAQ.ENABLE",0xF);
443 Write(
"FEMB3.DAQ.ENABLE",0xF);
444 Write(
"FEMB4.DAQ.ENABLE",0xF);
447 Write(
"FEMB_CNC.ENABLE_DTS_CMDS",1);
453 Write(
"SYSTEM.SLOW_CONTROL_DND",slow_control_dnd);
457 std::string reg =
"POWER.ENABLE.FEMB";
500 Write(
"FEMB_CNC.CNC_CLOCK_SELECT",1);
501 Write(
"FEMB_CNC.CNC_COMMAND_SELECT",1);
505 Write(
"FEMB_CNC.CNC_CLOCK_SELECT",0);
506 Write(
"FEMB_CNC.CNC_COMMAND_SELECT",0);
511 BUException::WIB_INDEX_OUT_OF_RANGE e;
512 e.Append(
"DAQ Link\n");
537 BUException::WIB_INDEX_OUT_OF_RANGE e;
538 e.Append(
"DAQ Link\n");
548 if(!((iFEMB > 0) && (iFEMB <=
FEMBCount))){
549 BUException::WIB_INDEX_OUT_OF_RANGE e;
575 BUException::WIB_INDEX_OUT_OF_RANGE e;
587 BUException::WIB_INDEX_OUT_OF_RANGE e;
588 e.Append(
"FEMB Stream");
596 BUException::WIB_INDEX_OUT_OF_RANGE e;
597 e.Append(
"FEMB CDA");
616 BUException::WIB_INDEX_OUT_OF_RANGE e;
617 e.Append(
"FEMB CDA\n");
628 printf(
"FEMB index out of range < 1\n");
639 std::string address(
"FEMB");
641 address.append(
".DAQ.FAKE_CD.FAKE_SOURCE");
void WriteWithRetry(uint16_t address, uint32_t value)
uint32_t ReadWithRetry(uint16_t address)
uint32_t Read(uint16_t address)
void Write(uint16_t address, uint32_t value)
bool CheckFEMBStreamInRange(uint8_t iStream)
void ResetWIB(bool reset_udp=false)
void EnableDAQLink(uint8_t iDAQLink)
void LoadConfigDTS_SI5344(std::string const &fileName)
void CheckedResetWIBAndCfgDTS(uint8_t localClock, uint8_t PDTS_TGRP, uint8_t PDTSsource=0, uint32_t PDTSAlignment_timeout=0)
char GetFEMBCDChar(uint8_t iCD)
void InitializeDTS(uint8_t PDTSsource=0, uint8_t clockSource=0, uint32_t PDTSAlignment_timeout=0)
void ResetWIBAndCfgDTS(uint8_t localClock, uint8_t PDTS_TGRP, uint8_t PDTSsource=0, uint32_t PDTSAlignment_timeout=0)
char GetDAQLinkChar(uint8_t iDAQLink)
void EnableDAQLink_Lite(uint8_t iDAQLink, uint8_t enable)
void SelectSI5344(uint64_t input, bool enable)
void SelectSI5342(uint64_t input, bool enable)
void FEMBPower(uint8_t iFEMB, bool turnOn)
void SourceFEMB(uint64_t iDAQLink, uint64_t real)
bool CheckFEMBCDInRange(uint8_t iCD)
bool CheckDAQLinkInRange(uint8_t iDAQLink)
void LoadConfigDAQ_SI5342(std::string const &fileName)
char GetFEMBChar(uint8_t iFEMB)
void StartStreamToDAQ(bool l1=true, bool l2=true, bool l3=false, bool l4=false)
bool CheckFEMBInRange(uint8_t iFEMB)