/************************************************************************* * * ti_slave_list.c - Library of routines for readout and buffering of * events using a JLAB Trigger Interface V3 (TI) with * a Linux VME controller in CODA 3.0. * * This is for a TI in Slave Mode controlled by a * Master TI or Trigger Supervisor * */ /* Event Buffer definitions */ #define MAX_EVENT_POOL 20 #define MAX_EVENT_LENGTH 4096*64 /* Size in Bytes */ /* Define TI Type (TI_MASTER or TI_SLAVE) */ #define TI_SLAVE /* TS Fiber Link trigger source (from TI Master, TD, or TS), POLL for available data */ #define TI_READOUT TI_READOUT_TS_POLL /* TI VME address, or 0 for Auto Initialize (search for TI by slot) */ #define TI_ADDR 0 #define TI_DATA_READOUT /* Measured longest fiber length in system */ #define FIBER_LATENCY_OFFSET 0x4A #include "dmaBankTools.h" /* Macros for handling CODA banks */ #include "tiprimary_list.c" /* Source required for CODA readout lists using the TI */ #include "fadcLib.h" /* library of FADC250 routines */ /*** Configuration functions ***/ #include "confutils.h" #include "confutils.c" /* Define buffering level */ #define BUFFERLEVEL 1 #define BLOCKLEVEL 1 unsigned int MAXFADCWORDS = 0; unsigned int MAXTIWORDS = 0; /* FADC Library Variables */ extern int fadcA32Base; int FA_SLOT; extern int fadcID[20]; extern int nfadc; /* Number of FADC250s verified with the library */ extern int fadcID[FA_MAX_BOARDS]; /* Array of slot numbers, discovered by the library */ int NFADC; /* The Maximum number of tries the library will */ unsigned int fadcSlotMask = 0; /* bit=slot (starting from 0) */ char conf_file[150]; char roc_name[ROCLEN]; /**************************************** * DOWNLOAD ****************************************/ void rocDownload() { int stat; gethostname(roc_name,ROCLEN); printf("\n TEST TEST TEST TEST %s\n",rol->usrConfig); printf("TEST TEST TEST TEST %s\n",rol->usrString); char *dummy = strdup( rol->usrConfig ); char *conf_dir = dirname( dummy ); // Temporary Run Control patch char *conf_name_tmp = basename(rol->usrConfig); printf("Directory name %s \n",conf_dir); printf("Configuration file name %s \n", conf_name_tmp); printf("KKKK %d \n",strcmp(conf_name_tmp, "pulse")); if(strcmp(conf_name_tmp, "pulse") == 0){ sprintf(conf_file,"%s/%s_pulser.cnf",conf_dir,roc_name); printf(" ====== SASCHA ====== %s \n",conf_file); } sprintf(conf_file,"%s/%s_pulser.cnf",conf_dir,roc_name); free(dummy); printf ("OPEN CONFIG FILE %s\n \n", conf_file); fadc250InitGlobals(); printf(" TEST CONFIG FILE \n"); printf(" TEST CONFIG FILE \n"); fadc250ReadConfigFile(conf_file); fadcA32Base=0x09000000; /* Setup Address and data modes for DMA transfers * * vmeDmaConfig(addrType, dataType, sstMode); * * addrType = 0 (A16) 1 (A24) 2 (A32) * dataType = 0 (D16) 1 (D32) 2 (BLK32) 3 (MBLK) 4 (2eVME) 5 (2eSST) * sstMode = 0 (SST160) 1 (SST267) 2 (SST320) */ vmeDmaConfig(2,5,1); /* Define BLock Level variable to a default */ blockLevel = 1; tiSetSlavePort(5); // tiSetTriggerSource(TI_TRIGGER_HFBR5); /***************** * TI SETUP *****************/ int overall_offset=0x80; // tiSetTriggerSource(TI_TRIGGER_HFBR5); /* Set the sync delay width to 0x40*32 = 2.048us */ tiSetSyncDelayWidth(0x54, 0x40, 1); /* Set Trigger Buffer Level */ tiSetBlockBufferLevel(BUFFERLEVEL); /* Set timestamp format 48 bits */ tiSetEventFormat(3); tiStatus(0); /*************************************** * FADC Setup ***************************************/ /* Here, we assume that the addresses of each board were set according to their * geographical address (slot number): * Slot 3: (3<<19) = 0x180000 * Slot 4: (4<<19) = 0x200000 * ... * Slot 20: (20<<19) = 0xA00000 */ // NFADC = 16+2; /* 16 slots + 2 (for the switch slots) */ NFADC = 1; MAXFADCWORDS = 16 * BLOCKLEVEL * (1 + 2 + 200*16 + 1) + 2*32; /* Setup the iFlag.. flags for FADC initialization */ int iFlag; iFlag = 0; /* Sync Source */ iFlag |= (1<<0); /* VXS */ /* Trigger Source */ iFlag |= (1<<2); /* VXS */ /* Clock Source */ iFlag |= (0<<5); /* self*/ vmeSetQuietFlag(1); /* skip the errors associated with BUS Errors */ if(AllSl == 0) { iFlag |= (1<<17); /* activate useing fadcAddrList in faInit */ /* faInit((unsigned int)(3<<19),(1<<19),Naddr,iFlag); */ faInit(fadcAddrList[0],0,Naddr,iFlag); } vmeSetQuietFlag(0); /* Turn the error statements back on */ NFADC = nfadc; /* Redefine our NFADC with what was found from the driver */ printf(" TEST TEST Redefine our NFADC=%d \n",NFADC); int slot; for(slot = 0;slot < NFADC;slot++){ printf(" CHECK CHECK: NFADC = %d SLOT = %d \n", NFADC, fadcID[slot]); FA_SLOT = fadcID[slot]; fadcSlotMask |= (1<0) { break; } } if(stat>0) { if(NFADC>1) roflag=2; /* Use token passing scheme to readout all modules */ dCnt = faReadBlock(FA_SLOT,dma_dabufp,MAXFADCWORDS,roflag); printf(" FADC words %d NFADC=%d\n",dCnt,NFADC); if(dCnt<=0) { printf("FADC%d: No data or error. dCnt = %d\n",FA_SLOT,dCnt); } else { dma_dabufp += dCnt; } } else { printf ("FADC%d: no events stat=%d intcount = %d gbready = 0x%08x fadcSlotMask = 0x%08x\n", FA_SLOT,stat,tiGetIntCount(),gbready,fadcSlotMask); } /* Reset the Token */ if(roflag==2) { for(islot=0; islot