/************************************************************************* * * 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 10 // #define MAX_EVENT_LENGTH 4096*64 /* Size in Bytes */ #define MAX_EVENT_LENGTH 4096*1000 /* 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 /* Measured longest fiber length in system */ // #define FIBER_LATENCY_OFFSET 0x4A // #define FIBER_LATENCY_OFFSET 0xCA #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 "conf_utils.h" #include "conf_utils.c" int NFADC; int FA_SLOT; #include "fa125_init.c" #include "fa250_init.c" #include "dsc_init.c" #include "caen1290_init.c" extern int fadcA32Base; /* Define buffering level */ #define BUFFERLEVEL 1 bd_type board_type = bd_unknown; /**************************************** * DOWNLOAD ****************************************/ void rocDownload() { int rc = -1; int stat; memset(fa250, 0, sizeof(fa250)); memset(fa125, 0, sizeof(fa125)); memset(&caen1290, 0, sizeof(caen1290)); memset(&dsc, 0, sizeof(dsc)); memset(&ti_bd, 0, sizeof(ti_bd)); gethostname(roc_name,ROCLEN); /* Global config file */ strcpy(filename,rol->usrConfig); printf(BOLDMAGENTA " Global Config File Name %s \n" RESET ,filename); rc = read_conf_global(filename,roc_name); if(rc != 0){ printf(BOLDRED " FATAL: Fail to read global configuration file %d \n" RESET, rc); daLogMsg(" FATAL: Fail to read global configuration file"); return; } rc = read_conf_common(roc_name); if(rc != 0){ printf(BOLDRED " FATAL: Fail to read file with crate specific parameters %d \n" RESET, rc); daLogMsg(" FATAL: Fail to read common configuration file"); return; } rc = read_conf_user(roc_name); if(rc != 0){ printf(BOLDRED " FATAL: Fail to read user config file %d \n" RESET, rc); daLogMsg(" FATAL: Fail to read user configuration file"); return; } board_type = get_board_type(roc_name); /* 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); fadcA32Base=0x09000000; /* Define BLock Level variable to a default */ blockLevel = 1; if(board_type == dsc2){ rc = dsc_download(); return; } /***************** * TI SETUP *****************/ if(ti_bd.ti_master == 1){ printf(BOLDBLUE " Stand alone run with the Master TI. Enable optical port 5 \n" RESET); tiSetSlavePort(5); tiSetTriggerSource(TI_TRIGGER_HFBR5); } else { printf(BOLDBLUE " Run with the TS. Optical port 1 is used \n" RESET); } /* 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); if(board_type == tdc1290){ /* Set the busy source to non-default value (no Switch Slot B busy) */ printf(BOLDBLUE " RESET BUSY HERE 0 \n" RESET); tiSetBusySource(TI_BUSY_FP_FADC,1); printf(BOLDBLUE " RESET BUSY HERE 1 \n" RESET); } tiStatus(0); if(board_type == fadc125) rc = fa125_download(); if(board_type == fadc250) rc = fa250_download(); if(board_type == tdc1290) rc = caen1290_download(); printf("rocDownload: User Download Executed\n"); printf("\n"); printf(" TI FIBER LATENCY MEASUREMENT DOWNLOAD %d \n", tiGetFiberLatencyMeasurement()); printf("\n"); } /**************************************** * PRESTART ****************************************/ void rocPrestart() { int rc = -1; if(board_type == dsc2){ return; } /* Unlock the VME Mutex */ vmeBusUnlock(); tiStatus(0); if(board_type == fadc125) rc = fa125_prestart(); if(board_type == fadc250) rc = fa250_prestart(); if(board_type == dsc) rc = dsc_prestart(); tiStatus(0); if(board_type != tdc1290) sdStatus(); printf("rocPrestart: User Prestart Executed\n"); } /**************************************** * GO ****************************************/ void rocGo() { if(board_type == dsc2){ return; } // TEST tiStatus(1); int islot; /* Get the broadcasted Block Level from TS or TI Master */ blockLevel = tiGetCurrentBlockLevel(); printf("rocGo: Block Level set to %d\n",blockLevel); /* Enable/Set Block Level on modules, if needed, here */ printf("\n"); printf(" TI FIBER LATENCY MEASUREMENT GO %d \n",tiGetFiberLatencyMeasurement()); printf("\n"); } /**************************************** * END ****************************************/ void rocEnd() { int rc = -1; if(board_type == fadc250) rc = fa250_end(); tiStatus(0); printf("rocEnd: Ended after %d blocks\n",tiGetIntCount()); } /**************************************** * TRIGGER ****************************************/ void rocTrigger(int arg) { int ii, islot; int stat = 0, dCnt, len = 0, idata; unsigned int val; unsigned int *start; int timeout = 100000; int iread; int itime, gbready; int roflag=1; tiStatus(1); /* Set TI output 1 high for diagnostics */ tiSetOutputPort(1,0,0,0); if(board_type == fadc125){ vmeDmaConfig(2,3,0); } /* Readout the trigger block from the TI Trigger Block MUST be reaodut first */ dCnt = tiReadTriggerBlock(dma_dabufp); if(dCnt<=0) { printf("No data or error. dCnt = %d\n",dCnt); } else { /* TI Data is already in a bank structure. Bump the pointer */ dma_dabufp += dCnt; printf("TI read block %d \n",dCnt); } // READOUT FADC250 if(board_type == fadc250){ printf("Sascha %d \n",blockLevel); BANKOPEN(6,BT_UI4,blockLevel); /* Readout FADC */ /* Configure Block Type... temp fix for 2eSST trouble with token passing */ if(NFADC!=0) { FA_SLOT = fadcID[0]; for(itime = 0; itime < 1000; itime++) { gbready = faGBready(); stat = (gbready == fadcSlotMask); if (stat>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\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 1) rflag=2; for(iread = 0; iread < timeout; iread++) { gbready = fa125GBready(); if(gbready == fa125ScanMask()) break; } if(iread==timeout) { printf("fa125 (%d) timeout (fa125GBready: 0x%08x != 0x%08x)\n"); fa125ResetToken(fa125Slot(0)); return ; } else { dCnt = fa125ReadBlock(0,(volatile UINT32 *)dma_dabufp, 0x59000, 0x2); } if(dCnt<=0) { fa125ResetToken(fa125Slot(0)); printf("FADC%d: No data or error \n",FA_SLOT); } else { dma_dabufp += dCnt; printf(" READ FADC %d \n",dCnt); } fa125ResetToken(fa125Slot(0)); BANKCLOSE; } /* Set TI output 0 low */ tiSetOutputPort(0,0,0,0); } void rocCleanup() { int islot=0; printf("%s: Reset all Modules\n",__FUNCTION__); }