/************************************************************************* * * vme_list.c - Library of routines for readout and buffering of * events using a JLAB Trigger Interface V3 (TI) with * a Linux VME controller. * */ /* Event Buffer definitions */ #define MAX_EVENT_POOL 10 #define MAX_EVENT_LENGTH 1024*60 /* Size in Bytes */ /* Define Interrupt source and address */ #define TI_SLAVE #ifdef TI_SLAVE #define TI_READOUT TI_READOUT_TS_POLL /* Poll for available data, external triggers */ #endif #ifdef TI_MASTER #define TI_READOUT TI_READOUT_EXT_POLL /* Poll for available data, external triggers */ #endif #define TI_ADDR (21<<19) /* GEO slot 3 */ /* Decision on whether or not to readout the TI for each block - Comment out to disable readout */ #define TI_DATA_READOUT #define FIBER_LATENCY_OFFSET 0x40 /* measured longest fiber length */ #include "dmaBankTools.h" #include "tiprimary_list.c" /* source required for CODA */ #include "fadcLib.h" /* library of FADC250 routines */ #define BLOCKLEVEL 1 unsigned int MAXFADCWORDS = 0; unsigned int MAXTIWORDS = 0; extern unsigned int tiTriggerSource; /* Redefine tsCrate according to TI_MASTER or TI_SLAVE */ #ifdef TI_SLAVE int tsCrate=0; #else #ifdef TI_MASTER int tsCrate=1; #endif #endif /* FADC Library Variables */ extern int fadcA32Base; int FA_SLOT; extern int fadcID[20]; extern int nfadc; /* Number of FADC250s verified with the library */ extern int fadcID[FA_MAX_BOARDS]; /* Array of slot numbers, discovered by the library */ int NFADC; /* The Maximum number of tries the library will */ unsigned int fadcSlotMask = 0; /* bit=slot (starting from 0) */ /* function prototype */ void rocTrigger(int arg); /**************************************** * DOWNLOAD ****************************************/ void rocDownload() { fadcA32Base=0x09000000; /* 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); /***************** * TI SETUP *****************/ int overall_offset=0x80; #ifndef TI_DATA_READOUT /* Disable data readout */ tiDisableDataReadout(); /* Disable A32... where that data would have been stored on the TI */ tiDisableA32(); #endif /* Set crate ID */ tiSetCrateID(0x02); /* ROC 1 */ tiSetTriggerSource(TI_TRIGGER_TSINPUTS); /* Set needed TS input bits */ // tiEnableTSInput( TI_TSINPUT_1 | TI_TSINPUT_6 ); // tiEnableTSInput( TI_TSINPUT_ALL ); /* Load the trigger table that associates pins 21/22 | 23/24 | 25/26 : trigger1 pins 29/30 | 31/32 | 33/34 : trigger2 */ // TEST tiLoadTriggerTable(); // TEST tiSetTriggerHoldoff(1,10,0); tiSetTriggerHoldoff(2,10,0); // TEST /* Set the sync delay width to 0x40*32 = 2.048us */ tiSetSyncDelayWidth(0x54, 0x40, 1); tiSetFiberDelay(0x40,FIBER_LATENCY_OFFSET); // TEST /* Set the busy source to non-default value (no Switch Slot B busy) */ // tiSetBusySource(TI_BUSY_LOOPBACK,1); /* Set number of events per block */ tiSetBlockLevel(BLOCKLEVEL); tiSetEventFormat(1); tiSetBlockBufferLevel(1); tiStatus(); /*************************************** * FADC Setup ***************************************/ /* Here, we assume that the addresses of each board were set according to their * geographical address (slot number): * Slot 3: (3<<19) = 0x180000 * Slot 4: (4<<19) = 0x200000 * ... * Slot 20: (20<<19) = 0xA00000 */ // NFADC = 16+2; /* 16 slots + 2 (for the switch slots) */ NFADC = 6; // MAXFADCWORDS = NFADC * BLOCKLEVEL * (1 + 2 + 200*16 + 1) + 2*32; MAXFADCWORDS = 2 * BLOCKLEVEL * (1 + 2 + 200*16 + 1) + 2*32; /* Setup the iFlag.. flags for FADC initialization */ int iFlag; iFlag = 0; /* Sync Source */ iFlag |= (1<<0); /* VXS */ /* Trigger Source */ iFlag |= (1<<2); /* VXS */ /* Clock Source */ // iFlag |= (1<<5); /* VXS */ iFlag |= (0<<5); /* self*/ vmeSetQuietFlag(1); /* skip the errors associated with BUS Errors */ // faInit((unsigned int)(5<<19),(unsigned int)(1<<19),NFADC,iFlag); faInit((unsigned int)(8<<19),(unsigned int)(1<<19),NFADC,iFlag); // faInit((unsigned int)(8<<19),0,NFADC,iFlag); vmeSetQuietFlag(0); /* Turn the error statements back on */ NFADC=nfadc; /* Redefine our NFADC with what was found from the driver */ printf(" TEST TEST %d \n",NFADC); int slot; for(slot = 0;slot < NFADC;slot++){ FA_SLOT = fadcID[slot]; fadcSlotMask |= (1< 16){ // adc_playback[sample] = 500 + sample; // } else adc_playback[sample] = 100; } } #if 0 unsigned short adc_playback[32] = { 2,3,4,5, 6,7,8,9, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 }; #endif unsigned short adc_playback_allchannels[512]; unsigned short channel_mask = 0x0003; // all channels enabled // unsigned short channel_mask = 0xFFFF; // all channels enabled int ichan, isample; for(ichan=0;ichan<16;ichan++) { for(isample=0;isample<32;isample++) { if((1<1000) { printf("iwait timeout allchup - 0x%x\n",allchanup); break; } } #endif printf("rocDownload: User Download Executed\n"); } /**************************************** * PRESTART ****************************************/ void rocPrestart() { unsigned short iflag; int stat; int islot; printf("SASCHA ------------------------ Initialize TI ---------------- \n"); printf("\n"); /* tiSetup(21); */ /* FADC Perform some resets, status */ for(islot=0;islot1000) { printf("iwait timeout allchup - 0x%x\n",allchanup); break; } } #endif // getchar(); // tiSyncReset(); } /**************************************** * END ****************************************/ void rocEnd() { int islot; faPPGDisable(FA_SLOT); /* FADC Disable */ for(islot=0;islot0) { 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); 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