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

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