-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfa125Lib.c
5875 lines (5042 loc) · 150 KB
/
fa125Lib.c
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
/*----------------------------------------------------------------------------*/
/**
* @mainpage
* <pre>
* Copyright (c) 2010 Southeastern Universities Research Association, *
* Thomas Jefferson National Accelerator Facility *
* *
* This software was developed under a United States Government license *
* described in the NOTICE file included as part of this distribution. *
* *
* Authors: Bryan Moffit *
* moffit@jlab.org Jefferson Lab, MS-12B3 *
* Phone: (757) 269-5660 12000 Jefferson Ave. *
* Fax: (757) 269-5800 Newport News, VA 23606 *
*
* Gerard Visser
* gvisser@indiana.edu
* Indiana University
*
* __DATE__:
* *
*----------------------------------------------------------------------------*
*
* Description:
* Driver library for readout of the 125MSPS ADC using vxWorks 5.5
* (or later) or Intel based single board computer
* </pre>
*----------------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <ctype.h>
#ifdef VXWORKS
#include <vxWorks.h>
#include <logLib.h>
#include <taskLib.h>
#include <intLib.h>
#include <iv.h>
#else
#include <stdlib.h>
#include "jvme.h"
#endif
#include <pthread.h>
#include "fa125Lib.h"
#ifndef LSWAP
#define LSWAP(x) ((((x) & 0x000000ff) << 24) | \
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x00ff0000) >> 8) | \
(((x) & 0xff000000) >> 24))
#endif
/* Mutex to guard TD read/writes */
pthread_mutex_t fa125Mutex = PTHREAD_MUTEX_INITIALIZER;
#define FA125LOCK if(pthread_mutex_lock(&fa125Mutex)<0) perror("pthread_mutex_lock");
#define FA125UNLOCK if(pthread_mutex_unlock(&fa125Mutex)<0) perror("pthread_mutex_unlock");
/* Define global variables */
int nfa125=0; /* Number of initialized modules */
volatile struct fa125_a24 *fa125p[(FA125_MAX_BOARDS+1)]; /* pointers to FA125 memory map */
volatile struct fa125_a32 *fa125pd[(FA125_MAX_BOARDS+1)]; /* pointers to FA125 FIFO memory */
volatile unsigned int *FA125pmb; /* pointer to Multblock window */
int fa125ID[FA125_MAX_BOARDS]; /* array of slot numbers for FA125s */
unsigned int fa125A32Base = 0x09000000; /* Minimum VME A32 Address for use by FA125s */
unsigned long fa125A32Offset = 0x08000000; /* Difference in CPU A32 Base - VME A32 Base */
unsigned long fa125A24Offset=0; /* Difference in CPU A24 Base and VME A24 Base */
unsigned int fa125AddrList[FA125_MAX_BOARDS]; /* array of a24 addresses for FA125s */
int fa125MaxSlot=0; /* Highest Slot hold an FA125 */
int fa125MinSlot=0; /* Lowest Slot holding an FA125 */
int fa125TriggerSource=0;
int berr_count=0; /* A count of the number of BERR that have occurred when running fa125Poll() */
/* store the dacOffsets in the library, until the firmware is able to read them back */
static unsigned short fa125dacOffset[FA125_MAX_BOARDS+1][72];
int fa125BlockError=FA125_BLOCKERROR_NO_ERROR; /* Whether (1) or not (0) Block Transfer had an error */
/**
* @defgroup Config Initialization/Configuration
* @defgroup PulserConfig Pulser Initialization/Configuration
* @ingroup Config
* @defgroup Status Status
* @defgroup Readout Data Readout
* @defgroup FWUpdate Firmware Updating Utilities
* @defgroup Deprec Deprecated - To be removed
*/
/**
* @ingroup Config
* @brief Initialize the fa125 Library
*
* @param addr
* - A24 VME Address of the fADC125
* @param addr_inc
* - Amount to increment addr to find the next fADC125
* @param nadc
* - Number of times to increment
*
* @param iFlag 17 bit integer
* <pre>
* Low 6 bits - Specifies the default Signal distribution (clock,trigger)
* sources for the board (Internal, FrontPanel, VXS, VME(Soft))
* bit 0: defines Sync Reset source
* 0 VXS (P0)
* 1 VME (software)
* bits 2-1: defines Trigger source
* (0) 0 0 VXS (P0)
* (1) 0 1 Internal Timer
* (2) 1 0 Internal Multiplicity Sum
* (3) 1 1 P2 Connector (Backplane)
* bit 3: NOT USED WITH THIS FIRMWARE VERSION
* bits 5-4: defines Clock Source
* (0) 0 0 P2 Connector (Backplane)
* (1) 0 1 VXS (P0)
* (2) 1 0 Internal 125MHz Clock
* bit 16: Exit before board initialization (just map structure pointer)
* 0: Initialize fa125(s)
* 1: Skip initialization
* bit 17: Use fa125AddrList instead of addr and addr_inc
* for VME addresses.
* 0: Initialize with addr and addr_inc
* 1: Use fa125AddrList
* bit 18: Skip firmware check. Useful for firmware updating.
* 0: Perform firmware check
* :1 Skip firmware check
* </pre>
* @return OK, or ERROR if the address is invalid or a board is not present.
*/
int
fa125Init (UINT32 addr, UINT32 addr_inc, int nadc, int iFlag)
{
int res=0;
volatile unsigned int rdata=0;
unsigned long laddr=0;
unsigned int a32addr=0;
volatile struct fa125_a24 *fa125;
int useList=0, noBoardInit=0, noFirmwareCheck=0;
int nfind=0, islot=0, FA_SLOT=0, ii=0;
int trigSrc=0, clkSrc=0, srSrc=0;
unsigned int boardID=0, fw_version=0;
int maxSlot = 1;
int minSlot = 21;
/* Initialize some global variables */
nfa125=0;
memset((char *)fa125ID,0,sizeof(fa125ID));
memset((char *)fa125dacOffset,0,sizeof(fa125dacOffset));
/* Check if we're skipping initialization, and just mapping the structure pointer */
if(iFlag & FA125_INIT_SKIP)
noBoardInit=1;
/* Check if we're initializing using a list */
if(iFlag & FA125_INIT_USE_ADDRLIST)
{
useList=1;
nfind = nadc;
}
/* Are we skipping the firmware check? */
if(iFlag & FA125_INIT_SKIP_FIRMWARE_CHECK)
{
noFirmwareCheck=1;
printf("%s: INFO: Firmware Check Disabled\n",
__FUNCTION__);
}
/* Check for valid address */
if((addr==0) && (useList==0))
{ /* Loop through JLab Standard GEOADDR to VME addresses to make a list */
useList=1;
nfind=16;
for(islot=3; islot<11; islot++) /* First 8 */
fa125AddrList[islot-3] = (islot<<19);
/* Skip Switch Slots */
for(islot=13; islot<21; islot++) /* Last 8 */
fa125AddrList[islot-5] = (islot<<19);
}
else if(addr > 0x00ffffff) /* A32 Addressing */
{
printf("\n%s: ERROR: A32 Addressing not allowed for FA125 configuration space\n\n",
__FUNCTION__);
return(ERROR);
}
else if((addr!=0) && (useList==0))
{ /* A24 Addressing */
if(addr_inc==0) /* Just one module */
{
fa125AddrList[0] = addr;
nfind=1;
}
else /* Up to nadc modules */
{
for(islot=0; islot<nadc; islot++)
{
fa125AddrList[islot] = addr+addr_inc*islot;
}
nfind=nadc;
}
}
/* Determine the A24 offset from the first module address */
#ifdef VXWORKS
res = sysBusToLocalAdrs(0x39,(char *)fa125AddrList[0],(char **)&laddr);
#else
res = vmeBusToLocalAdrs(0x39,(char *)(unsigned long)fa125AddrList[0],(char **)&laddr);
#endif
if (res != 0)
{
#ifdef VXWORKS
printf("\n%s: ERROR in sysBusToLocalAdrs(0x39,0x%x,&laddr) \n\n",
__FUNCTION__,addr);
#else
printf("\n%s: ERROR in vmeBusToLocalAdrs(0x39,0x%x,&laddr) \n\n",
__FUNCTION__,addr);
#endif
return(ERROR);
}
fa125A24Offset = laddr - fa125AddrList[0];
/* Calculate the A32 Offset for use in Block Transfers */
#ifdef VXWORKS
res = sysBusToLocalAdrs(0x09,(char *)fa125A32Base,(char **)&laddr);
if (res != 0)
{
printf("\n%s: ERROR in sysBusToLocalAdrs(0x09,0x%x,&laddr) \n\n",
__FUNCTION__,fa125A32Base);
return(ERROR);
}
else
{
fa125A32Offset = laddr - fa125A32Base;
}
#else
res = vmeBusToLocalAdrs(0x09,(char *)(unsigned long)fa125A32Base,(char **)&laddr);
if (res != 0)
{
printf("\n%s: ERROR in vmeBusToLocalAdrs(0x09,0x%x,&laddr) \n\n",
__FUNCTION__,fa125A32Base);
return(ERROR);
}
else
{
fa125A32Offset = laddr - fa125A32Base;
}
#endif
for(islot=0; islot<nfind; islot++)
{
fa125 = (volatile struct fa125_a24 *)(fa125AddrList[islot]+fa125A24Offset);
/* Check if Board exists at that address */
#ifdef VXWORKS
res = vxMemProbe((char *) &(fa125->main.id),VX_READ,4,(char *)&rdata);
#else
res = vmeMemProbe((char *)&(fa125->main.id),4,(char *)&rdata);
#endif
if(res < 0)
{
printf("%s: WARN: No addressable board at addr=0x%x\n",
__FUNCTION__,(UINT32) fa125AddrList[islot]);
}
else
{
/* Check that it is an FA125 */
if(rdata != FA125_ID)
{
printf("\n%s: ERROR: For module at 0x%x, Invalid Board ID: 0x%x\n\n",
__FUNCTION__,fa125AddrList[islot],rdata);
continue;
}
else
{
/* Check the Firmware Versions */
if(!noFirmwareCheck)
{
int fw_error=0;
/* MAIN */
fw_version = vmeRead32(&fa125->main.version);
if(fw_version==0xffffffff)
{ /* buggy firmware.. re-read */
printf("%s: bum main read\n",__FUNCTION__);
fw_version = vmeRead32(&fa125->main.version);
}
if(fw_version != FA125_MAIN_SUPPORTED_FIRMWARE)
{
printf("\n%s: ERROR: For module at 0x%x, Unsupported MAIN firmware version 0x%x\n\n",
__FUNCTION__,fa125AddrList[islot],fw_version);
fw_error=1;
}
/* PROC */
fw_version = vmeRead32(&fa125->proc.version);
if(fw_version==0xffffffff)
{ /* buggy firmware.. re-read */
printf("%s: bum proc read\n",__FUNCTION__);
fw_version = vmeRead32(&fa125->proc.version);
}
if(fw_version != FA125_PROC_SUPPORTED_FIRMWARE)
{
printf("\n%s: ERROR: For module at 0x%x, Unsupported PROC firmware version 0x%x\n\n",
__FUNCTION__,fa125AddrList[islot],fw_version);
fw_error=1;
}
/* FE - just check the first one */
fw_version = vmeRead32(&fa125->fe[0].version);
if(fw_version==0xffffffff)
{ /* buggy firmware.. re-read */
printf("%s: bum FE read\n",__FUNCTION__);
fw_version = vmeRead32(&fa125->fe[0].version);
}
if(fw_version != FA125_FE_SUPPORTED_FIRMWARE)
{
printf("\n%s: ERROR: For module at 0x%x, Unsupported FE firmware version 0x%x\n\n",
__FUNCTION__,fa125AddrList[islot],fw_version);
fw_error=1;
}
if(fw_error)
continue;
}
/* Get the Geographic Address */
boardID = vmeRead32(&fa125->main.slot_ga);
if((boardID<2) || (boardID>21))
{
printf("%s: For module at 0x%x, Invalid Slot Number %d\n",
__FUNCTION__,fa125AddrList[islot],boardID);
continue;
}
if(boardID >= maxSlot) maxSlot = boardID;
if(boardID <= minSlot) minSlot = boardID;
fa125p[boardID] = (struct fa125_a24 *) (fa125AddrList[islot]+fa125A24Offset);
fa125ID[nfa125] = boardID;
printf("Initialized FA125 %2d Slot # %2d at address 0x%08lx (0x%08x)\n",
nfa125,fa125ID[nfa125],
(unsigned long)fa125p[fa125ID[nfa125]],
(unsigned int)((unsigned long)fa125p[fa125ID[nfa125]] - fa125A24Offset));
}
nfa125++;
}
}
if(noBoardInit)
{
if(nfa125>0)
{
printf("%s: %d FA125(s) successfully mapped (not initialized)\n",
__FUNCTION__,nfa125);
return OK;
}
}
if(nfa125==0)
{
printf("\n%s: ERROR: Unable to initialize any FA125 modules\n\n",
__FUNCTION__);
return ERROR;
}
/* Determine the clock, sync, trigger configuration */
/* Sync Reset (only VXS available, ignore) */
srSrc = 1;
/* Trigger */
trigSrc = (iFlag&0x6)>>1;
fa125TriggerSource = trigSrc;
/* Clock Source */
clkSrc = (iFlag&0x30)>>4;
/* Perform some initialization here */
for(islot=0; islot<nfa125; islot++)
{
FA_SLOT = fa125ID[islot];
fa125Reset(FA_SLOT, 1);
fa125Clear(FA_SLOT);
/* Set the clock source */
fa125SetClockSource(FA_SLOT,clkSrc);
/* Set the trigger source */
fa125SetTriggerSource(FA_SLOT,fa125TriggerSource);
/* Set the SyncReset source */
fa125SetSyncResetSource(FA_SLOT,srSrc);
}
for(ii=0;ii<nfa125; ii++)
{
/* Program an A32 access address for this FA125's FIFO */
a32addr = fa125A32Base + ii*FA125_MAX_A32_MEM;
#ifdef VXWORKS
res = sysBusToLocalAdrs(0x09,(char *)a32addr,(char **)&laddr);
if (res != 0)
{
printf("\n%s: ERROR in sysBusToLocalAdrs(0x09,0x%x,&laddr) \n\n",
__FUNCTION__,a32addr);
return(ERROR);
}
#else
res = vmeBusToLocalAdrs(0x09,(char *)(unsigned long)a32addr,(char **)&laddr);
if (res != 0)
{
printf("\n%s: ERROR in vmeBusToLocalAdrs(0x09,0x%x,&laddr) \n\n",
__FUNCTION__,a32addr);
return(ERROR);
}
#endif
fa125pd[fa125ID[ii]] = (volatile struct fa125_a32 *)(laddr); /* Set a pointer to the FIFO */
if(!noBoardInit)
{
vmeWrite32(&fa125p[fa125ID[ii]]->main.adr32, (a32addr>>16) | FA125_ADR32_ENABLE); /* Write the register and enable */
vmeWrite32(&fa125p[fa125ID[ii]]->main.ctrl1,
vmeRead32(&fa125p[fa125ID[ii]]->main.ctrl1) | FA125_CTRL1_ENABLE_BERR);/* Enable Bus Error termination */
}
}
/* If there are more than 1 FA125 in the crate then setup the Muliblock Address
window. This must be the same on each board in the crate */
if(nfa125 > 1)
{
a32addr = fa125A32Base + (nfa125+1)*FA125_MAX_A32_MEM; /* set MB base above individual board base */
#ifdef VXWORKS
res = sysBusToLocalAdrs(0x09,(char *)a32addr,(char **)&laddr);
if (res != 0)
{
printf("\n%s: ERROR in sysBusToLocalAdrs(0x09,0x%x,&laddr) \n\n",__FUNCTION__,a32addr);
return(ERROR);
}
#else
res = vmeBusToLocalAdrs(0x09,(char *)(unsigned long)a32addr,(char **)&laddr);
if (res != 0)
{
printf("\n%s: ERROR in vmeBusToLocalAdrs(0x09,0x%x,&laddr) \n\n",__FUNCTION__,a32addr);
return(ERROR);
}
#endif
FA125pmb = (unsigned int *)(laddr); /* Set a pointer to the FIFO */
if(!noBoardInit)
{
unsigned int ctrl1=0;
for (ii=0;ii<nfa125;ii++)
{
/* Write to the register and enable */
vmeWrite32(&fa125p[fa125ID[ii]]->main.adr_mb,
(a32addr+FA125_MAX_A32MB_SIZE) | (a32addr>>16) | FA125_ADRMB_ENABLE);
ctrl1 = vmeRead32(&fa125p[fa125ID[ii]]->main.ctrl1) &
~(FA125_CTRL1_FIRST_BOARD | FA125_CTRL1_LAST_BOARD);
vmeWrite32(&fa125p[fa125ID[ii]]->main.ctrl1,
ctrl1 | FA125_CTRL1_ENABLE_MULTIBLOCK);
}
}
/* Set First Board and Last Board */
fa125MaxSlot = maxSlot;
fa125MinSlot = minSlot;
if(!noBoardInit)
{
vmeWrite32(&fa125p[minSlot]->main.ctrl1,
vmeRead32(&fa125p[minSlot]->main.ctrl1) | FA125_CTRL1_FIRST_BOARD);
vmeWrite32(&fa125p[maxSlot]->main.ctrl1,
vmeRead32(&fa125p[maxSlot]->main.ctrl1) | FA125_CTRL1_LAST_BOARD);
}
}
if(nfa125 > 0)
printf("%s: %d FA125(s) successfully initialized\n",__FUNCTION__,nfa125);
return(OK);
}
void
fa125CheckAddresses(int id)
{
unsigned int offset=0, expected=0;
unsigned long base=0;
int ife=0;
struct fa125_a24 fadcp;
printf("%s:\n\t ---------- Checking FA125 address space ---------- \n",__FUNCTION__);
base = (unsigned long) &fadcp.main;
for(ife=0; ife<12; ife++)
{
offset = ((unsigned long) &fadcp.fe[ife]) - base;
expected = 0x1000 + ife*0x1000;
if(offset != expected)
printf("\n%s: ERROR fa125p[%d]->fe[%d] not at offset = 0x%x (@ 0x%x)\n\n",
__FUNCTION__,id,ife,expected,offset);
}
offset = ((unsigned long) &fadcp.fe[0].ie) - base;
expected = 0x10b0;
if(offset != expected)
printf("\n%s: ERROR fa125p[%d]->fe[0].ie not at offset = 0x%x (@ 0x%x)\n\n",
__FUNCTION__,id,expected,offset);
offset = ((unsigned long) &fadcp.proc) - base;
expected = 0xD000;
if(offset != expected)
printf("\n%s: ERROR fa125p[%d]->proc not at offset = 0x%x (@ 0x%x)\n\n",
__FUNCTION__,id,expected,offset);
offset = ((unsigned long) &fadcp.proc.trigsrc) - base;
expected = 0xD008;
if(offset != expected)
printf("\n%s: ERROR fa125p[%d]->proc.trigsrc not at offset = 0x%x (@ 0x%x)\n\n",
__FUNCTION__,id,expected,offset);
}
/**
* @ingroup Config
* @brief Convert an index into a slot number, where the index is
* the element of an array of fA125s in the order in which they were
* initialized.
*
* @param i Initialization number
* @return Slot number if Successfull, otherwise ERROR.
*
*/
int
fa125Slot(unsigned int i)
{
if(i>=nfa125)
{
printf("\n%s: ERROR: Index (%d) >= FA125s initialized (%d).\n\n",
__FUNCTION__,i,nfa125);
return ERROR;
}
return fa125ID[i];
}
/**
* @ingroup Status
* @brief Print Status of fADC125 to standard out
* @param id Slot Number
* @param pflag Print option flag
* - bit 0 (FA125_STATUS_SHOWREGS): Show some register values to standard out
* @return OK if successful, otherwise ERROR.
*/
int
fa125Status(int id, int pflag)
{
struct fa125_a24_main m;
struct fa125_a24_proc p;
struct fa125_a24_fe f[12];
unsigned int clksrc, trigsrc, srsrc;
unsigned long faBase;
unsigned int a32Base, ambMin, ambMax;
int i=0, showregs=0, sign=1;
if(id==0) id=fa125ID[0];
if((id<0) || (id>21) || (fa125p[id] == NULL))
{
printf("\n%s: ERROR : FA125 in slot %d is not initialized \n\n",__FUNCTION__,id);
return ERROR;
}
if(pflag & FA125_STATUS_SHOWREGS)
showregs=1;
FA125LOCK;
m.id = vmeRead32(&fa125p[id]->main.id);
m.swapctl = vmeRead32(&fa125p[id]->main.swapctl);
m.version = vmeRead32(&fa125p[id]->main.version);
m.pwrctl = vmeRead32(&fa125p[id]->main.pwrctl);
m.slot_ga = vmeRead32(&fa125p[id]->main.slot_ga);
m.clock = vmeRead32(&fa125p[id]->main.clock);
for(i=0; i<4; i++)
m.serial[i] = vmeRead32(&fa125p[id]->main.serial[i]);
f[0].version = vmeRead32(&fa125p[id]->fe[0].version);
if(f[0].version==0xffffffff)
{
f[0].version = vmeRead32(&fa125p[id]->fe[0].version);
}
p.version = vmeRead32(&fa125p[id]->proc.version);
p.csr = vmeRead32(&fa125p[id]->proc.csr);
p.trigsrc = vmeRead32(&fa125p[id]->proc.trigsrc);
p.ctrl2 = vmeRead32(&fa125p[id]->proc.ctrl2);
m.adr32 = vmeRead32(&fa125p[id]->main.adr32);
m.adr_mb = vmeRead32(&fa125p[id]->main.adr_mb);
m.ctrl1 = vmeRead32(&fa125p[id]->main.ctrl1);
m.block_count = vmeRead32(&fa125p[id]->main.block_count);
p.trig_count = vmeRead32(&fa125p[id]->proc.trig_count);
p.ev_count = vmeRead32(&fa125p[id]->proc.ev_count);
m.blockCSR = vmeRead32(&fa125p[id]->main.blockCSR);
f[0].config1 = vmeRead32(&fa125p[id]->fe[0].config1);
f[0].nw = vmeRead32(&fa125p[id]->fe[0].nw) & FA125_FE_NW_MASK;
f[0].pl = vmeRead32(&fa125p[id]->fe[0].pl) & FA125_FE_PL_MASK;
f[0].ie = vmeRead32(&fa125p[id]->fe[0].ie);
f[0].ped_sf = vmeRead32(&fa125p[id]->fe[0].ped_sf);
sign = (f[0].ped_sf&FA125_FE_PED_SF_PBIT_SIGN)?-1:1;
for(i=0; i<12; i++)
{
f[i].test = vmeRead32(&fa125p[id]->fe[i].test);
}
FA125UNLOCK;
faBase = (unsigned long) &fa125p[id]->main.id;
a32Base = (m.adr32 & FA125_ADR32_BASE_MASK)<<16;
ambMin = (m.adr_mb & FA125_ADRMB_MIN_MASK)<<16;
ambMax = (m.adr_mb & FA125_ADRMB_MAX_MASK);
#ifdef VXWORKS
printf("\nSTATUS for FA125 in slot %d at base address 0x%x \n",
id, (UINT32) fa125p[id]);
#else
printf("\nSTATUS for FA125 in slot %d at VME (Local) base address 0x%x (0x%lx)\n",
id, (UINT32)((unsigned long)fa125p[id] - fa125A24Offset), (unsigned long) fa125p[id]);
#endif
printf("--------------------------------------------------------------------------------\n");
printf(" Main Firmware Revision = 0x%08x\n",
m.version);
printf(" FrontEnd Firmware Revision = 0x%08x\n",
f[0].version);
printf(" Processing Revision = 0x%08x\n",
p.version);
printf(" Main SN = 0x%04x%08x\n",m.serial[0], m.serial[1]);
printf(" Mezzanine SN = 0x%04x%08x\n",m.serial[2], m.serial[3]);
printf("\n");
if(showregs)
{
printf("Registers:\n");
printf(" blockCSR (0x%04lx) = 0x%08x\t",
(unsigned long)(&fa125p[id]->main.blockCSR) - faBase, m.blockCSR);
printf(" ctrl1 (0x%04lx) = 0x%08x\n",
(unsigned long)(&fa125p[id]->main.ctrl1) - faBase, m.ctrl1);
printf(" adr32 (0x%04lx) = 0x%08x\t",
(unsigned long)(&fa125p[id]->main.adr32) - faBase, m.adr32);
printf(" adr_mb (0x%04lx) = 0x%08x\n",
(unsigned long)(&fa125p[id]->main.adr_mb) - faBase, m.adr_mb);
printf(" trigsrc (0x%04lx) = 0x%08x\t",
(unsigned long)(&fa125p[id]->proc.trigsrc) - faBase, p.trigsrc);
printf(" clock (0x%04lx) = 0x%08x\n",
(unsigned long)(&fa125p[id]->main.clock) - faBase, m.clock);
printf(" config1 (0x%04lx) = 0x%08x\n",
(unsigned long)(&fa125p[id]->fe[0].config1) - faBase, f[0].config1);
printf("\n");
for(i=0; i<12; i=i+2)
{
printf(" test %2d (0x%04lx) = 0x%08x\t", i,
(unsigned long)(&fa125p[id]->fe[i].test) - faBase, f[i].test);
printf(" test %2d (0x%04lx) = 0x%08x\n", i+1,
(unsigned long)(&fa125p[id]->fe[i+1].test) - faBase, f[i+1].test);
}
printf("\n");
}
if(m.ctrl1 & FA125_CTRL1_ENABLE_MULTIBLOCK)
{
printf(" Alternate VME Addressing: Multiblock Enabled\n");
if(m.adr32&FA125_ADR32_ENABLE)
printf(" A32 Enabled at VME (Local) base 0x%08x (0x%08lx)\n",a32Base,
(unsigned long) fa125pd[id]);
else
printf(" A32 Disabled\n");
printf(" Multiblock VME Address Range 0x%08x - 0x%08x\n",ambMin,ambMax);
}
else
{
printf(" Alternate VME Addressing: Multiblock Disabled\n");
if(m.adr32&FA125_ADR32_ENABLE)
printf(" A32 Enabled at VME (Local) base 0x%08x (0x%08lx)\n",a32Base,
(unsigned long) fa125pd[id]);
else
printf(" A32 Disabled\n");
}
printf("\n");
/* POWER */
if(m.pwrctl)
printf(" Power is ON\n");
else
printf(" Power is OFF\n");
/* CLOCK */
printf(" Clock Source (0x%02x) :",m.clock);
clksrc = m.clock & 0xffff;
if(clksrc == FA125_CLOCK_P2)
printf(" P2\n");
else if (clksrc == FA125_CLOCK_P0)
printf(" P0 (VXS)\n");
else if (clksrc == FA125_CLOCK_INTERNAL)
printf(" Internal\n");
else
printf(" ????\n");
/* TRIGGER */
printf(" Trigger Source (0x%02x) :",p.trigsrc);
trigsrc = p.trigsrc & FA125_TRIGSRC_TRIGGER_MASK;
if(trigsrc == FA125_TRIGSRC_TRIGGER_P0)
printf(" P0 (VXS)\n");
else if (trigsrc == FA125_TRIGSRC_TRIGGER_SOFTWARE)
printf(" Software (VME)\n");
else if (trigsrc == FA125_TRIGSRC_TRIGGER_INTERNAL_SUM)
printf(" Internal Sum\n");
else if (trigsrc == FA125_TRIGSRC_TRIGGER_P2)
printf(" P2\n");
/* SYNCRESET */
printf(" SyncReset Source :");
srsrc = (f[0].test & FA125_FE_TEST_SYNCRESET_ENABLE)>>2;
if(srsrc)
printf(" P0 (VXS)\n");
else
printf(" DISABLED\n");
printf("\n");
printf(" Bus Error %s\n",
(m.ctrl1&FA125_CTRL1_ENABLE_BERR)?"ENABLED":"DISABLED");
if(m.ctrl1 & FA125_CTRL1_ENABLE_MULTIBLOCK)
{
if(m.ctrl1&FA125_CTRL1_FIRST_BOARD)
printf(" MultiBlock transfer ENABLED (First Board)\n");
else if(m.ctrl1&FA125_CTRL1_LAST_BOARD)
printf(" MultiBlock transfer ENABLED (Last Board)\n");
else
printf(" MultiBlock transfer ENABLED\n");
}
else
printf(" MultiBlock transfer DISABLED\n");
printf("\n");
printf(" Processing Configuration: \n");
printf(" Mode = %s (%d) - %s\n\n",
fa125_mode_names[(f[0].config1&FA125_FE_CONFIG1_MODE_MASK) + 1],
(f[0].config1&FA125_FE_CONFIG1_MODE_MASK)+1,
(f[0].config1 & FA125_FE_CONFIG1_ENABLE)?"ENABLED":"DISABLED");
printf(" Lookback (PL) = %5d %5dns\n",
f[0].pl, 8*f[0].pl);
printf(" Time Window (NW) = %5d %5dns\n",
f[0].nw, 8*f[0].nw);
printf(" Integration End (IE) = %5d %5dns\n",
(f[0].ie & FA125_FE_IE_INTEGRATION_END_MASK),
8*(f[0].ie & FA125_FE_IE_INTEGRATION_END_MASK));
printf(" Pedestal Gap (PG) = %5d %5dns\n",
((f[0].ie & FA125_FE_IE_PEDESTAL_GAP_MASK)>>12),
8*((f[0].ie & FA125_FE_IE_PEDESTAL_GAP_MASK)>>12));
printf(" Initial Pedestal exponent (P1) = %5d\n",
(f[0].ped_sf & FA125_FE_PED_SF_NP_MASK));
printf(" Initial Pedestal window (NP = 2**P1) = %5d %5dns\n",
(1<<(f[0].ped_sf & FA125_FE_PED_SF_NP_MASK)),
8*(1<<(f[0].ped_sf & FA125_FE_PED_SF_NP_MASK)));
printf(" Local Pedestal exponent (P2) = %5d\n",
(f[0].ped_sf & FA125_FE_PED_SF_NP2_MASK)>>8);
printf(" Local Pedestal window (NP2= 2**P2) = %5d %5dns\n",
(1<<((f[0].ped_sf & FA125_FE_PED_SF_NP2_MASK)>>8)),
8*(1<<((f[0].ped_sf & FA125_FE_PED_SF_NP2_MASK)>>8)));
printf("\n");
printf(" Scale Factors:\n");
printf(" Integration (IBIT) = %d Amplitude (ABIT) = %d Pedestal (PBIT) = %d\n",
((f[0].ped_sf & FA125_FE_PED_SF_IBIT_MASK)>>16),
((f[0].ped_sf & FA125_FE_PED_SF_ABIT_MASK)>>19),
sign*((f[0].ped_sf & FA125_FE_PED_SF_PBIT_MASK)>>22));
printf(" (2**IBIT) = %-3d (2**ABIT) = %-3d (2**PBIT) = ",
1<<((f[0].ped_sf & FA125_FE_PED_SF_IBIT_MASK)>>16),
1<<((f[0].ped_sf & FA125_FE_PED_SF_ABIT_MASK)>>19));
if(sign==1)
printf("%-2d\n\n",1<<((f[0].ped_sf & FA125_FE_PED_SF_PBIT_MASK)>>22));
else
printf("1/%-2d\n\n",1<<((f[0].ped_sf & FA125_FE_PED_SF_PBIT_MASK)>>22));
printf(" Max Peak Count = %d \n",(f[0].config1 & FA125_FE_CONFIG1_NPULSES_MASK)>>4);
printf(" Playback Mode = %s \n",
(f[0].config1 & FA125_FE_CONFIG1_PLAYBACK_ENABLE)?"ENABLED":"DISABLED");
printf("\n");
printf(" Block Count = %d\n",m.block_count);
printf(" Trig Count = %d\n",p.trig_count);
printf(" Ev Count = %d\n",p.ev_count);
printf("\n");
fa125CheckThresholds(id,1);
printf("--------------------------------------------------------------------------------\n");
return OK;
}
/**
* @ingroup Status
* @brief Print a summary of all initialized fADC1250s
* @param pflag Not used
*/
void
fa125GStatus(int pflag)
{
int ifa, id;
struct fa125_a24_main m[20];
struct fa125_a24_proc p[20];
struct fa125_a24_fe f[20];
unsigned int a24addr[20];
int th_check[20], sign[20];
FA125LOCK;
for (ifa=0;ifa<nfa125;ifa++)
{
id = fa125Slot(ifa);
a24addr[id] = (unsigned int)((unsigned long)fa125p[id] - fa125A24Offset);
m[id].version = vmeRead32(&fa125p[id]->main.version);
m[id].adr32 = vmeRead32(&fa125p[id]->main.adr32);
m[id].adr_mb = vmeRead32(&fa125p[id]->main.adr_mb);
m[id].pwrctl = vmeRead32(&fa125p[id]->main.pwrctl);
m[id].clock = vmeRead32(&fa125p[id]->main.clock);
m[id].ctrl1 = vmeRead32(&fa125p[id]->main.ctrl1);
m[id].blockCSR = vmeRead32(&fa125p[id]->main.blockCSR);
m[id].block_count = vmeRead32(&fa125p[id]->main.block_count);
p[id].version = vmeRead32(&fa125p[id]->proc.version);
p[id].trigsrc = vmeRead32(&fa125p[id]->proc.trigsrc);
p[id].ctrl2 = vmeRead32(&fa125p[id]->proc.ctrl2);
p[id].blocklevel = vmeRead32(&fa125p[id]->proc.blocklevel);
p[id].trig_count = vmeRead32(&fa125p[id]->proc.trig_count);
p[id].trig2_count = vmeRead32(&fa125p[id]->proc.trig2_count);
p[id].sync_count = vmeRead32(&fa125p[id]->proc.sync_count);
f[id].version = vmeRead32(&fa125p[id]->fe[0].version);
f[id].config1 = vmeRead32(&fa125p[id]->fe[0].config1);
f[id].pl = vmeRead32(&fa125p[id]->fe[0].pl) & FA125_FE_PL_MASK;
f[id].nw = vmeRead32(&fa125p[id]->fe[0].nw) & FA125_FE_NW_MASK;
f[id].ie = vmeRead32(&fa125p[id]->fe[0].ie);
f[id].ped_sf = vmeRead32(&fa125p[id]->fe[0].ped_sf);
sign[id] = (f[id].ped_sf & FA125_FE_PED_SF_PBIT_SIGN)?-1:1;
}
FA125UNLOCK;
for (ifa=0;ifa<nfa125;ifa++)
{
id = fa125Slot(ifa);
th_check[id] = fa125CheckThresholds(id, 0);
}
printf("\n");
printf(" fADC125 Module Configuration Summary\n\n");
printf(" ..........Firmware Rev.......... .................Addresses................\n");
printf("Slot Main FE Proc A24 A32 A32 Multiblock Range\n");
printf("--------------------------------------------------------------------------------\n");
for(ifa=0; ifa<nfa125; ifa++)
{
id = fa125Slot(ifa);
printf(" %2d ",id);
printf("%08x %08x %08x ",
m[id].version, f[id].version, p[id].version);
printf("%06x ",
a24addr[id]);
if(m[id].adr32 & FA125_ADR32_ENABLE)
{
printf("%08x ",
(m[id].adr32&FA125_ADR32_BASE_MASK)<<16);
}
else
{
printf(" Disabled ");
}
if(m[id].adr_mb & FA125_ADRMB_ENABLE)
{
printf("%08x-%08x",
(m[id].adr_mb&FA125_ADRMB_MIN_MASK)<<16,
(m[id].adr_mb&FA125_ADRMB_MAX_MASK));
}
else
{
printf("Disabled");
}
printf("\n");
}
printf("--------------------------------------------------------------------------------\n");
printf("\n");
printf(" .Signal Sources.. \n");
printf("Slot Power Clk Trig Sync MBlk Token BERR \n");
printf("--------------------------------------------------------------------------------\n");
for(ifa=0; ifa<nfa125; ifa++)
{
id = fa125Slot(ifa);
printf(" %2d ",id);
printf("%s ",
m[id].pwrctl ? " ON" : "OFF");
printf("%s ",
(m[id].clock & FA125_CLOCK_MASK)==FA125_CLOCK_INTERNAL ? " INT " :
(m[id].clock & FA125_CLOCK_MASK)==FA125_CLOCK_INTERNAL_ENABLE ? "*INT*" :
(m[id].clock & FA125_CLOCK_MASK)==FA125_CLOCK_P0 ? " VXS " :
(m[id].clock & FA125_CLOCK_MASK)==FA125_CLOCK_P2 ? " P2 " :
" ??? ");
printf("%s ",
(p[id].trigsrc & FA125_TRIGSRC_TRIGGER_MASK)
==FA125_TRIGSRC_TRIGGER_SOFTWARE ? " VME " :
(p[id].trigsrc & FA125_TRIGSRC_TRIGGER_MASK)
==FA125_TRIGSRC_TRIGGER_INTERNAL_SUM ? " SUM " :
(p[id].trigsrc & FA125_TRIGSRC_TRIGGER_MASK)
==FA125_TRIGSRC_TRIGGER_P0 ? " VXS " :
(p[id].trigsrc & FA125_TRIGSRC_TRIGGER_MASK)
==FA125_TRIGSRC_TRIGGER_P2 ? " P2 " :
" ??? ");
// FIXME: Just check enable bit... disabled or VXS
printf("%s ",
(f[id].test & FA125_FE_TEST_SYNCRESET_ENABLE)>>2
== 1 ? " VXS " : " OFF ");
printf("%s ",
(m[id].ctrl1 & FA125_CTRL1_ENABLE_MULTIBLOCK) ? "YES":" NO");
printf(" VXS");
printf("%s ",
m[id].ctrl1 & (FA125_CTRL1_FIRST_BOARD) ? "-F":
m[id].ctrl1 & (FA125_CTRL1_LAST_BOARD) ? "-L":
" ");
printf("%s ",
m[id].ctrl1 & FA125_CTRL1_ENABLE_BERR ? "YES" : " NO");
printf("\n");
}
printf("--------------------------------------------------------------------------------\n");
printf("\n");
printf(" fADC125 Processing Mode Config\n\n");
printf(" Block\n");
printf("Slot Level Mode ......PL...... ....NW..... ....IE.... ...PG...\n");
printf("--------------------------------------------------------------------------------\n");
for(ifa=0; ifa<nfa125; ifa++)
{
id = fa125Slot(ifa);
printf(" %2d ",id);
printf("%3d ",p[id].blocklevel & FA125_PROC_BLOCKLEVEL_MASK);
printf("%-12s ",fa125_modes[(f[id].config1 & FA125_FE_CONFIG1_MODE_MASK) + 1]);
printf("%5d %6dns ", f[id].pl, 8*f[id].pl);
printf("%4d %4dns ", f[id].nw, 8*f[id].nw);
printf("%3d %4dns ", (f[id].ie & FA125_FE_IE_INTEGRATION_END_MASK),
8*(f[id].ie & FA125_FE_IE_INTEGRATION_END_MASK));
printf("%d %2dns", ((f[id].ie & FA125_FE_IE_PEDESTAL_GAP_MASK)>>12),
8*((f[id].ie & FA125_FE_IE_PEDESTAL_GAP_MASK)>>12));