262{
263
265
266 std::stringstream ss;
267 fDeviceId = inet_network(conf->get_board_ip().c_str());
268 TLOG() <<
"DeviceInterface: trying to connect to " << boost::asio::ip::address_v4(
fDeviceId).to_string();
269
271 dunedaq::sspmodules::Device* device = 0;
272
274
275 if (!device) {
278 }
279
281
282
284
285 unsigned int pdts_status = 0;
286 unsigned int pdts_control = 0;
287 unsigned int dsp_clock_control = 0;
288
290 TLOG() <<
"The pdts_status read back as 0x" << std::hex << pdts_status << std::dec << std::endl;
292 TLOG() <<
"The pdts_control read back as 0x" << std::hex << pdts_control << std::dec << std::endl;
294 TLOG() <<
"The dsp_clock_control read back as 0x" << std::hex << dsp_clock_control << std::dec << std::endl;
295
296 unsigned int presentTimingAddress = (pdts_control >> 16) & 0xFF;
297 unsigned int presentTimingPartition = pdts_control & 0x3;
298
299 TLOG() <<
"SSP HW presently on partition " << presentTimingPartition <<
", address 0x" << std::hex
300 << presentTimingAddress << " with endpoint status 0x" << (pdts_status & 0xF) << " and dsp_clock_control at 0x"
301 << dsp_clock_control << std::dec << std::endl;
302
303
304
305 if ((pdts_status & 0xF) >= 0x6 && (pdts_status & 0xF) <= 0x8 && presentTimingAddress ==
fTimingAddress &&
307 (dsp_clock_control & 0xF) ==
308 0x1) {
309
310
311 TLOG() <<
"Clock already looks ok... skipping endpoint reset." << std::endl;
312 } else {
313
314 TLOG() <<
"Syncing SSP LED Calib to PDTS (partition " <<
fPartitionNumber <<
", endpoint address 0x" << std::hex
316
317 unsigned int nTries = 0;
318
319 while (nTries < 5) {
321 TLOG() <<
"The dsp_clock_control was set to 0x" << std::hex << 0x30 << std::dec
322 << std::endl;
324 TLOG() <<
"The pdts_control value was set to 0x" << std::hex
326 << std::endl;
327
329 TLOG() <<
"The pdts_status read back as 0x" << std::hex << pdts_status << std::dec << std::endl;
331 TLOG() <<
"The pdts_control read back as 0x" << std::hex << pdts_control << std::dec << std::endl;
333 TLOG() <<
"The dsp_clock_control read back as 0x" << std::hex << dsp_clock_control << std::dec << std::endl;
334
336 TLOG() <<
"The pdts_status value was set to 0x" << std::hex
338 usleep(2000000);
340 0x31);
341 TLOG() <<
"The dsp_clock_control was set to 0x" << std::hex << 0x31 << std::dec << std::endl;
342 usleep(2000000);
344 TLOG() <<
"The pdts_status read back as 0x" << std::hex << pdts_status << std::dec << std::endl;
345 if ((pdts_status & 0xF) >= 0x6 && (pdts_status & 0xF) <= 0x8)
346 break;
347 TLOG() <<
"Timing endpoint sync failed (try " << nTries <<
")" << std::endl;
348 ++nTries;
349 }
350
351 if ((pdts_status & 0xF) >= 0x6 && (pdts_status & 0xF) <= 0x8) {
352 TLOG() <<
"The pdts_status value is 0x" << std::hex << pdts_status <<
" and the 0xF bit masked value is 0x"
353 << (pdts_status & 0xF) << std::dec << std::endl;
354 TLOG() <<
"Timing endpoint synced!" << std::endl;
355 } else {
356 TLOG() <<
"The pdts_status value is 0x" << std::hex << pdts_status <<
" and the 0xF bit masked value is 0x"
357 << (pdts_status & 0xF) << std::dec << std::endl;
358 TLOG() <<
"Giving up on endpoint sync after 5 tries. Value of pdts_status register was 0x" << std::hex
359 << pdts_status << std::dec << std::endl;
360 }
361 }
362
363 TLOG() <<
"Woke up from 2 seconds of sleep and Waiting for endpoint to reach status 0x8..." << std::endl;
364
365 if ((pdts_status & 0xF) != 0x8) {
366 TLOG() <<
"Waiting for endpoint to reach status 0x8..." << std::endl;
367 TLOG() <<
"The pdts_status value is 0x" << std::hex << pdts_status <<
" and the 0xF bit masked value is 0x"
368 << (pdts_status & 0xF) << std::dec << std::endl;
369 }
370 int nTries = 0;
371 while ((pdts_status & 0xF) != 0x8) {
372 if (nTries == 2) {
373 TLOG() <<
"Wrong PDTS status!" << std::endl;
374 throw DeviceInterfacePDTSStatus(
ERS_HERE);
375 }
376 usleep(2000000);
377 TLOG() <<
"Woke up from 2 seconds of sleep and Waiting for endpoint to reach status 0x8..." << std::endl;
379 TLOG() <<
"The pdts_status value is 0x" << std::hex << pdts_status <<
" and the 0xF bit masked value is 0x"
380 << (pdts_status & 0xF) << std::dec << std::endl;
381 nTries++;
382 }
383
384 TLOG() <<
"Endpoint is in running state, continuing with configuration!" << std::endl;
385 TLOG() <<
"SSP LED Calib Device Interface Configured complete.";
386}
Device * OpenDevice(unsigned int deviceId, bool slowControlOnly=false)
static DeviceManager & Get()
virtual void DeviceRead(unsigned int address, unsigned int *value)=0
virtual void DeviceWrite(unsigned int address, unsigned int value)=0
unsigned int dsp_clock_control
unsigned int pdts_control
#define TLVL_ENTER_EXIT_METHODS
#define TLOG_DEBUG(lvl,...)