HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dccmacro.h
Go to the documentation of this file.
1 #ifndef DCCMACRO_H
2 #define DCCMACRO_H
3 
4 
5 #define MAX_ETH_PACKET_DATA_SIZE 4096
6 // -------- include gblink.h
7 // ??? FEM & DDC header macro in gblink ????
8 // Response Packet Header Decode Macros
9 #define GET_REQ_INDEX(word) ((word) & 0x000F)
10 #define GET_WR_ACK(word) ((word) & 0x0030)
11 #define GET_RD_ACK(word) ((word) & 0x0040)
12 #define GET_TR_OK(word) ((word) & 0x0080)
13 #define GET_TYPE(word) ((word) & 0xF000)
14 #define PUT_TYPE(word, ty) (((word) & 0x0FFF) | ((ty) & 0xF000) )
15 
16 // Response Packet Types from FEM (see t2k_pkg.vhd for coherence)
17 #define RESP_TYPE_ADC_DATA 0x0000
18 #define RESP_TYPE_SLOW_CTRL 0x1000
19 // These types are not among those returned by the FEM but by the DCC
20 #define RESP_TYPE_HISTOGRAM 0x2000
21 #define RESP_TYPE_HISTOSTAT 0x3000
22 #define RESP_TYPE_HISTOSUMMARY 0x4000
23 #define GET_RESP_TYPE(word) (((word) & 0xF000)>>12)
24 #define GET_RESP_INDEX(word) ((word) & 0x000F)
25 
26 // Macros to interpret DataPacket header
27 #define GET_FEC_ERROR(word) (((word) & 0x03F0)>>4)
28 #define GET_LOS_FLAG(word) (((word) & 0x0400)>>10)
29 #define GET_SYNCH_FAIL(word) (((word) & 0x0800)>>11)
30 
31 // Macros to interpret DataPacket read back arguments
32 #define GET_RB_MODE(word) (((word) & 0x4000)>>14)
33 #define GET_RB_COMPRESS(word) (((word) & 0x2000)>>13)
34 #define GET_RB_ARG2(word) (((word) & 0x1E00)>>9)
35 #define GET_RB_ARG1(word) (((word) & 0x01FF))
36 
37 // Macros to interpret DataPacket event type / count
38 #define GET_EVENT_TYPE(word) (((word) & 0xC000)>>14)
39 #define GET_EVENT_COUNT(word) (((word) & 0x3FFF))
40 
41 // Macros to interpret DataPacket Samples
42 #define CELL_INDEX_FLAG 0x1000
43 #define GET_CELL_INDEX(word) (((word) & 0x0FFF))
44 #define ARGUMENT_FLAG 0x2000
45 #define GET_ARGUMENTS(word) (((word) & 0xDFFF))
46 #define SAMPLE_COUNT_FLAG 0x4000
47 #define GET_SAMPLE_COUNT(word) (((word) & 0x0FFF))
48 
49 // Header structure common to old and new structure of DataPacket
50 // which actually not common ????
51 typedef struct _PacketRxCommonHdr {
52  unsigned short size;
53  unsigned short hdr;
55 
56 
57 // ------- end gblink.h
58 
59 // -------- include dcc.h
60 
61 // The number of FEM per DCC is passed by the preprocessor
62 // but a default value is set if not provided
63 #ifndef FEM_PER_DCC
64 #define FEM_PER_DCC 1
65 #endif
66 #define MAX_NB_OF_FEM_PER_DCC 12
67 #define MIN_FEM_INDEX 0
68 #define MAX_FEM_INDEX ((FEM_PER_DCC < MAX_NB_OF_FEM_PER_DCC) ? (MIN_FEM_INDEX+FEM_PER_DCC-1): (MAX_NB_OF_FEM_PER_DCC-1))
69 
70 // -------- end dcc.h
71 
72 
73 // End of Event Packet
74 // from endofevent_pocket.h
75 typedef struct _EndOfEventPacket {
76  unsigned short size; // size in bytes including the size of the size field itself
77  unsigned short dcchdr; // specific header added by the DCC
78  unsigned short hdr; // specific header similar to what is put by the FEM
79  unsigned short pad; // padding for 32-bit alignement
80  unsigned int byte_rcv[MAX_NB_OF_FEM_PER_DCC]; // data received per FEM
81  unsigned int byte_snd[MAX_NB_OF_FEM_PER_DCC]; // data sent per FEM
82  unsigned int tot_byte_rcv;
83  unsigned int tot_byte_snd;
85 
86 // New structure of DataPacket. Aliased to DataPacketV2
87 typedef struct _DataPacket {
88  unsigned short size; // size in bytes including the size of the size field itself
89  unsigned short dcchdr; // specific header added by the DCC
90  unsigned short hdr; // specific header put by the FEM
91  unsigned short args; // read-back arguments echoed by FEM
92  unsigned short ts_h; // local FEM timestamp MSB
93  unsigned short ts_l; // local FEM timestamp LSB
94  unsigned short ecnt; // local FEM event type/count
95  unsigned short scnt; // sample count in first pulse over thr or total sample count in packet
96  unsigned short samp[MAX_ETH_PACKET_DATA_SIZE/(sizeof(unsigned short))]; // data storage area
97 } DataPacket;
98 
100 
101 // Old structure of DataPacket. This is kept for backward compatibility
102 typedef struct _DataPacketV1 {
103  unsigned short size;
104  unsigned short hdr;
105  unsigned short args;
106  unsigned short ts_h;
107  unsigned short ts_l;
108  unsigned short ecnt;
109  unsigned short scnt;
110  unsigned short samp[MAX_ETH_PACKET_DATA_SIZE/(sizeof(unsigned short))];
111 } DataPacketV1;
112 
113 // Macros to manipulate DataPacket DCC header
114 #define FRAME_TYPE_FEM_DATA 0x0000
115 #define FRAME_TYPE_DCC_DATA 0x0001
116 #define FRAME_FLAG_EORQ 0x0004
117 #define FRAME_FLAG_EOEV 0x0008
118 #define GET_FEM_INDEX(word) (((word) & 0x000F)>>0)
119 #define GET_DCC_INDEX(word) (((word) & 0x03F0)>>4)
120 #define GET_FRAME_TY_V2(word) (((word) & 0x3C00)>>10)
121 #define PUT_FEM_INDEX(word, ix) (((word) & 0xFFF0) | (((ix) & 0x000F) << 0))
122 #define PUT_DCC_INDEX(word, ix) (((word) & 0xFC0F) | (((ix) & 0x003F) << 4))
123 #define PUT_FRAME_TY_V2(word, ty) (((word) & 0x03FF) | FRAME_HDR_V2 | (((ty) & 0x000F) <<10))
124 
125 // We now support the old and new version of the data packet structure
126 #define FRAME_HDR_V2_FIELD 0xC000
127 #define FRAME_HDR_V2 0x4000
128 #define IS_DATA_PACKET_V2(word) (((word) & FRAME_HDR_V2_FIELD) == FRAME_HDR_V2)
129 
130 /*******************************************************************************
131 +++ FemAdcDataDecode
132 *******************************************************************************/
133 #define DATA_PACKET_VER(word) (((word) & FRAME_HDR_V2_FIELD)>>12)
134 
135 #endif
struct _PacketRxCommonHdr PacketRxCommonHdr
struct _DataPacket DataPacket
DataPacket DataPacketV2
Definition: dccmacro.h:99
#define MAX_ETH_PACKET_DATA_SIZE
Definition: dccmacro.h:5
struct _DataPacketV1 DataPacketV1
struct _EndOfEventPacket EndOfEventPacket
#define MAX_NB_OF_FEM_PER_DCC
Definition: dccmacro.h:66