source: trunk/FACT++/src/HeadersFAD.h@ 11157

Last change on this file since 11157 was 11156, checked in by tbretz, 13 years ago
Added new bits in Status word; removed obsolete ref clock too high; added new command enable busy.
File size: 13.1 KB
Line 
1#ifndef FACT_HeadersFAD
2#define FACT_HeadersFAD
3
4#ifdef __cplusplus
5#include <ostream>
6
7// For debugging
8#include <iostream>
9
10#include "ByteOrder.h"
11
12// ====================================================================
13
14namespace FAD
15{
16#endif
17 enum Enable
18 {
19 kCmdDrsEnable = 0x0600, // CMD_DENABLE/CMD_DISABLE
20 kCmdDwrite = 0x0800, // CMD_DWRITE_RUN/CMD_DWRITE_STOP
21 kCmdSclk = 0x1000, // CMD_SCLK_ON/OFF
22 kCmdSrclk = 0x1500, // CMD_SRCLK_ON/OFF
23 kCmdTriggerLine = 0x1800, // CMD_TRIGGERS_ON/CMD_TRIGGERS_OFF
24 //kCmdContTrigger = 0x1f00,
25 kCmdContTriggerOff = 0x2000,
26 kCmdRun = 0x2200, // CMD_Start/Stop
27 kCmdBusy = 0x2400, //
28 kCmdResetTriggerId = 0x2A00, //
29 kCmdSocket = 0x3000, // CMD_mode_command/CMD_mode_all_sockets
30 kCmdSingleTrigger = 0xA000, // CMD_Trigger
31 kCmdContTriggerOn = 0xB000,
32 };
33
34 enum Commands
35 {
36 kCmdWriteExecute = 0x0400, // Configure FAD with the current config ram
37
38 kCmdWrite = 0x0500, // write to Config-RAM
39 kCmdWriteRoi = kCmdWrite|0x00, // Baseaddress ROI-Values
40 kCmdWriteDac = kCmdWrite|0x24, // Baseaddress DAC-Values
41
42 kCmdWriteRate = kCmdWrite|0x2c, // Continous trigger rate
43 kCmdWriteRunNumberMSW = kCmdWrite|0x2d, // Run Number most significant word
44 kCmdWriteRunNumberLSW = kCmdWrite|0x2e, // Run Number least significant word
45
46 /*
47 kCmdRead = 0x0a00, // read from Config-RAM
48 kCmdReadRoi = kCmdRead|0x00, // Baseaddress ROI-Values
49 kCmdReadDac = kCmdRead|0x24, // Baseaddress DAC-Values
50 */
51
52 kCmdPhaseIncrease = 0x1200, // CMD_PS_DIRINC
53 kCmdPhaseDecrease = 0x1300, // CMD_PS_DIRDEC
54 kCmdPhaseApply = 0x1400, // CMD_PS_DO
55 kCmdPhaseReset = 0x1700, // CMD_PS_RESET
56 };
57
58 enum States
59 {
60 // State Machine states
61 kOffline = 1,
62 kDisconnected,
63 kConnecting,
64 kConnected
65 };
66
67 enum
68 {
69 kMaxBins = 1024,
70 kNumTemp = 4,
71 kNumDac = 8,
72 kNumChips = 4,
73 kNumChannelsPerChip = 9,
74 kNumChannels = kNumChips*kNumChannelsPerChip,
75 };
76
77 enum
78 {
79 kMaxRegAddr = 0xff, // Highest address in config-ram
80 kMaxRegValue = 0xffff,
81 kMaxDacAddr = kNumDac-1,
82 kMaxDacValue = 0xffff,
83 kMaxRoiAddr = kNumChannels-1,
84 kMaxRoiValue = kMaxBins,
85 kMaxRunNumber = 0xffffffff,
86 };
87
88 enum
89 {
90 kDelimiterStart = 0xfb01,
91 kDelimiterEnd = 0x04fe,
92 };
93
94 // --------------------------------------------------------
95
96 struct EventHeader
97 {
98#ifdef __cplusplus
99 enum Bits
100 {
101 kDenable = 1<<11,
102 kDwrite = 1<<10,
103 //kRefClkTooHigh = 1<< 9,
104 kRefClkTooLow = 1<< 8,
105 kDcmLocked = 1<< 7,
106 kDcmReady = 1<< 6,
107 kSpiSclk = 1<< 5,
108 kBusy = 1<< 4, // Busy enabled
109 kTriggerLine = 1<< 3, // Trigger line enabled
110 kContTrigger = 1<< 2, // Cont trigger enabled
111 kSock17 = 1<< 1, // Socket 1-7 for data transfer
112 };
113#endif
114 // Einmalig: (new header changes entry in array --> send only if array changed)
115 // ----------------------------------
116 // Event builder stores an array with all available values.
117 // Disconnected boards are removed (replaced by def values)
118 // Any received header information is immediately put in the array.
119 // The array is transmitted whenever it changes.
120 // This will usually happen only very rarely when a new connection
121 // is opened.
122 //
123 // Array[40] of BoardId
124 // Array[40] of Version
125 // Array[40] of DNA
126
127 // Slow changes: (new header changes entry in array --> send only if arra changed)
128 // -------------------------------------------
129 // Event builder stores an array with all available values.
130 // Disconnected boards can be kept in the arrays.
131 // Any received header information is immediately put in the array.
132 // The array is transmitted whenever it changes.
133 //
134 // Connection status (disconnected, connecting, connected) / Array[40]
135 // Consistency of PLLLCK / Array[ 40] of PLLLCK
136 // Consistency of Trigger type / Array[ 40] of trigger type
137 // Consistency of ROI / Array[1440] of ROI
138 // Consistency of RefClock / Array[ 40] of ref clock
139 // Consistency of DAC values / Array[ 400] of DAC values
140 // Consistency of run number / Array[ 40] of Run numbers
141
142 // Fast changes (new header changes value --> send only if something changed)
143 // -------------------
144 // Event builder stores an internal array of all boards and
145 // transmits the min/max values determined from the array
146 // only if they have changed. Disconnected boards are not considered.
147 //
148 // Maximum/minimum Event counter of all boards in memory + board id
149 // Maximum/minimum time stamp of all boards in memory + board id
150 // Maximum/minimum temp of all boards in memory + board id
151
152 // Unknown:
153 // ------------------
154 // Trigger Id ?
155 // TriggerGeneratorPrescaler ?
156 // Number of Triggers to generate ?
157
158
159 // ------------------------------------------------------------
160
161 uint16_t fStartDelimiter; // 0x04FE
162 uint16_t fPackageLength;
163 uint16_t fVersion;
164 uint16_t fStatus;
165 //
166 uint16_t fTriggerCrc; // Receiver timeout / CRC ; 1 byte each
167 uint16_t fTriggerType;
168 uint32_t fTriggerId;
169 //
170 uint32_t fEventCounter;
171 uint32_t fFreqRefClock;
172 //
173 uint16_t fBoardId;
174 uint16_t fAdcClockPhaseShift;
175 uint16_t fNumTriggersToGenerate;
176 uint16_t fTriggerGeneratorPrescaler;
177 //
178 uint64_t fDNA; // Xilinx DNA
179 //
180 uint32_t fTimeStamp;
181 uint32_t fRunNumber;
182 //
183 int16_t fTempDrs[kNumTemp]; // In units of 1/16 deg(?)
184 //
185 uint16_t fDac[kNumDac];
186 //
187#ifdef __cplusplus
188 EventHeader() { init(*this); }
189 EventHeader(const std::vector<uint16_t> &vec) { *this = vec; }
190
191 void operator=(const std::vector<uint16_t> &vec)
192 {
193 ntohcpy(vec, *this);
194
195 Reverse(((uint16_t*)fEventCounter));
196 Reverse(((uint16_t*)fEventCounter)+1);
197
198 Reverse(&fEventCounter);
199
200 Reverse(((uint16_t*)fFreqRefClock));
201 Reverse(((uint16_t*)fFreqRefClock)+1);
202
203 Reverse(&fFreqRefClock);
204
205 Reverse(((uint16_t*)&fTimeStamp));
206 Reverse(((uint16_t*)&fTimeStamp)+1);
207
208 Reverse(&fTimeStamp);
209
210 Reverse(((uint16_t*)&fRunNumber));
211 Reverse(((uint16_t*)&fRunNumber)+1);
212
213 Reverse(&fRunNumber);
214 Reverse(&fDNA);
215 }
216
217 std::vector<uint16_t> HtoN() const
218 {
219 EventHeader h(*this);
220
221 Reverse(((uint16_t*)h.fEventCounter));
222 Reverse(((uint16_t*)h.fEventCounter)+1);
223
224 Reverse(&h.fEventCounter);
225
226 Reverse(((uint16_t*)h.fFreqRefClock));
227 Reverse(((uint16_t*)h.fFreqRefClock)+1);
228
229 Reverse(&h.fFreqRefClock);
230
231 Reverse(((uint16_t*)&h.fTimeStamp));
232 Reverse(((uint16_t*)&h.fTimeStamp)+1);
233
234 Reverse(&h.fTimeStamp);
235
236 Reverse(((uint16_t*)&h.fRunNumber));
237 Reverse(((uint16_t*)&h.fRunNumber)+1);
238
239 Reverse(&h.fRunNumber);
240 Reverse(&h.fDNA);
241
242 return htoncpy(h);
243 }
244
245 float GetTemp(int i) const
246 {
247 return (((fTempDrs[i]&0x8000)
248 ?
249 ((fTempDrs[i]&0x007fff)^0xffffffff)
250 : (fTempDrs[i]&0x007fff))>>3)/16.; }
251
252 uint8_t PLLLCK() const { return fStatus>>12; }
253
254 bool HasDenable() const { return fStatus&kDenable; }
255 bool HasDwrite() const { return fStatus&kDwrite; }
256// bool IsRefClockTooHigh() const { return fStatus&kRefClkTooHigh; }
257 bool IsRefClockTooLow() const { return fStatus&kRefClkTooLow; }
258 bool IsDcmLocked() const { return fStatus&kDcmLocked; }
259 bool IsDcmReady() const { return fStatus&kDcmReady; }
260 bool HasSpiSclk() const { return fStatus&kSpiSclk; }
261 bool HasBusy() const { return fStatus&kBusy; }
262 bool HasTriggerEnabled() const { return fStatus&kTriggerLine; }
263 bool HasContTriggerEnabled() const { return fStatus&kContTrigger; }
264 bool IsInSock17Mode() const { return fStatus&kSock17; }
265
266 uint16_t Crate() const { return fBoardId>>8; }
267 uint16_t Board() const { return fBoardId&0xff; }
268
269 void Enable(Bits pos, bool enable=true)
270 {
271 if (enable)
272 fStatus |= pos;
273 else
274 fStatus &= ~pos;
275 }
276
277 void clear() { reset(*this); }
278 void print(std::ostream &out) const;
279#endif
280
281 } __attribute__((__packed__));
282
283 struct ChannelHeader
284 {
285 uint16_t fId;
286 uint16_t fStartCell;
287 uint16_t fRegionOfInterest;
288 uint16_t fDummy;
289 // uint16_t fData[];
290
291#ifdef __cplusplus
292 ChannelHeader() { init(*this); }
293
294 void operator=(const std::vector<uint16_t> &vec)
295 {
296 ntohcpy(vec, *this);
297 }
298
299 std::vector<uint16_t> HtoN() const
300 {
301 ChannelHeader h(*this);
302 return htoncpy(h);
303 }
304
305 void clear() { reset(*this); }
306 void print(std::ostream &out) const;
307
308 uint16_t Chip() const { return fId>>4; }
309 uint16_t Channel() const { return fId&0xf; }
310#endif
311 } __attribute__((__packed__));
312
313 // Package ends with:
314 // 0x4242
315 // 0x04fe
316/*
317 struct DimPassport
318 {
319 uint32_t fTimeStamp;
320
321 uint16_t fVersion;
322 uint16_t fBoardId;
323 uint64_t fDNA; // Xilinx DNA
324
325 DimPassport(const EventHeader &h) :
326 fTimeStamp(h.fTimeStamp),
327 fVersion(h.fVersion),
328 fBoardId(h.fBoardId),
329 fDNA(h.fDNA)
330 {
331 }
332
333 } __attribute__((__packed__));
334
335 struct DimSetup
336 {
337 uint32_t fTimeStamp;
338
339 uint32_t fFreqRefClock;
340 uint16_t fStatus;
341 uint16_t fAdcClockPhaseShift;
342 uint16_t fNumTriggersToGenerate;
343 uint16_t fTriggerGeneratorPrescaler;
344 uint16_t fDac[kNumDac];
345
346 DimSetup(const EventHeader &h) :
347 fTimeStamp(h.fTimeStamp),
348 fFreqRefClock(h.fFreqRefClock),
349 fStatus(h.fStatus),
350 fAdcClockPhaseShift(h.fAdcClockPhaseShift),
351 fNumTriggersToGenerate(h.fNumTriggersToGenerate),
352 fTriggerGeneratorPrescaler(h.fTriggerGeneratorPrescaler)
353 {
354 memcpy(fDac, h.fDac, sizeof(fDac));
355 }
356
357 uint8_t PLLLCK() const { return fStatus>>12; }
358
359 bool HasDenable() const { return fStatus&EventHeader::kDenable; }
360 bool HasDwrite() const { return fStatus&EventHeader::kDwrite; }
361 bool IsRefClockTooHigh() const { return fStatus&EventHeader::kRefClkTooHigh; }
362 bool IsRefClockTooLow() const { return fStatus&EventHeader::kRefClkTooLow; }
363 bool IsDcmLocked() const { return fStatus&EventHeader::kDcmLocked; }
364 bool IsDcmReady() const { return fStatus&EventHeader::kDcmReady; }
365 bool HasSpiSclk() const { return fStatus&EventHeader::kSpiSclk; }
366
367 } __attribute__((__packed__));
368
369 struct DimTemperatures
370 {
371 uint32_t fTimeStamp;
372
373 float fTempDrs[kNumTemp];
374
375 DimTemperatures(const EventHeader &h) :
376 fTimeStamp(h.fTimeStamp)
377 {
378 for (int i=0; i<kNumTemp; i++)
379 fTempDrs[i] = h.GetTemp(i);
380 }
381
382 } __attribute__((__packed__));;
383
384 struct DimEventHeader
385 {
386 uint32_t fTimeStamp;
387
388 uint32_t fRunNumber;
389 uint32_t fEventCounter;
390 uint16_t fTriggerCrc;
391 uint16_t fTriggerType;
392 uint32_t fTriggerId;
393
394 DimEventHeader(const EventHeader &h) :
395 fTimeStamp(h.fTimeStamp),
396 fRunNumber(h.fRunNumber),
397 fEventCounter(h.fEventCounter),
398 fTriggerCrc(h.fTriggerCrc),
399 fTriggerType(h.fTriggerType),
400 fTriggerId(h.fTriggerId)
401 {
402 }
403
404 } __attribute__((__packed__));
405*/
406 // --------------------------------------------------------------------
407#ifdef __cplusplus
408 inline std::ostream &operator<<(std::ostream &out, const EventHeader &h)
409 {
410 h.print(out);
411 return out;
412 }
413
414 inline std::ostream &operator<<(std::ostream &out, const ChannelHeader &h)
415 {
416 h.print(out);
417 return out;
418 }
419#endif
420
421#ifdef __cplusplus
422};
423#endif
424
425#endif
Note: See TracBrowser for help on using the repository browser.