/**************************************************************************** * * dsc2Config.c - configuration library file for dsc2 board * * SP, 02-Dec-2013 * * empty lines and line startes with # - will be ignored * config file format: CRATE rocbcal1 <- ROC/crate name, usually IP name DSC2_ALLSLOTS <- just keyword - all settings after this line will be implemented # for all slots, till DSC2_SLOTS will be met DSC2_SLOTS 3 8 15 <- slot_numbers - in which next settings will be implemented # till file ends or next DSC2_SLOTS will be met DSC2_SLOT 2 <- slot_number - next settings will be implemented only to this slot DSC2_F_REV 0x010c <- firmware revision (0x0400 Bits:15-0) DSC2_ID 0x44534332 <- board type, 0x44534332 = "DSC2" in ASCII (0x0404 Bits:31-0) # /---- slots ## # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 DSC2_ALLSN 0 TRIS-010 TRIS-013 TRIS-014 TRIS-015 ACDI-016 ACDI-017 ACDI-018 ACDI-019 ACDI-020 0 0 ACDI-023 ACDI-024 ACDI-322 ACDI-026 ACDI-027 ACDI-037 ACDI-038 ACDI-043 ACDI-046 DSC2_SL_SN 15 ACDI-322 <- single board Serial Number: sl# , SN DSC2_WIDTH 20 40 <- TDC width (ns), TRG width (ns) # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - channels ## DSC2_TDCMASK 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 <- TDC enable mask DSC2_TRGMASK 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 <- TRG enable mask DSC2_TDCORMASK 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 <- TDC OR mask DSC2_TRGORMASK 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 <- TRG OR mask DSC2_THRESHOLD 20 50 <- board threshold: TDC threshold (mV), TRG threshold (mV) DSC2_CH_THRESHOLD 0 20 50 <- channel threshold: channel#, TDC threshold (mV), TRG threshold (mV) # following, if used, will supersede TRG width: DSC2_TRGDIGITAL 40 64 <- board digital TRG output: width (ns), delay (ns) DSC2_CH_TRGDIGITAL 0 40 64 <- channel digital TRG output: channel#, width (ns), delay (ns) cc -rdynamic -shared -o dsc2Config.so dsc2Config.c -DLinux_vme -I/home/halld/test_setup/coda/linuxvme/include /home/halld/test_setup/coda/linuxvme/jvme/libjvme.a /home/halld/test_setup/coda/linuxvme/dsc2/libdsc2.a -ldl -lpthread -lrt */ #if defined(VXWORKS) || defined(Linux_vme) #ifdef VXWORKS #include #include #include #else #include "jvme.h" #endif #include #include #include #include "dsc2Lib.h" #include "dsc2Config.h" #undef DEBUG #define FNLEN 128 /* length of config. file name */ #define STRLEN 250 /* length of str_tmp */ #define ROCLEN 80 /* length of ROC_name */ #define NBOARD 22 /* Global variables */ static int Ndsc = 0; /* Number of DSCs in Crate */ static DSC2_CONF dsc[NBOARD]; #define SCAN_MSK \ args = sscanf (str_tmp, "%*s %d %d %d %d %d %d %d %d \ %d %d %d %d %d %d %d %d", \ &msk[ 0], &msk[ 1], &msk[ 2], &msk[ 3], \ &msk[ 4], &msk[ 5], &msk[ 6], &msk[ 7], \ &msk[ 8], &msk[ 9], &msk[10], &msk[11], \ &msk[12], &msk[13], &msk[14], &msk[15]) #define DSC2_READ_MASKS(BKEYWORD,BSTRUCT) \ else if(strcmp(keyword,(BKEYWORD)) == 0) \ { \ SCAN_MSK; \ ui1 = 0; \ for(jj=0; jj 1)) \ { \ printf("\nReadConfigFile: Wrong mask bit value, %d\n\n",msk[jj]); return(-6); \ } \ ui1 |= (msk[jj]<%s<\n",fname); return(-1); } } else /* filename does not specified */ { /* sprintf(fname, "%s/dsc2/%s.conf", clonparms, host); */ sprintf(fname, "%s/dsc2/%s.conf", halldparms, host); if((fd=fopen(fname,"r")) == NULL) { /* sprintf(fname, "%s/dsc2/%s.conf", clonparms, expid); */ sprintf(fname, "%s/dsc2/default.cnf", halldparms); if((fd=fopen(fname,"r")) == NULL) { printf("\nReadConfigFile: Can't open config file >%s<\n",fname); return(-2); } } } printf("\nReadConfigFile: Using configuration file >%s<\n",fname); /* Parsing of config file */ while ((ch = getc(fd)) != EOF) { if ( ch == '#' || ch == ' ' || ch == '\t' ) { while (getc(fd) != '\n') {} } else if( ch == '\n' ) {} else { ungetc(ch,fd); fgets(str_tmp, STRLEN, fd); sscanf (str_tmp, "%s", keyword); #ifdef DEBUG printf("\nfgets returns %s so keyword=%s\n\n",str_tmp,keyword); #endif /* Start parsing real config inputs */ if(strcmp(keyword,"CRATE") == 0) { /* check if */ sprintf(ROC_name, "%s", host); if( (strstr(str_tmp,ROC_name) != NULL)) { printf("\nReadConfigFile: Wrong crate name in config file, %s\n",str_tmp); return(-3); } } else if(strcmp(keyword,"DSC2_ALLSLOTS") == 0) { gr++; for(ii=0; ii21) { printf("\nReadConfigFile: Wrong slot number %d, %s\n",slot,str_tmp); return(-4); } dsc[slot].group = gr; } } else if(strcmp(keyword,"DSC2_SLOT") == 0) { gr++; sscanf (str_tmp, "%*s %d", &slot); if(slot<1 || slot>21) { printf("\nReadConfigFile: Wrong slot number %d, %s\n",slot,str_tmp); return(-5); } dsc[slot].group = gr; } DSC2_B_XSCAN("DSC2_F_REV", dsc[ii].f_rev) DSC2_B_XSCAN("DSC2_ID", dsc[ii].b_ID) else if(strcmp(keyword,"DSC2_ALLSN") == 0) { args = sscanf (str_tmp, "%*s %s %s %s %s %s %s %s %s %s %s \ %s %s %s %s %s %s %s %s %s %s %s", &sn[ 1], &sn[ 2], &sn[ 3], &sn[ 4], &sn[ 5], &sn[ 6], &sn[ 7], &sn[ 8], &sn[ 9], &sn[10], &sn[11], &sn[12], &sn[13], &sn[14], &sn[15], &sn[16], &sn[17], &sn[18], &sn[19], &sn[20], &sn[21]); if(args != 21) { printf("\nReadConfigFile: Wrong number of SNs %d, should be 21 :: %s\n\n",args,str_tmp); return(-5); } for(ii=1; ii20) { printf("\nReadConfigFile: Wrong slot number %d, %s\n",slot,str_tmp); return(-6); } sprintf((char *)dsc[slot].SerNum, "%s", sn[0]); } DSC2_READ_MASKS("DSC2_TDCMASK", dsc[ii].TDCChMask) DSC2_READ_MASKS("DSC2_TRGMASK", dsc[ii].TRGChMask) DSC2_READ_MASKS("DSC2_TDCORMASK", dsc[ii].TDCORMask) DSC2_READ_MASKS("DSC2_TRGORMASK", dsc[ii].TRGORMask) else if(strcmp(keyword,"DSC2_WIDTH") == 0) { sscanf (str_tmp, "%*s %d %d", &i1, &i2); for(ii=0; ii=NCHAN)) { printf("\nReadConfigFile: Wrong channel number, %d\n\n",chan); return(-7); } for(ii=0; ii=NCHAN)) { printf("\nReadConfigFile: Wrong channel number, %d\n\n",chan); return(-8); } for(ii=0; ii0, set trigger output to the digital */ if(dsc[slot].TRGDigitalWidth[chan]>0) { /*printf("[%2d][%2d] befor 0x%04x\n",slot,chan,bypMask);*/ bypMask = bypMask ^ (1<= 0) { start = id; end = start + 1; } else { return; } printf("Ndsc=%d\n",Ndsc); for(kk=start; kk