-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontend.cpp
More file actions
3805 lines (3196 loc) · 164 KB
/
Copy pathfrontend.cpp
File metadata and controls
3805 lines (3196 loc) · 164 KB
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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* @file frontends/CaloReadoutAMC13/frontend.cpp
* @author Wes Gohn, Vladimir Tishchenko, Tim Gorringe
* @date Thu May 24 10:08:59 2012 (-0500)
* @date Last-Updated: Tue Oct 13 16:47:31 2018 (-0400)
* Update #: 954
* @version $Id$
*
* @copyright (c) (g-2) collaboration
*
* @brief 10GbE AMC13 readout frontend for (g-2)
*
* @ingroup page_frontends
*
* @details This frontend processes calorimeter and other data from an AMC13 over 10 Gbe
*
*
*
* @section Changelog
* @verbatim
* $Log$
* @endverbatim
*
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <midas.h>
#include <mfe.h>
#include <msystem.h>
#ifdef USE_PARALLEL_PORT // parallel port access
#include <sys/io.h>
#include <string.h>
#include <string>
int pp_addr = 0x37f;
#endif
#ifdef USE_GPU
#include <cuda.h>
#include <cuda_runtime_api.h>
#include "cuda_tools_g2.h"
#endif
#include "gpu_fit.hh" // for fit results
#include "experiment.h"
#include "frontend.h"
//#include "frontend_rpc.h"
#include "tcp_thread.h"
#include "gpu_thread.h"
#include "fe_compress_z_mt.h"
#include "amc13_odb.h"
#include "AMC13.hpp"
#include "FC7.hpp"
#include "WFD5.hpp"
#include "laser_config_handler.h"
#include "uhal/uhal.hpp"
#include "uhal/utilities/xml.hpp"
#include "uhal/log/exception.hpp"
#include "uhal/ProtocolUDP.hpp"
#include "boost/filesystem/operations.hpp"
#include "boost/algorithm/string.hpp"
#ifdef DEBUG
#define dbprintf(...) printf(__VA_ARGS__)
#else
#define dbprintf(...)
#endif
// counters for total trigger and got triggers in each run
int total_triggers_in_run = -1;
int got_triggers_in_run = 0;
BOOL got_triggers_sent = TRUE;
float dt_READY = 0.0;
int n_dt_READYs = 0;
unsigned long Midasfillnumber;
std::string MonitorODBRootKey;
/*
float toddiff(struct timeval *tod2, struct timeval *tod1) {
float fdt, fmudt;
long long t1, t2, mut1, mut2;
long long dt, mudt;
t1 = tod1->tv_sec;
mut1 = tod1->tv_usec;
t2 = tod2->tv_sec;
mut2 = tod2->tv_usec;
dt = (t2 - t1);
mudt = (mut2 - mut1);
fdt = (float)dt;
fmudt = (float)mudt;
return 1.0e6*fdt + fmudt;
} */
/*
* Trigger information
*/
/*
DWORD trigger_nr; // trigger number (via RPC message from master)
DWORD trigger_mask; // trigger mask (via RPC message from master)
DWORD time_master_got_eof_s; // master EOF trigger time (via RPC message from master), seconds
DWORD time_master_got_eof_us; // master EOF trigger time (via RPC message from master), microseconds
DWORD time_slave_got_eof_s; // slave EOF trigger time called from master via RPC message, seconds
DWORD time_slave_got_eof_us; // slave EOF trigger time called from master via RPC message, microseconds
DWORD time_slave_got_data_s; // slave got data fron tcp_thread and unloacked tcp_thread, seconds
DWORD time_slave_got_data_us; // slave got data fron tcp_thread and unloacked tcp_thread, microseconds
DWORD time_slave_lock_dataready_s; // slave locking mutex_data_ready in read_trigger_event
DWORD time_slave_lock_dataready_us; // slave locking mutex_data_ready in read_trigger_event
DWORD time_tcp_start_read_s; // start time of tcp read in tcp_thread, seconds
DWORD time_tcp_start_read_us; // start time of tcp read in tcp_thread, microseconds
DWORD time_tcp_finish_header_read_s; // finish time of tcp read in tcp_thread, seconds
DWORD time_tcp_finish_header_read_us; // finish time of tcp read in tcp_thread, microseconds
DWORD time_tcp_finish_data_read_s; // finish time of tcp read in tcp_thread, seconds
DWORD time_tcp_finish_data_read_us; // finish time of tcp read in tcp_thread, microseconds
DWORD time_gputhread_started_s; // woke-up gpu_thread for processing, seconds
DWORD time_gputhread_started_us; // woke-up gpu_thread for processing, microseconds
DWORD time_gputhread_copytogpu_done_s; // copy to gpu done, seconds
DWORD time_gputhread_copytogpu_done_us; // copy to gpu done, microseconds
DWORD time_gputhread_finished_s; // gpu_thread finished processing, seconds
DWORD time_gputhread_finished_us; // gpu_thread finished processing, microseconds
*/
S_TRIGGER_INFO trigger_info;
/* make frontend functions callable from the C framework */
//#ifdef __cplusplus
//extern "C" {
//#endif
/*-- Globals -------------------------------------------------------*/
// map from detector index in CT bank to rider module,channel to find thresholds for truncated calo bank processing
int map_from_caloxy_to_ridermodchan[60][TQMETHOD_MAX];
// declare WFD5 and AMC13 access objects
AMC13 *amc13lib = new AMC13();
FC7 *fc7lib = new FC7();
WFD5 *wfdlib = new WFD5();
uhal::HwInterface *amc13[2];
uhal::HwInterface *fc7[12];
uhal::HwInterface *wfd[12];
// Class to handle laser config.
g2laser::LaserConfigHandler *laser_config_handler = NULL;
// The frontend name (client name) as seen by other MIDAS clients
const char *frontend_name = "AMC13";
// The frontend file name, don't change it
const char *frontend_file_name = __FILE__;
// ODB database handle
extern HNDLE hDB;
// frontend_loop is called periodically if this variable is TRUE
BOOL frontend_call_loop = FALSE; //Set by Ran Hong
// frontend status page is displayed with this frequency in ms
INT display_period = 0;
// maximum event size produced by this frontend
INT max_event_size = DEFAULT_MAX_EVENT_SIZE / 2;
// maximum event size for fragmented events (EQ_FRAGMENTED)
INT max_event_size_frag = 0;
// buffer size to hold events
INT event_buffer_size = DEFAULT_MAX_EVENT_SIZE;
extern INT run_state; // run state (STATE_RUNNING, ...)
//extern INT frontend_index; // frontend index from command line argument -i
INT frontend_index_offset = CALO_READOUT_FE_INDEX_OFFSET; // for CaloReadoutAMC13
pthread_mutex_t mutex_midas = PTHREAD_MUTEX_INITIALIZER;
/*-- Local variables -----------------------------------------------*/
static int block_nr; // acquisition block number
int MIN_ISLAND_LENGTH = 25;
int encoder_fc7_slot = -1;
int trigger_fc7_slot = -1;
// for call to compress_z_eor in read_trigger_event()
INT run_number_compress_z_eor;
char* error_compress_z_eor;
/*-- Function declarations -----------------------------------------*/
// extern "C" {
INT amc13_odb_check();
INT fc7_odb_check();
INT wfd_odb_check();
INT frontend_init_fc7();
INT frontend_init_wfd();
INT frontend_init();
INT frontend_exit();
INT begin_of_run_wfd();
INT begin_of_run(INT run_number, char *error);
INT end_of_run(INT run_number, char *error);
INT pause_run(INT run_number, char *error);
INT resume_run(INT run_number, char *error);
INT frontend_loop();
INT interrupt_configure(INT cmd, INT source, POINTER_T adr);
INT poll_event(INT source, INT count, BOOL test);
INT read_trigger_event(char *pevent, INT off);
// INT rpc_g2_end_of_fill(INT index, void *prpc_param[]);
// INT rpc_g2_arm_sampling_logic(INT index, void *prpc_param[]);
// INT rpc_g2_recv_trigger_number(INT index, void *prpc_param[]);
//extern int send_event(INT idx, BOOL manual_trig);
// };
/*-- Equipment list ------------------------------------------------*/
/**
* @brief AMC13
* @details MIDAS equipment for uTCA with AMC13, FC7, and WFD5 boards
* @ingroup group_equipment
*/
EQUIPMENT equipment[] = {
{
"AMC13%02d", /* equipment name */
{1, 0xffff, /* event ID, trigger mask */
"BUF%02d", /* event buffer */
EQ_POLLED | EQ_EB, /* equipment type */
LAM_SOURCE(0, 0xFFFFFF), /* event source crate 0, all stations */
"MIDAS", /* format */
TRUE, /* enabled */
RO_RUNNING , /* read only when running and end of run */
10, /* poll for 1ms */
0, /* stop run after this event limit */
0, /* number of sub events */
0, /* don't log history */
"", "", "", /* frontend host, frontend name, frontend file name */
"", "", FALSE}, /* status, status color, hidden */
read_trigger_event, /* readout routine */
},
{""}
};
//#ifdef __cplusplus
//}
//#endif
/*-- Frontend Init -------------------------------------------------*/
/**
* Frontend Init
* This routing is called when the frontend program is started.
*
* @return SUCCESS if success
*/
// Verify AMC13 ODB parameter values
INT amc13_odb_check()
{
std::vector<const char *> messages;
// T1 Firmware Version Required
if (amc13_amc13_odb.t1_fw_version > 65535) {
messages.push_back("/AMC13/: Invalid \"T1 Firmware Version Required\"");
}
// T2 Firmware Version Required
if (amc13_amc13_odb.t2_fw_version > 65535) {
messages.push_back("/AMC13/: Invalid \"T2 Firmware Version Required\"");
}
/*
// Note: The uhal::HwInterface initialization is now responsible for catching
// invalid address table locations. This is because environment variables
// are now being used to specify the file locations. The needed logic to
// expand the environmet variable is possible but like not needed.
// T1 Address Table Location
if (!boost::filesystem::exists(amc13_amc13_odb.addrTab1)) {
messages.push_back("/AMC13/: Invalid \"T1 Address Table Location\"");
}
// T2 Address Table Location
if (!boost::filesystem::exists(amc13_amc13_odb.addrTab2)) {
messages.push_back("/AMC13/: Invalid \"T2 Address Table Location\"");
}
*/
// Enabled
if (amc13_link_odb[0].enabled) {
// AMC13 SFP Port Number
if (amc13_link_odb[0].source_port > 65535) {
messages.push_back("/Link01/: Invalid \"AMC13 SFP Port Number\"");
}
// AMC13 SFP IP Address
struct in_addr amc13_sfp_addr;
if (inet_aton(amc13_link_odb[0].source_ip, &amc13_sfp_addr) == 0) {
messages.push_back("/Link01/: Invalid \"AMC13 SFP IP Address\"");
}
} // if link enabled
if (messages.size() > 0) {
for (unsigned int i = 0; i < messages.size(); ++i) {
cm_msg(MERROR, __FUNCTION__, messages.at(i));
}
return FE_ERR_ODB;
}
return SUCCESS;
} // amc13_odb_check
// Verify FC7 ODB parameter values
INT fc7_odb_check()
{
std::vector<const char *> messages;
std::vector<int> slots;
for (int i = 0; i < 12; ++i) {
// Enabled
// Frontend Configuration Enabled
if (amc13_fc7_odb[i].common.enabled &&
amc13_fc7_odb[i].common.fe_config_enabled) {
/*
// Note: The uhal::HwInterface initialization is now responsible for catching
// invalid address table locations. This is because environment variables
// are now being used to specify the file locations. The needed logic to
// expand the environmet variable is possible but like not needed.
// Address Table Location
if (!boost::filesystem::exists(amc13_fc7_odb[i].common.addr_table_file)) {
messages.push_back("/FC7-%02i/Common/: Invalid \"Address Table Location\"");
}
*/
// Board Type
boost::algorithm::to_lower( amc13_fc7_odb[i].common.board_type );
if (strcmp(amc13_fc7_odb[i].common.board_type, "encoder") != 0 &&
strcmp(amc13_fc7_odb[i].common.board_type, "fanout") != 0 &&
strcmp(amc13_fc7_odb[i].common.board_type, "trigger") != 0) {
messages.push_back("/FC7-%02i/Common/: Invalid \"Board Type\"");
}
// FPGA Firmware Version Required
struct in_addr fw_ver;
if (inet_aton(amc13_fc7_odb[i].common.firmware_version, &fw_ver) == 0) {
messages.push_back("/FC7-%02i/Common/: Invalid \"FPGA Firmware Version Required\"");
}
// Threshold: Client Overflow
if (amc13_fc7_odb[i].encoder.thres_overflow > 16777215) {
messages.push_back("/FC7-%02i/Encoder/: Invalid \"Threshold: Client Overflow\"");
}
// Threshold: Cycle Start Gap
if (amc13_fc7_odb[i].encoder.thres_cycle_start_gap % 25 != 0) {
messages.push_back("/FC7-%02i/Encoder/: Invalid \"Threshold: Cycle Start Gap\"");
}
// TTS Lock: Total Length
if (amc13_fc7_odb[i].common.thres_tts_lock % 25 != 0) {
messages.push_back("/FC7-%02i/Common/: Invalid \"TTS Lock: Total Length\"");
}
// TTS Lock: Valid Length
if (amc13_fc7_odb[i].common.thres_tts_valid % 25 != 0 ||
amc13_fc7_odb[i].common.thres_tts_valid > amc13_fc7_odb[i].common.thres_tts_lock) {
messages.push_back("/FC7-%02i/Common/: Invalid \"TTS Lock: Valid Length\"");
}
// Input Trigger Select
boost::algorithm::to_lower( amc13_fc7_odb[i].encoder.input_trig_sel );
if (strcmp(amc13_fc7_odb[i].encoder.input_trig_sel, "left") != 0 &&
strcmp(amc13_fc7_odb[i].encoder.input_trig_sel, "right") != 0) {
messages.push_back("/FC7-%02i/Encoder/: Invalid \"Input Trigger Select\"");
}
// Post-Reset Delay: Trigger Count
if (amc13_fc7_odb[i].encoder.post_reset_delay_count % 25 != 0) {
messages.push_back("/FC7-%02i/Encoder/: Invalid \"Post-Reset Delay: Trigger Count\"");
}
// Post-Reset Delay: Timestamp
if (amc13_fc7_odb[i].encoder.post_reset_delay_timestamp % 25 != 0) {
messages.push_back("/FC7-%02i/Encoder/: Invalid \"Post-Reset Delay: Timestamp\"");
}
// Left Trigger Output: Short Pulse Width
if (amc13_fc7_odb[i].lotrig.short_pulse_width < 25 ||
amc13_fc7_odb[i].lotrig.short_pulse_width > 6375 ||
amc13_fc7_odb[i].lotrig.short_pulse_width % 25 != 0) {
messages.push_back("/FC7-%02i/Left Trigger Output/: Invalid \"Short Pulse Width\"");
}
// Left Trigger Output: Long Pulse Width
if (amc13_fc7_odb[i].lotrig.long_pulse_width < 25 ||
amc13_fc7_odb[i].lotrig.long_pulse_width > 6375 ||
amc13_fc7_odb[i].lotrig.long_pulse_width % 25 != 0) {
messages.push_back("/FC7-%02i/Left Trigger Output/: Invalid \"Long Pulse Width\"");
}
// Left Trigger Output: Trigger Type XX: Width
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_00 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_01 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_02 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_03 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_04 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_05 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_06 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_07 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_08 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_09 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_10 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_11 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_12 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_13 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_14 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_15 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_16 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_17 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_18 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_19 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_20 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_21 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_22 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_23 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_24 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_25 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_26 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_27 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_28 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_29 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_30 );
boost::algorithm::to_lower( amc13_fc7_odb[i].lotrig.width_31 );
std::vector<const char *> left_output_width_xx;
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_00 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_01 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_02 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_03 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_04 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_05 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_06 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_07 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_08 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_09 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_10 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_11 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_12 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_13 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_14 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_15 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_16 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_17 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_18 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_19 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_20 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_21 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_22 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_23 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_24 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_25 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_26 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_27 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_28 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_29 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_30 );
left_output_width_xx.push_back( amc13_fc7_odb[i].lotrig.width_31 );
for (int j = 0; j < 32; ++j) {
if (strcmp(left_output_width_xx.at(j), "disabled") != 0 &&
strcmp(left_output_width_xx.at(j), "short") != 0 &&
strcmp(left_output_width_xx.at(j), "long") != 0) {
messages.push_back("/FC7-%02i/Left Trigger Output/: Invalid \"Trigger Type XX: Width\"");
break; // send only one message
}
}
// Left Trigger Output: Trigger Type XX: Delay
std::vector<DWORD> left_output_delay_xx;
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_00 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_01 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_02 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_03 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_04 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_05 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_06 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_07 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_08 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_09 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_10 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_11 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_12 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_13 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_14 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_15 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_16 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_17 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_18 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_19 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_20 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_21 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_22 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_23 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_24 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_25 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_26 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_27 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_28 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_29 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_30 );
left_output_delay_xx.push_back( amc13_fc7_odb[i].lotrig.delay_31 );
for (int j = 0; j < 32; ++j) {
if (left_output_delay_xx.at(j) % 25 != 0) {
messages.push_back("/FC7-%02i/Left Trigger Output/: Invalid \"Trigger Type XX: Delay (ns)\"");
break; // send only one message
}
}
// Right Trigger Output: Short Pulse Width
if (amc13_fc7_odb[i].rotrig.short_pulse_width < 25 ||
amc13_fc7_odb[i].rotrig.short_pulse_width > 6375 ||
amc13_fc7_odb[i].rotrig.short_pulse_width % 25 != 0) {
messages.push_back("/FC7-%02i/Right Trigger Output/: Invalid \"Short Pulse Width\"");
}
// Right Trigger Output: Long Pulse Width
if (amc13_fc7_odb[i].rotrig.long_pulse_width < 25 ||
amc13_fc7_odb[i].rotrig.long_pulse_width > 6375 ||
amc13_fc7_odb[i].rotrig.long_pulse_width % 25 != 0) {
messages.push_back("/FC7-%02i/Right Trigger Output/: Invalid \"Long Pulse Width\"");
}
// Right Trigger Output: Trigger Type XX: Width
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_00 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_01 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_02 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_03 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_04 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_05 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_06 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_07 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_08 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_09 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_10 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_11 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_12 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_13 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_14 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_15 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_16 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_17 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_18 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_19 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_20 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_21 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_22 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_23 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_24 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_25 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_26 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_27 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_28 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_29 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_30 );
boost::algorithm::to_lower( amc13_fc7_odb[i].rotrig.width_31 );
std::vector<const char *> right_output_width_xx;
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_00 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_01 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_02 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_03 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_04 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_05 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_06 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_07 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_08 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_09 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_10 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_11 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_12 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_13 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_14 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_15 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_16 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_17 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_18 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_19 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_20 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_21 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_22 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_23 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_24 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_25 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_26 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_27 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_28 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_29 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_30 );
right_output_width_xx.push_back( amc13_fc7_odb[i].rotrig.width_31 );
for (int j = 0; j < 32; ++j) {
if (strcmp(left_output_width_xx.at(j), "disabled") != 0 &&
strcmp(left_output_width_xx.at(j), "short") != 0 &&
strcmp(left_output_width_xx.at(j), "long") != 0) {
messages.push_back("/FC7-%02i/Right Trigger Output/: Invalid \"Trigger Type XX: Width\"");
break; // send only one message
}
}
// Right Trigger Output: Trigger Type XX: Delay
std::vector<DWORD> right_output_delay_xx;
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_00 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_01 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_02 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_03 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_04 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_05 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_06 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_07 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_08 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_09 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_10 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_11 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_12 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_13 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_14 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_15 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_16 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_17 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_18 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_19 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_20 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_21 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_22 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_23 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_24 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_25 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_26 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_27 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_28 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_29 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_30 );
right_output_delay_xx.push_back( amc13_fc7_odb[i].rotrig.delay_31 );
for (int j = 0; j < 32; ++j) {
if (left_output_delay_xx.at(j) % 25 != 0) {
messages.push_back("/FC7-%02i/Right Trigger Output/: Invalid \"Trigger Type XX: Delay (ns)\"");
break; // send only one message
}
}
for (unsigned int j = 0; j < messages.size(); ++j) {
slots.push_back(i+1);
}
} // if board enabled
} // for slot
if (messages.size() > 0) {
for (unsigned int i = 0; i < messages.size(); ++i) {
cm_msg(MERROR, __FUNCTION__, messages.at(i), slots.at(i));
}
return FE_ERR_ODB;
}
return SUCCESS;
} // fc7_odb_check
// Verify WFD5 ODB parameter values
INT wfd_odb_check()
{
std::vector<const char *> messages;
std::vector<int> slots, channels;
for (int i = 0; i < 12; ++i) {
// Enabled
// Frontend Configuration Enabled
if (amc13_rider_odb[i].board.rider_enabled &&
amc13_rider_odb[i].board.fe_config_enabled) {
/*
// Note: The uhal::HwInterface initialization is now responsible for catching
// invalid address table locations. This is because environment variables
// are now being used to specify the file locations. The needed logic to
// expand the environmet variable is possible but like not needed.
// Address Table Location
if (!boost::filesystem::exists(amc13_rider_odb[i].board.addr_table_file)) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Address Table Location\"");
}
*/
// FPGA Firmware Version Required
struct in_addr mfw_ver;
if (inet_aton(amc13_rider_odb[i].board.firmware_version, &mfw_ver) == 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"FPGA Firmware Version Required\"");
}
// Digitization Frequency
if (strcmp(amc13_rider_odb[i].board.digitizer_freq, "800") != 0 &&
strcmp(amc13_rider_odb[i].board.digitizer_freq, "600") != 0 &&
strcmp(amc13_rider_odb[i].board.digitizer_freq, "400") != 0 &&
strcmp(amc13_rider_odb[i].board.digitizer_freq, "300") != 0 &&
strcmp(amc13_rider_odb[i].board.digitizer_freq, "200") != 0 &&
strcmp(amc13_rider_odb[i].board.digitizer_freq, "100") != 0 &&
strcmp(amc13_rider_odb[i].board.digitizer_freq, "80") != 0 &&
strcmp(amc13_rider_odb[i].board.digitizer_freq, "60") != 0 &&
strcmp(amc13_rider_odb[i].board.digitizer_freq, "40") != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Digitization Frequency (MHz)\"");
}
// Front Panel Clock Enabled
if (amc13_rider_odb[i].board.fp_clock_enabled) {
// Front Panel Clock Frequency
boost::algorithm::to_lower( amc13_rider_odb[i].board.fp_clock_freq );
if (strcmp(amc13_rider_odb[i].board.fp_clock_freq, "ttc") != 0 &&
strcmp(amc13_rider_odb[i].board.fp_clock_freq, "digitization") != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Front Panel Clock Frequency\"");
}
}
// ADC Data Endianness
boost::algorithm::to_lower( amc13_rider_odb[i].board.ADC_endianness );
if (strcmp(amc13_rider_odb[i].board.ADC_endianness, "big") != 0 &&
strcmp(amc13_rider_odb[i].board.ADC_endianness, "little") != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"ADC Data Endianness\"");
}
// Trigger Delay
if (amc13_rider_odb[i].board.trig_delay % 25 != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Delay (ns)\"");
}
// Async Mode: Enabled
if (amc13_rider_odb[i].board.asyncmode_enabled) {
// Async Mode: Waveform Length
if (amc13_rider_odb[i].board.asyncmode_wvfm_length > 131064 ||
amc13_rider_odb[i].board.asyncmode_wvfm_length % 8 != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Async Mode: Waveform Length\"");
}
// Async Mode: Waveform Presamples
if (amc13_rider_odb[i].board.asyncmode_wvfm_presamples > 131064 ||
amc13_rider_odb[i].board.asyncmode_wvfm_length % 2 != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Async Mode: Waveform Presamples\"");
}
}
// Trigger Type 1: Enabled
if (amc13_rider_odb[i].board.trig1_enabled) {
// Trigger Type 1: Waveform Count
if (amc13_rider_odb[i].board.trig1__wvfm_count > 4095) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Type 1: Waveform Count\"");
}
// Trigger Type 1: Waveform Length
if (amc13_rider_odb[i].board.trig1__wvfm_length > 66944960 ||
amc13_rider_odb[i].board.trig1__wvfm_length % 8 != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Type 1: Waveform Length\"");
}
// Trigger Type 1: Waveform Gap
if (amc13_rider_odb[i].board.trig1__wvfm_gap < 16 ||
amc13_rider_odb[i].board.trig1__wvfm_gap > 8388606 ||
amc13_rider_odb[i].board.trig1__wvfm_gap % 2 != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Type 1: Waveform Gap\"");
}
}
// Trigger Type 2: Enabled
if (amc13_rider_odb[i].board.trig2_enabled) {
// Trigger Type 2: Waveform Count
if (amc13_rider_odb[i].board.trig2__wvfm_count > 4095) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Type 2: Waveform Count\"");
}
// Trigger Type 2: Waveform Length
if (amc13_rider_odb[i].board.trig2__wvfm_length > 66944960 ||
amc13_rider_odb[i].board.trig2__wvfm_length % 8 != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Type 2: Waveform Length\"");
}
// Trigger Type 2: Waveform Gap
if (amc13_rider_odb[i].board.trig2__wvfm_gap < 16 ||
amc13_rider_odb[i].board.trig2__wvfm_gap > 8388606 ||
amc13_rider_odb[i].board.trig2__wvfm_gap % 2 != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Type 2: Waveform Gap\"");
}
}
// Trigger Type 3: Enabled
if (amc13_rider_odb[i].board.trig3_enabled) {
// Trigger Type 3: Waveform Count
if (amc13_rider_odb[i].board.trig3__wvfm_count > 4095) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Type 3: Waveform Count\"");
}
// Trigger Type 3: Waveform Length
if (amc13_rider_odb[i].board.trig3__wvfm_length > 66944960 ||
amc13_rider_odb[i].board.trig3__wvfm_length % 8 != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Type 3: Waveform Length\"");
}
// Trigger Type 3: Waveform Gap
if (amc13_rider_odb[i].board.trig3__wvfm_gap < 16 ||
amc13_rider_odb[i].board.trig3__wvfm_gap > 8388606 ||
amc13_rider_odb[i].board.trig3__wvfm_gap % 2 != 0) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Trigger Type 3: Waveform Gap\"");
}
}
// Error Threshold: DDR3 Overflow
if (amc13_rider_odb[i].board.error_thres_DDR3ovflw > 8388608) {
messages.push_back("/WFD5-%02i/Board/: Invalid \"Error Threshold: DDR3 Overflow\"");
}
for (unsigned int j = 0; j < messages.size(); ++j) {
slots.push_back(i+1);
channels.push_back(-1); // not used
}
for (int j = 0; j < 5; ++j) {
// Enabled
// Frontend Configuration Enabled
if (amc13_rider_odb[i].channel[j].enabled &&
amc13_rider_odb[i].channel[j].fe_config_enabled) {
// FPGA Firmware Version Required
struct in_addr cfw_ver;
if (inet_aton(amc13_rider_odb[i].channel[j].FPGA_firmware_version, &cfw_ver) == 0) {
messages.push_back("/WFD5-%02i/Channel%02i/: Invalid \"FPGA Firmware Version Required\"");
slots.push_back(i+1);
channels.push_back(j);
}
// Input Signal Offset
if (amc13_rider_odb[i].channel[j].input_signal_offset < 0 ||
amc13_rider_odb[i].channel[j].input_signal_offset > 65535) {
messages.push_back("/WFD5-%02i/Channel%02i/: Invalid \"Input Signal Offset\"");
slots.push_back(i+1);
channels.push_back(j);
}
} // if channel enabled
} // for channel
} // if board enabled
} // for slot
if (messages.size() > 0) {
for (unsigned int i = 0; i < messages.size(); ++i) {
cm_msg(MERROR, __FUNCTION__, messages.at(i), slots.at(i), channels.at(i));
}
return FE_ERR_ODB;
}
return SUCCESS;
} // wfd_odb_check
INT frontend_init_fc7()
{
/* Level 1 initialization */
for (int i = 0; i < 12; ++i) {
if (amc13_fc7_odb[i].common.enabled) {
// read device address
std::string fc7_ip = fc7lib->getAddress(10, 2, amc13_settings_odb.mch_ip_addr, (i+1));
printf("%s(%d): Slot %02i: Read FC7 IP Address: %s \n", __FUNCTION__, __LINE__, (i+1), fc7_ip.c_str());
if (fc7_ip == "") {
cm_msg(MERROR, __FUNCTION__, "FC7-%02i: IP Address Read Failed", (i+1));
return FE_ERR_HW;
}
// initialize device object
try {
std::stringstream uri; uri << "ipbusudp-2.0://" << fc7_ip << ":50001";
std::stringstream atf; atf << "file://" << amc13_fc7_odb[i].common.addr_table_file;
fc7[i] = new uhal::HwInterface( uhal::ConnectionManager::getDevice("hw_id", uri.str(), atf.str()) );
} catch (uhal::exception::exception& e) {
cm_msg(MERROR, __FUNCTION__, "/FC7-%02i/Common/: Invalid \"Address Table Location\"", (i+1));
printf("%s(%d): uHAL Exception: %s \n", __FUNCTION__, __LINE__, e.what());
return FE_ERR_ODB;
}
} // if slot enabled
} // for slot
for (int i = 0; i < 12; ++i) {
if (amc13_fc7_odb[i].common.enabled) {
// Note: Do not issue a hard reset here because it would disable all
// of the SFP ports that were enabled by MasterGM2 init.
// firmware soft reset
sleep(1); // inter-command delay
printf("%s(%d): Slot %02i: FC7 Firmware Soft Reset \n", __FUNCTION__, __LINE__, (i+1));
if (fc7lib->resetFirmware(3, 1, fc7[i], 0) == -1) {
cm_msg(MERROR, __FUNCTION__, "FC7-%02i: FPGA Communication Failed", (i+1));
return FE_ERR_HW;
}
} // if slot enabled
} // for slot
// post-reset delay
printf("%s(%d): Waiting 5 s ... \n", __FUNCTION__, __LINE__);
sleep(5);
/* Level 1 configuration */
double inter_cmd_delay = 0.1;
for (int i = 0; i < 12; ++i) {
if (amc13_fc7_odb[i].common.enabled) {
printf("%s(%d): Slot %02i: FC7 Configuration Initiated \n", __FUNCTION__, __LINE__, (i+1));
// Frontend Configuration Enabled
if (amc13_fc7_odb[i].common.fe_config_enabled) {
// FPGA Firmware Version
char addr_hex[9];
sprintf(addr_hex, "%08x", inet_addr(amc13_fc7_odb[i].common.firmware_version));
std::stringstream ss_fw_ver;
ss_fw_ver << addr_hex[6] << addr_hex[7];
ss_fw_ver << addr_hex[4] << addr_hex[5];
ss_fw_ver << addr_hex[0] << addr_hex[1];
std::string fw_ver_str = ss_fw_ver.str();
int fw_ver = strtol(fw_ver_str.c_str(), NULL, 16);
sleep(inter_cmd_delay); // inter-command delay
printf("%s(%d): Slot %02i: Read: FPGA Firmware Version \n", __FUNCTION__, __LINE__, (i+1));
int val_read = fc7lib->getFirmwareVersion(3, 1, fc7[i]);
if (val_read == -1) {
cm_msg(MERROR, __FUNCTION__, "FC7-%02i: FPGA Communication Failed", (i+1));
return FE_ERR_HW;
} else if (val_read != fw_ver) {
cm_msg(MERROR, __FUNCTION__, "/FC7-%02i/Common/: Conflict: \"FPGA Firmware Version\"", (i+1));
return FE_ERR_HW;
}
// Board Type
sleep(inter_cmd_delay); // inter-command delay
printf("%s(%d): Slot %02i: Read: Board Type \n", __FUNCTION__, __LINE__, (i+1));
int brd_type = 1; // encoder
if (strcmp(amc13_fc7_odb[i].common.board_type, "fanout") == 0) {
brd_type = 2;
} else if (strcmp(amc13_fc7_odb[i].common.board_type, "trigger") == 0) {
brd_type = 3;
}
val_read = fc7lib->getBoardType(2, 1, fc7[i]);
printf("i = %d, val_read = %d, brd_type = %d\n",i,val_read,brd_type);
if (val_read == -1) {
cm_msg(MERROR, __FUNCTION__, "FC7-%02i: FPGA Communication Failed", (i+1));
return FE_ERR_HW;
} else if (val_read != brd_type) {
cm_msg(MERROR, __FUNCTION__, "/FC7-%02i/Common/: Conflict: \"Board Type\"", (i+1));
return FE_ERR_HW;
}
// cache the encoder and trigger fc7 slot numbers
if ( brd_type == 1) {
encoder_fc7_slot = i;
} else if ( brd_type == 3 ) {
trigger_fc7_slot = i;
}
// FMC Startup Status
if (fc7lib->getStartupStatus(2, 1, fc7[i]) != 1) {
// Note: The recovery procedure from this error would be to issue a
// hard reset, but such a reset should not be issued because it
// would disable all of the SFP ports.
cm_msg(MERROR, __FUNCTION__, "FC7-%02i: FMC Startup Failed", (i+1));
return FE_ERR_HW;
}
int code = 0;
bool print_code = false;
// Threshold: TTC Single Bit Error
sleep(inter_cmd_delay); // inter-command delay
printf("%s(%d): Slot %02i: Write: Threshold: TTC Single-Bit Error \n", __FUNCTION__, __LINE__, (i+1));
code += fc7lib->setThreshold(2, 1, fc7[i], 1, amc13_fc7_odb[i].common.thres_ttc_sbit_error);
if (print_code) printf("%s(%d): Return Code: %i \n", __FUNCTION__, __LINE__, code);
// Threshold: TTC Multi Bit Error
sleep(inter_cmd_delay); // inter-command delay
printf("%s(%d): Slot %02i: Write: Threshold: TTC Multi-Bit Error \n", __FUNCTION__, __LINE__, (i+1));
code += fc7lib->setThreshold(2, 1, fc7[i], 2, amc13_fc7_odb[i].common.thres_ttc_mbit_error);
if (print_code) printf("%s(%d): Return Code: %i \n", __FUNCTION__, __LINE__, code);
// TTS Lock: Total Length
sleep(inter_cmd_delay); // inter-command delay
printf("%s(%d): Slot %02i: Write: TTS Lock: Total Length \n", __FUNCTION__, __LINE__, (i+1));