DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::sspmodules::DeviceInterface Class Reference

#include <DeviceInterface.hpp>

Collaboration diagram for dunedaq::sspmodules::DeviceInterface:
[legend]

Public Types

enum  State_t {
  kUninitialized , kInitialized , kRunning , kStopping ,
  kStopped , kBad
}
 

Public Member Functions

 DeviceInterface ()
 
 ~DeviceInterface ()
 
void OpenSlowControl ()
 
void ConfigureLEDCalib (const appmodel::SSPLEDCalibModule *conf)
 
void ReadEventFromDevice (EventPacket &event)
 
void SetRegister (unsigned int address, unsigned int value, unsigned int mask=0xFFFFFFFF)
 
void SetRegisterArray (unsigned int address, std::vector< unsigned int > value)
 
void SetRegisterArray (unsigned int address, unsigned int *value, unsigned int size)
 
void ReadRegister (unsigned int address, unsigned int &value, unsigned int mask=0xFFFFFFFF)
 
void ReadRegisterArray (unsigned int address, std::vector< unsigned int > &value, unsigned int size)
 
void ReadRegisterArray (unsigned int address, unsigned int *value, unsigned int size)
 
void SetRegisterByName (std::string name, unsigned int value)
 
void SetRegisterElementByName (std::string name, unsigned int index, unsigned int value)
 
void SetRegisterArrayByName (std::string name, unsigned int value)
 
void SetRegisterArrayByName (std::string name, std::vector< unsigned int > values)
 
void ReadRegisterByName (std::string name, unsigned int &value)
 
void ReadRegisterElementByName (std::string name, unsigned int index, unsigned int &value)
 
void ReadRegisterArrayByName (std::string name, std::vector< unsigned int > &values)
 
void SetHardwareClockRateInMHz (unsigned int rate)
 
void SetDummyPeriod (int period)
 
void SetUseExternalTimestamp (bool val)
 
void SetPartitionNumber (unsigned int val)
 
void SetTimingAddress (unsigned int val)
 
void PrintHardwareState ()
 
std::string GetIdentifier ()
 
bool exception () const
 

Private Member Functions

void set_exception (bool exception)
 

Private Attributes

DevicefDevice
 
unsigned long fDeviceId
 
State_t fState
 
bool fUseExternalTimestamp
 
unsigned int fHardwareClockRateInMHz
 
int fDummyPeriod
 
bool fSlowControlOnly
 
unsigned int fPartitionNumber
 
unsigned int fTimingAddress
 
std::atomic< bool > exception_
 

Detailed Description

Definition at line 36 of file DeviceInterface.hpp.

Member Enumeration Documentation

◆ State_t

Constructor & Destructor Documentation

◆ DeviceInterface()

◆ ~DeviceInterface()

dunedaq::sspmodules::DeviceInterface::~DeviceInterface ( )
inline

Definition at line 46 of file DeviceInterface.hpp.

46{ }

Member Function Documentation

◆ ConfigureLEDCalib()

void dunedaq::sspmodules::DeviceInterface::ConfigureLEDCalib ( const appmodel::SSPLEDCalibModule * conf)

Definition at line 261 of file DeviceInterface.cxx.

262{
263
264 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "SSP LED Calib Device Interface Configure called.";
265
266 std::stringstream ss;
267 fDeviceId = inet_network(conf->get_board_ip().c_str()); // inet_network("10.73.137.56");
268
269 // Ask device manager for a pointer to the specified device
271 dunedaq::sspmodules::Device* device = 0;
272
273
274 device = devman.OpenDevice(fDeviceId);
275
276 if (!device) {
277 TLOG_DEBUG(TLVL_WORK_STEPS) << "Unable to get handle to device; giving up!" << std::endl;
278 throw(ENoSuchDevice());
279 }
280
281 fDevice = device;
282
283 // Reset timing endpoint
285
286 unsigned int pdts_status = 0;
287 unsigned int pdts_control = 0;
288 unsigned int dsp_clock_control = 0;
289
290 fDevice->DeviceRead(duneReg.pdts_status, &pdts_status);
291 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_status read back as 0x" << std::hex << pdts_status << std::dec << std::endl;
292 fDevice->DeviceRead(duneReg.pdts_control, &pdts_control);
293 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_control read back as 0x" << std::hex << pdts_control << std::dec << std::endl;
294 fDevice->DeviceRead(duneReg.dsp_clock_control, &dsp_clock_control);
295 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The dsp_clock_control read back as 0x" << std::hex << dsp_clock_control << std::dec
296 << std::endl;
297
298 unsigned int presentTimingAddress = (pdts_control >> 16) & 0xFF;
299 unsigned int presentTimingPartition = pdts_control & 0x3;
300
301 TLOG_DEBUG(TLVL_WORK_STEPS) << "SSP HW presently on partition " << presentTimingPartition << ", address 0x" << std::hex
302 << presentTimingAddress << " with endpoint status 0x" << (pdts_status & 0xF)
303 << " and dsp_clock_control at 0x" << dsp_clock_control << std::dec << std::endl;
304
305 //if ((pdts_status & 0xF) >= 0x6 && (pdts_status & 0xF) <= 0x8 && presentTimingAddress == fTimingAddress &&
306 // presentTimingPartition == fPartitionNumber && dsp_clock_control == 0x31) {
307 if ((pdts_status & 0xF) >= 0x6 && (pdts_status & 0xF) <= 0x8 && presentTimingAddress == fTimingAddress &&
308 presentTimingPartition == fPartitionNumber && (dsp_clock_control & 0xF) == 0x1) { //NOTE THAT THIS WAS CHANGED SO THAT IF THE DSP_CLOCK_STATUS LOWEST BIT IS STILL HIGH 0x1
309 //THEN THE CLOCK ALREADY IS ASSUMED TO BE GOOD, AND WE DON'T TRY TO RESYNCH WITH THE PDTS
310
311 TLOG_DEBUG(TLVL_WORK_STEPS) << "Clock already looks ok... skipping endpoint reset." << std::endl;
312 } else {
313
314 TLOG_DEBUG(TLVL_WORK_STEPS) << "Syncing SSP LED Calib to PDTS (partition " << fPartitionNumber << ", endpoint address 0x"
315 << std::hex << fTimingAddress << std::dec << ")" << std::endl;
316
317 unsigned int nTries = 0;
318
319 while (nTries < 5) {
320 fDevice->DeviceWrite(duneReg.dsp_clock_control, 0x30);
321 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The dsp_clock_control was set to 0x" << std::hex << 0x30 << std::dec
322 << std::endl; // setting the lowest bit to 0 sets the DSP clock to internal.
323 fDevice->DeviceWrite(duneReg.pdts_control, 0x80000000 + fPartitionNumber + fTimingAddress * 0x10000);
325 << "The pdts_control value was set to 0x" << std::hex << 0x80000000 + fPartitionNumber + fTimingAddress * 0x10000
326 << std::dec << std::endl; // setting the highest bit (0x80000000) to 1 puts the SSP in Reset mode for the PDTS.
327
328 fDevice->DeviceRead(duneReg.pdts_status, &pdts_status);
329 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_status read back as 0x" << std::hex << pdts_status << std::dec
330 << std::endl;
331 fDevice->DeviceRead(duneReg.pdts_control, &pdts_control);
332 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_control read back as 0x" << std::hex << pdts_control << std::dec
333 << std::endl;
334 fDevice->DeviceRead(duneReg.dsp_clock_control, &dsp_clock_control);
335 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The dsp_clock_control read back as 0x" << std::hex << dsp_clock_control << std::dec
336 << std::endl;
337
338 fDevice->DeviceWrite(duneReg.pdts_control, 0x00000000 + fPartitionNumber + fTimingAddress * 0x10000);
339 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_status value was set to 0x" << std::hex
340 << 0x00000000 + fPartitionNumber + fTimingAddress * 0x10000 << std::dec << std::endl;
341 usleep(2000000); // setting the highest bit (0x80000000) to zero puts the SSP in run mode for the PDTS.
343 0x31); // setting the lowest bit to 1 sets the DSP clock to external.
344 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The dsp_clock_control was set to 0x" << std::hex << 0x31 << std::dec << std::endl;
345 usleep(2000000);
346 fDevice->DeviceRead(duneReg.pdts_status, &pdts_status);
347 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_status read back as 0x" << std::hex << pdts_status << std::dec
348 << std::endl;
349 if ((pdts_status & 0xF) >= 0x6 && (pdts_status & 0xF) <= 0x8)
350 break;
351 TLOG_DEBUG(TLVL_WORK_STEPS) << "Timing endpoint sync failed (try " << nTries << ")" << std::endl;
352 ++nTries;
353 }
354
355 if ((pdts_status & 0xF) >= 0x6 && (pdts_status & 0xF) <= 0x8) {
356 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_status value is 0x" << std::hex << pdts_status
357 << " and the 0xF bit masked value is 0x" << (pdts_status & 0xF) << std::dec
358 << std::endl;
359 TLOG_DEBUG(TLVL_WORK_STEPS) << "Timing endpoint synced!" << std::endl;
360 } else {
361 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_status value is 0x" << std::hex << pdts_status
362 << " and the 0xF bit masked value is 0x" << (pdts_status & 0xF) << std::dec
363 << std::endl;
364 TLOG_DEBUG(TLVL_WORK_STEPS) << "Giving up on endpoint sync after 5 tries. Value of pdts_status register was 0x"
365 << std::hex << pdts_status << std::dec << std::endl;
366 }
367 }
368
369 TLOG_DEBUG(TLVL_WORK_STEPS) << "Woke up from 2 seconds of sleep and Waiting for endpoint to reach status 0x8..."
370 << std::endl;
371 // Wait until pdts_status reaches exactly 0x8 before resolving.
372 if ((pdts_status & 0xF) != 0x8) {
373 TLOG_DEBUG(TLVL_WORK_STEPS) << "Waiting for endpoint to reach status 0x8..." << std::endl;
374 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_status value is 0x" << std::hex << pdts_status
375 << " and the 0xF bit masked value is 0x" << (pdts_status & 0xF) << std::dec << std::endl;
376 }
377 int nTries = 0;
378 while ((pdts_status & 0xF) != 0x8) {
379 if (nTries == 2) {
380 TLOG_DEBUG(TLVL_WORK_STEPS) << "Wrong PDTS status!" << std::endl;
381 //ers::fatal( DeviceInterfacePDTSStatus(ERS_HERE) );
383 }
384 usleep(2000000);
385 TLOG_DEBUG(TLVL_WORK_STEPS) << "Woke up from 2 seconds of sleep and Waiting for endpoint to reach status 0x8..."
386 << std::endl;
387 fDevice->DeviceRead(duneReg.pdts_status, &pdts_status);
388 TLOG_DEBUG(TLVL_FULL_DEBUG) << "The pdts_status value is 0x" << std::hex << pdts_status
389 << " and the 0xF bit masked value is 0x" << (pdts_status & 0xF) << std::dec << std::endl;
390 nTries++;
391 }
392
393 TLOG_DEBUG(TLVL_WORK_STEPS) << "Endpoint is in running state, continuing with configuration!" << std::endl;
394 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "SSP LED Calib Device Interface Configured complete.";
395} // NOLINT(readability/fn_size)
@ TLVL_FULL_DEBUG
#define ERS_HERE
Device * OpenDevice(unsigned int deviceId, bool slowControlOnly=false)
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
Definition RegMap.hpp:251
static RegMap & Get()
Definition RegMap.cxx:14
#define TLVL_ENTER_EXIT_METHODS
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
LED calibration failed to ERS_EMPTY DeviceInterfacePDTSStatus
Definition SSPIssues.hpp:31

◆ exception()

bool dunedaq::sspmodules::DeviceInterface::exception ( ) const
inline

Definition at line 118 of file DeviceInterface.hpp.

118{ return exception_.load(); }

◆ GetIdentifier()

std::string dunedaq::sspmodules::DeviceInterface::GetIdentifier ( )

Definition at line 398 of file DeviceInterface.cxx.

399{
400 std::string ident;
401 boost::asio::ip::address ip = boost::asio::ip::address_v4(fDeviceId);
402 std::string ipString = ip.to_string();
403 ident += "(";
404 ident += ipString;
405 ident += "):";
406 return ident;
407}

◆ OpenSlowControl()

void dunedaq::sspmodules::DeviceInterface::OpenSlowControl ( )

Definition at line 50 of file DeviceInterface.cxx.

51{
52
53 TLOG_DEBUG(TLVL_FULL_DEBUG) << "SSP Device Interface OpenSlowControl called.";
54 // Ask device manager for a pointer to the specified device
57
58 device = devman.OpenDevice(fDeviceId, true); // slow control only
59
60 if (!device) {
61 TLOG_DEBUG(TLVL_WORK_STEPS) << "Unable to get handle to device; giving up!" << std::endl;
62 throw(ENoSuchDevice());
63 }
64
65 fDevice = device;
66 fSlowControlOnly = true;
67 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "SSP Device Interface OpenSlowControl completed.";
68}

◆ PrintHardwareState()

void dunedaq::sspmodules::DeviceInterface::PrintHardwareState ( )

Definition at line 409 of file DeviceInterface.cxx.

410{
411
412 TLOG_DEBUG(TLVL_WORK_STEPS) << "===SSP DIAGNOSTIC REGISTERS===" << std::endl;
413
415 unsigned int val;
416
417 fDevice->DeviceRead(duneReg.dp_clock_status, &val);
418 TLOG_DEBUG(TLVL_WORK_STEPS) << "dsp_clock_status: 0x" << std::hex << val << std::endl;
419 fDevice->DeviceRead(duneReg.live_timestamp_msb, &val);
420 TLOG_DEBUG(TLVL_WORK_STEPS) << "live_timestamp_msb: " << val << std::endl;
421 fDevice->DeviceRead(duneReg.live_timestamp_lsb, &val);
422 TLOG_DEBUG(TLVL_WORK_STEPS) << "live_timestamp_lsb: " << val << std::endl;
423 fDevice->DeviceRead(duneReg.sync_delay, &val);
424 TLOG_DEBUG(TLVL_WORK_STEPS) << "sync_delay: " << val << std::endl;
425 fDevice->DeviceRead(duneReg.sync_count, &val);
426 TLOG_DEBUG(TLVL_WORK_STEPS) << "sync_count: " << val << std::dec << std::endl;
427}
unsigned int dp_clock_status
Definition RegMap.hpp:198
unsigned int live_timestamp_msb
Definition RegMap.hpp:239
unsigned int live_timestamp_lsb
Definition RegMap.hpp:238

◆ ReadEventFromDevice()

void dunedaq::sspmodules::DeviceInterface::ReadEventFromDevice ( EventPacket & event)

◆ ReadRegister()

void dunedaq::sspmodules::DeviceInterface::ReadRegister ( unsigned int address,
unsigned int & value,
unsigned int mask = 0xFFFFFFFF )

Definition at line 172 of file DeviceInterface.cxx.

173{
174
175 if (mask == 0xFFFFFFFF) {
176 fDevice->DeviceRead(address, &value);
177 } else {
178 fDevice->DeviceReadMask(address, mask, &value);
179 }
180}
virtual void DeviceReadMask(unsigned int address, unsigned int mask, unsigned int *value)=0

◆ ReadRegisterArray() [1/2]

void dunedaq::sspmodules::DeviceInterface::ReadRegisterArray ( unsigned int address,
std::vector< unsigned int > & value,
unsigned int size )

Definition at line 183 of file DeviceInterface.cxx.

186{
187
188 value.resize(size);
189 this->ReadRegisterArray(address, &(value[0]), size);
190}
void ReadRegisterArray(unsigned int address, std::vector< unsigned int > &value, unsigned int size)
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size

◆ ReadRegisterArray() [2/2]

void dunedaq::sspmodules::DeviceInterface::ReadRegisterArray ( unsigned int address,
unsigned int * value,
unsigned int size )

Definition at line 193 of file DeviceInterface.cxx.

194{
195
197}
virtual void DeviceArrayRead(unsigned int address, unsigned int size, unsigned int *data)=0

◆ ReadRegisterArrayByName()

void dunedaq::sspmodules::DeviceInterface::ReadRegisterArrayByName ( std::string name,
std::vector< unsigned int > & values )

Definition at line 254 of file DeviceInterface.cxx.

◆ ReadRegisterByName()

void dunedaq::sspmodules::DeviceInterface::ReadRegisterByName ( std::string name,
unsigned int & value )

Definition at line 236 of file DeviceInterface.cxx.

237{
239
240 this->ReadRegister(reg, value, reg.ReadMask());
241}
void ReadRegister(unsigned int address, unsigned int &value, unsigned int mask=0xFFFFFFFF)
unsigned int ReadMask() const
Definition RegMap.hpp:66

◆ ReadRegisterElementByName()

void dunedaq::sspmodules::DeviceInterface::ReadRegisterElementByName ( std::string name,
unsigned int index,
unsigned int & value )

Definition at line 244 of file DeviceInterface.cxx.

247{
249
250 this->ReadRegister(reg, value, reg.ReadMask());
251}

◆ set_exception()

void dunedaq::sspmodules::DeviceInterface::set_exception ( bool exception)
inlineprivate

Definition at line 133 of file DeviceInterface.hpp.

◆ SetDummyPeriod()

void dunedaq::sspmodules::DeviceInterface::SetDummyPeriod ( int period)
inline

Definition at line 106 of file DeviceInterface.hpp.

Unable to receive within timeout period(timeout period was " << timeout << " milliseconds)"

◆ SetHardwareClockRateInMHz()

void dunedaq::sspmodules::DeviceInterface::SetHardwareClockRateInMHz ( unsigned int rate)
inline

Definition at line 104 of file DeviceInterface.hpp.

◆ SetPartitionNumber()

void dunedaq::sspmodules::DeviceInterface::SetPartitionNumber ( unsigned int val)
inline

Definition at line 110 of file DeviceInterface.hpp.

110{fPartitionNumber=val;}

◆ SetRegister()

void dunedaq::sspmodules::DeviceInterface::SetRegister ( unsigned int address,
unsigned int value,
unsigned int mask = 0xFFFFFFFF )

Definition at line 147 of file DeviceInterface.cxx.

148{
149
150 if (mask == 0xFFFFFFFF) {
151 fDevice->DeviceWrite(address, value);
152 } else {
153 fDevice->DeviceWriteMask(address, mask, value);
154 }
155}
virtual void DeviceWriteMask(unsigned int address, unsigned int mask, unsigned int value)=0

◆ SetRegisterArray() [1/2]

void dunedaq::sspmodules::DeviceInterface::SetRegisterArray ( unsigned int address,
std::vector< unsigned int > value )

Definition at line 158 of file DeviceInterface.cxx.

159{
160
161 this->SetRegisterArray(address, &(value[0]), value.size());
162}
void SetRegisterArray(unsigned int address, std::vector< unsigned int > value)

◆ SetRegisterArray() [2/2]

void dunedaq::sspmodules::DeviceInterface::SetRegisterArray ( unsigned int address,
unsigned int * value,
unsigned int size )

Definition at line 165 of file DeviceInterface.cxx.

166{
167
169}
virtual void DeviceArrayWrite(unsigned int address, unsigned int size, unsigned int *data)=0

◆ SetRegisterArrayByName() [1/2]

void dunedaq::sspmodules::DeviceInterface::SetRegisterArrayByName ( std::string name,
std::vector< unsigned int > values )

Definition at line 224 of file DeviceInterface.cxx.

225{
227 if (reg.Size() != values.size()) {
228 TLOG_DEBUG(TLVL_WORK_STEPS) << "Request to set named register array " << name << ", length " << reg.Size()
229 << "with vector of " << values.size() << " values!" << std::endl;
230 throw(std::invalid_argument(""));
231 }
232 this->SetRegisterArray(reg[0], values);
233}

◆ SetRegisterArrayByName() [2/2]

void dunedaq::sspmodules::DeviceInterface::SetRegisterArrayByName ( std::string name,
unsigned int value )

Definition at line 215 of file DeviceInterface.cxx.

216{
217 unsigned int regSize = (dunedaq::sspmodules::RegMap::Get())[name].Size();
218 std::vector<unsigned int> arrayContents(regSize, value);
219
220 this->SetRegisterArrayByName(name, arrayContents);
221}
void SetRegisterArrayByName(std::string name, unsigned int value)

◆ SetRegisterByName()

void dunedaq::sspmodules::DeviceInterface::SetRegisterByName ( std::string name,
unsigned int value )

Definition at line 199 of file DeviceInterface.cxx.

200{
202
203 this->SetRegister(reg, value, reg.WriteMask());
204}
void SetRegister(unsigned int address, unsigned int value, unsigned int mask=0xFFFFFFFF)
unsigned int WriteMask() const
Definition RegMap.hpp:70

◆ SetRegisterElementByName()

void dunedaq::sspmodules::DeviceInterface::SetRegisterElementByName ( std::string name,
unsigned int index,
unsigned int value )

Definition at line 207 of file DeviceInterface.cxx.

208{
210
211 this->SetRegister(reg, value, reg.WriteMask());
212}

◆ SetTimingAddress()

void dunedaq::sspmodules::DeviceInterface::SetTimingAddress ( unsigned int val)
inline

Definition at line 112 of file DeviceInterface.hpp.

112{fTimingAddress=val;}

◆ SetUseExternalTimestamp()

void dunedaq::sspmodules::DeviceInterface::SetUseExternalTimestamp ( bool val)
inline

Definition at line 108 of file DeviceInterface.hpp.

Member Data Documentation

◆ exception_

std::atomic<bool> dunedaq::sspmodules::DeviceInterface::exception_
private

Definition at line 148 of file DeviceInterface.hpp.

◆ fDevice

Device* dunedaq::sspmodules::DeviceInterface::fDevice
private

Definition at line 124 of file DeviceInterface.hpp.

◆ fDeviceId

unsigned long dunedaq::sspmodules::DeviceInterface::fDeviceId
private

Definition at line 127 of file DeviceInterface.hpp.

◆ fDummyPeriod

int dunedaq::sspmodules::DeviceInterface::fDummyPeriod
private

Definition at line 139 of file DeviceInterface.hpp.

◆ fHardwareClockRateInMHz

unsigned int dunedaq::sspmodules::DeviceInterface::fHardwareClockRateInMHz
private

Definition at line 137 of file DeviceInterface.hpp.

◆ fPartitionNumber

unsigned int dunedaq::sspmodules::DeviceInterface::fPartitionNumber
private

Definition at line 143 of file DeviceInterface.hpp.

◆ fSlowControlOnly

bool dunedaq::sspmodules::DeviceInterface::fSlowControlOnly
private

Definition at line 141 of file DeviceInterface.hpp.

◆ fState

State_t dunedaq::sspmodules::DeviceInterface::fState
private

Definition at line 131 of file DeviceInterface.hpp.

◆ fTimingAddress

unsigned int dunedaq::sspmodules::DeviceInterface::fTimingAddress
private

Definition at line 145 of file DeviceInterface.hpp.

◆ fUseExternalTimestamp

bool dunedaq::sspmodules::DeviceInterface::fUseExternalTimestamp
private

Definition at line 135 of file DeviceInterface.hpp.


The documentation for this class was generated from the following files: