/************************************************************************* * * vme_list.c - Library of routines for readout and buffering of * events using a JLAB Trigger Interface V3 (TI) with * a Linux VME controller. * */ /* Event Buffer definitions */ #define MAX_EVENT_POOL 20 #define MAX_EVENT_LENGTH 1024*60 /* Size in Bytes */ /* Define Interrupt source and address */ #define TI_MASTER #define TI_READOUT TI_READOUT_EXT_POLL /* Poll for available data, external triggers */ #define TI_ADDR 0 #define TI_DATA_READOUT /* Decision on whether or not to readout the TI for each block - Comment out to disable readout */ #define FIBER_LATENCY_OFFSET 0x40 #include "dmaBankTools.h" #include "tiprimary_list.c" /* source required for CODA */ #include "fadcLib.h" /* library of FADC250 routines */ #include "confutils.h" #include "confutils.c" #define BLOCKLEVEL 1 #define BUFFERLEVEL 1 //#define BUFFERLEVEL 10 unsigned int MAXFADCWORDS = 0; unsigned int MAXTIWORDS = 0; extern unsigned int tiTriggerSource; #if 0 /* Redefine tsCrate according to TI_MASTER or TI_SLAVE */ #ifdef TI_SLAVE int tsCrate=0; #else #ifdef TI_MASTER int tsCrate=1; #endif #endif #endif /* 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_dir; char conf_file[100]; char roc_name[ROCLEN]; /* function prototype */ void rocTrigger(int arg); /**************************************** * DOWNLOAD ****************************************/ void rocDownload() { gethostname(roc_name,ROCLEN); conf_dir = getenv ("CONF_DIR"); if (conf_dir == NULL) printf ("WRONG PATH TO CONFIG FILES %s\n", conf_dir); printf ("CONFIG FILES TAKEN FROM host: %s conf_dir: %s \n", roc_name, conf_dir); sprintf(conf_file,"%s/%s_pulser.cnf",conf_dir,roc_name); printf ("OPEN CONFIG FILE %s\n", conf_dir); printf ("OPEN CONFIG FILE %s\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]); 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); /***************** * TI SETUP *****************/ int overall_offset=0x80; #ifndef TI_DATA_READOUT /* Disable data readout */ tiDisableDataReadout(); /* Disable A32... where that data would have been stored on the TI */ tiDisableA32(); #endif tiSetCrateID(ROCID); printf("TI CrateID register set to %d\n",ROCID); // Trigger Sources: // TI_TRIGGER_PULSER 5 tiSetTriggerSource(TI_TRIGGER_PULSER); /* Set needed TS input bits */ // tiEnableTSInput( TI_TSINPUT_1 | TI_TSINPUT_6 ); /* 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 the busy source to non-default value (no Switch Slot B busy) */ tiSetBusySource(TI_BUSY_LOOPBACK,1); /* Set number of events per block */ blockLevel = BLOCKLEVEL; tiSetBlockLevel(BLOCKLEVEL); /* Set timestamp format 48 bits */ tiSetEventFormat(3); tiSetBlockBufferLevel(BUFFERLEVEL); // tiAddSlave(1); // tiAddSlave(2); // tiAddSlave(3); // tiAddSlave(4); // tiAddSlave(5); 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 = NFADC * BLOCKLEVEL * (1 + 2 + 200*16 + 1) + 2*32; // MAXFADCWORDS = 2 * BLOCKLEVEL * (1 + 2 + 200*16 + 1) + 2*32; MAXFADCWORDS = 8 * BLOCKLEVEL * (1 + 2 + 60*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<1000) { printf("iwait timeout allchup - 0x%x\n",allchanup); break; } } #endif printf("rocDownload: User Download Executed\n"); } /**************************************** * PRESTART ****************************************/ void rocPrestart() { unsigned short iflag; int stat; int islot; /* Unlock the VME Mutex */ vmeBusUnlock(); /* FADC Perform some resets, status */ for(islot=0;islot1000) { printf("iwait timeout allchup - 0x%x\n",allchanup); break; } } #endif // getchar(); // tiSyncReset(); } /**************************************** * END ****************************************/ void rocEnd() { int islot; faPPGDisable(FA_SLOT); /* FADC Disable */ for(islot=0;islot0) { 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); 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