/************************************************************************* * * 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 * * Modified: Tue Apr 29 09:57:23 EDT 2014 B. Zihlmann * adaped for CDC readout using TS * */ /* Event Buffer definitions */ #define MAX_EVENT_POOL 10 #define MAX_EVENT_LENGTH 4096*1000 /* Size in Bytes: can not be more than 4MB*/ /* 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 (21<<19) /* Measured longest fiber length in system */ /*#define FIBER_LATENCY_OFFSET 0x3A */ #define FIBER_LATENCY_OFFSET 0xCA #define BLOCKLEVEL 1 #define BUFFERLEVEL 1 /*int blockLevel = BLOCKLEVEL;*/ /*int tsCrate=0;*/ #include "dmaBankTools.h" /* Macros for handling CODA banks */ #include "tiprimary_list.c" /* Source required for CODA readout lists using the TI */ #include "f1tdcLib.h" extern int f1AddrList[F1_MAX_BOARDS]; extern int f1tdcA32Base; #include "ccdb_inc.h" /* include file for C++ API wrapper*/ /* private variables for the time being needed for hard coded stuff*/ int HOSTROC = 0; char hnam[128]; char str1[128]; char DETECTOR[128]; int NTDCS = 0; int SLOT = 3; int NODAC = 1; /* if set to 1 set all DAC valvues to 0x8000 */ int ERRORCounter = 0; int ERRORLOG = 100; /* CCDB DATABASE VARIABLES*/ int DAC_Values[20][72]; int Thresholds[20][72]; int FA125ReadOutMode; int FA125Latency; int FA125WindowSize; int FA125NSB; int FA125NSA; int FA125NP; int EventCounter = 0; /**************************************** * DOWNLOAD ****************************************/ void rocDownload() { int stat; int iFlag; int offset = 0; int k = 0; f1tdcA32Base = 0x09000000; /* hard code numbers here for the time being*/ /* and code that I understand */ /* CONFIGURATION PARAMETERS FOR THE CRATE AND THE ADCS ARE CURRENTLY TAKEN FROM */ /* ONLINE_CCDB AS DAQ CONFIGURATiON SCHEEME IS STILL UNDER CONTRUCTION */ gethostname(hnam,128); strncpy(str1, &hnam[6], 128); HOSTROC = atoi(str1); strncpy(DETECTOR,&hnam[3],3); DETECTOR[3] = '\0'; NTDCS = GetCrateConfigfromdatabase(HOSTROC, DETECTOR); printf("Number of TDCs: %d\n",NTDCS); if (NTDCS<1) { printf("rocDownload ERROR: %s ROC %d failed to read configuration from database!", DETECTOR, HOSTROC); } else { printf("rocDownload: %s ROC %d: configure for %d TDCs !", DETECTOR, HOSTROC, NTDCS); } /* 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 */ /* will be set by TS */ blockLevel = 1; /***************** * TI SETUP *****************/ /* Set the sync delay width to 0x40*32 = 2.048us */ tiSetSyncDelayWidth(0x54, 0x40, 1); /* Set Trigger Buffer Level */ tiSetBlockBufferLevel(BUFFERLEVEL); printf("rocDownload: Initialize TDCs\n"); offset = 0; for (k=0; k