/* 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 16 /* global variables */ extern int nvetroc; /* Number of VETROCs in Crate */ static unsigned int vetrocSlotMask; static unsigned int MAXVETROCWORDS = 10000; int block_level=1; int read_stat=0; int *tdcbuf; 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 = (int *)malloc(MAXVETROCWORDS*sizeof(int)); vmeOpenDefaultWindows(); vmeBusLock(); if (narg>=1) setup(); if (narg>=2) findtrigger(); if (narg==3) getdata(); 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; nvetroc = 0; nvetroc = vetrocInit((VETROC_SLOT<<19), 0x80000, 1, iflag); if (nvetroc <= 0) { printf("ERROR: no VETROC. Bye ! \n"); return; } 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<0) { printf("expected mask 0x%08x, got 0x%08x\n",vetrocSlotMask,gbready); break; } } if(read_stat!=0) printf("vetroc IS ready !!!\n"); if(read_stat==0) printf("vetroc not ready !!!\n"); } void getdata() { int len; if (read_stat <= 0) { printf("No data. Bye ! \n"); return; } len = vetrocReadBlock(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"); 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<