/* 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 2 struct vetroc_data_struct { // We're told the VETROC is similar to FADC, so I copied that struct; // but surely some of this is not used unsigned int new_type; unsigned int type; unsigned int slot_id_hd; unsigned int slot_id_tr; unsigned int slot_id_evh; unsigned int n_evts; unsigned int blk_num; unsigned int modID; unsigned int PL; unsigned int NSB; unsigned int NSA; unsigned int n_words; unsigned int evt_num_1; unsigned int evt_num_2; unsigned int time_now; unsigned int time_1; unsigned int time_2; unsigned int time_3; unsigned int time_4; unsigned int chan; unsigned int width; unsigned int valid_1; unsigned int adc_1; unsigned int valid_2; unsigned int adc_2; unsigned int over; unsigned int adc_sum; unsigned int pulse_num; unsigned int thres_bin; unsigned int quality; unsigned int integral; unsigned int time; unsigned int chan_a; unsigned int source_a; unsigned int chan_b; unsigned int source_b; unsigned int group; unsigned int time_coarse; unsigned int time_fine; unsigned int vmin; unsigned int vpeak; unsigned int trig_type_int; unsigned int trig_state_int; unsigned int evt_num_int; unsigned int err_status_int; unsigned int scaler_data_words; }; /* 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; unsigned int *tdcbuf; struct vetroc_data_struct vetroc_data; void usage(int ix); void setup(); void findtrigger(); void getdata(); void vetrocDataDecode(unsigned int data); 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(unsigned 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 = 0x00; 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,i; if (read_stat <= 0) { printf("No data. Bye ! \n"); return; } // len = vetrocReadBlock(VETROC_SLOT, tdcbuf, MAXVETROCWORDS, 1); len = vetrocReadBlock(VETROC_SLOT, tdcbuf, MAXVETROCWORDS, 0); 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"); for (i=0; i> 27; } else { vetroc_data.new_type = 0; vetroc_data.type = type_last; } switch( vetroc_data.type ) { case 0: /* BLOCK HEADER */ vetroc_data.slot_id_hd = ((data) & 0x7C00000) >> 22; vetroc_data.n_evts = (data & 0x3FF800) >> 11; vetroc_data.blk_num = (data & 0x7FF); if( i_print ) printf("%8X - BLOCK HEADER - slot = %d n_evts = %d n_blk = %d\n", data, vetroc_data.slot_id_hd, vetroc_data.n_evts, vetroc_data.blk_num); break; case 1: /* BLOCK TRAILER */ vetroc_data.slot_id_tr = (data & 0x7C00000) >> 22; vetroc_data.n_words = (data & 0x3FFFFF); if( i_print ) printf("%8X - BLOCK TRAILER - slot = %d n_words = %d\n", data, vetroc_data.slot_id_tr, vetroc_data.n_words); break; case 2: /* EVENT HEADER */ if( vetroc_data.new_type ) { vetroc_data.evt_num_1 = (data & 0x7FFFFFF); if( i_print ) printf("%8X - EVENT HEADER 1 - evt_num = %d\n", data, vetroc_data.evt_num_1); } else { vetroc_data.evt_num_2 = (data & 0x7FFFFFF); if( i_print ) printf("%8X - EVENT HEADER 2 - evt_num = %d\n", data, vetroc_data.evt_num_2); } break; case 3: /* TRIGGER TIME */ if( vetroc_data.new_type ) { vetroc_data.time_1 = (data & 0xFFFFFF); if( i_print ) printf("%8X - TRIGGER TIME 1 - time = %08x\n", data, vetroc_data.time_1); vetroc_data.time_now = 1; time_last = 1; } else { if( time_last == 1 ) { vetroc_data.time_2 = (data & 0xFFFFFF); if( i_print ) printf("%8X - TRIGGER TIME 2 - time = %08x\n", data, vetroc_data.time_2); vetroc_data.time_now = 2; } else if( time_last == 2 ) { vetroc_data.time_3 = (data & 0xFFFFFF); if( i_print ) printf("%8X - TRIGGER TIME 3 - time = %08x\n", data, vetroc_data.time_3); vetroc_data.time_now = 3; } else if( time_last == 3 ) { vetroc_data.time_4 = (data & 0xFFFFFF); if( i_print ) printf("%8X - TRIGGER TIME 4 - time = %08x\n", data, vetroc_data.time_4); vetroc_data.time_now = 4; } else if( i_print ) printf("%8X - TRIGGER TIME - (ERROR)\n", data); time_last = vetroc_data.time_now; } break; case 4: /* nothing yet */ case 5: case 6: case 7: break; case 8: /* PULSE TIME */ vetroc_data.chan = (data & 0x7800000) >> 23; vetroc_data.pulse_num = (data & 0x600000) >> 21; vetroc_data.quality = (data & 0x180000) >> 19; vetroc_data.time = (data & 0xFFFF); if( i_print ) printf("%8X - PULSE TIME - chan = %d pulse # = %d quality = %d time = %d\n", data, vetroc_data.chan, vetroc_data.pulse_num, vetroc_data.quality, vetroc_data.time); break; case 9: /* nothing yet */ case 10: case 11: case 12: break; case 13: /* END OF EVENT */ if( i_print ) printf("%8X - END OF EVENT = %d\n", data, vetroc_data.type); break; case 14: /* DATA NOT VALID (no data available) */ if( i_print ) printf("%8X - DATA NOT VALID = %d\n", data, vetroc_data.type); break; case 15: /* FILLER WORD */ if( i_print ) printf("%8X - FILLER WORD = %d\n", data, vetroc_data.type); break; } type_last = vetroc_data.type; /* save type of current data word */ }