1 | #ifndef FACT_HeadersFTM
|
---|
2 | #define FACT_HeadersFTM
|
---|
3 |
|
---|
4 | #include <ostream>
|
---|
5 |
|
---|
6 | // For debugging
|
---|
7 | #include <iostream>
|
---|
8 |
|
---|
9 | #include "ByteOrder.h"
|
---|
10 |
|
---|
11 | // ====================================================================
|
---|
12 |
|
---|
13 |
|
---|
14 | namespace FTM
|
---|
15 | {
|
---|
16 | enum States
|
---|
17 | {
|
---|
18 | kFtmUndefined = 0,
|
---|
19 |
|
---|
20 | // FTM internal states
|
---|
21 | kFtmIdle = 1, ///< Trigger output disabled, configuration possible
|
---|
22 | kFtmConfig = 2, ///< FTM and FTUs are being reconfigured
|
---|
23 | kFtmRunning = 3, ///< Trigger output enabled, configuration ignored
|
---|
24 | kFtmCalib = 4,
|
---|
25 |
|
---|
26 | kFtmStates = 0x0ff,
|
---|
27 | kFtmLocked = 0x100,
|
---|
28 |
|
---|
29 | };
|
---|
30 |
|
---|
31 | // idle: not locked: 0x2711
|
---|
32 | // running: not locked: 0x2713
|
---|
33 |
|
---|
34 | enum StateMachine
|
---|
35 | {
|
---|
36 | kDisconnected = 1, //ConnectionFTM::kDisconnected,
|
---|
37 | kConnected ,//= ConnectionFTM::kConnected,
|
---|
38 | kIdle ,//= ConnectionFTM::kIdle,
|
---|
39 | kTakingData ,//= ConnectionFTM::kTakingData,
|
---|
40 | kConfiguring1,
|
---|
41 | kConfiguring2,
|
---|
42 | kConfigured,
|
---|
43 |
|
---|
44 | kConfigError1 = 0x101,
|
---|
45 | kConfigError2 = 0x102,
|
---|
46 |
|
---|
47 | kCmdTest
|
---|
48 | };
|
---|
49 |
|
---|
50 | /// Command codes for FTM communication
|
---|
51 | enum Commands
|
---|
52 | {
|
---|
53 | // First word
|
---|
54 | kCmdRead = 0x0001, ///< Request data
|
---|
55 | kCmdWrite = 0x0002, ///< Send data
|
---|
56 | kCmdStartRun = 0x0004, ///< Enable the trigger output
|
---|
57 | kCmdStopRun = 0x0008, ///< Disable the trigger output
|
---|
58 | kCmdPing = 0x0010, ///< Ping all FTUs (get FTU list)
|
---|
59 | kCmdCrateReset = 0x0020, ///< Reboot (no power cycle) all FTUs and FADs of one crate
|
---|
60 | kCmdDisableReports = 0x0040, ///< Disable transmission of rate-reports (dynamic data)
|
---|
61 | kCmdConfigFTU = 0x0080, ///< Configure single FTU board
|
---|
62 | kCmdToggleLed = 0xc000,
|
---|
63 |
|
---|
64 | // second word for read and write
|
---|
65 | kCmdStaticData = 0x0001, ///< Specifies that static (configuration) data is read/written
|
---|
66 | kCmdDynamicData = 0x0002, ///< Specifies that dynamic data is read/written
|
---|
67 | kCmdRegister = 0x0004, ///< Specifies that a register is read/written
|
---|
68 |
|
---|
69 | // second word for StartRun
|
---|
70 | kStartRun = 0x0001, ///< ...until kCmdStopRun
|
---|
71 | kTakeNevents = 0x0002, ///< ...fixed number of events
|
---|
72 |
|
---|
73 | // second word for kCmdCrateReset
|
---|
74 | kResetCrate0 = 0x0001,
|
---|
75 | kResetCrate1 = 0x0002,
|
---|
76 | kResetCrate2 = 0x0004,
|
---|
77 | kResetCrate3 = 0x0008,
|
---|
78 | };
|
---|
79 |
|
---|
80 |
|
---|
81 | /// Types sent in the header of the following data
|
---|
82 | enum Types
|
---|
83 | {
|
---|
84 | kHeader = 0, ///< Local extension to identify a header in fCounter
|
---|
85 | kStaticData = 1, ///< Static (configuration) data
|
---|
86 | kDynamicData = 2, ///< Dynamic data (rates)
|
---|
87 | kFtuList = 3, ///< FTU list (answer of ping)
|
---|
88 | kErrorList = 4, ///< Error list (error when FTU communication failed)
|
---|
89 | kRegister = 5, ///< A requested register value
|
---|
90 | };
|
---|
91 |
|
---|
92 | // --------------------------------------------------------------------
|
---|
93 |
|
---|
94 | enum Delimiter
|
---|
95 | {
|
---|
96 | kDelimiterStart = 0xfb01, ///< Start delimiter send before each header
|
---|
97 | kDelimiterEnd = 0x04fe ///< End delimiter send after each data block
|
---|
98 | };
|
---|
99 |
|
---|
100 | struct Header
|
---|
101 | {
|
---|
102 | uint16_t fDelimiter; ///< Start delimiter
|
---|
103 | uint16_t fType; ///< Type of the data to be received after the header
|
---|
104 | uint16_t fDataSize; ///< Size in words to be received after the header (incl end delim.)
|
---|
105 | uint16_t fState; ///< State of the FTM central state machine
|
---|
106 | uint64_t fBoardId; ///< FPGA device DNA (unique chip id)
|
---|
107 | uint16_t fFirmwareId; ///< Version number
|
---|
108 | uint32_t fTriggerCounter; ///< FTM internal counter of all trigger decision independant of trigger-line enable/disable (reset: start/stop run)
|
---|
109 | uint64_t fTimeStamp; ///< Internal counter (micro-seconds, reset: start/stop run)
|
---|
110 |
|
---|
111 | Header() { init(*this); }
|
---|
112 |
|
---|
113 | std::vector<uint16_t> HtoN() const
|
---|
114 | {
|
---|
115 | Header h(*this);
|
---|
116 |
|
---|
117 | Reverse(&h.fBoardId);
|
---|
118 | Reverse(&h.fTriggerCounter);
|
---|
119 | Reverse(&h.fTimeStamp);
|
---|
120 |
|
---|
121 | return htoncpy(h);
|
---|
122 | }
|
---|
123 | void operator=(const std::vector<uint16_t> &vec)
|
---|
124 | {
|
---|
125 | ntohcpy(vec, *this);
|
---|
126 |
|
---|
127 | Reverse(&fBoardId);
|
---|
128 | Reverse(&fTriggerCounter);
|
---|
129 | Reverse(&fTimeStamp);
|
---|
130 | }
|
---|
131 |
|
---|
132 | void clear() { reset(*this); }
|
---|
133 | void print(std::ostream &out) const;
|
---|
134 |
|
---|
135 | } __attribute__((__packed__));
|
---|
136 |
|
---|
137 | struct DimPassport
|
---|
138 | {
|
---|
139 | uint64_t fBoardId;
|
---|
140 | uint16_t fFirmwareId;
|
---|
141 |
|
---|
142 | DimPassport(const Header &h) :
|
---|
143 | fBoardId(h.fBoardId),
|
---|
144 | fFirmwareId(h.fFirmwareId)
|
---|
145 | {
|
---|
146 | }
|
---|
147 | } __attribute__((__packed__));
|
---|
148 |
|
---|
149 | struct DimTriggerCounter
|
---|
150 | {
|
---|
151 | uint64_t fTimeStamp;
|
---|
152 | uint32_t fTriggerCounter;
|
---|
153 |
|
---|
154 | DimTriggerCounter(const Header &h) :
|
---|
155 | fTimeStamp(h.fTimeStamp),
|
---|
156 | fTriggerCounter(h.fTriggerCounter)
|
---|
157 | {
|
---|
158 | }
|
---|
159 | } __attribute__((__packed__));
|
---|
160 |
|
---|
161 |
|
---|
162 | struct StaticDataBoard
|
---|
163 | {
|
---|
164 | uint16_t fEnable[4]; /// enable of 4x9 pixels coded as 4x9bits
|
---|
165 | uint16_t fDAC[5]; /// 0-3 (A-D) Threshold of patches, 4 (H) Threshold for N out of 4 (12 bit each)
|
---|
166 | uint16_t fPrescaling; /// Internal readout time of FTUs for trigger counter
|
---|
167 |
|
---|
168 | StaticDataBoard() { init(*this); }
|
---|
169 |
|
---|
170 | void print(std::ostream &out) const;
|
---|
171 |
|
---|
172 | } __attribute__((__packed__));
|
---|
173 |
|
---|
174 | struct StaticData
|
---|
175 | {
|
---|
176 | enum Limits
|
---|
177 | {
|
---|
178 | kMaxMultiplicity = 40, ///< Minimum required trigger multiplicity
|
---|
179 | kMaxWindow = 0xf, ///< (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
|
---|
180 | kMaxDeadTime = 0xffff, ///< (4ns * x + 8ns)
|
---|
181 | kMaxDelayTimeMarker = 0x3ff, ///< (4ns * x + 8ns)
|
---|
182 | kMaxDelayTrigger = 0x3ff, ///< (4ns * x + 8ns)
|
---|
183 | kMaxTriggerInterval = 0x3ff, ///<
|
---|
184 | kMaxIntensity = 0x7f,
|
---|
185 | kMaxSequence = 0x1f,
|
---|
186 | kMaxDAC = 0xfff,
|
---|
187 | kMaxAddr = 0xfff,
|
---|
188 | kMaxPatchIdx = 159,
|
---|
189 | kMaxPixelIdx = 1439,
|
---|
190 | kMaskSettings = 0xf,
|
---|
191 | kMaskLEDs = 0xf,
|
---|
192 | };
|
---|
193 |
|
---|
194 | enum GeneralSettings
|
---|
195 | {
|
---|
196 | kTrigger = 0x80, ///< Physics trigger decision (PhysicTrigger)
|
---|
197 | kPedestal = 0x40, ///< Pedestal trigger (artifical)
|
---|
198 | kLPint = 0x20, ///< Enable artificial trigger after light pulse (LP2)
|
---|
199 | kLPext = 0x10, ///< Enable trigger decision after light pulse (CalibrationTrigger, LP1)
|
---|
200 | kExt2 = 0x08, ///< External trigger signal 2
|
---|
201 | kExt1 = 0x04, ///< External trigger signal 1
|
---|
202 | kVeto = 0x02, ///< Veto trigger decision / artifical triggers
|
---|
203 | kClockConditioner = 0x01, ///< Select clock conditioner frequency (1) / time marker (0) as output
|
---|
204 | };
|
---|
205 |
|
---|
206 | enum LightPulserEnable
|
---|
207 | {
|
---|
208 | kGroup1 = 0x4,
|
---|
209 | kGroup2 = 0x8,
|
---|
210 | };
|
---|
211 |
|
---|
212 | uint16_t fGeneralSettings; /// Enable for different trigger types / select for TIM/ClockConditioner output (only 8 bit used)
|
---|
213 | uint16_t fStatusLEDs; /// only 8 bit used
|
---|
214 | uint16_t fTriggerInterval; /// [ms] Interval between two artificial triggers (no matter which type) minimum 1ms, 10 bit
|
---|
215 | uint16_t fTriggerSequence; /// Ratio between trigger types send as artificial trigger (in this order) 3x5bit
|
---|
216 | uint8_t fEnableLPext; /// Enable for LED group 1/2 (LightPulserEnable)
|
---|
217 | uint8_t fIntensityLPext; /// Intensity of LEDs (0-127)
|
---|
218 | uint8_t fEnableLPint; /// Enable for LED group 1/2 (LightPulserEnable)
|
---|
219 | uint8_t fIntensityLPint; /// Intensity of LEDs (0-127)
|
---|
220 | uint32_t fDummy0;
|
---|
221 | uint16_t fMultiplicityPhysics; /// Required trigger multiplicity for physcis triggers (0-40)
|
---|
222 | uint16_t fMultiplicityCalib; /// Required trigger multiplicity calibration (LPext) triggers (0-40)
|
---|
223 | uint16_t fDelayTrigger; /// (4ns * x + 8ns) FTM internal programmable delay between trigger decision and output
|
---|
224 | uint16_t fDelayTimeMarker; /// (4ns * x + 8ns) FTM internal programmable delay between trigger descision and time marker output
|
---|
225 | uint16_t fDeadTime; /// (4ns * x + 8ns) FTM internal programmable dead time after trigger decision
|
---|
226 | uint32_t fClockConditioner[8]; /// R0, R1, R8, R9, R11, R13, R14, R15
|
---|
227 | uint16_t fWindowPhysics; /// (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
|
---|
228 | uint16_t fWindowCalib; /// (4ns * x + 8ns) At least N (multiplicity) rising edges (trigger signal) within this window
|
---|
229 | uint16_t fDummy1;
|
---|
230 |
|
---|
231 | StaticDataBoard fBoard[4][10]; // 4 crates * 10 boards (Crate0/FTU0 == readout time of FTUs)
|
---|
232 |
|
---|
233 | uint16_t fActiveFTU[4]; // 4 crates * 10 bits (FTU enable)
|
---|
234 |
|
---|
235 | StaticData() { init(*this); }
|
---|
236 | StaticData(const std::vector<uint16_t> &vec)
|
---|
237 | {
|
---|
238 | ntohcpy(vec, *this);
|
---|
239 |
|
---|
240 | for (int i=0; i<8; i++)
|
---|
241 | Reverse(fClockConditioner+i);
|
---|
242 | }
|
---|
243 |
|
---|
244 | std::vector<uint16_t> HtoN() const
|
---|
245 | {
|
---|
246 | StaticData d(*this);
|
---|
247 | for (int i=0; i<8; i++)
|
---|
248 | Reverse(d.fClockConditioner+i);
|
---|
249 |
|
---|
250 | return htoncpy(d);
|
---|
251 | }
|
---|
252 |
|
---|
253 | bool operator==(const StaticData &d) const
|
---|
254 | {
|
---|
255 | return memcmp(this, &d, sizeof(StaticData))==0;
|
---|
256 | }
|
---|
257 |
|
---|
258 | void clear() { reset(*this); }
|
---|
259 | void print(std::ostream &out) const;
|
---|
260 |
|
---|
261 | StaticDataBoard &operator[](int i) { return fBoard[i/10][i%10]; }
|
---|
262 | const StaticDataBoard &operator[](int i) const { return fBoard[i/10][i%10]; }
|
---|
263 |
|
---|
264 | void EnableFTU(int i) { fActiveFTU[i/10] |= (1<<(i%10)); }
|
---|
265 | void DisableFTU(int i) { fActiveFTU[i/10] &= ~(1<<(i%10)); }
|
---|
266 |
|
---|
267 | void EnableAllFTU() { for (int i=0; i<4; i++) fActiveFTU[i] = 0x3ff; }
|
---|
268 | void DisableAllFTU() { for (int i=0; i<4; i++) fActiveFTU[i] = 0; }
|
---|
269 |
|
---|
270 | void EnableLPint(LightPulserEnable group, bool enable)
|
---|
271 | {
|
---|
272 | if (enable)
|
---|
273 | fEnableLPint |= group;
|
---|
274 | else
|
---|
275 | fEnableLPint &= ~group;
|
---|
276 | }
|
---|
277 |
|
---|
278 | void EnableLPext(LightPulserEnable group, bool enable)
|
---|
279 | {
|
---|
280 | if (enable)
|
---|
281 | fEnableLPext |= group;
|
---|
282 | else
|
---|
283 | fEnableLPext &= ~group;
|
---|
284 | }
|
---|
285 |
|
---|
286 | void ToggleFTU(int i) { fActiveFTU[i/10] ^= (1<<(i%10)); }
|
---|
287 |
|
---|
288 | void Enable(GeneralSettings type, bool enable)
|
---|
289 | {
|
---|
290 | if (enable)
|
---|
291 | fGeneralSettings |= uint16_t(type);
|
---|
292 | else
|
---|
293 | fGeneralSettings &= ~uint16_t(type);
|
---|
294 | }
|
---|
295 |
|
---|
296 | bool IsEnabled(GeneralSettings type) const { return fGeneralSettings&uint16_t(type); }
|
---|
297 |
|
---|
298 | uint16_t *EnablePixel(int idx, bool enable)
|
---|
299 | {
|
---|
300 | const int pixel = idx%9;
|
---|
301 | const int patch = (idx/9)%4;
|
---|
302 | const int board = (idx/9)/4;
|
---|
303 |
|
---|
304 | uint16_t &pix = fBoard[board/10][board%10].fEnable[patch];
|
---|
305 |
|
---|
306 | if (enable)
|
---|
307 | pix |= (1<<pixel);
|
---|
308 | else
|
---|
309 | pix &= ~(1<<pixel);
|
---|
310 |
|
---|
311 | return &pix;
|
---|
312 | }
|
---|
313 |
|
---|
314 | void EnableAllPixel()
|
---|
315 | {
|
---|
316 | for (int c=0; c<4; c++)
|
---|
317 | for (int b=0; b<10; b++)
|
---|
318 | for (int p=0; p<4; p++)
|
---|
319 | fBoard[c][b].fEnable[p] = 0x1ff;
|
---|
320 | }
|
---|
321 |
|
---|
322 | bool Enabled(uint16_t idx) const
|
---|
323 | {
|
---|
324 | const int pixel = idx%9;
|
---|
325 | const int patch = (idx/9)%4;
|
---|
326 | const int board = (idx/9)/4;
|
---|
327 |
|
---|
328 | return (fBoard[board/10][board%10].fEnable[patch]>>pixel)&1;
|
---|
329 | }
|
---|
330 |
|
---|
331 | uint8_t GetSequencePed() const { return (fTriggerSequence>>10)&0x1f; }
|
---|
332 | uint8_t GetSequenceLPint() const { return (fTriggerSequence>> 5)&0x1f; }
|
---|
333 | uint8_t GetSequenceLPext() const { return (fTriggerSequence) &0x1f; }
|
---|
334 |
|
---|
335 | void SetSequence(uint8_t ped, uint8_t lpint, uint8_t lpext)
|
---|
336 | {
|
---|
337 | fTriggerSequence = ((ped&0x1f)<<10)|((lpint&0x1f)<<5)|(lpext&0x1f);
|
---|
338 |
|
---|
339 | Enable(kPedestal, ped >0);
|
---|
340 | Enable(kLPext, lpext>0);
|
---|
341 | Enable(kLPint, lpint>0);
|
---|
342 | }
|
---|
343 |
|
---|
344 | void SetClockRegister(const uint64_t reg[])
|
---|
345 | {
|
---|
346 | for (int i=0; i<8; i++)
|
---|
347 | fClockConditioner[i] = reg[i];
|
---|
348 | }
|
---|
349 |
|
---|
350 | void SetPrescaling(uint16_t val)
|
---|
351 | {
|
---|
352 | for (int c=0; c<4; c++)
|
---|
353 | for (int b=0; b<10; b++)
|
---|
354 | fBoard[c][b].fPrescaling = val;
|
---|
355 | }
|
---|
356 |
|
---|
357 | } __attribute__((__packed__));
|
---|
358 |
|
---|
359 | // DimStructures must be a multiple of two... I don't know why
|
---|
360 | struct DimStaticData
|
---|
361 | {
|
---|
362 | uint64_t fTimeStamp;
|
---|
363 | //8
|
---|
364 | uint16_t fGeneralSettings; // only 8 bit used
|
---|
365 | uint16_t fStatusLEDs; // only 8 bit used
|
---|
366 | uint64_t fActiveFTU; // 40 bits in row
|
---|
367 | //20
|
---|
368 | uint16_t fTriggerInterval; // only 10 bit used
|
---|
369 | //22
|
---|
370 | uint16_t fTriggerSeqLPint; // only 5bits used
|
---|
371 | uint16_t fTriggerSeqLPext; // only 5bits used
|
---|
372 | uint16_t fTriggerSeqPed; // only 5bits used
|
---|
373 | //28
|
---|
374 | uint16_t fMultiplicityPhysics; // 0-40
|
---|
375 | uint16_t fMultiplicityCalib; // 0-40
|
---|
376 | //32
|
---|
377 | uint16_t fWindowPhysics;
|
---|
378 | uint16_t fWindowCalib;
|
---|
379 | //36
|
---|
380 | uint16_t fDelayTrigger;
|
---|
381 | uint16_t fDelayTimeMarker;
|
---|
382 | uint32_t fDeadTime;
|
---|
383 | //44
|
---|
384 | uint32_t fClockConditioner[8];
|
---|
385 | //60
|
---|
386 | uint16_t fEnable[90]; // 160*9bit = 180byte
|
---|
387 | uint16_t fThreshold[160];
|
---|
388 | uint16_t fMultiplicity[40]; // N out of 4
|
---|
389 | uint16_t fPrescaling[40];
|
---|
390 | // 640+60 = 700
|
---|
391 |
|
---|
392 | bool HasTrigger() const { return fGeneralSettings & StaticData::kTrigger; }
|
---|
393 | bool HasPedestal() const { return fGeneralSettings & StaticData::kPedestal; }
|
---|
394 | bool HasLPext() const { return fGeneralSettings & StaticData::kLPext; }
|
---|
395 | bool HasLPint() const { return fGeneralSettings & StaticData::kLPint; }
|
---|
396 | bool HasExt2() const { return fGeneralSettings & StaticData::kExt2; }
|
---|
397 | bool HasExt1() const { return fGeneralSettings & StaticData::kExt1; }
|
---|
398 | bool HasVeto() const { return fGeneralSettings & StaticData::kVeto; }
|
---|
399 | bool HasClockConditioner() const { return fGeneralSettings & StaticData::kClockConditioner; }
|
---|
400 |
|
---|
401 | bool IsActive(int i) const { return fActiveFTU&(uint64_t(1)<<i); }
|
---|
402 | bool IsEnabled(int i) const { return fEnable[i/16]&(1<<(i%16)); }
|
---|
403 |
|
---|
404 | DimStaticData() { memset(this, 0, sizeof(DimStaticData)); }
|
---|
405 |
|
---|
406 | DimStaticData(const Header &h, const StaticData &d) :
|
---|
407 | fTimeStamp(h.fTimeStamp),
|
---|
408 | fGeneralSettings(d.fGeneralSettings),
|
---|
409 | fStatusLEDs(d.fStatusLEDs),
|
---|
410 | fActiveFTU( uint64_t(d.fActiveFTU[0]) |
|
---|
411 | (uint64_t(d.fActiveFTU[1])<<10) |
|
---|
412 | (uint64_t(d.fActiveFTU[2])<<20) |
|
---|
413 | (uint64_t(d.fActiveFTU[3])<<30)),
|
---|
414 | fTriggerInterval(d.fTriggerInterval),
|
---|
415 | fTriggerSeqLPint((d.fTriggerSequence>>5)&0x1f),
|
---|
416 | fTriggerSeqLPext((d.fTriggerSequence)&0x1f),
|
---|
417 | fTriggerSeqPed((d.fTriggerSequence>>10)&0x1f),
|
---|
418 | fMultiplicityPhysics(d.fMultiplicityPhysics),
|
---|
419 | fMultiplicityCalib(d.fMultiplicityCalib),
|
---|
420 | fWindowPhysics(d.fWindowPhysics*4+8),
|
---|
421 | fWindowCalib(d.fWindowCalib*4+8),
|
---|
422 | fDelayTrigger(d.fDelayTrigger*4+8),
|
---|
423 | fDelayTimeMarker(d.fDelayTimeMarker*4+8),
|
---|
424 | fDeadTime(uint32_t(d.fDeadTime)*4+8)
|
---|
425 | {
|
---|
426 | memcpy(fClockConditioner, d.fClockConditioner, sizeof(uint32_t)*8);
|
---|
427 |
|
---|
428 | uint16_t src[160];
|
---|
429 | for (int i=0; i<40; i++)
|
---|
430 | {
|
---|
431 | for (int j=0; j<4; j++)
|
---|
432 | {
|
---|
433 | src[i*4+j] = d[i].fEnable[j];
|
---|
434 | fThreshold[i*4+j] = d[i].fDAC[j];
|
---|
435 | }
|
---|
436 |
|
---|
437 | fMultiplicity[i] = d[i].fDAC[4];
|
---|
438 | fPrescaling[i] = d[i].fPrescaling+1;
|
---|
439 | }
|
---|
440 | bitcpy(fEnable, 90, src, 160, 9);
|
---|
441 | }
|
---|
442 |
|
---|
443 | } __attribute__((__packed__));
|
---|
444 |
|
---|
445 |
|
---|
446 | struct DynamicDataBoard
|
---|
447 | {
|
---|
448 | uint32_t fRatePatch[4]; // Patch 0,1,2,3
|
---|
449 | uint32_t fRateTotal; // Sum
|
---|
450 |
|
---|
451 | uint16_t fOverflow; // Patches: bits 0-3, total 4
|
---|
452 | uint16_t fCrcError;
|
---|
453 |
|
---|
454 | void print(std::ostream &out) const;
|
---|
455 |
|
---|
456 | void reverse()
|
---|
457 | {
|
---|
458 | for (int i=0; i<4; i++)
|
---|
459 | Reverse(fRatePatch+i);
|
---|
460 |
|
---|
461 | Reverse(&fRateTotal);
|
---|
462 | }
|
---|
463 |
|
---|
464 | uint32_t &operator[](int i) { return fRatePatch[i]; }
|
---|
465 |
|
---|
466 | } __attribute__((__packed__));
|
---|
467 |
|
---|
468 |
|
---|
469 | struct DynamicData
|
---|
470 | {
|
---|
471 | uint64_t fOnTimeCounter;
|
---|
472 | uint16_t fTempSensor[4]; // U45, U46, U48, U49
|
---|
473 |
|
---|
474 | DynamicDataBoard fBoard[4][10]; // 4 crates * 10 boards
|
---|
475 |
|
---|
476 | DynamicData() { init(*this); }
|
---|
477 |
|
---|
478 | std::vector<uint16_t> HtoN() const
|
---|
479 | {
|
---|
480 | DynamicData d(*this);
|
---|
481 |
|
---|
482 | Reverse(&d.fOnTimeCounter);
|
---|
483 |
|
---|
484 | for (int c=0; c<4; c++)
|
---|
485 | for (int b=0; b<10; b++)
|
---|
486 | d.fBoard[c][b].reverse();
|
---|
487 |
|
---|
488 | return htoncpy(d);
|
---|
489 | }
|
---|
490 |
|
---|
491 | void operator=(const std::vector<uint16_t> &vec)
|
---|
492 | {
|
---|
493 | ntohcpy(vec, *this);
|
---|
494 |
|
---|
495 | Reverse(&fOnTimeCounter);
|
---|
496 |
|
---|
497 | for (int c=0; c<4; c++)
|
---|
498 | for (int b=0; b<10; b++)
|
---|
499 | fBoard[c][b].reverse();
|
---|
500 | }
|
---|
501 |
|
---|
502 | void clear() { reset(*this); }
|
---|
503 | void print(std::ostream &out) const;
|
---|
504 |
|
---|
505 | DynamicDataBoard &operator[](int i) { return fBoard[i/10][i%10]; }
|
---|
506 | const DynamicDataBoard &operator[](int i) const { return fBoard[i/10][i%10]; }
|
---|
507 |
|
---|
508 | } __attribute__((__packed__));
|
---|
509 |
|
---|
510 |
|
---|
511 | struct DimDynamicData
|
---|
512 | {
|
---|
513 | uint64_t fTimeStamp;
|
---|
514 |
|
---|
515 | uint64_t fOnTimeCounter;
|
---|
516 | float fTempSensor[4];
|
---|
517 |
|
---|
518 | uint32_t fRatePatch[160];
|
---|
519 |
|
---|
520 | uint32_t fRateBoard[40];
|
---|
521 | uint16_t fRateOverflow[40];
|
---|
522 |
|
---|
523 | uint16_t fCrcError[40];
|
---|
524 |
|
---|
525 | uint16_t fState;
|
---|
526 |
|
---|
527 | DimDynamicData(const Header &h, const DynamicData &d) :
|
---|
528 | fTimeStamp(h.fTimeStamp),
|
---|
529 | fOnTimeCounter(d.fOnTimeCounter),
|
---|
530 | fState(h.fState)
|
---|
531 | {
|
---|
532 | for (int i=0; i<4; i++)
|
---|
533 | fTempSensor[i] = d.fTempSensor[i];
|
---|
534 |
|
---|
535 | for (int i=0; i<40; i++)
|
---|
536 | {
|
---|
537 | fRateBoard[i] = d[i].fRateTotal;
|
---|
538 | fRateOverflow[i] = d[i].fOverflow;
|
---|
539 | fCrcError[i] = d[i].fCrcError;
|
---|
540 | for (int j=0; j<4; j++)
|
---|
541 | fRatePatch[i*4+j] = d[i].fRatePatch[j];
|
---|
542 | }
|
---|
543 | }
|
---|
544 |
|
---|
545 | } __attribute__((__packed__));
|
---|
546 |
|
---|
547 |
|
---|
548 | struct FtuResponse
|
---|
549 | {
|
---|
550 | uint16_t fPingAddr; // Number of Pings and addr (pings= see error)
|
---|
551 | uint64_t fDNA;
|
---|
552 | uint16_t fErrorCounter; //
|
---|
553 |
|
---|
554 | void reverse() { Reverse(&fDNA); }
|
---|
555 |
|
---|
556 | void print(std::ostream &out) const;
|
---|
557 |
|
---|
558 | } __attribute__((__packed__));
|
---|
559 |
|
---|
560 | struct FtuList
|
---|
561 | {
|
---|
562 | uint16_t fNumBoards; /// Total number of boards responded
|
---|
563 | uint16_t fNumBoardsCrate[4]; /// Num of board responded in crate 0-3
|
---|
564 | uint16_t fActiveFTU[4]; /// List of active FTU boards in crate 0-3
|
---|
565 |
|
---|
566 | FtuResponse fFTU[4][10];
|
---|
567 |
|
---|
568 | FtuList() { init(*this); }
|
---|
569 |
|
---|
570 | std::vector<uint16_t> HtoN() const
|
---|
571 | {
|
---|
572 | FtuList d(*this);
|
---|
573 |
|
---|
574 | for (int c=0; c<4; c++)
|
---|
575 | for (int b=0; b<10; b++)
|
---|
576 | d.fFTU[c][b].reverse();
|
---|
577 |
|
---|
578 | return htoncpy(d);
|
---|
579 | }
|
---|
580 |
|
---|
581 | void operator=(const std::vector<uint16_t> &vec)
|
---|
582 | {
|
---|
583 | ntohcpy(vec, *this);
|
---|
584 |
|
---|
585 | for (int c=0; c<4; c++)
|
---|
586 | for (int b=0; b<10; b++)
|
---|
587 | fFTU[c][b].reverse();
|
---|
588 | }
|
---|
589 |
|
---|
590 | void clear() { reset(*this); }
|
---|
591 | void print(std::ostream &out) const;
|
---|
592 |
|
---|
593 | FtuResponse &operator[](int i) { return fFTU[i/10][i%10]; }
|
---|
594 | const FtuResponse &operator[](int i) const { return fFTU[i/10][i%10]; }
|
---|
595 |
|
---|
596 | } __attribute__((__packed__));
|
---|
597 |
|
---|
598 | struct DimFtuList
|
---|
599 | {
|
---|
600 | uint64_t fTimeStamp;
|
---|
601 | uint64_t fActiveFTU;
|
---|
602 |
|
---|
603 | uint16_t fNumBoards; /// Number of boards answered in total
|
---|
604 | uint8_t fNumBoardsCrate[4]; /// Number of boards answered per crate
|
---|
605 |
|
---|
606 | uint64_t fDNA[40]; /// DNA of FTU board
|
---|
607 | uint8_t fAddr[40]; /// Address of FTU board
|
---|
608 | uint8_t fPing[40]; /// Number of pings until response (same as in Error)
|
---|
609 |
|
---|
610 | DimFtuList(const Header &h, const FtuList &d) :
|
---|
611 | fTimeStamp(h.fTimeStamp),
|
---|
612 | fActiveFTU( uint64_t(d.fActiveFTU[0]) |
|
---|
613 | (uint64_t(d.fActiveFTU[1])<<10) |
|
---|
614 | (uint64_t(d.fActiveFTU[2])<<20) |
|
---|
615 | (uint64_t(d.fActiveFTU[3])<<30)),
|
---|
616 | fNumBoards(d.fNumBoards)
|
---|
617 | {
|
---|
618 | for (int i=0; i<4; i++)
|
---|
619 | fNumBoardsCrate[i] = d.fNumBoardsCrate[i];
|
---|
620 |
|
---|
621 | for (int i=0; i<40; i++)
|
---|
622 | {
|
---|
623 | fDNA[i] = d[i].fDNA;
|
---|
624 | fAddr[i] = d[i].fPingAddr&0x3f;
|
---|
625 | fPing[i] = (d[i].fPingAddr>>8)&0x3;
|
---|
626 | }
|
---|
627 | }
|
---|
628 |
|
---|
629 | bool IsActive(int i) const { return fActiveFTU&(uint64_t(1)<<i); }
|
---|
630 |
|
---|
631 | } __attribute__((__packed__));
|
---|
632 |
|
---|
633 |
|
---|
634 | struct Error
|
---|
635 | {
|
---|
636 | uint16_t fNumCalls; // 0=error, >1 needed repetition but successfull
|
---|
637 |
|
---|
638 | uint16_t fDelimiter;
|
---|
639 | uint16_t fDestAddress;
|
---|
640 | uint16_t fSrcAddress;
|
---|
641 | uint16_t fFirmwareId;
|
---|
642 | uint16_t fCommand;
|
---|
643 | uint16_t fData[21];
|
---|
644 | uint16_t fCrcErrorCounter;
|
---|
645 | uint16_t fCrcCheckSum;
|
---|
646 |
|
---|
647 | Error() { init(*this); }
|
---|
648 |
|
---|
649 | std::vector<uint16_t> HtoN() const
|
---|
650 | {
|
---|
651 | return htoncpy(*this);
|
---|
652 | }
|
---|
653 |
|
---|
654 | void operator=(const std::vector<uint16_t> &vec) { ntohcpy(vec, *this); }
|
---|
655 |
|
---|
656 | void clear() { reset(*this); }
|
---|
657 |
|
---|
658 | uint16_t &operator[](int idx) { return fData[idx]; }
|
---|
659 | const uint16_t &operator[](int idx) const { return fData[idx]; }
|
---|
660 |
|
---|
661 | void print(std::ostream &out) const;
|
---|
662 |
|
---|
663 | } __attribute__((__packed__));
|
---|
664 |
|
---|
665 | struct DimError
|
---|
666 | {
|
---|
667 | uint64_t fTimeStamp;
|
---|
668 | Error fError;
|
---|
669 |
|
---|
670 | DimError(const Header &h, const Error &e) :
|
---|
671 | fTimeStamp(h.fTimeStamp),
|
---|
672 | fError(e)
|
---|
673 | {
|
---|
674 | fError.fDestAddress = (e.fDestAddress&0x3)*10 + ((e.fDestAddress>>2)&0xf);
|
---|
675 | fError.fSrcAddress = (e.fSrcAddress &0x3)*10 + ((e.fSrcAddress >>2)&0xf);
|
---|
676 | }
|
---|
677 |
|
---|
678 | } __attribute__((__packed__));
|
---|
679 |
|
---|
680 | /*
|
---|
681 | struct Command
|
---|
682 | {
|
---|
683 | uint16_t fStartDelimiter;
|
---|
684 | uint16_t fCommand;
|
---|
685 | uint16_t fParam[3];
|
---|
686 |
|
---|
687 | Command() { init(*this); }
|
---|
688 |
|
---|
689 | void HtoN() { hton(*this); }
|
---|
690 | void NtoH() { ntoh(*this); }
|
---|
691 |
|
---|
692 | void operator=(const std::vector<uint16_t> &vec) { ntohcpy(vec, *this); }
|
---|
693 |
|
---|
694 | void clear() { reset(*this); }
|
---|
695 |
|
---|
696 |
|
---|
697 | } __attribute__((__packed__));
|
---|
698 | */
|
---|
699 |
|
---|
700 | // --------------------------------------------------------------------
|
---|
701 |
|
---|
702 | inline std::ostream &operator<<(std::ostream &out, const FtuResponse &h)
|
---|
703 | {
|
---|
704 | h.print(out);
|
---|
705 | return out;
|
---|
706 | }
|
---|
707 |
|
---|
708 | inline std::ostream &operator<<(std::ostream &out, const Header &h)
|
---|
709 | {
|
---|
710 | h.print(out);
|
---|
711 | return out;
|
---|
712 | }
|
---|
713 |
|
---|
714 |
|
---|
715 | inline std::ostream &operator<<(std::ostream &out, const FtuList &h)
|
---|
716 | {
|
---|
717 | h.print(out);
|
---|
718 | return out;
|
---|
719 | }
|
---|
720 |
|
---|
721 | inline std::ostream &operator<<(std::ostream &out, const DynamicDataBoard &h)
|
---|
722 | {
|
---|
723 | h.print(out);
|
---|
724 | return out;
|
---|
725 | }
|
---|
726 |
|
---|
727 | inline std::ostream &operator<<(std::ostream &out, const DynamicData &h)
|
---|
728 | {
|
---|
729 | h.print(out);
|
---|
730 | return out;
|
---|
731 | }
|
---|
732 |
|
---|
733 | inline std::ostream &operator<<(std::ostream &out, const StaticDataBoard &h)
|
---|
734 | {
|
---|
735 | h.print(out);
|
---|
736 | return out;
|
---|
737 | }
|
---|
738 |
|
---|
739 | inline std::ostream &operator<<(std::ostream &out, const StaticData &h)
|
---|
740 | {
|
---|
741 | h.print(out);
|
---|
742 | return out;
|
---|
743 | }
|
---|
744 |
|
---|
745 | inline std::ostream &operator<<(std::ostream &out, const Error &h)
|
---|
746 | {
|
---|
747 | h.print(out);
|
---|
748 | return out;
|
---|
749 | }
|
---|
750 | };
|
---|
751 |
|
---|
752 | #endif
|
---|