-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpenn_daq.h
291 lines (249 loc) · 7.25 KB
/
penn_daq.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#ifndef PENN_DAQ_H
#define PENN_DAQ_H
typedef u_char byte;
//_!_DEFINITIONS_!_
// XL3
#define MAX_XL3_CON 19
#define XL3_PORT 44601
// Monitor
#define MAX_MON_CON 1
#define MON_PORT 44598
// Controller
#define MAX_CONT_CON 1
#define CONT_PORT 44600
// Viewer
#define MAX_VIEW_CON 3
#define VIEW_PORT 44599
// SBC/MTC
#define MAX_SBC_CON 1
#define SBC_PORT 44630
#define SBC_SERVER "10.0.0.30"
#define SBC_USER "daq"
// Xilinx
#define MTC_XILINX_LOCATION "data/mtcxilinx.rbt"
// CoucHDB
#define DB_SERVER "http://localhost:5984"
#define DB_ADDRESS "localhost"
#define DB_PORT "5984"
#define DB_BASE_NAME "penndb1"
#define DB_VIEWDOC "_design/view_doc/_view"
// Maximum request timeouts
#define SECONDS 20
#define USECONDS 0
//_!_END_DEFINTIONS_!_
// the total number of pending requests (11 is a good guestimate; this number isn't all that important)
#define MAX_PENDING_CONS 11
// the number of packet/socket pairs to be stored to be sent out
#define BACKLOG 100
// timeout values
#define SECONDS 20
#define USECONDS 0
// acknowledgement to send to control terminal upon successful reception of command
#define COMACK "_!_"
// the largest number of bytes in a packet
#define MAX_PACKET_SIZE 1444
// database stuff
#define DB_SERVER "http://localhost:5984"
#define DB_ADDRESS "localhost"
#define DB_PORT "5984"
#define DB_BASE_NAME "penndb1"
#define DB_VIEWDOC "_design/view_doc/_view"
//#define kSBC_MaxPayloadSizeBytes 1024*400
#define kSBC_MaxPayloadSizeBytes 1440
#define kSBC_MaxMessageSizeBytes 256
#define MAX_ACKS_SIZE 80
#define MAX_FEC_COMMANDS 60000
#define NeedToSwap
// possible cmdID's for packets recieved by XL3 (from the DAQ)
#define CHANGE_MODE_ID (0x1) // change mode
#define XL3_TEST_CMD_ID (0x2) // do any of the test functions (check test_function.h)
#define SINGLE_CMD_ID (0x4) // execute one cmd and get result
#define DAQ_QUIT_ID (0x5) // quit
#define FEC_CMD_ID (0x6) // put one or many cmds in cmd queue
#define FEC_TEST_ID (0x7) // DAQ functions below ...
#define MEM_TEST_ID (0x8)
#define CRATE_INIT_ID (0x9)
#define VMON_START_ID (0xA)
#define BOARD_ID_READ_ID (0xB)
#define ZERO_DISCRIMINATOR_ID (0xC)
#define FEC_LOAD_CRATE_ADD_ID (0xD)
#define SET_CRATE_PEDESTALS_ID (0xE)
#define DESELECT_FECS_ID (0xF)
#define BUILD_CRATE_CONFIG_ID (0x10)
#define LOADSDAC_ID (0x11)
#define CALD_TEST_ID (0x12)
#define STATE_MACHINE_RESET_ID (0x13)
#define MULTI_CMD_ID (0x14)
#define DEBUGGING_MODE_ID (0x15)
#define READ_PEDESTALS_ID (0x16)
#define PONG_ID (0x17)
#define MULTI_LOADSDAC_ID (0x18)
#define CGT_TEST_ID (0x19)
#define LOADTACBITS_ID (0x1A)
#define CMOSGTVALID_ID (0x1B)
#define RESET_FIFOS_ID (0x1C)
#define READ_LOCAL_VOLTAGE_ID (0x23)
#define HV_READBACK_ID (0x24)
#define CHECK_TOTAL_COUNT_ID (0x25)
// possible cmdID's for packets sent by XL3 (to the DAQ)
#define CALD_RESPONSE_ID (0xAA)
#define PING_ID (0xBB)
#define MEGA_BUNDLE_ID (0xCC)
#define CMD_ACK_ID (0xDD)
#define MESSAGE_ID (0xEE)
#define STATUS_ID (0xFF)
// ############### DEFINITION OF STRUCTS ###################
// structs copied from SBC_Cmds.h
typedef struct {
int32_t baseAddress;
int32_t addressModifier;
int32_t programRegOffset;
uint32_t errorCode;
int32_t fileSize;
} SNOMtc_XilinxLoadStruct;
typedef
struct {
uint32_t address; /*first address*/
uint32_t addressModifier;
uint32_t addressSpace;
uint32_t unitSize; /*1,2,or 4*/
uint32_t errorCode; /*filled on return*/
uint32_t numItems; /*number of items to read*/
}
SBC_VmeReadBlockStruct;
typedef
struct {
uint32_t address; /*first address*/
uint32_t addressModifier;
uint32_t addressSpace;
uint32_t unitSize; /*1,2,or 4*/
uint32_t errorCode; /*filled on return*/
uint32_t numItems; /*number Items of data to follow*/
/*followed by the requested data, number of items from above*/
}
SBC_VmeWriteBlockStruct;
typedef
struct {
uint32_t destination; /*should be kSBC_Command*/
uint32_t cmdID;
uint32_t numberBytesinPayload;
}
SBC_CommandHeader;
typedef
struct {
uint32_t numBytes; //filled in automatically
SBC_CommandHeader cmdHeader;
char message[kSBC_MaxMessageSizeBytes];
char payload[kSBC_MaxPayloadSizeBytes];
}
SBC_Packet;
// XL3 structs (same should be on the actual XL3)
typedef
struct {
uint32_t cmd_num;
uint16_t packet_num;
uint8_t flags;
uint32_t address;
uint32_t data;
}
FECCommand;
typedef
struct {
uint32_t howmany;
FECCommand cmd[MAX_ACKS_SIZE];
}
MultiFC;
typedef
struct {
//uint32_t destination;
uint16_t packet_num;
uint8_t packet_type;
uint8_t num_bundles;
//uint32_t numberBytesinPayload;
}
XL3_CommandHeader;
typedef
struct {
//uint32_t numBytes; //filled in automatically
XL3_CommandHeader cmdHeader;
char payload[kSBC_MaxPayloadSizeBytes];
}
XL3_Packet;
typedef
struct {
uint32_t word1;
uint32_t word2;
uint32_t word3;
}
PMTBundle;
// ############### vARIOUS GLOBALS ###################
int count_d;
MultiFC multifc_buffer;
int multifc_buffer_full;
int command_number;
// determines whether or not a log is opened for writing
int write_log; //(by default, false)
FILE *ps_log_file;
FILE *cald_test_file;
// timeout for select functions (any function that reads/writes)
struct timeval delay_value;
// output file
FILE *fp;
int sbc_is_connected;
int current_location;
uint32_t current_hv_level;
// WHERE TO SAVE TO DATABASE - DEBUG ENTRIES OR HW ENTRIES
int db_debug;
typedef struct {
uint16_t mb_id;
uint16_t dc_id[4];
} hware_vals_t;
hware_vals_t crate_config[19][16];
////////////////////////////////////////////
// for bundle readout speed test //
long int delta_t;
long int dt;
long int start_time;
long int new_time, old_time;
float rec_bytes;
float rec_fake_bytes;
// //
////////////////////////////////////////////
// ############### FUNCTION DECLARATIONS #################
void proc_xl3_rslt(XL3_Packet *packet, int crate_location,int numbytes);
int process_command(char *buffer);
int store_mega_bundle(int nbundles);
// various utilities
int get_xl3_location(int value, int array[]);
void set_delay_values(int seconds, int useconds);
void sigint_func(int sig);
void start_logging();
void stop_logging();
void SwapLongBlock(void* p, int32_t n);
void SwapShortBlock(void* p, int32_t n);
// from crate_init.c
int crate_init(char *buffer);
// from readout_test.c
int readout_test(char *buffer);
int readout_add_crate(char *buffer);
int readout_add_mtc(char *buffer);
int end_readout(char *buffer);
int change_pulser(char *buffer);
// from ped_run.c
int ped_run(char *buffer);
// from cgt_test_1.c
int cgt_test_1(char *buffer);
int mb_stability_test(char *buffer);
int fifo_test(char *buffer);
static void checkfifo(uint32_t *thediff, int crate_num, uint32_t select_reg,char* msg_buff);
// from cmos_m_gtvalid.c
int cmos_m_gtvalid(char *buffer);
// from cald_test.c
int cald_test(char *buffer);
// from chinj_test.c
int chinj_test(char *buffer);
// from final_test.c
int final_test(char *buffer);
// from disc_check.c
int disc_check(char *buffer);
#endif