/* Standalone test code to check VETROC at a basic level */ /* R. Michaels May 2015 */ #include #include #include #include #include #include "jvme.h" #include "vetrocLib.h" #define VETROC_SLOT 3 #define MAX_EVENT_LENGTH 10240 #define MAX_EVENT_POOL 500 /* global variables */ extern int nvetroc; /* Number of VETROCs in Crate */ /*! Buffer node pointer */ extern DMANODE *the_event; static unsigned int vetrocSlotMask; static unsigned int MAXVETROCWORDS = 10000; int block_level=1; int read_stat=0; unsigned long *tdcbuf; /* Input and Output Partitions for VME Readout */ DMA_MEM_ID vmeIN, vmeOUT; void usage(int ix); void setup(); void findtrigger(); void getdata(); int main(int argc, char *argv[]) { int vetroc_addr, iflag, nvetroc; int narg; printf("argc %d \n",argc); if (argc < 2) { usage(0); exit(0); } narg = atoi(argv[1]); printf("narg = %d \n"); if (narg < 1 || narg > 3) { usage(1); exit(0); } tdcbuf = (unsigned long *)malloc(MAXVETROCWORDS*sizeof(unsigned long)); vmeOpenDefaultWindows(); vmeBusLock(); printf("about to setup \n"); if (narg>=1) setup(); printf("about to findtrigger \n"); if (narg>=2) findtrigger(); printf("about to getdata \n"); if (narg==3) getdata(); printf("all done ! \n"); vmeBusUnlock(); vmeCloseDefaultWindows(); return 0; } void usage(int iwhich) { if (iwhich == 0) printf("Need 1 arg, which tells what to do \n"); if (iwhich == 1) printf("Arg must be within a range \n"); printf(" usage: ./tstvet N \n"); printf(" N >= 1, initialize then exit \n"); printf(" N >= 2, look for a trigger \n"); printf(" N = 3, read data into a buffer and print it \n"); } void setup() { int vetroc_addr, iflag, ii; vetroc_addr = (VETROC_SLOT<<19); /* 0 = software synch-reset, FP input 1, internal clock */ iflag = 0x20; /* FP 1 0x020; */ nvetroc = 0; nvetroc = vetrocInit((VETROC_SLOT<<19), 0x80000, 1, iflag); if (nvetroc <= 0) { printf("ERROR: no VETROC. Bye ! \n"); return; } printf("aaaa\n"); vetrocGSetProcMode(2000,2000); /* Maybe ? pick one of these 2 ? */ /* vetrocEnableMultiBlock(1); */ /* vetrocDisableMultiBlock(); */ /* Construct SlotMask Here you'd want to loop over slots if you had more than 1 slot, using vetrocSlot(index) to find slot numbers */ vetrocSlotMask=0; vetrocSlotMask |= (1<0) { printf("expected mask 0x%08x, got 0x%08x read_stat = %d \n",vetrocSlotMask,gbready,read_stat); break; } } printf("read_stat = %d \n",read_stat); if(read_stat!=0) printf("vetroc IS ready !!!\n"); if(read_stat==0) printf("vetroc not ready !!!\n"); } void getdata() { int len,ii,rdat; int intCount=0; struct dma_mem_part *part; if (read_stat <= 0) { printf("No data. Bye ! \n"); return; } /* this segment faults, so we avoid it for now */ /* the_event = dmaPGetItem(part); if(the_event == (DMANODE *) 0) printf("DMA BUFFER ERROR: no pool buffer available %s\n"); */ /* if(the_event->length!=0) { printf("Interrupt Count = %d\t",intCount); printf("the_event->length = %d\n",the_event->length); } */ /* the following results in ERROR, so we avoid it for now jlabgefDmaSend: ERROR: the_event pointer is invalid! */ /* len = vetrocReadBlock(VETROC_SLOT, tdcbuf, MAXVETROCWORDS, 1); */ len = vetrocReadFIFO(VETROC_SLOT, tdcbuf, MAXVETROCWORDS, 1); printf("VETROC: slot=%d, nw=%d, data-> 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", VETROC_SLOT,len,LSWAP(tdcbuf[0]),LSWAP(tdcbuf[1]),LSWAP(tdcbuf[2]),LSWAP(tdcbuf[3]),LSWAP(tdcbuf[4]),LSWAP(tdcbuf[5]),LSWAP(tdcbuf[6])); if (len == 0) printf("VETROC: no data or error. Bye ! \n"); /* Overwrites old data file when new data taken. Data written to file in vetrocLib.c under vetrocDataDecode. */ FILE *f; f = fopen("data.dat","w"); for (ii=0; ii>0)&0xFFFF, 2, 1, f); fclose(f); */ } vetrocGSetProcMode(/*4000*/2000,/*4000*/2000); /* Maybe ? pick one of these 2 ? */ /* vetrocEnableMultiBlock(1); */ /* vetrocDisableMultiBlock(); */ /* Construct SlotMask Here you'd want to loop over slots if you had more than 1 slot, using vetrocSlot(index) to find slot numbers */ vetrocSlotMask=0; // vetrocSlotMask |= (1<