#include "tpcD32.h" #include #include #include #include #include #include #include #include #include int fd, fd1; ioctl_irq_t intr; static struct TPC_REG *tpc[MAX_NUMBER_OF_FADC]; volatile int intr_count = 0; int channel; LW *buf = NULL; int rc; static FILE *stream1; static int thresh_read[NUMBER_OF_CHANNEL*MAX_NUMBER_OF_FADC]; static LW *block_start_addr[MAX_NUMBER_OF_FADC+1]; static int update_thresh = 0, update_irqevt = 0, number_of_words = 0; static int sp8f_module, sp8f_channel, sp8f_event, sp8f_suppr; static int fadc_data, data_id, data_value, first_fadc_number; static int NUMBER_OF_FADC = 0; static W module_flag, channel_flag, event_flag; static int header_sum = 0, header1_sum = 0, header2_sum = 0, trailer_sum = 0; static int adc_counter = 0, tdc_counter = 0; static unsigned int fadc_board_mask[2]; static int REG_FADC_VMEADR[MAX_NUMBER_OF_FADC]; static int REG_FADC_MODNUM[MAX_NUMBER_OF_FADC]; enum data_type{BLOCK_END = -1,TRAILER,HEADER1,ADC,TDC,HEADER2,CHANNEL_CHANGE}; static int id ; static caddr_t vaddr; volatile int intr_flag; volatile int intr_VMEread_flag; int word_error=0; /* function declaration */ #define data_read 1 #define data_check 0 int num_IRQ; void clean_error_file(); /* Clean the error_log.dat */ void read_thresh(); /* Read the options of file SP8F_thresh.dat */ void read_option(); /* Read the options of file SP8F_option.dat */ void check_sum(); /* Check check-sum bit of the fadc_data */ void hamming_code_check(); /* Check Hamming bits of the fadc_data */ int identify(); /* Check the data type of the fadc_data */ void display_header_hex(); /* Display the data in the HEX form */ void check_adc_bin_sum(); /* Check counter value */ void check_suppr(int); /* Check the consistent of the supression */ int initialization(); /* Initialize the system */ void close_main(); /* Close all declaration */ void clean_identify_counter(); void read_mod_cha_eve_sup(); void check_mod_cha_eve_continue(); void reset_and_wait(); void event_structure_check(int); void check_h1_h2_trail_sum(); void fadc_board_mask_extract(); /* ========================================= */ /* Read FADC FIFO data to a memory block(buf)*/ /* pdata -> the start address of buf */ /* each read -> size of the number_of_words */ /* rc -> the total bytes sent to PC */ /* ========================================= */ void sighdl( arg ) /* Interupt handler */ { tpc[0]->CSR = 30; int i,ii; LW *pdata = NULL; LW *pdata_begin = NULL; off_t blt_addr; int tmprc = 0; static int ifirst = 0; static int inactive[18]; static int iloop[18]; if (ifirst == 0){ ifirst = 1; for (i=0; i<18; i++) inactive[i]=0; for (i=0; i<18; i++) iloop[i]=0; } tpc[0]->CSR = 31; /* disable interrupt and increment the counter */ vui_intr_dis(fd, &intr); tpc[0]->CSR = 32; intr_count++; intr_flag = 1; intr_VMEread_flag = 0; tpc[0]->CSR = 33; if (data_read != 0){ /* use local buffer pointer */ pdata=buf - 1; block_start_addr[0] = buf; /* Read the FIFO */ for(i=0; iCSR = 34; ii = i ; iloop[i] = 0; tmprc = 0; blt_addr = BLT_ADDR + REG_FADC_VMEADR[i]*BASE_OFFSET; do{ tpc[0]->CSR = 35; pdata++; pdata_begin = pdata; iloop[i]++; tpc[0]->CSR = 36; if (lseek(fd1, blt_addr, SEEK_SET) == -1) perror("read lseek"); tpc[0]->CSR = 37; /* rc:how many words has been transferred */ rc = read (fd1, (void *)pdata, sizeof(LW)*number_of_words); tpc[0]->CSR = 38; if (rc <=0) { perror("read error"); printf("i= %d rc %d\n",i,rc); } pdata = pdata + (number_of_words - 1); rc = rc/4; tmprc = tmprc + rc; //tpc[0]->CSR = 36; } while (*pdata != BLOCK_END_IDENTIFY); //tpc[0]->CSR = 37; /* new criteria for EMPTY FIFO*/ if (iloop[i] <= 1 && *pdata_begin == BLOCK_END_IDENTIFY ){ inactive[i]++; } block_start_addr[ii+1] = pdata+1; } tpc[0]->CSR = 39; printf("ILOOP %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", iloop[0], iloop[1], iloop[2], iloop[3], iloop[4], iloop[5], iloop[6], iloop[7], iloop[8], iloop[9], iloop[10], iloop[11], iloop[12], iloop[13], iloop[14], iloop[15], iloop[16], iloop[17]); printf("INACTIVE %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", inactive[0], inactive[1], inactive[2], inactive[3], inactive[4], inactive[5], inactive[6], inactive[7], inactive[8], inactive[9], inactive[10], inactive[11], inactive[12], inactive[13], inactive[14], inactive[15], inactive[16], inactive[17]); } /* This makrs the finishing of VME READ */ intr_VMEread_flag = 1; /* enable interrupt for the next event */ tpc[0]->CSR = 40; vui_intr_ena(fd, &intr); tpc[0]->CSR = 41; } /***********************************************************************/ main(argc,argv) int argc; char **argv; { int block_counter, i, last_id = TRAILER; unsigned int *buf_redirect = NULL; int iii; int word_error_tmp = 0; if(initialization()==-1) exit(0); iii = 0; while(intr_count < num_IRQ) { clean_identify_counter(); /* Wait for interrupt */ while (intr_flag == 0||(intr_flag ==1 && intr_VMEread_flag == 0)){ } if (data_check != 0){ for(block_counter=0;block_counter 1018){ printf("ERROR-# of ADC %d ; Module %d Chan %d Evt %d\n", adc_counter,sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-# of ADC %d ; Module %d Chan %d Evt %d IRQ %d\n", adc_counter,sp8f_module,sp8f_channel,sp8f_event, intr_count); } adc_counter = 0; } event_structure_check(last_id); check_sum(); last_id = id; i++; } } while (fadc_data != BLOCK_END_IDENTIFY); check_h1_h2_trail_sum(); clean_identify_counter(); } /* for data decoding */ } if (word_error_tmp>0) word_error++; word_error_tmp = 0; reset_and_wait(); iii++; printf("*** Issuing Reset %d !\n",iii); fflush(stream1); } close_main(); printf("word_error %d\n",word_error); return 0; } /* Clean the data inside the error_log.dat */ void clean_error_file() { int file_pointer; file_pointer = open(ERR_FILE,O_RDWR|O_TRUNC); close(file_pointer); } /* Read the suppressive level on each channel */ void read_thresh() { FILE *fp; float xchan; int istatus,data,addr; fp = fopen(SP8F_THRESH_FILE,"r"); if(fp == NULL){ printf("Threshold file %s cannot be opened! \n",SP8F_THRESH_FILE); exit(8); } while (1){ istatus = fscanf(fp,"%f %d \n",&xchan,&data); if (istatus<=0) break; addr = xchan; if (addr <= NUMBER_OF_CHANNEL*MAX_NUMBER_OF_FADC){ thresh_read[addr-1] = data; #ifdef DISPLAY_SP8F_THRESH printf("SP8F_THRESH_FILE: %d addr %d \n",thresh_read[addr-1],addr); fprintf(stream1,"SP8F_THRESH_FILE: %d addr %d \n",thresh_read[addr-1],addr); #endif } } fclose(fp); } /* Read SP8F_option.dat to setup variable update_thresh & update_option */ void read_option() { FILE *fro; int i; int num_FADC_installed; int index_VME, index_MOD, index_enable; fro=fopen(SP8F_OPTION_FILE,"r"); if (fro == NULL){ printf("Option file %s cannot be opened! \n",SP8F_OPTION_FILE); exit(8); } NUMBER_OF_FADC = 0; fscanf(fro,"%d \n",&num_IRQ); fscanf(fro,"%d \n",&update_thresh); fscanf(fro,"%d \n",&update_irqevt); fscanf(fro,"%x \n",&number_of_words); fscanf(fro,"%d \n",&num_FADC_installed); for (i=0; i>iloop & 1); if(ibit_checksum != ((fadc_data>>15)&1)){ printf("ERROR-Check Sum: Header1; Module %d Chan %d Evt %d\n",sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Check Sum: Header1; Module %d Chan %d Evt %d IRQ %d 0x%x %d %d\n",sp8f_module,sp8f_channel,sp8f_event,intr_count,fadc_data,ibit_checksum,(fadc_data>>15)&1); } break; case HEADER2: for (iloop=0; iloop<11; iloop++) ibit_checksum = ibit_checksum^(fadc_data>>iloop & 1); if(ibit_checksum != ((fadc_data>>15)&1)){ printf("ERROR-Check Sum: Header2; Module %d Chan %d Evt %d\n",sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Check Sum: Header2; Module %d Chan %d Evt %d IRQ %d 0x%x %d %d\n",sp8f_module,sp8f_channel,sp8f_event,intr_count,fadc_data,ibit_checksum,(fadc_data>>15)&1); } break; /* ADC,TDC,Trailer D0,D1,D2....D9 <--- 10 bits */ case ADC: for (iloop=0; iloop<10; iloop++) ibit_checksum = ibit_checksum^(fadc_data>>iloop & 1); if(ibit_checksum != ((fadc_data>>15)&1)){ printf("ERROR-Check Sum: ADC; Module %d Chan %d Evt %d\n",sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Check Sum: ADC; Module %d Chan %d Evt %d IRQ\n",sp8f_module,sp8f_channel,sp8f_event,intr_count); } break; case TDC: for (iloop=0; iloop<10; iloop++) ibit_checksum = ibit_checksum^(fadc_data>>iloop & 1); if(ibit_checksum != ((fadc_data>>15)&1)){ printf("ERROR-Check Sum: TDC; Module %d Chan %d Evt %d\n",sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Check Sum: TDC; Module %d Chan %d Evt %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,intr_count); } break; case TRAILER: for (iloop=0; iloop<10; iloop++){ ibit_checksum = ibit_checksum^(fadc_data>>iloop & 1); } if(ibit_checksum != ((fadc_data>>15)&1)){ printf("ERROR-Check Sum: Tailer; Module %d Chan %d Evt %d\n",sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Check Sum: Tailer; Module %d Chan %d Evt %d IRQ %d 0x%x %d %d\n",sp8f_module,sp8f_channel,sp8f_event,intr_count,fadc_data,ibit_checksum,(fadc_data>>15)&1); } break; default: break; } /* switch(id) end */ } /* Hamming code check */ /* ============================================= */ /* hamming_code1 = D12 = D15 (XOR) D14 (XOR) D13 */ /* hamming_code2 = D11 = D15 (XOR) D14 (XOR) D0 */ /* hamming_code3 = D10 = D15 (XOR) D13 (XOR) D0 */ /* ============================================= */ void hamming_code_check() { unsigned int h1,h2,h3,d15,d14,d13,d12,d11,d10,d0; d15 = (fadc_data>>15)&1; d14 = (fadc_data>>14)&1; d13 = (fadc_data>>13)&1; d12 = (fadc_data>>12)&1; d11 = (fadc_data>>11)&1; d10 = (fadc_data>>10)&1; d0 = fadc_data&1; h1 = d15^d14^d13; h2 = d15^d14^d0 ; h3 = d15^d13^d0 ; if((d12!=h1)||(d11!=h2)||(d10!=h3)){ switch(id){ case ADC: printf("ERROR-Check Hamming: ADC; Module %d Chan %d Evt %d\n",sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Check Hamming: ADC; Module %d Chan %d Evt %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,intr_count); break; case TDC: printf("ERROR-Check Hamming: TDC; Module %d Chan %d Evt %d\n",sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Check Hamming: TDC; Module %d Chan %d Evt %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,intr_count); break; case TRAILER: printf("ERROR-Check Hamming: Trailer; Module %d Chan %d Evt %d\n",sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Check Hamming: Trailer; Module %d Chan %d Evt %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,intr_count); break; default: break; } /* switch(id){ end */ } /* if((d12!=h1)||(d11!=h2)||(d10!=h3)){ end */ } /* Check header type and calculation */ /* =================================================== */ /* Check the data structure of the data in memory */ /* 0x0000 => 0000 XXXX XXXX XXXX ==> Header Data */ /* 0x2000 => 0010 XXXX XXXX XXXX ==> ADC Data */ /* 0x4000 => 0100 XXXX XXXX XXXX ==> TDC Data */ /* 0x6000 => 0110 XXXX XXXX XXXX ==> Trail Data */ /* =================================================== */ int identify() { #ifdef SHOW_DATA_VALUE printf("Orginal--%x ,Header--%x ,Data--%x \n",fadc_data,data_id,data_value); fprintf(stream1,"Orginal--%x ,Header--%x ,Data--%x \n",fadc_data,data_id,data_value); #endif switch(data_id){ case 0x0000: /* Header data */ if(fadc_data == CHANNEL_CHANGE_IDENTIFY){ id = CHANNEL_CHANGE; break; } header_sum++; /*Check HEADER1 or HEADER2 */ if(header_sum%2 == 1){ /* Header1 */ id = HEADER1; header1_sum++; } else{ /* Header2 */ id = HEADER2; header2_sum++; } break; case 0x2000: /* ADC data */ id = ADC; adc_counter++; break; case 0x4000: /* TDC data */ id = TDC; tdc_counter++; break; case 0x6000: /* Trailer data */ if(fadc_data == BLOCK_END_IDENTIFY){ id = BLOCK_END; break; } id = TRAILER; trailer_sum++; break; default: /* impossible */ printf("ERROR-id: Unknown: Module %d Chan %d Evt %d \n",sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-id: Unknown: Module %d Chan %d Evt %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,intr_count); break; }/* switch loop end */ return id; } /* Display the separated type header */ /* like this -->01 010 0101010 type */ void display_header_hex(void) { int iloop; if (data_id!=0x2000) { for (iloop=15; iloop>=15; iloop--){ if (fadc_data & (1<=13; iloop--){ if (fadc_data & (1<=10; iloop--){ if (fadc_data & (1<=0; iloop--){ if (fadc_data & (1< Write_open error_log.dat.\n"); return -1; } read_option(); /* fadc_board_mask_extract(); */ module_flag = REG_FADC_MODNUM[0]; channel_flag = 0; event_flag = 0; /* open the dma device */ if ((fd1=open("/dev/vmedma24blt", O_RDWR)) == -1) { perror("open vme24blt"); return -1; } printf("VME device opened for BLT\n"); /* open vmeplus for interrupt */ if ((fd=open("/dev/vme24blt", O_RDWR)) == -1) { perror("open vme24blt"); return -1; } printf("VME device opened for IRQ \n"); /* mmap FADC address starting from 0x10000 */ win_size = FADC_MAP_SIZE; win_base = BASE_ADDR; win_flag = PROT_READ | PROT_WRITE; /* ============================================= */ /* write data to FADC FIFO with vme24blt mode(fd)*/ /* directly map CSR(struct TPC_REG) to 0x10000 */ /* ============================================= */ vaddr = mmap((caddr_t)0, win_size, win_flag, MAP_SHARED, fd, win_base); printf("win_size %x win_flag %d MAP_SHARED %d\n",win_size,win_flag,MAP_SHARED); if (vaddr == (caddr_t)-1) { perror("Mapping"); return -1; } /* allocate tpc structure */ for (i=0; iCSR)); } /* tpc = (struct TPC_REG *)vaddr; */ printf("begin\n"); /* allocate buffer for data storage */ buf=(LW *)vui_dma_malloc(fd1,DMA_BUFFER_SIZE); if (buf == NULL) { perror("vui_dma_malloc"); exit(-1); } printf("buf = %p, end of buf = %p\n", buf, buf+0x7fffff); /* initial fadc and print out */ for (i=NUMBER_OF_FADC-1; i>=0; i--) { tpc[i]->CSR = TRIGGER_DISABLE; tpc[i]->CSR = RESET; tpc[i]->CSR = IRQ_EVENT_BASE + update_irqevt; } /* load pedestal supression level */ if(update_thresh != 0){ read_thresh(); for (i=NUMBER_OF_FADC-1; i>=0; i--) { for(channel = 0; channel< NUMBER_OF_CHANNEL; channel++) { tpc[i]->CH[channel].DATA = thresh_read[REG_FADC_VMEADR[i]*NUMBER_OF_CHANNEL+channel]; } } } /* set signal handler and enable interrupt */ intr.level = 5; intr.prop = 0; intr.sig = SIGINT; /* Enable the direct mapping */ sigset(SIGINT, sighdl); /* Set signal handler */ status = vui_intr_ena(fd, &intr); /* enable interrupt */ printf("status vui_intr_ena : %d\n", status); if( status != VUI_OK ) { perror("vui_intr_ena"); return -1; } /* Enable trigger */ for (i=0; iCSR = TRIGGER_ENABLE; } printf("trigger enabled, wait for triggers \n"); return 0; } /* Disable and release all memory and functions*/ void close_main() { int i; for (i=0; iCSR = TRIGGER_DISABLE; } vui_intr_dis(fd, &intr); sigset(SIGINT, SIG_DFL); free(buf); munmap(vaddr, FADC_MAP_SIZE); close(fd); close(fd1); printf("\n"); printf("exit\n"); fclose(stream1); /* Close the opened file */ } /* Clear all counter inside identify() */ void clean_identify_counter() { /* Clear variable to 0 means one data structure end */ tdc_counter = 0; header_sum = 0; header1_sum = 0; header2_sum = 0; trailer_sum = 0; } /* Read module,channel,event,suppression value from Header1,Header2 */ /* ================================================================= */ /* Header1:XXXX XXXX XMMM MMMX XXXX => M: Module value X:Don't care*/ /* Header1:XXXX XXXX XXXX XXXC CCCC => C: Channel value X:Don't care*/ /* ================================================================= */ /* Header2:XXXX XXXX XXXX XXXX XEEE => E: Event value X:Don't care*/ /* Header2:XXXX XXXX XSSS SSSS SXXX => S: Suppression X:Don't care*/ /* ================================================================= */ void read_mod_cha_eve_sup() { if(id == HEADER1){ /* Header1 */ sp8f_module = (unsigned char) ((fadc_data & 0x000007E0) >> 5); /* 6 bits = 64 modules */ sp8f_channel = (unsigned char) (fadc_data & 0x0000001F); /* 5 bits = 32 channels */ } if(id == HEADER2){ /* Header2 */ sp8f_event = (unsigned char) (fadc_data & 0x00000007); /* 3 bits = 8 events */ sp8f_suppr = (unsigned char) ((fadc_data & 0x000007F8) >> 3); /* 8 bits = 256 suppression levels */ } } /* ================================= */ /* Check the module,channel,event is */ /* added by 1 on each measurement */ /* ================================= */ void check_mod_cha_eve_continue() { /* module => next */ switch(sp8f_module - module_flag){ case 0: switch(sp8f_channel - channel_flag){ case 1: /* channel => next */ /* event => 1 */ /* if(sp8f_event != 1){ */ printf("ERROR:sp8f_channel inconsistent: channel_flag %d Module %d sp8f_channel %d Event %d\n ",channel_flag,sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR:sp8f_channel inconsistent: channel_flag %d Module %d sp8f_channel %d Event %d IRQ %d\n ",channel_flag,sp8f_module,sp8f_channel,sp8f_event,intr_count); /* } */ break; case 0:/* channel => same */ /* event => next */ /* if((sp8f_event - event_flag) == 1){ */ if((sp8f_event - event_flag) == 0){ break; } /* event => others */ else{ printf("ERROR:sp8f_event inconsistent: event_flag %d Module %d sp8f_channel %d Event %d\n ",event_flag,sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR:sp8f_event inconsistent: event_flag %d Module %d sp8f_channel %d Event %d IRQ %d\n ",event_flag,sp8f_module,sp8f_channel,sp8f_event,intr_count); } break; default: printf("ERROR:sp8f_channel inconsistent: channel_flag %d Module %d sp8f_channel %d Event %d\n ",channel_flag,sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR:sp8f_channel inconsistent: channel_flag %d Module %d sp8f_channel %d Event %d IRQ %d\n ",channel_flag,sp8f_module,sp8f_channel,sp8f_event,intr_count); } break; default: if((sp8f_event != 1)||(sp8f_channel != 0)){ printf("ERROR:sp8f_module inconsistent: module_flag %d Module %d sp8f_channel %d Event %d\n ",module_flag,sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR:sp8f_module inconsistent: module_flag %d Module %d sp8f_channel %d Event %d IRQ %d\n ",module_flag,sp8f_module,sp8f_channel,sp8f_event,intr_count); } break; } if (event_flag < (update_irqevt+1)){ event_flag++; } else { event_flag = 1; channel_flag++; } } /* ================================================== */ /* Check structure complete using following algorithm */ /* Header1 Header2 ADC TDC Trailer BLOCK_END */ /* id => 1 4 2 3 0 -1 */ /* Header1 -> if(id!=0) wrong */ /* Header2 -> if(id!=HEADER1) wrong */ /* ADC -> if(!((id == ADC)||(id == HEADER2))) wrong */ /* TDC -> if(!((id == ADC)||(id == HEADER2))) wrong */ /* Trailer -> if(id != TDC) wrong */ /* BLOCK_END -> if(id != Trailer) wrong */ /* ================================================== */ void event_structure_check(int last_id) { switch(id){ case HEADER1: if(!((last_id == TRAILER)||(last_id == BLOCK_END)||(last_id == CHANNEL_CHANGE))){ printf("ERROR-id: Header1: Module %d Channel %d value %d id %d\n",sp8f_module,sp8f_channel,data_value,id); fprintf(stream1,"ERROR-id: Header1: Module %d Channel %d value %d %value %d id %d IRQ %d\n",sp8f_module,sp8f_channel,data_value,id,intr_count); } break; case HEADER2: if(last_id != HEADER1){ printf("ERROR-id: Header2: Module %d Channel %d Event %d value %d id %d\n",sp8f_module,sp8f_channel,sp8f_event,data_value,id); fprintf(stream1,"ERROR-id: Header2: Module %d Channel %d Event %d value %d strup_comp %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,data_value,id,intr_count); } break; case ADC: if(!((last_id == ADC)||(last_id == TDC) ||(last_id == HEADER2))){ printf("ERROR-id: ADC: Module %d Chan %d Evt %d value %d id %d\n",sp8f_module,sp8f_channel,sp8f_event,data_value,last_id); fprintf(stream1,"ERROR-id: ADC: Module %d Chan %d Evt %d value %d id %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,data_value,last_id,intr_count); } break; case TDC: if(last_id != ADC){ printf("ERROR-id: TDC: Module %d Chan %d Evt %d value %d \n",sp8f_module,sp8f_channel,sp8f_event,data_value); fprintf(stream1,"ERROR-id: TDC: Module %d Chan %d Evt %d value %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,data_value,intr_count); } break; case TRAILER: if(!((last_id == TDC)||(last_id == HEADER2))){ printf("ERROR-id: Trailer: Module %d Chan %d Evt %d value %d \n",sp8f_module,sp8f_channel,sp8f_event,data_value); fprintf(stream1,"ERROR-id: Trailer: Module %d Chan %d Evt %d value %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,data_value,intr_count); break; } break; case BLOCK_END: if(last_id != TRAILER){ printf("ERROR-id: BLOCK_END: Module %d Chan %d Evt %d value %d lastID %d \n",sp8f_module,sp8f_channel,sp8f_event,data_value,last_id); fprintf(stream1,"ERROR-id: BLOCK_END: Module %d Chan %d Evt %d value %d IRQ %d lastID %d\n",sp8f_module,sp8f_channel,sp8f_event,data_value,intr_count,last_id); } break; case CHANNEL_CHANGE: if(last_id != TRAILER){ printf("ERROR-id: CHANNEL_CHANGE: Module %d Chan %d Evt %d value %d \n",sp8f_module,sp8f_channel,sp8f_event,data_value); fprintf(stream1,"ERROR-id: CHANNEL_CHANGE: Module %d Chan %d Evt %d value %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,data_value,intr_count); } break; default: printf("ERROR-id: Unknown: Module %d Chan %d Evt %d value %d \n",sp8f_module,sp8f_channel,sp8f_event,data_value); fprintf(stream1,"ERROR-id: Unknown: Module %d Chan %d Evt %d value %d IRQ %d\n",sp8f_module,sp8f_channel,sp8f_event,data_value,intr_count); break; } } /* inline void reset_and_wait() */ void reset_and_wait() { int i; intr_flag = 0; for (i=NUMBER_OF_FADC-1; i>=1; i--){ tpc[i]->CSR = RESET; } tpc[0]->CSR = RESET; } void check_h1_h2_trail_sum() { int summation = (update_irqevt+1)*NUMBER_OF_CHANNEL; if(header1_sum != summation){ printf("ERROR-Header1_sum:Header1_sum %d summation %d Module %d Chan %d Evt %d \n",header1_sum,summation,sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Header1_sum:Header1_sum %d summation %d Module %d Chan %d Evt %d IRQ %d\n",header1_sum,summation,sp8f_module,sp8f_channel,sp8f_event,intr_count); } if(header2_sum != summation){ printf("ERROR-Header2_sum:Header2_sum %d summation %d Module %d Chan %d Evt %d \n",header2_sum,summation,sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Header2_sum:Header2_sum %d summation %d Module %d Chan %d Evt %d IRQ %d\n",header2_sum,summation,sp8f_module,sp8f_channel,sp8f_event,intr_count); } if(trailer_sum != summation){ printf("ERROR-Trailer_sum:Trailer_sum %d summation %d Module %d Chan %d Evt %d \n",trailer_sum,summation,sp8f_module,sp8f_channel,sp8f_event); fprintf(stream1,"ERROR-Trailer_sum:Trailer_sum %d summation %d Module %d Chan %d Evt %d IRQ %d\n",trailer_sum,summation,sp8f_module,sp8f_channel,sp8f_event,intr_count); } } void fadc_board_mask_extract() { int i,j,bit_check; unsigned int extract_mask = 0x000000FF; fadc_board_mask[1] = fadc_board_mask[1] & extract_mask; for(j=0;j<2;j++){ for(i=0;i<32;i++){ bit_check = (fadc_board_mask[j]>>i)&1; if(bit_check == 1){ REG_FADC_VMEADR[NUMBER_OF_FADC] = j*32+i; /* REG_FADC_MODNUM[NUMBER_OF_FADC] = MODNUM[j*32+i]; */ NUMBER_OF_FADC++; } } } printf("NUMBER_OF_FADC %d \n",NUMBER_OF_FADC); }