Line data Source code
1 : /*
2 : * CTBPacketContent.hpp
3 : *
4 : * Ported from https://cdcvs.fnal.gov/redmine/projects/dune-raw-data/repository/revisions/develop/entry/dune-raw-data/Overlays/CTB_content.h
5 : *
6 : * Developer: willpvazquez (27 July 2022)
7 : *
8 : * Originally Created on: Oct 8, 2017
9 : * Author: nbarros
10 : */
11 :
12 : #ifndef CTBMODULES_SRC_CTBPACKETCONTENT_HPP_
13 : #define CTBMODULES_SRC_CTBPACKETCONTENT_HPP_
14 :
15 : #include <cstdint>
16 :
17 : namespace dunedaq {
18 : namespace ctbmodules{
19 : namespace content {
20 :
21 : // NFB: Note that order denotes bit order in the word:
22 : // Upper fields are in the lsb and lower field is in the msb
23 : /// Internal buffer definition
24 : ///
25 : //static uint8_t format_version = 0x2;
26 :
27 : typedef struct buffer_t {
28 : int handle;
29 : size_t len;
30 : } buffer_t;
31 :
32 : ///
33 : /// -- TCP header
34 : ///
35 :
36 : typedef struct tcp_header_t {
37 : typedef uint16_t pkt_size_t;
38 : typedef uint8_t seq_size_t;
39 : typedef uint8_t ver_size_t;
40 : uint16_t packet_size : 16; // Size of the data content in bytes
41 : uint8_t sequence_id : 8; // packet order...rotates every 256
42 : uint8_t format_version : 8;
43 : static size_t const size_bytes = sizeof(uint32_t);
44 : static size_t const n_bits_size = 16;
45 : static size_t const n_bits_sequence_id = 8;
46 : static size_t const n_bits_version = 8;
47 : } tcp_header_t;
48 :
49 : // NFB: Careful with unions. Setting one member and then accessing another
50 : // is undefined behavior in C++.
51 : // However, I have tested that they work on gcc on the PTB
52 :
53 : typedef union tcp_header {
54 : tcp_header_t word;
55 : uint32_t value;
56 : } tcp_header;
57 :
58 : namespace word {
59 : enum word_type {t_fback=0x0,t_lt=0x1,t_gt=0x2, t_ch=0x3,t_chksum=0x4,t_ts=0x7};
60 : ///
61 : /// -- payload
62 : ///
63 : // -- The body of a word is composed of 12 bytes
64 : typedef uint16_t trigger_code_t;
65 : ///
66 : /// N. Barros - May 7, 2018 : Changed the structure of the parsing
67 : ///
68 : /// Now all structures cast into 16 bytes, but declare different
69 : /// bit fields to interpret each frame in the context of its respective type
70 : ///
71 : /// Also, to move into a format where the full timestamp is stored, the full timestamp
72 : /// is now placed in the 64 lsb, instead of the msb. Does complies with the memory alignment
73 : /// and simplifies the parsing of the structures
74 : ///
75 :
76 : typedef struct word_t {
77 : typedef uint64_t ts_size_t;
78 : typedef uint64_t pad_size_t;
79 : typedef uint64_t word_type_t;
80 : ts_size_t timestamp;
81 : pad_size_t payload : 61;
82 : word_type_t word_type : 3;
83 : static size_t const size_bytes = 4*sizeof(uint32_t);
84 : static size_t const size_u32 = 4*sizeof(uint32_t)/sizeof(uint32_t);
85 : static size_t const n_bits_timestamp = 64;
86 : static size_t const n_bits_payload = 61;
87 : static size_t const n_bits_type = 3;
88 : } word_t;
89 :
90 : typedef union word{
91 : word_t frame;
92 : uint8_t *get_bytes() {return reinterpret_cast<uint8_t*>(&frame);}
93 : } word;
94 :
95 : /// -- Several different structures that can be used to reinterpret the payload depending on
96 : /// the word type. All these structures map into the full 16 bytes of the CTB words
97 : ///
98 :
99 : typedef struct feedback_t {
100 : typedef uint64_t ts_size_t;
101 : typedef uint16_t code_size_t;
102 : typedef uint16_t source_size_t;
103 : typedef uint32_t wtype_size_t;
104 : typedef uint32_t pad_size_t;
105 : ts_size_t timestamp;
106 : code_size_t code : 16;
107 : source_size_t source : 16;
108 : pad_size_t padding : 29;
109 : wtype_size_t word_type : 3;
110 : static size_t const size_bytes = 2*sizeof(uint64_t);
111 : static size_t const size_u32 = size_bytes/sizeof(uint32_t);
112 : static size_t const n_bits_timestamp = 64;
113 : static size_t const n_bits_payload = 32;
114 : static size_t const n_bits_type = 3;
115 : } feedback_t;
116 :
117 : typedef struct ch_status_t {
118 : typedef uint64_t ts_size_t;
119 : typedef uint64_t pds_size_t;
120 : typedef uint64_t crt_size_t;
121 : typedef uint64_t beam_size_t;
122 : typedef uint64_t wtype_size_t;
123 : ts_size_t timestamp : 60;
124 : beam_size_t beam_lo : 4;
125 : beam_size_t beam_hi : 12;
126 : crt_size_t crt : 32;
127 : pds_size_t pds : 17;
128 : wtype_size_t word_type : 3;
129 : static size_t const size_bytes = 2*sizeof(uint64_t);
130 : static size_t const size_u32 = size_bytes/sizeof(uint32_t);
131 : static size_t const n_bits_timestamp = 60;
132 : static size_t const n_bits_payload = 32;
133 : static size_t const n_bits_type = 3;
134 :
135 : // aux_functions
136 0 : beam_size_t get_beam() const {return (beam_hi << 4 | beam_lo);}
137 0 : crt_size_t get_crt() const {return (crt & 0xFFFFFFFF);}
138 0 : pds_size_t get_pds() const {return (pds & 0x1FFFF);}
139 :
140 : bool get_state_crt(const uint16_t channel) {
141 : return ((crt & (0x1 << channel)) != 0x0);
142 : }
143 :
144 : bool get_state_pds(const uint16_t channel) {
145 : return ((pds & (0x1 << channel)) != 0x0);
146 : }
147 :
148 : bool get_state_beam(const uint16_t channel) {
149 : return (((beam_hi << 4 | beam_lo) & (0x1 << channel)) != 0x0);
150 : }
151 : } ch_status_t;
152 :
153 : typedef struct timestamp_t {
154 : typedef uint64_t ts_size_t;
155 : typedef uint64_t pad_size_t;
156 : typedef uint64_t wtype_size_t;
157 : ts_size_t timestamp;
158 : pad_size_t padding : 61;
159 : wtype_size_t word_type : 3;
160 : static size_t const size_bytes = 2*sizeof(uint64_t);
161 : static size_t const size_u32 = size_bytes/sizeof(uint32_t);
162 : static size_t const n_bits_timestamp = 64;
163 : static size_t const n_bits_unused = 61;
164 : static size_t const n_bits_type = 3;
165 : } timestamp_t;
166 :
167 : typedef struct trigger_t {
168 : typedef uint64_t ts_size_t;
169 : typedef uint64_t mask_size_t;
170 : typedef uint64_t wtype_size_t;
171 : ts_size_t timestamp ;
172 : mask_size_t trigger_word : 61 ;
173 : wtype_size_t word_type : 3 ;
174 : static size_t const size_bytes = 2*sizeof(uint64_t);
175 : static size_t const size_u32 = size_bytes/sizeof(uint32_t);
176 : static size_t const n_bits_timestamp = 64;
177 : static size_t const n_bits_tmask = 61;
178 : static size_t const n_bits_type = 3;
179 :
180 0 : bool IsHLT() const { return word_type == word_type::t_gt ; }
181 : bool IsLLT() const { return word_type == word_type::t_lt ; }
182 : bool IsTrigger( const unsigned int i ) const {
183 : if ( IsHLT() ) return trigger_word & ( 0x1 << i ) ;
184 : if ( IsLLT() ) return i == 0 ? false : trigger_word & ( 0x1 << (i-1) ) ;
185 : return false ;
186 : }
187 : } trigger_t;
188 :
189 : } // -- namespace word
190 : } // -- namespace content
191 : } // -- namespace ctbmodules
192 : } // -- namespace dunedaq
193 :
194 : #endif /* CTBMODULES_SRC_CTBPACKETCONTENT_HPP_ */
|