Line data Source code
1 : /**
2 : * @file DeviceInterface.hpp
3 : *
4 : * This is part of the DUNE DAQ , copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 : #ifndef SSPMODULES_SRC_ANLBOARD_DEVICEINTERFACE_HPP_
9 : #define SSPMODULES_SRC_ANLBOARD_DEVICEINTERFACE_HPP_
10 :
11 : #include "appmodel/SSPLEDCalibModule.hpp"
12 : #include "appmodel/SSPRegister.hpp"
13 : #include "logging/Logging.hpp"
14 :
15 : #include "Device.hpp"
16 : #include "DeviceManager.hpp"
17 : #include "EventPacket.hpp"
18 :
19 : #include <deque>
20 : #include <map>
21 : #include <memory>
22 : #include <queue>
23 : #include <string>
24 : #include <vector>
25 :
26 : namespace dunedaq {
27 : namespace sspmodules {
28 :
29 : struct TriggerInfo
30 : {
31 : unsigned long startTime; // NOLINT(runtime/int)
32 : unsigned long endTime; // NOLINT(runtime/int)
33 : unsigned long triggerTime; // NOLINT(runtime/int)
34 : unsigned short triggerType; // NOLINT(runtime/int)
35 : };
36 :
37 : class DeviceInterface
38 : {
39 :
40 : public:
41 : enum State_t
42 : {
43 : kUninitialized,
44 : kInitialized,
45 : kRunning,
46 : kStopping,
47 : kStopped,
48 : kBad
49 : };
50 :
51 : // Just sets the fields needed to request the device.
52 : // Real work is done in Initialize which is called manually.
53 : explicit DeviceInterface();
54 :
55 : ~DeviceInterface() {}
56 :
57 : void OpenSlowControl();
58 :
59 : void ConfigureLEDCalib(const appmodel::SSPLEDCalibModule* conf);
60 :
61 : // Called by ReadEvents
62 : // Get an event off the hardware buffer.
63 : // Timeout after some wait period
64 : void ReadEventFromDevice(EventPacket& event);
65 :
66 : // Obtain current state of device
67 : // inline State_t State(){return fState;}
68 :
69 : // Setter for single register
70 : // If mask is given then only bits which are high in the mask will be set.
71 : void SetRegister(unsigned int address, unsigned int value, unsigned int mask = 0xFFFFFFFF);
72 :
73 : // Setter for series of contiguous registers, with vector input
74 : void SetRegisterArray(unsigned int address, std::vector<unsigned int> value);
75 :
76 : // Setter for series of contiguous registers, with C array input
77 : void SetRegisterArray(unsigned int address, unsigned int* value, unsigned int size);
78 :
79 : // Getter for single register
80 : // If mask is set then bits which are low in the mask will be returned as zeros.
81 : void ReadRegister(unsigned int address, unsigned int& value, unsigned int mask = 0xFFFFFFFF);
82 :
83 : // Getter for series of contiguous registers, with vector output
84 : void ReadRegisterArray(unsigned int address, std::vector<unsigned int>& value, unsigned int size);
85 :
86 : // Getter for series of contiguous registers, with C array output
87 : void ReadRegisterArray(unsigned int address, unsigned int* value, unsigned int size);
88 :
89 : // Methods to set registers with names (as defined in SSPDAQ::RegMap)
90 :
91 : // Set single named register
92 : void SetRegisterByName(std::string name, unsigned int value);
93 :
94 : // Set single element of an array of registers
95 : void SetRegisterElementByName(std::string name, unsigned int index, unsigned int value);
96 :
97 : // Set all elements of an array to a single value
98 : void SetRegisterArrayByName(std::string name, unsigned int value);
99 :
100 : // Set all elements of an array using values vector
101 : void SetRegisterArrayByName(std::string name, std::vector<unsigned int> values);
102 :
103 : // Read single named register
104 : void ReadRegisterByName(std::string name, unsigned int& value);
105 :
106 : // Read single element of an array of registers
107 : void ReadRegisterElementByName(std::string name, unsigned int index, unsigned int& value);
108 :
109 : // Read all elements of an array into values vector
110 : void ReadRegisterArrayByName(std::string name, std::vector<unsigned int>& values);
111 :
112 : void SetHardwareClockRateInMHz(unsigned int rate) { fHardwareClockRateInMHz = rate; }
113 :
114 : void SetDummyPeriod(int period) { fDummyPeriod = period; }
115 :
116 : void SetUseExternalTimestamp(bool val) { fUseExternalTimestamp = val; }
117 :
118 0 : void SetPartitionNumber(unsigned int val) { fPartitionNumber = val; }
119 :
120 0 : void SetTimingAddress(unsigned int val) { fTimingAddress = val; }
121 :
122 : void PrintHardwareState();
123 :
124 : std::string GetIdentifier();
125 :
126 : bool exception() const { return exception_.load(); }
127 :
128 : private:
129 : // Internal device object used for hardware operations.
130 : // Owned by the device manager, not this object.
131 : Device* fDevice;
132 :
133 : // Index of the device in the hardware-returned list
134 : unsigned long fDeviceId; // NOLINT(runtime/int)
135 :
136 : // Holds current device state. Hopefully this matches the state of the
137 : // hardware itself.
138 : State_t fState;
139 :
140 : void set_exception(bool exception) { exception_.store(exception); }
141 :
142 : bool fUseExternalTimestamp;
143 :
144 : unsigned int fHardwareClockRateInMHz;
145 :
146 : int fDummyPeriod;
147 :
148 : bool fSlowControlOnly;
149 :
150 : unsigned int fPartitionNumber;
151 :
152 : unsigned int fTimingAddress;
153 :
154 : std::atomic<bool> exception_;
155 : };
156 :
157 : } // namespace sspmodules
158 : } // namespace dunedaq
159 :
160 : #endif // SSPMODULES_SRC_ANLBOARD_DEVICEINTERFACE_HPP_
|