Frame14Format.hh
Go to the documentation of this file.
1 // Frame14Format.hh
2 // Ben Land (2020)
3 
4 #ifndef artdaq_dune_Overlays_FrameFormat_hh
5 #define artdaq_dune_Overlays_FrameFormat_hh
6 
7 #include <cstddef>
8 #include <stdint.h>
9 #include <vector>
10 
11 namespace dune {
12 
13 namespace frame14 {
14 
15 // Bitfields in the binary format of the Frame frame14 from the WIB
16 typedef struct {
17  uint32_t start_frame;
18  uint32_t crate_num : 8, frame_version: 4, slot_num : 3, fiber_num : 1;
19  uint32_t femb_valid : 2, link_mask : 8, reserved : 6;
20  uint32_t wib_data;
21  uint64_t timestamp;
22  uint32_t femb_a_seg[56];
23  uint32_t femb_b_seg[56];
24  uint32_t crc20 : 20, flex12 : 12;
25  uint32_t eof: 8, flex24 : 24;
26  uint32_t idle_frame;
27 } __attribute__ ((packed, aligned(4))) frame14;
28 
29 
30 // Return a single value from packed channel data (56 uint32 words from the WIB)
31 inline uint16_t unpack14(const uint32_t *packed, size_t i) {
32  const size_t low_bit = i*14;
33  const size_t low_word = low_bit / 32;
34  const size_t high_bit = (i+1)*14-1;
35  const size_t high_word = high_bit / 32;
36  //printf("word %li :: low %li (%li[%li]) high %li (%li[%li])\n",i,low_bit,low_word,low_bit%32,high_bit,high_word,high_bit%32);
37  if (low_word == high_word) { //all the bits are in the same word
38  return (packed[low_word] >> (low_bit%32)) & 0x3FFF;
39  } else { //some of the bits are in the next word
40  size_t high_off = high_word*32-low_bit;
41  //printf("pre_mask 0x%X post_mask 0x%X\n", (0x3FFF >> (14-high_off)), ((0x3FFF << high_off) & 0x3FFF) );
42  uint16_t result = (packed[low_word] >> (low_bit%32)) & (0x3FFF >> (14-high_off));
43  result |= (packed[high_word] << high_off) & ((0x3FFF << high_off) & 0x3FFF);
44  return result;
45  }
46 }
47 
48 } // namespace frame14
49 
50 } // namespace dune
51 
52 #endif /* artdaq_dune_Overlays_Frame14Format_hh */
static QCString result
uint16_t unpack14(const uint32_t *packed, size_t i)
aligned(4))) frame14