/* * File: * tiLibTest.c * * Description: * Test Vme TI interrupts with GEFANUC Linux Driver * and TI library * * */ #include #include #include #include #include "jvme.h" #include "tiLib.h" #include "c1190Lib.h" /* #include "remexLib.h" */ DMA_MEM_ID vmeIN,vmeOUT; extern DMANODE *the_event; extern unsigned int *dma_dabufp; extern int tiA32Base; extern int Nc1190; #define BLOCKLEVEL 50 // 0: CBLT 1: LL-DMA #define ROMODE 1 #define DO_READOUT const int NUM_V1190 = 6; unsigned int scanmask=0; void sig_handler(int signo); /* Interrupt Service routine */ void mytiISR(int arg) { volatile unsigned short reg; int dCnt, len=0,idata; DMANODE *outEvent; int tibready=0, timeout=0; int printout = 1; unsigned int tiIntCount = tiGetIntCount(); #ifdef DO_READOUT GETEVENT(vmeIN,tiIntCount); #ifdef DOINT tibready = tiBReady(); if(tibready==ERROR) { printf("%s: ERROR: tiIntPoll returned ERROR.\n",__FUNCTION__); return; } if(tibready==0 && timeout<100) { printf("NOT READY!\n"); tibready=tiBReady(); timeout++; } if(timeout>=100) { printf("TIMEOUT!\n"); return; } #endif vmeDmaConfig(2,5,1); dCnt = tiReadBlock(dma_dabufp,10*BLOCKLEVEL+10,1); /* dCnt = tiReadTriggerBlock(dma_dabufp); */ if(dCnt<=0) { printf("No data or error. dCnt = %d\n",dCnt); } else { /* dma_dabufp += dCnt; */ /* printf("dCnt = %d\n",dCnt); */ } int ii, itdc, status, dma, count; int nwords, scan; unsigned int datascan; /* Check for valid data here */ for(ii=0;ii<1000;ii++) { datascan = tdc1190GDready(BLOCKLEVEL); if (datascan==scanmask) break; } /* Now wait until the first TDC has one more than the blocklevel */ int brick=0; while(tdc1190Dready(0) < BLOCKLEVEL) { if(brick++>60) break; taskDelay(1); } printf("tdc1190Dready(0) = %d <= %d\n",tdc1190Dready(0),BLOCKLEVEL); tiStatus(0); if(datascan==scanmask) { /* Get the TDC data from all modules... rflag=2 for Linked List DMA "64" is ignored in Linux */ #if(ROMODE==0) vmeDmaConfig(2,3,2); nwords = tdc1190CBLTReadBlock(0,dma_dabufp,0x70000<<2,2); #else vmeDmaConfig(2,5,2); nwords = tdc1190ReadBlock(0,dma_dabufp,64000,2|(BLOCKLEVEL<<8)); #endif if(nwords < 0) { printf("ERROR: in transfer (event = %d), status = 0x%x\n", tiGetIntCount(),nwords); *dma_dabufp++ = LSWAP(0xda000bad); } else { dma_dabufp += nwords; } } else { printf("ERROR: Data not ready in event %d.. 0x%08x != 0x%08x\n", tiGetIntCount(), datascan, scanmask); *dma_dabufp++ = LSWAP(datascan); *dma_dabufp++ = LSWAP(scanmask); *dma_dabufp++ = LSWAP(0xda000bad); } PUTEVENT(vmeOUT); outEvent = dmaPGetItem(vmeOUT); #define READOUT #ifdef READOUT if(tiIntCount%printout==0) { printf("Received %d triggers...\n", tiIntCount); len = outEvent->length; for(idata=0;idatadata[idata])); */ tdc1190DataDecode(LSWAP(outEvent->data[idata])); } printf("\n\n"); } #endif dmaPFreeItem(outEvent); #else /* DO_READOUT */ /* tiResetBlockReadout(); */ #endif /* DO_READOUT */ if(tiIntCount%printout==0) printf("intCount = %d\n",tiIntCount ); /* sleep(1); */ if(tiGetIntCount()==5) tiSetBlockLimit(1); } int main(int argc, char *argv[]) { int stat; /* Initalize the signal handler */ signal(SIGINT,sig_handler); printf("\nJLAB TI Tests\n"); printf("----------------------------\n"); /* remexSetCmsgServer("dafarm28"); */ /* remexInit(NULL,1); */ vmeOpenDefaultWindows(); vmeCheckMutexHealth(1); vmeDmaAllocLLBuffer(); /* 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); /* INIT dmaPList */ dmaPFreeAll(); vmeIN = dmaPCreate("vmeIN",0x80000,500,0); vmeOUT = dmaPCreate("vmeOUT",0,0,0); dmaPStatsAll(); dmaPReInitAll(); /* gefVmeSetDebugFlags(vmeHdl,0x0); */ /* Set the TI structure pointer */ /* tiInit((2<<19),TI_READOUT_EXT_POLL,0); */ tiA32Base=0x09000000; tiInit(0,TI_READOUT_EXT_POLL,0); tiCheckAddresses(); tiSetSyncEventInterval(10); tiSetEventFormat(3); #ifndef DO_READOUT tiDisableDataReadout(); tiDisableA32(); #endif tiLoadTriggerTable(0); tiSetTriggerHoldoff(1,4,0); tiSetTriggerHoldoff(2,4,0); tiSetPrescale(0); tiSetBlockLevel(BLOCKLEVEL); stat = tiIntConnect(TI_INT_VEC, mytiISR, 0); if (stat != OK) { printf("ERROR: tiIntConnect failed \n"); goto CLOSE; } else { printf("INFO: Attached TI Interrupt\n"); } /* tiSetTriggerSource(TI_TRIGGER_TSINPUTS); */ tiSetTriggerSource(TI_TRIGGER_PULSER); tiEnableTSInput(0x1); tiSetBusySource(TI_BUSY_FP_FTDC|TI_BUSY_LOOPBACK,1); tiSetBlockBufferLevel(50); tiSetFiberDelay(1,2); tiSetSyncDelayWidth(1,0x3f,1); tiSetBlockLimit(0); tdc1190Init(0x11180000,0x80000,NUM_V1190,1); if(Nc1190==0) goto CLOSE; int itdc; int iexcept=0; unsigned int mcstaddr; tdc1190InitMCST(&mcstaddr); tdc1190GSetTriggerMatchingMode(); tdc1190GSetEdgeResolution(100); tdc1190ConfigureGReadout(ROMODE); tdc1190GSetBLTEventNumber(BLOCKLEVEL); for(itdc=0; itdc