/* * File: * tiLibTest.c * * Description: * Test Vme TI interrupts with GEFANUC Linux Driver * and TI library * * */ #include #include #include #include "jvme.h" #include "tiLib.h" DMA_MEM_ID vmeIN,vmeOUT; extern DMANODE *the_event; extern unsigned int *dma_dabufp; extern int tiA32Base; #define MAXVETROCDATA 10000 #define VETROC_SLOT 6 unsigned int vetrocSlotMask=0; #define BLOCKLEVEL 1 #define DO_READOUT #define SOFTTRIG /* Interrupt Service routine */ void mytiISR(int arg) { volatile unsigned short reg; int dCnt, len=0,idata; DMANODE *outEvent; int tibready=0, timeout=0; unsigned int tiIntCount = tiGetIntCount(); printf(" tiIntCount = %d\n", tiIntCount); #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 /* *dma_dabufp++; */ dCnt = tiReadBlock(dma_dabufp,900>>2,1); if(dCnt<=0) { printf("No data or error. dCnt = %d\n",dCnt); } else { /* dma_dabufp += dCnt; */ /* printf("dCnt = %d\n",dCnt); */ } vetrocGTrig(0); int read_stat = 0, itime=0, debug=1; unsigned int gbready=0; for(itime=0; itime<1000; itime++) { gbready = vetrocGBready(); read_stat = (gbready == vetrocSlotMask); if (read_stat>0) break; } if (debug) { printf("gbready = %d read_stat = %d \n",gbready, read_stat); printf("vetrocSlotMask = %d \n",vetrocSlotMask); } if(read_stat>0) { /* read the data here */ dCnt = vetrocReadBlock(VETROC_SLOT,dma_dabufp, MAXVETROCDATA, 1); dma_dabufp += dCnt; *dma_dabufp++ = LSWAP(0xb0b0b0b4); *dma_dabufp++ = LSWAP(dCnt); *dma_dabufp++ = LSWAP(read_stat); *dma_dabufp++ = LSWAP(vetrocDready(VETROC_SLOT,1)); *dma_dabufp++ = LSWAP(vetrocDready(VETROC_SLOT,0)); } else { printf("ERROR: Data not ready in event %d\n",tiGetIntCount()); *dma_dabufp++ = LSWAP(0xda000bad); } PUTEVENT(vmeOUT); outEvent = dmaPGetItem(vmeOUT); #define READOUT #ifdef READOUT if(tiIntCount%1==0) { printf("Received %d triggers...\n", tiIntCount); len = outEvent->length; for(idata=0;idatadata[idata])); } printf("\n\n"); } #endif dmaPFreeItem(outEvent); #else /* DO_READOUT */ tiResetBlockReadout(); #endif /* DO_READOUT */ /* tiStatus(1); */ /* sleep(1); */ } int main(int argc, char *argv[]) { int stat; printf("\nJLAB TI Tests\n"); printf("----------------------------\n"); vmeOpenDefaultWindows(); /* 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",40240,500,0); vmeOUT = dmaPCreate("vmeOUT",0,0,0); dmaPStatsAll(); dmaPReInitAll(); /* gefVmeSetDebugFlags(vmeHdl,0x0); */ /* Set the TI structure pointer */ /* tiA32Base = 0x09000000; */ tiInit(0,TI_READOUT_EXT_POLL,0); tiCheckAddresses(); char mySN[20]; printf("0x%08x\n",tiGetSerialNumber((char **)&mySN)); printf("mySN = %s\n",mySN); #ifndef DO_READOUT tiDisableA32(); #endif tiLoadTriggerTable(3); /* tiSetTriggerHoldoff(1,12,0); */ /* tiSetTriggerHoldoff(2,12,0); */ /* tiSetPrescale(1); */ 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"); } #ifdef SOFTTRIG tiSetTriggerSource(TI_TRIGGER_PULSER); #else tiSetTriggerSource(TI_TRIGGER_TSINPUTS); #endif tiEnableTSInput(0x3f); /* tiSetFPInput(0x0); */ /* tiSetGenInput(0xffff); */ /* tiSetGTPInput(0x0); */ tiSetBusySource(TI_BUSY_LOOPBACK,1); tiSetBlockBufferLevel(0x1); /* SETUP VETROC */ int iflag = 0; int nvetroc = vetrocInit((VETROC_SLOT<<19), 0x80000, 1, iflag); if (nvetroc <= 0) { printf("ERROR: no VETROC !!! \n"); } vetrocSlotMask=0; vetrocSlotMask |= (1<