EUDAQ
 All Classes Namespaces Files Functions Variables Pages
PyBAR.hh
1 #ifndef PYBAR_H
2 #define PYBAR_H
3 
4 /*
5  * macros & defines for for FE-I4 raw data and trigger data processing
6  */
7 
8 /*
9  * unformatted records
10  */
11 
12 // Data Header (DH)
13 #define PYBAR_DATA_HEADER 0x04E90000
14 #define PYBAR_DATA_HEADER_MASK 0xFFFF0000
15 #define PYBAR_DATA_HEADER_FLAG_MASK 0x00008000
16 #define PYBAR_DATA_HEADER_LV1ID_MASK 0x00007F00
17 #define PYBAR_DATA_HEADER_BCID_MASK 0x000000FF
18 
19 #define PYBAR_DATA_HEADER_MACRO(X) \
20  ((PYBAR_DATA_HEADER_MASK & X) == PYBAR_DATA_HEADER ? true : false)
21 #define PYBAR_DATA_HEADER_FLAG_MACRO(X) \
22  ((PYBAR_DATA_HEADER_FLAG_MASK & X) >> 15)
23 #define PYBAR_DATA_HEADER_FLAG_SET_MACRO(X) \
24  ((PYBAR_DATA_HEADER_FLAG_MASK & X) == PYBAR_DATA_HEADER_FLAG_MASK ? true \
25  : false)
26 #define PYBAR_DATA_HEADER_LV1ID_MACRO(X) \
27  ((PYBAR_DATA_HEADER_LV1ID_MASK & X) >> 8)
28 #define PYBAR_DATA_HEADER_BCID_MACRO(X) (PYBAR_DATA_HEADER_BCID_MASK & X)
29 
30 // Data Record (DR)
31 #define PYBAR_DATA_RECORD_COLUMN_MASK 0x00FE0000
32 #define PYBAR_DATA_RECORD_ROW_MASK 0x0001FF00
33 #define PYBAR_DATA_RECORD_TOT1_MASK 0x000000F0
34 #define PYBAR_DATA_RECORD_TOT2_MASK 0x0000000F
35 
36 #define PYBAR_RAW_DATA_MIN_COLUMN 0x00000001 // 1
37 #define PYBAR_RAW_DATA_MAX_COLUMN 0x00000050 // 80
38 #define PYBAR_RAW_DATA_MIN_ROW 0x00000001 // 1
39 #define PYBAR_RAW_DATA_MAX_ROW 0x00000150 // 336
40 #define PYBAR_DATA_RECORD_MIN_COLUMN (PYBAR_RAW_DATA_MIN_COLUMN << 17)
41 #define PYBAR_DATA_RECORD_MAX_COLUMN (PYBAR_RAW_DATA_MAX_COLUMN << 17)
42 #define PYBAR_DATA_RECORD_MIN_ROW (PYBAR_RAW_DATA_MIN_ROW << 8)
43 #define PYBAR_DATA_RECORD_MAX_ROW (PYBAR_RAW_DATA_MAX_ROW << 8)
44 
45 #define PYBAR_DATA_RECORD_MACRO(X) \
46  (((PYBAR_DATA_RECORD_COLUMN_MASK & X) <= PYBAR_DATA_RECORD_MAX_COLUMN) && \
47  ((PYBAR_DATA_RECORD_COLUMN_MASK & X) >= \
48  PYBAR_DATA_RECORD_MIN_COLUMN) && \
49  ((PYBAR_DATA_RECORD_ROW_MASK & X) <= PYBAR_DATA_RECORD_MAX_ROW) && \
50  ((PYBAR_DATA_RECORD_ROW_MASK & X) >= PYBAR_DATA_RECORD_MIN_ROW) \
51  ? true \
52  : false)
53 #define PYBAR_DATA_RECORD_COLUMN1_MACRO(X) \
54  ((PYBAR_DATA_RECORD_COLUMN_MASK & X) >> 17)
55 #define PYBAR_DATA_RECORD_ROW1_MACRO(X) ((PYBAR_DATA_RECORD_ROW_MASK & X) >> 8)
56 #define PYBAR_DATA_RECORD_TOT1_MACRO(X) ((PYBAR_DATA_RECORD_TOT1_MASK & X) >> 4)
57 #define PYBAR_DATA_RECORD_COLUMN2_MACRO(X) \
58  ((PYBAR_DATA_RECORD_COLUMN_MASK & X) >> 17)
59 #define PYBAR_DATA_RECORD_ROW2_MACRO(X) \
60  (((PYBAR_DATA_RECORD_ROW_MASK & X) >> 8) + 1)
61 #define PYBAR_DATA_RECORD_TOT2_MACRO(X) (PYBAR_DATA_RECORD_TOT2_MASK & X)
62 
63 // Address Record (AR)
64 #define PYBAR_ADDRESS_RECORD 0x04EA0000
65 #define PYBAR_ADDRESS_RECORD_MASK 0xFFFF0000
66 #define PYBAR_ADDRESS_RECORD_TYPE_MASK 0x00008000
67 #define PYBAR_ADDRESS_RECORD_ADDRESS_MASK 0x00007FFF
68 
69 #define PYBAR_ADDRESS_RECORD_MACRO(X) \
70  ((PYBAR_ADDRESS_RECORD_MASK & X) == PYBAR_ADDRESS_RECORD ? true : false)
71 #define PYBAR_ADDRESS_RECORD_TYPE_MACRO(X) \
72  ((PYBAR_ADDRESS_RECORD_TYPE_MASK & X) >> 15)
73 #define PYBAR_ADDRESS_RECORD_TYPE_SET_MACRO(X) \
74  ((PYBAR_ADDRESS_RECORD_TYPE_MASK & X) == PYBAR_ADDRESS_RECORD_TYPE_MASK \
75  ? true \
76  : false)
77 #define PYBAR_ADDRESS_RECORD_ADDRESS_MACRO(X) \
78  (PYBAR_ADDRESS_RECORD_ADDRESS_MASK & X)
79 
80 // Value Record (VR)
81 #define PYBAR_VALUE_RECORD 0x04EC0000
82 #define PYBAR_VALUE_RECORD_MASK 0xFFFF0000
83 #define PYBAR_VALUE_RECORD_VALUE_MASK 0x0000FFFF
84 
85 #define PYBAR_VALUE_RECORD_MACRO(X) \
86  ((PYBAR_VALUE_RECORD_MASK & X) == PYBAR_VALUE_RECORD ? true : false)
87 #define PYBAR_VALUE_RECORD_VALUE_MACRO(X) (PYBAR_VALUE_RECORD_VALUE_MASK & X)
88 
89 // Service Record (SR)
90 #define PYBAR_SERVICE_RECORD 0x04EF0000
91 #define PYBAR_SERVICE_RECORD_MASK 0xFFFF0000
92 #define PYBAR_SERVICE_RECORD_CODE_MASK 0x0000FC00
93 #define PYBAR_SERVICE_RECORD_COUNTER_MASK 0x000003FF
94 
95 #define PYBAR_SERVICE_RECORD_MACRO(X) \
96  ((PYBAR_SERVICE_RECORD_MASK & X) == PYBAR_SERVICE_RECORD ? true : false)
97 #define PYBAR_SERVICE_RECORD_CODE_MACRO(X) \
98  ((PYBAR_SERVICE_RECORD_CODE_MASK & X) >> 10)
99 #define PYBAR_SERVICE_RECORD_COUNTER_MACRO(X) \
100  (PYBAR_SERVICE_RECORD_COUNTER_MASK & X)
101 
102 // Empty Record (ER)
103 #define PYBAR_EMPTY_RECORD 0x04000000
104 #define PYBAR_EMPTY_RECORD_MASK 0xFFFFFFFF
105 
106 #define PYBAR_EMPTY_RECORD_MACRO(X) \
107  ((PYBAR_EMPTY_RECORD_MASK & X) == PYBAR_EMPTY_RECORD ? true : false)
108 
109 /*
110  * trigger data
111  */
112 
113 #define PYBAR_TRIGGER_WORD_HEADER_V10 0x04FFFF00
114 #define PYBAR_TRIGGER_WORD_HEADER_MASK_V10 0xFFFFFF00
115 
116 #define PYBAR_TRIGGER_WORD_HEADER \
117  0x04F80000 // tolerant to 1-bit flips and not equal to control/comma symbols
118 #define PYBAR_TRIGGER_WORD_HEADER_MASK 0xFFFF0000
119 #define PYBAR_TRIGGER_NUMBER_31_24_MASK 0x000000FF
120 #define PYBAR_TRIGGER_NUMBER_23_0_MASK 0x00FFFFFF
121 
122 #define PYBAR_TRIGGER_DATA_MASK 0x0000FF00 // trigger error + trigger mode
123 #define PYBAR_TRIGGER_MODE_MASK 0x0000E000 // trigger mode
124 #define PYBAR_TRIGGER_ERROR_MASK \
125  0x00001F00 // error code: bit 0: wrong number of dh, bit 1 service record
126  // recieved
127 
128 #define PYBAR_TRIGGER_WORD_MACRO(X) \
129  ((((PYBAR_TRIGGER_WORD_HEADER_MASK & X) == PYBAR_TRIGGER_WORD_HEADER) || \
130  ((PYBAR_TRIGGER_WORD_HEADER_MASK_V10 & X) == \
131  PYBAR_TRIGGER_WORD_HEADER_V10)) \
132  ? true \
133  : false)
134 #define PYBAR_TRIGGER_NUMBER_MACRO2(X, Y) \
135  (((PYBAR_TRIGGER_NUMBER_31_24_MASK & X) << 24) | \
136  (PYBAR_TRIGGER_NUMBER_23_0_MASK & Y)) // returns full trigger number;
137  // reference and dereference of
138  // following array element
139 
140 #define PYBAR_TRIGGER_ERROR_OCCURRED_MACRO(X) \
141  (((((PYBAR_TRIGGER_ERROR_MASK & X) >> 8) == 0x00000000) || \
142  ((PYBAR_TRIGGER_WORD_HEADER_MASK_V10 & X) == \
143  PYBAR_TRIGGER_WORD_HEADER_V10)) \
144  ? false \
145  : true)
146 #define PYBAR_TRIGGER_DATA_MACRO(X) ((PYBAR_TRIGGER_DATA_MASK & X) >> 8)
147 #define PYBAR_TRIGGER_ERROR_MACRO(X) ((PYBAR_TRIGGER_ERROR_MASK & X) >> 8)
148 #define PYBAR_TRIGGER_MODE_MACRO(X) ((PYBAR_TRIGGER_MODE_MASK & X) >> 13)
149 
150 #endif // PYBAR_H