/************************************************************************* * * ti_master_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 for a TI in Master Mode controlling multiple ROCs */ /* 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_MASTER /* EXTernal trigger source (e.g. front panel ECL input), POLL for available data */ #define TI_READOUT TI_READOUT_EXT_POLL /* TI VME address, or 0 for Auto Initialize (search for TI by slot) */ #define TI_ADDR 0 /* 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 */ #include "confutils.h" #include "confutils.c" /* Define initial blocklevel and buffering level */ #define BLOCKLEVEL 1 #define BUFFERLEVEL 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; int opt_port = -1; 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 ); char *conf_name_tmp = basename(rol->usrConfig); printf("Directory name %s \n",conf_dir); printf("Configuration file name %s \n", conf_name_tmp); 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); printf(" TI_FOFT_TRIG %d %d %d %d\n", ti_bd.ti_soft_trig[0], ti_bd.ti_soft_trig[1], ti_bd.ti_soft_trig[2], ti_bd.ti_soft_trig[3]); printf(" TI_FIBER_EN 0x%x \n", ti_bd.ti_fiber_en); 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 */ blockLevel = BLOCKLEVEL; /***************** * TI SETUP *****************/ /* * Set Trigger source * For the TI-Master, valid sources: * TI_TRIGGER_FPTRG 2 Front Panel "TRG" Input * TI_TRIGGER_TSINPUTS 3 Front Panel "TS" Inputs * TI_TRIGGER_TSREV2 4 Ribbon cable from Legacy TS module * TI_TRIGGER_PULSER 5 TI Internal Pulser (Fixed rate and/or random) */ int overall_offset=0x80; // tiSetTriggerSource(TI_TRIGGER_PULSER); tiSetTriggerSource(TI_TRIGGER_TSINPUTS); tiEnableTSInput( TI_TSINPUT_3); // tiSetTriggerSource(TI_TRIGGER_TSINPUTS); /* TS Inputs enabled */ /* Enable set specific TS input bits (1-6) */ // tiEnableTSInput( TI_TSINPUT_1 | TI_TSINPUT_2 ); /* Load the trigger table that associates * pins 21/22 | 23/24 | 25/26 : trigger1 * pins 29/30 | 31/32 | 33/34 : trigger2 */ tiLoadTriggerTable(2); tiSetTriggerHoldoff(1,10,0); tiSetTriggerHoldoff(2,10,0); /* Set the sync delay width to 0x40*32 = 2.048us */ tiSetSyncDelayWidth(0x54, 0x40, 1); /* Set initial number of events per block */ tiSetBlockLevel(blockLevel); /* Set Trigger Buffer Level */ tiSetBlockBufferLevel(BUFFERLEVEL); /* Set timestamp format 48 bits */ tiSetEventFormat(3); // FCAL for(opt_port = 2; opt_port < 7; opt_port++){ if(ti_bd.ti_fiber_en & (1 << (opt_port - 1))) printf("TI Add Slave for optical port = %d %d \n",opt_port,tiAddSlave(opt_port)); } // BCAL // tiAddSlave(2); // tiAddSlave(4); // tiAddSlave(5); #if 0 tiAddSlave(2); tiAddSlave(3); tiAddSlave(4); tiAddSlave(5); tiAddSlave(6); #endif 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) */ 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 |= (1<<5); /* VXS */ iFlag |= (0<<5); /* self*/ vmeSetQuietFlag(1); /* skip the errors associated with BUS Errors */ // faInit((unsigned int)(4<<19),(unsigned int)(1<<19),NFADC,iFlag); 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); } else faInit((unsigned int)(3<<19),(unsigned int)(1<<19),18,iFlag); vmeSetQuietFlag(0); /* Turn the error statements back on */ NFADC=nfadc; /* Redefine our NFADC with what was found from the driver */ printf("\n"); printf(" TEST NUMBER of FADCS INITIALIZED %d \n",NFADC); printf("\n"); int slot; for(slot = 0;slot < NFADC;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 */ printf("Read out FADC250 \n"); dCnt = faReadBlock(FA_SLOT,dma_dabufp,MAXFADCWORDS,roflag); printf(" FADC words %d\n",dCnt); 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