File indexing completed on 2024-04-06 12:04:09
0001 #ifndef DIGIFTL_ETLSAMPLE_H
0002 #define DIGIFTL_ETLSAMPLE_H
0003
0004 #include <iostream>
0005 #include <ostream>
0006 #include <cstdint>
0007
0008
0009
0010
0011
0012
0013 class ETLSample {
0014 public:
0015 enum ETLSampleMasks {
0016 kThreshMask = 0x1,
0017 kModeMask = 0x1,
0018 kColumnMask = 0x1f,
0019 kRowMask = 0x3f,
0020 kToAMask = 0x7ff,
0021 kDataMask = 0xff,
0022 kToTMask = 0x7ff
0023 };
0024 enum ETLSampleShifts {
0025 kThreshShift = 31,
0026 kModeShift = 30,
0027 kColumnShift = 25,
0028 kRowShift = 19,
0029 kToAShift = 8,
0030 kDataShift = 0,
0031 kToTShift = 0
0032 };
0033
0034
0035
0036
0037 ETLSample() : value_(0), valueToT_(0) {}
0038 ETLSample(uint32_t value) : value_(value), valueToT_(0) {}
0039 ETLSample(uint32_t value, uint32_t valueToT) : value_(value), valueToT_(valueToT) {}
0040 ETLSample(const ETLSample& o) : value_(o.value_), valueToT_(o.valueToT_) {}
0041 ETLSample& operator=(const ETLSample&) = default;
0042
0043
0044
0045
0046 void setThreshold(bool thr) { setWord(thr, kThreshMask, kThreshShift); }
0047 void setMode(bool mode) { setWord(mode, kModeMask, kModeShift); }
0048 void setColumn(uint8_t col) { setWord(col, kColumnMask, kColumnShift); }
0049 void setRow(uint8_t row) { setWord(row, kRowMask, kRowShift); }
0050 void setToA(uint16_t toa) { setWord(toa, kToAMask, kToAShift); }
0051 void setToT(uint16_t tot) { setWordToT(tot, kToTMask, kToTShift); }
0052 void setData(uint16_t data) { setWord(data, kDataMask, kDataShift); }
0053 void set(bool thr, bool mode, uint16_t toa, uint16_t tot, uint16_t data, uint8_t row, uint8_t col) {
0054 value_ = (((uint32_t)thr & kThreshMask) << kThreshShift | ((uint32_t)mode & kModeMask) << kModeShift |
0055 ((uint32_t)col & kColumnMask) << kColumnShift | ((uint32_t)row & kRowMask) << kRowShift |
0056 ((uint32_t)toa & kToAMask) << kToAShift | ((uint32_t)data & kDataMask) << kDataShift);
0057 valueToT_ = ((uint32_t)tot & kToTMask) << kToTShift;
0058 }
0059 void print(std::ostream& out = std::cout) {
0060 out << "(row,col) : (" << row() << ',' << column() << ") "
0061 << "THR: " << threshold() << " Mode: " << mode() << " ToA: " << toa() << " ToT: " << tot()
0062 << " Data: " << data() << " Raw=0x" << std::hex << raw() << std::dec << std::endl;
0063 }
0064
0065
0066
0067
0068 uint32_t raw() const { return value_; }
0069 bool threshold() const { return ((value_ >> kThreshShift) & kThreshMask); }
0070 bool mode() const { return ((value_ >> kModeShift) & kModeMask); }
0071 uint32_t column() const { return ((value_ >> kColumnShift) & kColumnMask); }
0072 uint32_t row() const { return ((value_ >> kRowShift) & kRowMask); }
0073 uint32_t toa() const { return ((value_ >> kToAShift) & kToAMask); }
0074 uint32_t tot() const { return ((valueToT_ >> kToTShift) & kToTMask); }
0075 uint32_t data() const { return ((value_ >> kDataShift) & kDataMask); }
0076 uint32_t operator()() { return value_; }
0077
0078 private:
0079
0080
0081
0082 void setWord(uint32_t word, uint32_t mask, uint32_t pos) {
0083
0084 value_ &= ~(mask << pos);
0085
0086 value_ |= ((word & mask) << pos);
0087 }
0088
0089 void setWordToT(uint32_t word, uint32_t mask, uint32_t pos) {
0090
0091 valueToT_ &= ~(mask << pos);
0092
0093 valueToT_ |= ((word & mask) << pos);
0094 }
0095
0096
0097 uint32_t value_;
0098 uint32_t valueToT_;
0099 };
0100
0101 #endif