/* CAEN V785 32 channel ADC*/ #include "stdio.h" #include "s_veshe.h" //---------------------------------------------- #define MWPC_downscale 0 // reduction = 2**MWPC_downscale #define SI_downscale 0 #define VME_BASE 0x00000000 #define TB__OFFSET 0x05000000 #define TB__No_Ch 16 #define TB__No_Ch_enabled 16 #define TB__lmd_offset 0x300 #define ADC_V785__VME_OFFSET 0x00200000 #define ADC_V785__VME_SIZE 0x10000 #define ADC_V785__No_Ch 32 #define ADC_V785__lmd_offset 0x00 #define ADC_V785__No_Mod 3 #define SCA_V830_VME_OFFSET 0x00000000 #define SCA_V830_VME_SIZE 0x10000 #define SCA_V830__No_Ch 32 #define SCA_V830__lmd_offset 0x100 #define TDC_V1190a__OFFSET 0x01200000 #define TDC_V1190a__VME_SIZE 0x10000 #define TDC_V1190a__No_Ch 128 #define TDC_V1190a__No_hit_per_Ch 1 //only single hit allowed #define TDC_V1190a__lmd_offset 0x200 #define TDC_V1190a__win_width 200 #define TDC_V1190a__win_offset -180 const long TB_Ch_enable_reg_F_0 = 0x00FF ; //------------// // scale down: ch00, ch01, ch02 const long TB_scale_down_0_F[TB__No_Ch] ={ SI_downscale,MWPC_downscale,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0} ; const long ADC_threshold_value = 0x0000 ; /*****************************************************************************/ /* * all pointer wllhich are used for read/write operations in the functions * f_user_init and f_user_readout must be defined here as static variables */ static long volatile *pl_VME_virtual_mem_base ; static long volatile *pl_trig_vme_str; // triva status register static long ll_evt_ctr = 0; /* TB - Triggerbox on Vulom3 */ static long volatile *pl_TB__base ; static long volatile *pl_TB__Ch_enable_reg_F_0 ; static long volatile *pl_TB__scale_down_7_0 ; static long volatile *pl_TB__scale_down_F_8 ; static long volatile *pl_TB__latch_reg ; static long volatile *pl_TB__version ; static long volatile *pl_TB__scaler_inp [TB__No_Ch]; static long volatile *pl_TB__scaler_inhib [TB__No_Ch] ; static long volatile *pl_TB__scaler_after_reduction [TB__No_Ch] ; long TB__scaler_inp_old [TB__No_Ch] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0} ; long TB__scaler_inhib_old [TB__No_Ch] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0} ; long TB__scaler_after_reduction_old [TB__No_Ch] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0} ; /* ADC - Analog to Digital Converter CAEN V785AH */ static long volatile *pl_ADC_V785__base [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__firm_rev [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__geo_adr [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__oui_msb [ADC_V785__No_Mod] ; static short volatile *ps_ADC_V785__oui [ADC_V785__No_Mod] ; static short volatile *ps_ADC_V785__oui_lsb [ADC_V785__No_Mod] ; static short volatile *ps_ADC_V785__version [ADC_V785__No_Mod] ; static short volatile *ps_ADC_V785__board_id_msb [ADC_V785__No_Mod] ; static short volatile *ps_ADC_V785__board_id [ADC_V785__No_Mod] ; static short volatile *ps_ADC_V785__board_id_lsb [ADC_V785__No_Mod] ; static short volatile *ps_ADC_V785__revision [ADC_V785__No_Mod] ; static short volatile *ps_ADC_V785__serial_msb [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__serial_lsb [ADC_V785__No_Mod]; static long volatile *pl_ADC_V785__outp_buffer [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__bit_set_1 [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__bit_clr_1 [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__stat_reg_1 [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__ctrl_reg_1 [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__stat_reg_2 [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__bit_set_2 [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__bit_clr_2 [ADC_V785__No_Mod]; static short volatile *ps_ADC_V785__threshs[ADC_V785__No_Ch] [ADC_V785__No_Mod]; /* SCA - Scaler CAEN V830 */ static long volatile *pl_SCA_V830__base; static long volatile *pl_SCA_V830__outp_buffer; static long volatile *pl_SCA_V830__counter[SCA_V830__No_Ch]; static short volatile *ps_SCA_V830__scaler_clr; static short volatile *ps_SCA_V830__scaler_status_reg; static short volatile *ps_SCA_V830__fixed_code; static short volatile *ps_SCA_V830__manuf_mod_type; static short volatile *ps_SCA_V830__version_series; static short volatile *ps_SCA_V830__firm_rev; static short volatile *ps_SCA_V830__geo_adr; static short volatile *ps_SCA_V830__oui_msb ; static short volatile *ps_SCA_V830__oui ; static short volatile *ps_SCA_V830__oui_lsb ; static short volatile *ps_SCA_V830__version ; static short volatile *ps_SCA_V830__board_id_msb ; static short volatile *ps_SCA_V830__board_id ; static short volatile *ps_SCA_V830__board_id_lsb ; static short volatile *ps_SCA_V830__revision ; static short volatile *ps_SCA_V830__serial_msb; static short volatile *ps_SCA_V830__serial_lsb; static short volatile *ps_SCA_V830__bit_set_1 ; static short volatile *ps_SCA_V830__bit_clr_1 ; static short volatile *ps_SCA_V830__stat_reg_1; static short volatile *ps_SCA_V830__ctrl_reg_1; static short volatile *ps_SCA_V830__sw_clr_reg ; long SCA_V830__data_old [SCA_V830__No_Ch] ; /* TDC - Time to Digital Converter CAEN V1190a */ static long volatile *pl_TDC_V1190a__base ; static long volatile *pl_TDC_V1190a__outp_buffer ; static short volatile *ps_TDC_V1190a__ctrl_reg_1 ; static short volatile *ps_TDC_V1190a__stat_reg_1 ; static short volatile *ps_TDC_V1190a__geo_adr ; static short volatile *ps_TDC_V1190a__module_reset ; static short volatile *ps_TDC_V1190a__sw_clr ; static short volatile *ps_TDC_V1190a__sw_evt_reset ; static short volatile *ps_TDC_V1190a__sw_trig ; static short volatile *pl_TDC_V1190a__evt_cnt ; static short volatile *ps_TDC_V1190a__firmware_rev ; static short volatile *ps_TDC_V1190a__micro_reg ; static short volatile *ps_TDC_V1190a__micro_hdshk_reg ; static short volatile *ps_TDC_V1190a__oui_2 ; static short volatile *ps_TDC_V1190a__oui_1 ; static short volatile *ps_TDC_V1190a__oui_0 ; static short volatile *ps_TDC_V1190a__board_ver ; static short volatile *ps_TDC_V1190a__board_id_2 ; static short volatile *ps_TDC_V1190a__board_id_1 ; static short volatile *ps_TDC_V1190a__board_id_0 ; static short volatile *ps_TDC_V1190a__revision_3 ; static short volatile *ps_TDC_V1190a__revision_2 ; static short volatile *ps_TDC_V1190a__revision_1 ; static short volatile *ps_TDC_V1190a__revision_0 ; static short volatile *ps_TDC_V1190a__serial_1 ; static short volatile *ps_TDC_V1190a__serial_0 ; int l_mod; int l_ch; long l_event_counter; /*****************************************************************************/ /*****************************************************************************/ int f_user_get_virt_ptr (long *pl_loc_hwacc, long pl_rem_cam[]) { int i; long l_i, l_j; /* * create virtual pointer to be used in f_user_init and f_user_readout */ l_event_counter = 0; //*************** // CAEN mapping //*************** { //#ifdef CAEN pl_VME_virtual_mem_base = (long*) ((long)pl_loc_hwacc) ; } //#endif // CAEN // *****************************************************************************/ { // * create virtual pointer to be used in f_user_init and f_user_readout /*------------------------------------------------------------------------------*/ /* TB on VULOM3 */ /*------------------------------------------------------------------------------*/ { pl_TB__base = (long*) ((long) pl_VME_virtual_mem_base + TB__OFFSET ) ; pl_TB__Ch_enable_reg_F_0 = (long*) ( (long) pl_TB__base + 0x0000 ); pl_TB__scale_down_7_0 = (long*) ( (long) pl_TB__base + 0x0004 ); pl_TB__scale_down_F_8 = (long*) ( (long) pl_TB__base + 0x0008 ) ; pl_TB__latch_reg = (long*) ( (long) pl_TB__base + 0x000c ); pl_TB__version = (long*) ( (long) pl_TB__base + 0x003c ); long l_ch ; for (l_ch=0; l_ch>8; /* readout data and put it into event buffer */ do { //read data word fromm adc buffer l_ADC_V785__buffer_h= *pl_ADC_V785__outp_buffer[l_mod]; // if HEADER then do nothing if (((l_ADC_V785__buffer_h >> 24) & 0x07 ) == 0x02 ) { } // read ADC data if (((l_ADC_V785__buffer_h >> 24) & 0x07 ) == 0x00 ) { l_ADC_V785__ch = ((l_ADC_V785__buffer_h & 0x001f0000) >> 16) ; // isolate underflow bit, overflow bit and adc data l_ADC_V785__val = (l_ADC_V785__buffer_h & 0x00003fff); *pl_dat++ = ((l_ADC_V785__val<<16)+ l_ADC_V785__ch + l_mod*ADC_V785__No_Ch + ADC_V785__lmd_offset); *l_se_read_len += 4; } // if TRAILER then do nothing if (((l_ADC_V785__buffer_h >> 24) & 0x07 ) == 0x04 ) { } } while (((l_ADC_V785__buffer_h >> 24 )& 0x07 ) != 0x04) ; // test if buffer is empty to avoid pile up if (*ps_ADC_V785__stat_reg_1[l_mod] & 0x0001==1) { printf ("\n\nPileup: ADC_V785 Buffer not empty after readout. Reseting Buffer. \n "); /* ADC_V785 DATA CLEAR */ *ps_ADC_V785__bit_set_2[l_mod] = 0x04; *ps_ADC_V785__bit_clr_2[l_mod] = 0x04; printf ("\n\n"); } } } { // READOUT V830 // ------------------------------------------------------ // // readout with trigger: CAEN calls it random triggering // // ------------------------------------------------------ long l_dummy; long l_value; long l_SCA_V830__buffer_h; l_SCA_V830__buffer_h = 0 ; l_dummy = 0 ; //test variable if data was in the event // start of readout loop over all hits and additional data of this event read from the buffer MEB if ((*ps_SCA_V830__stat_reg_1 & 0x0001)==1) { l_SCA_V830__buffer_h = *pl_SCA_V830__outp_buffer; // GLOBAL HEADER // printf ("\n header: %x \n ",(long)(l_SCA_V830__buffer_h )); // fflush(stdout); if (((l_SCA_V830__buffer_h >> 26) & 0x0001 ) == 0x0001 ) { ; // if header then do readout loop // printf ("\n eventno: %d \n ",(long)(l_SCA_V830__buffer_h & 0x0000FFFF)); // fflush(stdout); long l_ch; for (l_ch=0; l_ch<32; l_ch++) { // SCA DATA: write data to listmode file l_SCA_V830__buffer_h = *pl_SCA_V830__outp_buffer; // printf ("eventdata: %d \n ",(long)(l_SCA_V830__buffer_h )); // fflush(stdout); l_value = l_SCA_V830__buffer_h; SCA_V830__data_tmp = l_value; l_value = l_value - SCA_V830__data_old [l_ch]; SCA_V830__data_old [l_ch] = SCA_V830__data_tmp ; *pl_dat++ = (( l_value & 0xFFFF0000) + SCA_V830__lmd_offset )+(2 * l_ch) ; *l_se_read_len += 4; *pl_dat++ = ((( l_value & 0x0000FFFF) << 16) + SCA_V830__lmd_offset )+(2 * l_ch)+1 ; *l_se_read_len += 4; l_dummy++; } } } // check if SCA buffer is empty after readout if ((*ps_SCA_V830__stat_reg_1 & 0x00000001)==1) { printf ("PILEUP: SCA_V830 buffer not empty! Serious problem! Maybe, instable trigger!!!!!!!!!!!!!\n"); fflush(stdout); *ps_SCA_V830__sw_clr_reg = 0; printf ("PILEUP: SCA_V830 buffer cleared!\n\n"); fflush(stdout); } } // END of SCA V830 readout { // READOUT TDC V1190a // printf (" Event start \n "); // fflush(stdout); l_TDC_V1190a__header = 0 ; l_TDC_V1190a__eo_block = 0; for (l_ch=0; l_ch> 21 )& 3 ) == 2) // { // printf ("Header found \n"); // printf ("Header: %x Eventno : %d \n",l_TDC_V1190a__buffer_h ,l_TDC_V1190a__buffer_h&0x00000fff) ; // fflush(stdout); // } l_dummy = 0 ; do { l_TDC_V1190a__buffer_h = *pl_TDC_V1190a__outp_buffer; // if global header then do nothing if (((l_TDC_V1190a__buffer_h >> 27) & 0x1f ) == 0x08 ) { ; } // loop over all hits of this event if (((l_TDC_V1190a__buffer_h >> 27) & 0x1f ) == 0x00) { l_ch = ((l_TDC_V1190a__buffer_h & 0x03f80000)>> 19) ; l_TDC_V1190a__ch_low = (l_ch *2 +1) ; l_TDC_V1190a__ch_high = (l_ch *2 ) ; l_TDC_V1190a__val_low = ((l_TDC_V1190a__buffer_h & 0x0000ffff)<<16) + l_TDC_V1190a__ch_low ; l_TDC_V1190a__val_high = (l_TDC_V1190a__buffer_h & 0x00070000)+ l_TDC_V1190a__ch_high ; l_TDC_V1190a__buffer[l_TDC_V1190a__ch_low ] = l_TDC_V1190a__val_low ; l_TDC_V1190a__buffer[l_TDC_V1190a__ch_high]= l_TDC_V1190a__val_high ; l_dummy++; } // printf ("Ch: %x Time: %x Eventdata : %x \n" ,(l_TDC_V1190a__buffer_h &0x7f000000)>>24, (l_TDC_V1190a__buffer_h &0x000fffff),l_TDC_V1190a__buffer_h) ; // fflush(stdout); // if (((l_TDC_V1190a__buffer_h >> 21 )& 0x0003 ) == 0x0) // { // printf (" dataset found \n"); // fflush(stdout); // } // if global trailer then do nothing if (((l_TDC_V1190a__buffer_h >> 27) & 0x1f ) == 0x10 ) { ; } } while (((l_TDC_V1190a__buffer_h >> 27 )& 0x1f ) != 0x10) ; // check for buffer empty after readout if (l_dummy==0 ) { printf ("Event No %d Empty event in TDC V1190a or data structure error \n ", l_event_counter); } if ((*ps_TDC_V1190a__stat_reg_1 & 0x00000001)==1) { printf ("Pileup: TDC 1190a buffer not empty after readout! Reseting buffer. \n\n"); *ps_TDC_V1190a__sw_clr = 0; } // printf ( "\n End of event \n " ); // *ps_TDC_V1190a__sw_clr = 0; // check for buffer empty after readout if (l_dummy>0) { for (l_ch=0; l_ch