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

Last change on this file since 10798 was 10783, checked in by tbretz, 14 years ago
Moved soem decoding from print to header; commented obsolete Dim stuff.
File size: 9.8 KB
Line 
1#ifndef FACT_HeadersFAD
2#define FACT_HeadersFAD
3
4#include <ostream>
5
6// For debugging
7#include <iostream>
8
9#include "ByteOrder.h"
10
11// ====================================================================
12
13namespace FAD
14{
15 enum States
16 {
17 // State Machine states
18 kDisconnected = 1,
19 kConnecting,
20 kConnected
21 };
22
23 enum
24 {
25 kMaxBins = 1024,
26 kNumTemp = 4,
27 kNumDac = 8,
28 kNumChips = 4,
29 kNumChannelsPerChip = 9,
30 kNumChannels = kNumChips*kNumChannelsPerChip,
31 };
32
33 enum
34 {
35 kMaxRegAddr = 0xff, // Highest address in config-ram
36 kMaxRegValue = 0xffff,
37 kMaxDacAddr = kNumDac-1,
38 kMaxDacValue = 0xffff,
39 kMaxRoiAddr = kNumChannels-1,
40 kMaxRoiValue = kMaxBins,
41 };
42
43 enum
44 {
45 kDelimiterStart = 0xfb01,
46 kDelimiterEnd = 0x04fe,
47 };
48
49 // --------------------------------------------------------
50
51 struct EventHeader
52 {
53 enum Bits
54 {
55 kDenable = 1<<11,
56 kDwrite = 1<<10,
57 kRefClkTooHigh = 1<< 9,
58 kRefClkTooLow = 1<< 8,
59 kDcmLocked = 1<< 7,
60 kDcmReady = 1<< 6,
61 kSpiSclk = 1<< 5,
62 };
63
64 // Einmalig: (new header changes entry in array --> send only if array changed)
65 // ----------------------------------
66 // Event builder stores an array with all available values.
67 // Disconnected boards are removed (replaced by def values)
68 // Any received header information is immediately put in the array.
69 // The array is transmitted whenever it changes.
70 // This will usually happen only very rarely when a new connection
71 // is opened.
72 //
73 // Array[40] of BoardId
74 // Array[40] of Version
75 // Array[40] of DNA
76
77 // Slow changes: (new header changes entry in array --> send only if arra changed)
78 // -------------------------------------------
79 // Event builder stores an array with all available values.
80 // Disconnected boards can be kept in the arrays.
81 // Any received header information is immediately put in the array.
82 // The array is transmitted whenever it changes.
83 //
84 // Connection status (disconnected, connecting, connected) / Array[40]
85 // Consistency of PLLLCK / Array[ 40] of PLLLCK
86 // Consistency of Trigger type / Array[ 40] of trigger type
87 // Consistency of ROI / Array[1440] of ROI
88 // Consistency of RefClock / Array[ 40] of ref clock
89 // Consistency of DAC values / Array[ 400] of DAC values
90 // Consistency of run number / Array[ 40] of Run numbers
91
92 // Fast changes (new header changes value --> send only if something changed)
93 // -------------------
94 // Event builder stores an internal array of all boards and
95 // transmits the min/max values determined from the array
96 // only if they have changed. Disconnected boards are not considered.
97 //
98 // Maximum/minimum Event counter of all boards in memory + board id
99 // Maximum/minimum time stamp of all boards in memory + board id
100 // Maximum/minimum temp of all boards in memory + board id
101
102 // Unknown:
103 // ------------------
104 // Trigger Id ?
105 // TriggerGeneratorPrescaler ?
106 // Number of Triggers to generate ?
107
108
109 // ------------------------------------------------------------
110
111 uint16_t fStartDelimiter; // 0x04FE
112 uint16_t fPackageLength;
113 uint16_t fVersion;
114 uint16_t fStatus;
115 //
116 uint16_t fTriggerCrc;
117 uint16_t fTriggerType;
118 uint32_t fTriggerId;
119 //
120 uint32_t fEventCounter;
121 uint32_t fFreqRefClock;
122 //
123 uint16_t fBoardId;
124 uint16_t fAdcClockPhaseShift;
125 uint16_t fNumTriggersToGenerate;
126 uint16_t fTriggerGeneratorPrescaler;
127 //
128 uint64_t fDNA; // Xilinx DNA
129 //
130 uint32_t fTimeStamp;
131 uint32_t fRunNumber;
132 //
133 int16_t fTempDrs[kNumTemp]; // In units of 1/16 deg(?)
134 //
135 uint16_t fDac[kNumDac];
136 //
137
138 EventHeader() { init(*this); }
139
140 void operator=(const std::vector<uint16_t> &vec)
141 {
142 ntohcpy(vec, *this);
143
144 Reverse(((uint16_t*)fEventCounter));
145 Reverse(((uint16_t*)fEventCounter)+1);
146
147 Reverse(&fEventCounter);
148
149 Reverse(((uint16_t*)fFreqRefClock));
150 Reverse(((uint16_t*)fFreqRefClock)+1);
151
152 Reverse(&fFreqRefClock);
153
154 Reverse(((uint16_t*)&fTimeStamp));
155 Reverse(((uint16_t*)&fTimeStamp)+1);
156
157 Reverse(&fTimeStamp);
158
159 Reverse(((uint16_t*)&fRunNumber));
160 Reverse(((uint16_t*)&fRunNumber)+1);
161
162 Reverse(&fRunNumber);
163 Reverse(&fDNA);
164
165/*
166 // Extract temperatures (MSB indicates if temperature
167 // is positive or negative)
168 for (int i=0; i<kNumTemp; i++)
169 {
170 if (fTempDrs[i]&0x8000)
171 fTempDrs[i] |= 0xE000;
172 fTempDrs[i]>>=3;
173 }
174 */
175 }
176
177 float GetTemp(int i) const
178 {
179 return (((fTempDrs[i]&0x8000)
180 ?
181 ((fTempDrs[i]&0x007fff)^0xffffffff)
182 : (fTempDrs[i]&0x007fff))>>3)/16.; }
183
184 uint8_t PLLLCK() const { return fStatus>>12; }
185
186 bool HasDenable() const { return fStatus&kDenable; }
187 bool HasDwrite() const { return fStatus&kDwrite; }
188 bool IsRefClockTooHigh() const { return fStatus&kRefClkTooHigh; }
189 bool IsRefClockTooLow() const { return fStatus&kRefClkTooLow; }
190 bool IsDcmLocked() const { return fStatus&kDcmLocked; }
191 bool IsDcmReady() const { return fStatus&kDcmReady; }
192 bool HasSpiSclk() const { return fStatus&kSpiSclk; }
193
194 uint16_t Crate() const { return fBoardId>>8; }
195 uint16_t Board() const { return fBoardId&0xff; }
196
197 void clear() { reset(*this); }
198 void print(std::ostream &out) const;
199
200 } __attribute__((__packed__));
201
202 struct ChannelHeader
203 {
204 uint16_t fId;
205 uint16_t fStartCell;
206 uint16_t fRegionOfInterest;
207 uint16_t fDummy;
208 // uint16_t fData[];
209
210 ChannelHeader() { init(*this); }
211
212 void operator=(const std::vector<uint16_t> &vec)
213 {
214 ntohcpy(vec, *this);
215 }
216
217 void clear() { reset(*this); }
218 void print(std::ostream &out) const;
219
220 uint16_t Chip() const { return fId>>4; }
221 uint16_t Channel() const { return fId&0xf; }
222
223 } __attribute__((__packed__));
224
225 // Package ends with:
226 // 0x4242
227 // 0x04fe
228/*
229 struct DimPassport
230 {
231 uint32_t fTimeStamp;
232
233 uint16_t fVersion;
234 uint16_t fBoardId;
235 uint64_t fDNA; // Xilinx DNA
236
237 DimPassport(const EventHeader &h) :
238 fTimeStamp(h.fTimeStamp),
239 fVersion(h.fVersion),
240 fBoardId(h.fBoardId),
241 fDNA(h.fDNA)
242 {
243 }
244
245 } __attribute__((__packed__));
246
247 struct DimSetup
248 {
249 uint32_t fTimeStamp;
250
251 uint32_t fFreqRefClock;
252 uint16_t fStatus;
253 uint16_t fAdcClockPhaseShift;
254 uint16_t fNumTriggersToGenerate;
255 uint16_t fTriggerGeneratorPrescaler;
256 uint16_t fDac[kNumDac];
257
258 DimSetup(const EventHeader &h) :
259 fTimeStamp(h.fTimeStamp),
260 fFreqRefClock(h.fFreqRefClock),
261 fStatus(h.fStatus),
262 fAdcClockPhaseShift(h.fAdcClockPhaseShift),
263 fNumTriggersToGenerate(h.fNumTriggersToGenerate),
264 fTriggerGeneratorPrescaler(h.fTriggerGeneratorPrescaler)
265 {
266 memcpy(fDac, h.fDac, sizeof(fDac));
267 }
268
269 uint8_t PLLLCK() const { return fStatus>>12; }
270
271 bool HasDenable() const { return fStatus&EventHeader::kDenable; }
272 bool HasDwrite() const { return fStatus&EventHeader::kDwrite; }
273 bool IsRefClockTooHigh() const { return fStatus&EventHeader::kRefClkTooHigh; }
274 bool IsRefClockTooLow() const { return fStatus&EventHeader::kRefClkTooLow; }
275 bool IsDcmLocked() const { return fStatus&EventHeader::kDcmLocked; }
276 bool IsDcmReady() const { return fStatus&EventHeader::kDcmReady; }
277 bool HasSpiSclk() const { return fStatus&EventHeader::kSpiSclk; }
278
279 } __attribute__((__packed__));
280
281 struct DimTemperatures
282 {
283 uint32_t fTimeStamp;
284
285 float fTempDrs[kNumTemp];
286
287 DimTemperatures(const EventHeader &h) :
288 fTimeStamp(h.fTimeStamp)
289 {
290 for (int i=0; i<kNumTemp; i++)
291 fTempDrs[i] = h.GetTemp(i);
292 }
293
294 } __attribute__((__packed__));;
295
296 struct DimEventHeader
297 {
298 uint32_t fTimeStamp;
299
300 uint32_t fRunNumber;
301 uint32_t fEventCounter;
302 uint16_t fTriggerCrc;
303 uint16_t fTriggerType;
304 uint32_t fTriggerId;
305
306 DimEventHeader(const EventHeader &h) :
307 fTimeStamp(h.fTimeStamp),
308 fRunNumber(h.fRunNumber),
309 fEventCounter(h.fEventCounter),
310 fTriggerCrc(h.fTriggerCrc),
311 fTriggerType(h.fTriggerType),
312 fTriggerId(h.fTriggerId)
313 {
314 }
315
316 } __attribute__((__packed__));
317*/
318 // --------------------------------------------------------------------
319
320 inline std::ostream &operator<<(std::ostream &out, const EventHeader &h)
321 {
322 h.print(out);
323 return out;
324 }
325
326 inline std::ostream &operator<<(std::ostream &out, const ChannelHeader &h)
327 {
328 h.print(out);
329 return out;
330 }
331};
332
333#endif
Note: See TracBrowser for help on using the repository browser.