/************************************************************************* * * 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 1300000 /* 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 0 /* Measured longest fiber length in system */ /* #define FIBER_LATENCY_OFFSET 0x4A */ #define FIBER_LATENCY_OFFSET 0xCA #include "dmaBankTools.h" /* Macros for handling CODA banks */ #include "tiprimary_list.c" /* Source required for CODA readout lists using the TI */ #define BLOCKLEVEL 1 #include "fa125Lib.h" extern unsigned int fa125AddrList[FA125_MAX_BOARDS]; /* array of a24 addresses for FA125s */ /* CONFIGURATION IS CURRENTLY DONE USING ONLINE_CCDB */ /* #include "confutils.h" #include "confutils.c" */ #include "ccdb_inc.h" /* include file for C++ API wrapper*/ /* Define buffering level */ #define BUFFERLEVEL 10 /* private variables for the time being needed for hard coded stuff*/ int HOSTROC = 0; char hnam[128]; char str1[128]; char DETECTOR[128]; int NADCS = 0; int SLOT = 3; int NODAC = 1; /* if set to 1 set all DAC valvues to 0x8000 */ int DAC_Values[20][72]; int Thresholds[20][72]; int ERRORCounter = 0; int ERRORLOG = 100; int EventCounter = 0; /* NOTE THE FOLLOWING IS NEED TO DO SPARSIFICATION ON THE FLY ON THE ROC */ unsigned int new_array[325000]; /**************************************** * DOWNLOAD ****************************************/ void rocDownload() { int stat; int iFlag; /* 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'; NADCS = GetDACfromdatabase(HOSTROC, DETECTOR); if (NADCS<1) { printf("rocDownload ERROR: %s ROC %d failed to read DAC values from database!", DETECTOR, HOSTROC); } else { printf("rocDownload: %s ROC %d DAC and sparsification values loaded from database for %d ADCs!", DETECTOR, HOSTROC, NADCS); } /* 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); /* Init the SD library so we can get status info */ stat = sdInit(); if(stat==0) { tiSetBusySource(TI_BUSY_SWB,1); sdSetActiveVmeSlots(0); sdStatus(0); } else { /* No SD or the TI is not in the Proper slot */ tiSetBusySource(TI_BUSY_LOOPBACK,1); } tiStatus(0); printf("rocDownload: Initialize ADCs\n"); int offset = 0; int k = 0; for (k=0;k>27) == 0x10) { SLOTNUM = ((dataword & 0x7C00000)>>22); if (SLOTNUM<11) { SLOTNUM -=3; } else { SLOTNUM -= 5; } } if (((dataword & 0xf8000000)>>27) != 0x14) { OT = 0; CHANNEL = ((dataword & 0x7F00000)>>20) ; WSize = (dataword & 0xFFF) / 2 ; int k = 0; int pedcnt = 0; float ped = 0.; for (k=0;k> 16); adc2 = (float) (dataword & 0x1FFF); if (pedcnt<9) { ped += (float) (adc1+adc2); pedcnt += 2; if (pedcnt>9) { ped /= 10.; } } else { float v1 = adc1 - ped ; float v2 = adc2 - ped ; if ((v1>Thresholds[SLOTNUM][CHANNEL] || v2>Thresholds[SLOTNUM][CHANNEL])) { OT = 1; } } } if (!OT) { dCnt_new--; idata += WSize+1; } else { for (k=0;k