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