forked from cms-gem-daq-project/xhal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rwreg.cpp
525 lines (468 loc) · 13.4 KB
/
rwreg.cpp
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xhal/rpc/wiscrpcsvc.h"
#define DLLEXPORT extern "C"
#define STANDARD_CATCH \
catch (wisc::RPCSvc::NotConnectedException &e) { \
printf("Caught NotConnectedException: %s\n", e.message.c_str()); \
return 1; \
} \
catch (wisc::RPCSvc::RPCErrorException &e) { \
printf("Caught RPCErrorException: %s\n", e.message.c_str()); \
return 1; \
} \
catch (wisc::RPCSvc::RPCException &e) { \
printf("Caught exception: %s\n", e.message.c_str()); \
return 1; \
} \
catch (wisc::RPCMsg::BadKeyException &e) { \
printf("Caught exception: %s\n", e.key.c_str()); \
return 0xdeaddead; \
}
#define ASSERT(x) do { \
if (!(x)) { \
printf("Assertion Failed on line %u: %s\n", __LINE__, #x); \
return 1; \
} \
} while (0)
static wisc::RPCSvc rpc;
static wisc::RPCMsg req, rsp;
DLLEXPORT uint32_t init(char * hostname)
{
try {
rpc.connect(hostname);
}
catch (wisc::RPCSvc::ConnectionFailedException &e) {
printf("Caught RPCErrorException: %s\n", e.message.c_str());
return 1;
}
catch (wisc::RPCSvc::RPCException &e) {
printf("Caught exception: %s\n", e.message.c_str());
return 1;
}
try {
ASSERT(rpc.load_module("memory", "memory v1.0.1"));
ASSERT(rpc.load_module("extras", "extras v1.0.1"));
ASSERT(rpc.load_module("utils", "utils v1.0.1"));
ASSERT(rpc.load_module("optohybrid", "optohybrid v1.0.1"));
ASSERT(rpc.load_module("amc", "amc v1.0.1"));
ASSERT(rpc.load_module("calibration_routines", "calibration_routines v1.0.1"));
ASSERT(rpc.load_module("vfat3", "vfat3 v1.0.1"));
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT uint32_t update_atdb(char * xmlfilename)
{
req = wisc::RPCMsg("utils.update_address_table");
req.set_string("at_xml", xmlfilename);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
if (rsp.get_key_exists("error")) {
return 1;
}
return 0;
}
DLLEXPORT uint32_t getRegInfoDB(char * regName)
{
uint32_t address, mask;
std::string permissions;
req = wisc::RPCMsg("utils.readRegFromDB");
req.set_string("reg_name", regName);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
if (rsp.get_key_exists("error")) {
return 1;
}
printf("Register %s is found \n",regName);
try {
address = rsp.get_word("address");
mask = rsp.get_word("mask");
permissions = rsp.get_string("permissions");
printf("Address: 0x%8x, permissions: %s, mask: 0x%8x \n", address, permissions.c_str(), mask);
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT uint32_t configureVT1(char * ohN, char * config, unsigned int vt1 = 0x64)
{
req = wisc::RPCMsg("optohybrid.loadVT1");
req.set_string("oh_number", ohN);
req.set_word("vt1",vt1);
if (config && config[0]!='\0') req.set_string("thresh_config_filename", config);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
return 0;
}
DLLEXPORT uint32_t configureTRIMDAC(char * ohN, char * config)
{
req = wisc::RPCMsg("optohybrid.loadTRIMDAC");
req.set_string("oh_number", ohN);
req.set_string("trim_config_filename", config);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
return 0;
}
DLLEXPORT uint32_t configureVFATs(char * ohN, char * trim_config, char * thresh_config, unsigned int set_run = 1, unsigned int vt1 = 0x64)
{
req = wisc::RPCMsg("optohybrid.configureVFATs");
req.set_string("oh_number", ohN);
req.set_word("vt1",vt1);
req.set_string("trim_config_filename", trim_config);
if (set_run) req.set_word("set_run", set_run);
if (thresh_config && thresh_config[0]!='\0') req.set_string("thresh_config_filename", thresh_config);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
return 0;
}
DLLEXPORT uint32_t vfatSyncCheck(uint32_t* result, unsigned int ohN){
req = wisc::RPCMsg("vfat3.vfatSyncCheck");
req.set_word("ohN", ohN);
try{
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
else {
rsp.get_word("goodVFATs", result);
}
}
STANDARD_CATCH;
return 0;
} //End vfatSyncCheck()
DLLEXPORT uint32_t configureVFAT3s(unsigned int ohN, unsigned int vfatMask){
req = wisc::RPCMsg("vfat3.configureVFAT3s");
req.set_word("ohN", ohN);
req.set_word("vfatMask", vfatMask)
try{
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
}
STANDARD_CATCH;
return 0;
} //End configureVFAT3s()
DLLEXPORT uint32_t configureTTC(unsigned int l1AInt, unsigned int pDelay){
req = wisc::RPCMsg("calibration_routines.ttcGenConf");
req.set_word("L1Ainterval",l1AInt);
req.set_word("pulseDelay",pDelay);
try{
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
return 0;
} //End configureTTC()
DLLEXPORT uint32_t getmonTTCmain(uint32_t* result)
{
req = wisc::RPCMsg("amc.getmonTTCmain");
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
else {
result[0] = rsp.get_word("MMCM_LOCKED");
result[1] = rsp.get_word("TTC_SINGLE_ERROR_CNT");
result[2] = rsp.get_word("BC0_LOCKED");
result[3] = rsp.get_word("L1A_ID");
result[4] = rsp.get_word("L1A_RATE");
}
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT uint32_t getmonTRIGGERmain(uint32_t* result, uint32_t noh = 10)
{
req = wisc::RPCMsg("amc.getmonTRIGGERmain");
req.set_word("NOH",noh);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
else {
std::string t;
result[0] = rsp.get_word("OR_TRIGGER_RATE");
for (int i = 0; i < noh; i++) {
t = "OH"+std::to_string(i)+".TRIGGER_RATE";
result[i+1] = rsp.get_word(t);
}
}
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT uint32_t getmonTRIGGEROHmain(uint32_t* result, uint32_t noh = 10)
{
req = wisc::RPCMsg("amc.getmonTRIGGEROHmain");
req.set_word("NOH",noh);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
else {
std::string t;
for (int i = 0; i < noh; i++) {
t = "OH"+std::to_string(i)+".LINK0_NOT_VALID_CNT";
result[i] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".LINK1_NOT_VALID_CNT";
result[i+noh] = rsp.get_word(t);
}
}
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT uint32_t getmonDAQmain(uint32_t* result)
{
req = wisc::RPCMsg("amc.getmonDAQmain");
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
else {
result[0] = rsp.get_word("DAQ_ENABLE");
result[1] = rsp.get_word("DAQ_LINK_READY");
result[2] = rsp.get_word("DAQ_LINK_AFULL");
result[3] = rsp.get_word("DAQ_OFIFO_HAD_OFLOW");
result[4] = rsp.get_word("L1A_FIFO_HAD_OFLOW");
result[5] = rsp.get_word("L1A_FIFO_DATA_COUNT");
result[6] = rsp.get_word("DAQ_FIFO_DATA_COUNT");
result[7] = rsp.get_word("EVENT_SENT");
result[8] = rsp.get_word("TTS_STATE");
}
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT uint32_t getmonDAQOHmain(uint32_t* result, uint32_t noh = 10)
{
req = wisc::RPCMsg("amc.getmonDAQOHmain");
req.set_word("NOH",noh);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
else {
std::string t;
for (int i = 0; i < noh; i++) {
t = "OH"+std::to_string(i)+".STATUS.EVT_SIZE_ERR";
result[i] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".STATUS.EVENT_FIFO_HAD_OFLOW";
result[i+noh] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".STATUS.INPUT_FIFO_HAD_OFLOW";
result[i+2*noh] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".STATUS.INPUT_FIFO_HAD_UFLOW";
result[i+3*noh] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".STATUS.VFAT_TOO_MANY";
result[i+4*noh] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".STATUS.VFAT_NO_MARKER";
result[i+5*noh] = rsp.get_word(t);
}
}
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT uint32_t getmonOHmain(uint32_t* result, uint32_t noh = 10)
{
req = wisc::RPCMsg("amc.getmonOHmain");
req.set_word("NOH",noh);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
else {
std::string t;
for (int i = 0; i < noh; i++) {
t = "OH"+std::to_string(i)+".FW_VERSION";
result[i] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".EVENT_COUNTER";
result[i+noh] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".EVENT_RATE";
result[i+2*noh] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".GTX.TRK_ERR";
result[i+3*noh] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".GTX.TRG_ERR";
result[i+4*noh] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".GBT.TRK_ERR";
result[i+5*noh] = rsp.get_word(t);
t = "OH"+std::to_string(i)+".CORR_VFAT_BLK_CNT";
result[i+6*noh] = rsp.get_word(t);
}
}
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT unsigned long getReg(unsigned int address)
{
req = wisc::RPCMsg("memory.read");
req.set_word("address", address);
req.set_word("count", 1);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
uint32_t result;
try{
if (rsp.get_key_exists("error")) {
return 0xdeaddead;
}
else {
ASSERT(rsp.get_word_array_size("data") == 1);
rsp.get_word_array("data", &result);
}
}
STANDARD_CATCH;
return result;
}
DLLEXPORT unsigned long getBlock(unsigned int address, uint32_t* result, ssize_t size)
{
req = wisc::RPCMsg("extras.blockread");
req.set_word("address", address);
req.set_word("count", size);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
return 1;
}
else {
ASSERT(rsp.get_word_array_size("data") == size);
rsp.get_word_array("data", result);
}
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT unsigned long getList(uint32_t* addresses, uint32_t* result, ssize_t size)
{
req = wisc::RPCMsg("extras.listread");
req.set_word_array("addresses", addresses,size);
req.set_word("count", size);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
return 1;
}
else {
ASSERT(rsp.get_word_array_size("data") == size);
rsp.get_word_array("data", result);
}
}
STANDARD_CATCH;
return 0;
}
DLLEXPORT unsigned long putReg(unsigned int address, unsigned int value)
{
req = wisc::RPCMsg("memory.write");
req.set_word("address", address);
req.set_word_array("data", &value,1);
try {
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
if (rsp.get_key_exists("error")) {
return 0xdeaddead;
}
else return value;
}
DLLEXPORT uint32_t scanDAC(uint32_t* result, ssize_t size,
unsigned int ohN, unsigned int vfatMask, unsigned int chan, std::string scanReg,
unsigned int nEvts, unsigned int scanMin, unsigned int scanMax, unsigned int stepSize){
req = wisc::RPCMsg("calibration_routines.genScan");
req.set_word("ohN",ohN);
req.set_word("mask",vfatMask);
req.set_word("ch",chan);
req.set_word("scanReg",scanReg);
req.set_word("nevts",nEvts);
req.set_word("dacMin",scanMin);
req.set_word("dacMax",scanMax);
req.set_word("dacStep",stepSize);
try{
rsp = rpc.call_method(req);
}
STANDARD_CATCH;
try{
if (rsp.get_key_exists("error")) {
printf("Error: %s",rsp.get_string("error").c_str());
return 1;
}
else {
ASSERT(rsp.get_word_array_size("data") == size);
rsp.get_word_array("data", result);
}
}
STANDARD_CATCH;
return 0;
} //End scanDAC()