#ifdef GNU_PLOT #include #include "gnuplot_i.hpp" #endif #ifdef CERN_ROOT_PLOT #include "TApplication.h" #include "TObject.h" #include "TH1.h" #include "TH1D.h" #include "TH1F.h" #include "TH2D.h" #include "TGraph.h" #include "TMultiGraph.h" #include "TMath.h" #include "TCanvas.h" //#include "TRandom.h" //#include "TThread.h" #include #include "TLatex.h" #endif #include #include #include #include #include #include #include #include //#include "../../driver/hllpciex4_defs.h" //#include "../../driver/hllpciex4_ioctl.h" #include "../../driver/sis8300_defs.h" #include "../../driver/sis8300_reg.h" #define SIS8300_MEMORY_MAX_BLOCK_LENGTH 0x1000000 // 256-bit blocks -> 8 x 32-bit -> 16 x 16-bit int SIS8300_ADC_SPI_Setup(int device, unsigned int adc_device_no); int SIS8300_ADC_SPI_Set_Test_mode(int device, unsigned int adc_device_no, unsigned int testmode); int SIS8300_AD9510_SPI_Setup(int device, unsigned int* ch_divider_configuration_array, unsigned int ad9510_synch_cmd); //#include "/home/th/cern_root_source/root/include/TCanvas.h" //#include //#include //#include unsigned int gl_sample_length; unsigned int gl_multievent_nof_events; #define min_max #ifdef min_max unsigned short gl_adc_min[10], gl_adc_max[10]; #endif #define ADC_BUFFER_LENGTH 0x1000000 // 16 Msamples / 32MByte //#define ADC_BUFFER_LENGTH 0x400000 // 4 Msamples / 8MByte unsigned int gl_uint_adc_buffer[ADC_BUFFER_LENGTH]; // 32MByte unsigned short gl_ushort_adc1_buffer[ADC_BUFFER_LENGTH]; // unsigned short gl_ushort_adc2_buffer[ADC_BUFFER_LENGTH]; // unsigned short gl_ushort_adc3_buffer[ADC_BUFFER_LENGTH]; // unsigned short gl_ushort_adc4_buffer[ADC_BUFFER_LENGTH]; // unsigned short gl_ushort_adc5_buffer[ADC_BUFFER_LENGTH]; // unsigned short gl_ushort_adc6_buffer[ADC_BUFFER_LENGTH]; // unsigned short gl_ushort_adc7_buffer[ADC_BUFFER_LENGTH]; // unsigned short gl_ushort_adc8_buffer[ADC_BUFFER_LENGTH]; // unsigned short gl_ushort_adc9_buffer[ADC_BUFFER_LENGTH]; // unsigned short gl_ushort_adc10_buffer[ADC_BUFFER_LENGTH]; // unsigned int i_ch; unsigned int max_nof_channels=10; unsigned short* ushort_adc_buffer_ptr[10]; // unsigned short* ushort_adcA_buffer_ptr; // unsigned short* ushort_adcB_buffer_ptr; // #define MAXIF 10 //handling cmd line input int numSlot=1; int numWrapSizeMode=9; // EVENT_CONF_PAGE_SIZE_256_WRAP int numSamples=256; // EVENT_CONF_PAGE_SIZE_256_WRAP int numEvents=10; int numPre = 64; char gl_command[256]; int main(int argc, char **argv) { //main(int argc, char *argv[]){ int i, k; int ymin, ymax ; int ywidth, y_delta ; int j; // unsigned short* ushort_adc_data_ptr ; int fp; unsigned int i_adc; volatile sis8300_reg myReg; char ch ; int cmd_autozoom = 0 ; int cmd_adc_no = -1 ; int cmd_sample_block_length = -1 ; int cmd_pre_trigger_delay = -1 ; int cmd_sample_mode = -1 ; int cmd_clock_mode = -1; int cmd_file_seqno = -1; // --- added by Z.Geng, 2011.01.20 --- // command to set the divider int cmd_divider_ratio = -1; int test_adc_no = -1 ; int test_sample_block_length = -1 ; int test_sample_length = -1 ; int test_pre_trigger_delay = -1 ; int test_sample_mode = -1 ; /* for saving data samples */ FILE *outfile[10] = {NULL}; char filename[20]; unsigned int ad9510_divider_configuration_array[8] ; ushort_adc_buffer_ptr[0] = gl_ushort_adc1_buffer; ushort_adc_buffer_ptr[1] = gl_ushort_adc2_buffer; ushort_adc_buffer_ptr[2] = gl_ushort_adc3_buffer; ushort_adc_buffer_ptr[3] = gl_ushort_adc4_buffer; ushort_adc_buffer_ptr[4] = gl_ushort_adc5_buffer; ushort_adc_buffer_ptr[5] = gl_ushort_adc6_buffer; ushort_adc_buffer_ptr[6] = gl_ushort_adc7_buffer; ushort_adc_buffer_ptr[7] = gl_ushort_adc8_buffer; ushort_adc_buffer_ptr[8] = gl_ushort_adc9_buffer; ushort_adc_buffer_ptr[9] = gl_ushort_adc10_buffer; /********************************************************************************************************************/ // decode command and set configuration parameters /* Save command line into string "command" */ memset(gl_command,0,sizeof(gl_command)); // memset(startchoice,0,sizeof(startchoice)); for (i=0;i 2) { /* Save command line into string "command" */ memset(gl_command,0,sizeof(gl_command)); // memset(startchoice,0,sizeof(startchoice)); for (i=2;i 2) // chack parameters if ((cmd_adc_no >= 0) && (cmd_adc_no <= 10)) { test_adc_no = cmd_adc_no ; } else { printf("parameter cmd_adc_no not valid: %d \n",cmd_adc_no); test_adc_no = 0 ; } if ((cmd_sample_block_length >= 1) && (cmd_sample_block_length <= 0x100000)) { test_sample_length = cmd_sample_block_length * 16 ; test_sample_block_length = cmd_sample_block_length ; } else { printf("parameter cmd_adc_no not valid: %d \n",cmd_sample_block_length); cmd_sample_block_length = 0x100 ; test_sample_length = cmd_sample_block_length * 16 ; test_sample_block_length = cmd_sample_block_length ; } if ((cmd_pre_trigger_delay >= 1) && (cmd_pre_trigger_delay <= 2046)) { test_pre_trigger_delay = cmd_pre_trigger_delay ; } else { printf("parameter cmd_adc_no not valid: %d \n",cmd_pre_trigger_delay); test_pre_trigger_delay = 100 ; } if ((cmd_sample_mode >= 0) && (cmd_sample_mode <= 2)) { test_sample_mode = cmd_sample_mode ; } else { printf("parameter cmd_adc_no not valid: %d \n",test_sample_mode); test_sample_mode = 0 ; } if(cmd_file_seqno > 0) { for(i=0; i<10; i++) { sprintf(filename, "data%d_%d.bin", cmd_file_seqno, i); outfile[i] = fopen(filename, "w"); if(!outfile[i]) { printf("Error opening file %s for write, no data will be saved for channel %d\n", filename, i); } } } printf("cmd_autozoom = %d \n", cmd_autozoom); printf("test_adc_no = %d \n", test_adc_no); printf("test_sample_block_length = %d \n", test_sample_block_length); printf("test_sample_length = %d \n", test_sample_length); printf("test_pre_trigger_delay = %d \n", test_pre_trigger_delay); printf("test_sample_mode = %d \n", test_sample_mode); printf(" \n"); #ifdef GNU_PLOT #define NPOINTS 256 vector vx; vector vy; Gnuplot g1 = Gnuplot("lines"); #endif #ifdef CERN_ROOT_PLOT //int CanvasBackgroundColor = 33 ; // light blue int CanvasBackgroundColor = 10 ; // white int Channel_1_Color = 2 ; // int Channel_2_Color = 3 ; // int Channel_3_Color = 4 ; // int Channel_4_Color = 6 ; // int Channel_5_Color = 7 ; // int Channel_6_Color = 8 ; // int Channel_7_Color = 9 ; // int Channel_8_Color = 28 ; // int Channel_9_Color = 30 ; // int Channel_10_Color = 50 ; // Int_t n=0x20000 ; int x[n] , y[n] ; // a global canvas for the drawing of histograms TApplication theApp("SIS8300 Test", &argc, argv); //TCanvas *c1 = new TCanvas("c1","SIS8300",800,400); TCanvas *c1 = new TCanvas("c1","SIS8300",10,10,1400,600); c1->SetGrid(); c1->SetFillColor(CanvasBackgroundColor); c1->Divide(1); c1->cd(1); TGraph *gr0 = new TGraph(n,x,y); TGraph *gr1 = new TGraph(n,x,y); TGraph *gr2 = new TGraph(n,x,y); TGraph *gr3 = new TGraph(n,x,y); TGraph *gr4 = new TGraph(n,x,y); TGraph *gr5 = new TGraph(n,x,y); TGraph *gr6 = new TGraph(n,x,y); TGraph *gr7 = new TGraph(n,x,y); TGraph *gr8 = new TGraph(n,x,y); TGraph *gr9 = new TGraph(n,x,y); TGraph *gr10 = new TGraph(n,x,y); gr0->SetLineColor(CanvasBackgroundColor); gr1->SetLineColor(Channel_1_Color); gr2->SetLineColor(Channel_2_Color); gr3->SetLineColor(Channel_3_Color); gr4->SetLineColor(Channel_4_Color); gr5->SetLineColor(Channel_5_Color); gr6->SetLineColor(Channel_6_Color); gr7->SetLineColor(Channel_7_Color); gr8->SetLineColor(Channel_8_Color); gr9->SetLineColor(Channel_9_Color); gr10->SetLineColor(Channel_10_Color); TLatex *text_adc1 = new TLatex(10,10,"Ch 1"); TLatex *text_adc2 = new TLatex(10,10,"Ch 2"); TLatex *text_adc3 = new TLatex(10,10,"Ch 3"); TLatex *text_adc4 = new TLatex(10,10,"Ch 4"); TLatex *text_adc5 = new TLatex(10,10,"Ch 5"); TLatex *text_adc6 = new TLatex(10,10,"Ch 6"); TLatex *text_adc7 = new TLatex(10,10,"Ch 7"); TLatex *text_adc8 = new TLatex(10,10,"Ch 8"); TLatex *text_adc9 = new TLatex(10,10,"Ch 9"); TLatex *text_adc10 = new TLatex(10,10,"Ch 10"); text_adc1->SetTextColor(Channel_1_Color); text_adc2->SetTextColor(Channel_2_Color); text_adc3->SetTextColor(Channel_3_Color); text_adc4->SetTextColor(Channel_4_Color); text_adc5->SetTextColor(Channel_5_Color); text_adc6->SetTextColor(Channel_6_Color); text_adc7->SetTextColor(Channel_7_Color); text_adc8->SetTextColor(Channel_8_Color); text_adc9->SetTextColor(Channel_9_Color); text_adc10->SetTextColor(Channel_10_Color); c1->Update(); usleep(10); #endif myReg.offset = SIS8300_INDENTIFIER_VERSION_REG; ioctl(fp, SIS8300_REG_READ, &myReg); printf("Version = 0x%08X\n", myReg.data); // Clock Distribution Multiplexer myReg.offset = SIS8300_CLOCK_DISTRIBUTION_MUX_REG; if(cmd_clock_mode == 0) myReg.data = 0x0000F; else myReg.data = 0x00000; /* use RTM_CLK2 */ ioctl(fp, SIS8300_REG_WRITE, &myReg); // ADC for (i_adc=0;i_adc<5;i_adc++) { SIS8300_ADC_SPI_Setup(fp, i_adc); } // AD9510 Clock Distributuon IC //ch_divider_configuration_array[i] : // bits <3:0>: Divider High // bits <7:4>: Divider Low // bits <11:8>: Phase Offset // bit <12>: Select Start High // bit <13>: Force // bit <14>: Nosyn (individual) // bit <15>: Bypass Divider //#define CLK_25MHZ //with Phase #ifdef CLK_25MHZ ad9510_divider_configuration_array[0] = 0x0000 + 0x44 ; // (ADC1-CLK, ch1/2) //ad9510_divider_configuration_array[1] = 0x0200 + 0x44 ; // (ADC2-CLK, ch3/4) phase: 2 clks ad9510_divider_configuration_array[1] = 0x0000 + 0x44 ; // (ADC2-CLK, ch3/4) ad9510_divider_configuration_array[2] = 0x0000 + 0x44 ; // (ADC3-CLK, ch4/5) ad9510_divider_configuration_array[3] = 0x0000 + 0x44 ; // (ADC4-CLK, ch6/7) ad9510_divider_configuration_array[4] = 0x0000 + 0x44 ; // (ADC5-CLK, ch8/9) ad9510_divider_configuration_array[5] = 0x0000 + 0x44 ; // (Frontpanel Clk, Harlink) ad9510_divider_configuration_array[6] = 0x0000 + 0x44 ; // (FPGA DIV-CLK05) used for synch. of external Triggers #else unsigned int divide_cmd = 0x00; unsigned int div_bypass = 0x8000; switch(cmd_divider_ratio) { case 1: div_bypass = 0x8000; divide_cmd = 0x00; break; case 2: div_bypass = 0x0000; divide_cmd = 0x00; break; case 4: div_bypass = 0x0000; divide_cmd = 0x11; break; case 6: div_bypass = 0x0000; divide_cmd = 0x22; break; case 8: div_bypass = 0x0000; divide_cmd = 0x33; break; case 10: div_bypass = 0x0000; divide_cmd = 0x44; break; case 12: div_bypass = 0x0000; divide_cmd = 0x55; break; case 14: div_bypass = 0x0000; divide_cmd = 0x66; break; case 16: div_bypass = 0x0000; divide_cmd = 0x77; break; case 18: div_bypass = 0x0000; divide_cmd = 0x88; break; } printf("divider ratio is %d\n", cmd_divider_ratio); printf("div_bypass = 0x%04X\n", div_bypass); printf("divide_cmd = 0x%04X\n", divide_cmd); ad9510_divider_configuration_array[0] = div_bypass + divide_cmd ; // (ADC1-CLK, ch1/2) ad9510_divider_configuration_array[1] = div_bypass + divide_cmd ; // (ADC2-CLK, ch3/4) ad9510_divider_configuration_array[2] = div_bypass + divide_cmd ; // (ADC3-CLK, ch4/5) ad9510_divider_configuration_array[3] = div_bypass + divide_cmd ; // (ADC4-CLK, ch6/7) ad9510_divider_configuration_array[4] = div_bypass + divide_cmd ; // (ADC5-CLK, ch8/9) ad9510_divider_configuration_array[5] = div_bypass + divide_cmd ; // (Frontpanel Clk, Harlink) ad9510_divider_configuration_array[6] = div_bypass + divide_cmd ; // (FPGA DIV-CLK05) used for synch. of external Triggers // ad9510_divider_configuration_array[0] = 0x8000 + 0x00 ; // (ADC1-CLK, ch1/2) // ad9510_divider_configuration_array[1] = 0x8000 + 0x00 ; // (ADC2-CLK, ch3/4) // ad9510_divider_configuration_array[2] = 0x8000 + 0x00 ; // (ADC3-CLK, ch4/5) // ad9510_divider_configuration_array[3] = 0x8000 + 0x00 ; // (ADC4-CLK, ch6/7) // ad9510_divider_configuration_array[4] = 0x8000 + 0x00 ; // (ADC5-CLK, ch8/9) // ad9510_divider_configuration_array[5] = 0x8000 + 0x00 ; // (Frontpanel Clk, Harlink) // ad9510_divider_configuration_array[6] = 0x8000 + 0x00 ; // (FPGA DIV-CLK05) used for synch. of external Triggers #endif ad9510_divider_configuration_array[7] = 0xC000 + 0x00 ; // (FPGA DIV-CLK69) used for sychn. of AD910 ISc and Bypass SIS8300_AD9510_SPI_Setup(fp, ad9510_divider_configuration_array, 1 /*ad9510_synch_cmd*/ ); // SIS8300_AD9510_SPI_Setup(fp, ad9510_divider_configuration_array, 0 /*ad9510_synch_cmd*/ ); /***************/ // disable ddr2 test write interface myReg.offset = DDR2_ACCESS_CONTROL; myReg.data = 0 ; // (1<ProcessEvents(); // handle GUI events ioctl(fp, SIS8300_REG_READ, &myReg); //printf("ctrl_reg = 0x%08X\n", myReg.data); } while ((myReg.data & 0x3) != 0 ) ; memset(gl_ushort_adc1_buffer, 0, numSamples*2); memset(gl_ushort_adc2_buffer, 0, numSamples*2); memset(gl_ushort_adc3_buffer, 0, numSamples*2); memset(gl_ushort_adc4_buffer, 0, numSamples*2); memset(gl_ushort_adc5_buffer, 0, numSamples*2); memset(gl_ushort_adc6_buffer, 0, numSamples*2); memset(gl_ushort_adc7_buffer, 0, numSamples*2); memset(gl_ushort_adc8_buffer, 0, numSamples*2); memset(gl_ushort_adc9_buffer, 0, numSamples*2); memset(gl_ushort_adc10_buffer, 0, numSamples*2); // read all ADC channels #ifdef SINGLE_CHANNEL_BUFFER_LOGIC // else DUAL_CHANNEL_BUFFER_LOGIC for (i_ch=0; i_ch> 16) & 0xffff; } } #endif #ifdef min_max for(i = 0;i < 10;i++){ gl_adc_min[i] = 0xFFFF; gl_adc_max[i] = 0; } // calc min/max for(k = 0;k < 10;k++){ for(i = 0;i < numSamples;i++){ if(ushort_adc_buffer_ptr[k][i] < gl_adc_min[k]) gl_adc_min[k] = ushort_adc_buffer_ptr[k][i]; if(ushort_adc_buffer_ptr[k][i] > gl_adc_max[k]) gl_adc_max[k] = ushort_adc_buffer_ptr[k][i]; } } //myReg.offset = SIS8300_SAMPLE_START_ADDRESS_CH1_REG; //ioctl(fp, SIS8300_REG_READ, &myReg); //printf("addr reg = 0x%08X\n", myReg.data); // all channels or just one? if(test_adc_no == 0){ i = 0; k = 10; }else{ i = test_adc_no - 1; k = i + 1; } for(;i < k;i++){ printf("adc%d min:%u max:%u ampl:%u 0.7:%.1f\n", i, gl_adc_min[i], gl_adc_max[i], gl_adc_max[i] - gl_adc_min[i], (gl_adc_max[i] - gl_adc_min[i]) * 0.7); } printf(" \n"); #endif if(test_adc_no == 0) { j = 0; k = 10; }else{ j = test_adc_no - 1; k = j + 1; } printf(" Saving data to files...\n"); for(i=j; i= 8) { var_cnt = 0; printf("\n"); } } } #ifdef CERN_ROOT_PLOT c1->Clear(); c1->cd(1); // check min and max for y-cordiante ymin = 0 ; ymax = 0xffff ; if (cmd_autozoom != 0) { ymax = 0 ; ymin = 0xffff ; if ((test_adc_no == 0) || (test_adc_no == 1)) { for(i=0; i ymax) ymax = gl_ushort_adc1_buffer[i]; } } if ((test_adc_no == 0) || (test_adc_no == 2)) { for(i=0; i ymax) ymax = gl_ushort_adc2_buffer[i]; } } if ((test_adc_no == 0) || (test_adc_no == 3)) { for(i=0; i ymax) ymax = gl_ushort_adc3_buffer[i]; } } if ((test_adc_no == 0) || (test_adc_no == 4)) { for(i=0; i ymax) ymax = gl_ushort_adc4_buffer[i]; } } if ((test_adc_no == 0) || (test_adc_no == 5)) { for(i=0; i ymax) ymax = gl_ushort_adc5_buffer[i]; } } if ((test_adc_no == 0) || (test_adc_no == 6)) { for(i=0; i ymax) ymax = gl_ushort_adc6_buffer[i]; } } if ((test_adc_no == 0) || (test_adc_no == 7)) { for(i=0; i ymax) ymax = gl_ushort_adc7_buffer[i]; } } if ((test_adc_no == 0) || (test_adc_no == 8)) { for(i=0; i ymax) ymax = gl_ushort_adc8_buffer[i]; } } if ((test_adc_no == 0) || (test_adc_no == 9)) { for(i=0; i ymax) ymax = gl_ushort_adc9_buffer[i]; } } if ((test_adc_no == 0) || (test_adc_no == 10)) { for(i=0; i ymax) ymax = gl_ushort_adc10_buffer[i]; } } } printf("numSamples = %d \n", numSamples); printf("cmd_autozoom = %d \n", cmd_autozoom); printf("test_adc_no = %d \n", test_adc_no); printf("ymin = %d ymax = %d \n", ymin, ymax); // plot cordinates // initialze x-cordinates for (i=0;iDrawGraph(numSamples,x,y,"AL"); ywidth = ymax - ymin ; y_delta = ywidth/11 ; // plot channel 1 if ((test_adc_no == 0) || (test_adc_no == 1)) { for (i=0;iDrawGraph(numSamples,x,y, "L"); text_adc1->DrawLatex(numSamples+10,ymax-y_delta,"Ch 1"); } // plot channel 2 if ((test_adc_no == 0) || (test_adc_no == 2)) { for (i=0; i DrawGraph(numSamples,x,y, "L"); text_adc2->DrawLatex(numSamples+10,ymax-(2*y_delta),"Ch 2"); } // plot channel 3 if ((test_adc_no == 0) || (test_adc_no == 3)) { for (i=0; i DrawGraph(numSamples,x,y, "L"); text_adc3->DrawLatex(numSamples+10,ymax-(3*y_delta),"Ch 3"); } // plot channel 4 if ((test_adc_no == 0) || (test_adc_no == 4)) { for (i=0; i DrawGraph(numSamples,x,y, "L"); text_adc4->DrawLatex(numSamples+10,ymax-(4*y_delta),"Ch 4"); } // plot channel 5 if ((test_adc_no == 0) || (test_adc_no == 5)) { for (i=0; i DrawGraph(numSamples,x,y, "L"); text_adc5->DrawLatex(numSamples+10,ymax-(5*y_delta),"Ch 5"); } // plot channel 6 if ((test_adc_no == 0) || (test_adc_no == 6)) { for (i=0; i DrawGraph(numSamples,x,y, "L"); text_adc6->DrawLatex(numSamples+10,ymax-(6*y_delta),"Ch 6"); } // plot channel 7 if ((test_adc_no == 0) || (test_adc_no == 7)) { for (i=0; i DrawGraph(numSamples,x,y, "L"); text_adc7->DrawLatex(numSamples+10,ymax-(7*y_delta),"Ch 7"); } // plot channel 8 if ((test_adc_no == 0) || (test_adc_no == 8)) { for (i=0; i DrawGraph(numSamples,x,y, "L"); text_adc8->DrawLatex(numSamples+10,ymax-(8*y_delta),"Ch 8"); } // plot channel 9 if ((test_adc_no == 0) || (test_adc_no == 9)) { for (i=0; i DrawGraph(numSamples,x,y, "L"); text_adc9->DrawLatex(numSamples+10,ymax-(9*y_delta),"Ch 9"); } // plot channel 10 if ((test_adc_no == 0) || (test_adc_no == 10)) { for (i=0; i DrawGraph(numSamples,x,y, "L"); text_adc10->DrawLatex(numSamples+10,ymax-(10*y_delta),"Ch 10"); } c1->Update(); //gSystem->ProcessEvents(); // handle GUI events #endif usleep(1000000) ; //gSystem->ProcessEvents(); // handle GUI events } while (0); for(i=0; i<10; i++) if(outfile[i]) fclose(outfile[i]); usleep(1) ; close(fp); } /****************************************************************************************************************************************/ /****************************************************************************************************************************************/ /****************************************************************************************************************************************/ // Out 4 (FPGA DIV-CLK05) : LVDS 3.5 mA // Out 5 (ADC3-CLK, ch4/5) : LVDS 3.5 mA // Out 6 (ADC2-CLK, ch3/4) : LVDS 3.5 mA // Out 7 (ADC1-CLK, ch1/2) : LVDS 3.5 mA // Out 4 (FPGA DIV-CLK69) : LVDS 3.5 mA // Out 5 (ADC5-CLK, ch8/9) : LVDS 3.5 mA // Out 6 (ADC4-CLK, ch6/7) : LVDS 3.5 mA // Out 7 (Frontpanel Clk, Harlink) : LVDS 3.5 mA //ch_divider_configuration_array[i] : // bits <3:0>: Divider High // bits <7:4>: Divider Low // bits <11:8>: Phase Offset // bit <12>: Select Start High // bit <13>: Force // bit <14>: Nosyn (individual) // bit <15>: Bypass Divider // // i=0: AD910 #1 Out 7 (ADC1-CLK, ch1/2) // i=1: AD910 #1 Out 6 (ADC2-CLK, ch3/4) // i=2: AD910 #1 Out 5 (ADC3-CLK, ch4/5) // i=3: AD910 #2 Out 6 (ADC4-CLK, ch6/7) // i=4: AD910 #2 Out 5 (ADC5-CLK, ch8/9) // i=5: AD910 #2 Out 7 (Frontpanel Clk, Harlink) // i=6: AD910 #1 Out 4 (FPGA DIV-CLK05) used for synch. of external Triggers // i=7: AD910 #2 Out 4 (FPGA DIV-CLK69) used for sychn. of AD910 ISc int SIS8300_AD9510_SPI_Setup(int device, unsigned int* ch_divider_configuration_array, unsigned int ad9510_synch_cmd ) { sis8300_reg myReg; // myReg.data = 0xAADD; // AA: address // DD: data // AD9510 (ADC channels 1 to 6) // set AD9510 to Bidirectional Mode and Soft Reset myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x00B0; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // set AD9510 to Bidirectional Mode myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x0090; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // default: Asychrnon PowerDown, no Prescaler myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x0A01; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 0 (not used) : total Power-Down myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x3c0B; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 1 (not used) : total Power-Down myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x3D0B; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 2 (not used) : total Power-Down myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x3E0B; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 3 (not used) : total Power-Down myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x3F0B; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 4 (FPGA DIV-CLK05) : LVDS 3.5 mA myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x4002; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 5 (ADC3-CLK, ch4/5) : LVDS 3.5 mA myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x4102; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 6 (ADC2-CLK, ch3/4) : LVDS 3.5 mA myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x4202; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 7 (ADC1-CLK, ch1/2) : LVDS 3.5 mA myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x4302; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x4500; // addr //myReg.data = myReg.data + 0x1D ; myReg.data = myReg.data + 0x10 ; // Power-Down RefIn myReg.data = myReg.data + 0x08 ; // Shut Down Clk to PLL Prescaler myReg.data = myReg.data + 0x04 ; // Power-Down CLK2 myReg.data = myReg.data + 0x01 ; // CLK1 Drives Distribution Section ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 4 (FPGA DIV-CLK05) : Divider Low/High myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5000; // addr myReg.data = myReg.data + (ch_divider_configuration_array[6] & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 4 (FPGA DIV-CLK05) : Bypasse Diver (7), No Sychn (6), Force Individual Start (5), Start High (4), Phase Offset (3:0) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5100; // addr myReg.data = myReg.data + ((ch_divider_configuration_array[6] >> 8) & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 5 (ADC3-CLK, ch4/5) : Divider Low/High myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5200; // addr myReg.data = myReg.data + (ch_divider_configuration_array[2] & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 5 (ADC3-CLK, ch4/5) : Bypasse Diver (7), No Sychn (6), Force Individual Start (5), Start High (4), Phase Offset (3:0) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5300; // addr myReg.data = myReg.data + ((ch_divider_configuration_array[2] >> 8) & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 6 (ADC2-CLK, ch2/3) : Divider Low/High myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5400; // addr myReg.data = myReg.data + (ch_divider_configuration_array[1] & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 6 (ADC2-CLK, ch2/3) : Bypasse Diver (7), No Sychn (6), Force Individual Start (5), Start High (4), Phase Offset (3:0) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5500; // addr myReg.data = myReg.data + ((ch_divider_configuration_array[1] >> 8) & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 7 (ADC1-CLK, ch1/2) : Divider Low/High myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5600; // addr myReg.data = myReg.data + (ch_divider_configuration_array[0] & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 7 (ADC1-CLK, ch1/2) : Bypasse Diver (7), No Sychn (6), Force Individual Start (5), Start High (4), Phase Offset (3:0) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5700; // addr myReg.data = myReg.data + ((ch_divider_configuration_array[0] >> 8) & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // update command myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5A01; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // AD9510 (ADC channels 7 to 10) // set AD9510 to Bidirectional Mode and Soft Reset myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x00B0; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // set AD9510 to Bidirectional Mode myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x0090; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x0A01; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 0 (not used) : total Power-Down myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x3c0B; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 1 (not used) : total Power-Down myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x3D0B; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 2 (not used) : total Power-Down myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x3E0B; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 3 (not used) : total Power-Down myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x3F0B; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 4 (FPGA DIV-CLK69) : LVDS 3.5 mA myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x4002; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 5 (ADC5-CLK, ch8/9) : LVDS 3.5 mA myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x4102; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 6 (ADC4-CLK, ch6/7) : LVDS 3.5 mA myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x4202; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 7 (Frontpanel Clk, Harlink) : LVDS 3.5 mA myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x4302; // on ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x4500; // addr myReg.data = myReg.data + 0x10 ; // Power-Down RefIn myReg.data = myReg.data + 0x08 ; // Shut Down Clk to PLL Prescaler myReg.data = myReg.data + 0x04 ; // Power-Down CLK2 myReg.data = myReg.data + 0x01 ; // CLK1 Drives Distribution Section ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 4 (FPGA DIV-CLK69) : Divider Low/High myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5000; // addr myReg.data = myReg.data + (ch_divider_configuration_array[7] & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 4 (FPGA DIV-CLK69) : Bypasse Diver (7), No Sychn (6), Force Individual Start (5), Start High (4), Phase Offset (3:0) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5100; // addr myReg.data = myReg.data + ((ch_divider_configuration_array[7] >> 8) & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 5 (ADC5-CLK, ch8/9) : Divider Low/High myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5200; // addr myReg.data = myReg.data + (ch_divider_configuration_array[4] & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 5 (ADC5-CLK, ch8/9) : Bypasse Diver (7), No Sychn (6), Force Individual Start (5), Start High (4), Phase Offset (3:0) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5300; // addr myReg.data = myReg.data + ((ch_divider_configuration_array[4] >> 8) & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 6 (ADC4-CLK, ch6/7) : Divider Low/High myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5400; // addr myReg.data = myReg.data + (ch_divider_configuration_array[3] & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 6 (ADC4-CLK, ch6/7) : Bypasse Diver (7), No Sychn (6), Force Individual Start (5), Start High (4), Phase Offset (3:0) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5500; // addr myReg.data = myReg.data + ((ch_divider_configuration_array[3] >> 8) & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 7 (Frontpanel Clk, Harlink) : Divider Low/High myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5600; // addr myReg.data = myReg.data + (ch_divider_configuration_array[5] & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // Out 7 (Frontpanel Clk, Harlink) : Bypasse Diver (7), No Sychn (6), Force Individual Start (5), Start High (4), Phase Offset (3:0) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5700;// addr myReg.data = myReg.data + ((ch_divider_configuration_array[5] >> 8) & 0xff) ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // update command myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5A01; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // synch Cmd if (ad9510_synch_cmd == 1) { // set Function of "Function pin" to SYNCB (Default Reset) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5822; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // update command myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + 0x5A01; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // set Function of "Function pin" to SYNCB (Default Reset) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5822; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // update command myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_SPI_RW_CMD + AD9510_SPI_SELECT_NO2 + 0x5A01; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // set use "FPGA DIV-CLK69" for Sychn Pulse - Logic (VIRTEX5) myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_SPI_SET_FUNCTION_SYNCH_FPGA_CLK69 ; //set clock ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // generate sych Pulse (pulse Function pins) and hold FPGA_CLK69 to sycnh pulse myReg.offset = SIS8300_AD9510_SPI_REG; myReg.data = AD9510_GENERATE_FUNCTION_PULSE_CMD + AD9510_SPI_SET_FUNCTION_SYNCH_FPGA_CLK69 ; // ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; } return 0; } /******************************************************************************/ /* */ /* SIS8300_ADC_SPI_Setup */ /* */ /******************************************************************************/ /* */ /* input: */ /* adc_device_no: 0 to 4 */ /* */ /* return_codes: */ /* 0: OK */ /* 0x800 FSM is BUSY */ /* */ /******************************************************************************/ int SIS8300_ADC_SPI_Setup(int device, unsigned int adc_device_no) { unsigned int uint_adc_mux_select; unsigned int addr,data; sis8300_reg myReg; if (adc_device_no > 4) {return -1;} uint_adc_mux_select = adc_device_no << 24 ; myReg.offset = SIS8300_ADC_SPI_REG; // output type LVDS addr = (0x14 & 0xffff) << 8 ; data = (0x40 & 0xff) ; myReg.data = uint_adc_mux_select + addr + data; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; addr = (0x16 & 0xffff) << 8 ; data = (0x00 & 0xff) ; myReg.data = uint_adc_mux_select + addr + data; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; addr = (0x17 & 0xffff) << 8 ; data = (0x00 & 0xff) ; myReg.data = uint_adc_mux_select + addr + data; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // register update cmd addr = (0xff & 0xffff) << 8 ; data = (0x01 & 0xff) ; myReg.data = uint_adc_mux_select + addr + data; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; return 0; } int SIS8300_ADC_SPI_Set_Test_mode(int device, unsigned int adc_device_no, unsigned int testmode) { unsigned int uint_adc_mux_select; unsigned int addr,data; sis8300_reg myReg; if (adc_device_no > 4) {return -1;} if (testmode > 7) {testmode=0;} uint_adc_mux_select = adc_device_no << 24 ; myReg.offset = SIS8300_ADC_SPI_REG; addr = (0x0d & 0xffff) << 8 ; data = (testmode & 0xff) ; myReg.data = uint_adc_mux_select + addr + data; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; // register update cmd addr = (0xff & 0xffff) << 8 ; data = (0x01 & 0xff) ; myReg.data = uint_adc_mux_select + addr + data; ioctl(device, SIS8300_REG_WRITE, &myReg); usleep(1) ; return 0; } #ifdef raus struct SIS8300_ADC_SPI_Config_Struct { unsigned int uintChipID[2]; // addr=0, read unsigned int uintControl[2]; // addr=1 write unsigned int uintStatus[2]; // addr=2 read unsigned int uintTestMode[2]; // addr=5 write unsigned int uint_spi_phase_adc[8]; unsigned int uint_spi_4chMode_gain_adc[8]; // 4-channel Mode unsigned int uint_spi_4chMode_offset_adc[8]; // 4-channel Mode unsigned int uint_spi_2chModeAC_gain_adc[8]; // 2-channel Mode use inputs A,C unsigned int uint_spi_2chModeAC_offset_adc[8]; // 2-channel Mode use inputs A,C unsigned int uint_spi_2chModeBD_gain_adc[8]; // 2-channel Mode use inputs B,D unsigned int uint_spi_2chModeBD_offset_adc[8]; // 2-channel Mode use inputs B,D unsigned int uint_spi_1chModeA_gain_adc[8]; // 1-channel Mode use input A unsigned int uint_spi_1chModeA_offset_adc[8]; // 1-channel Mode use input A unsigned int uint_spi_1chModeB_gain_adc[8]; // 1-channel Mode use input B unsigned int uint_spi_1chModeB_offset_adc[8]; // 1-channel Mode use input B unsigned int uint_spi_1chModeC_gain_adc[8]; // 1-channel Mode use input C unsigned int uint_spi_1chModeC_offset_adc[8]; // 1-channel Mode use input C unsigned int uint_spi_1chModeD_gain_adc[8]; // 1-channel Mode use input D unsigned int uint_spi_1chModeD_offset_adc[8]; // 1-channel Mode use input D } ; int SIS8300_ADC_SPI_Setup(int device, unsigned int adc_device_no, struct SIS8300_ADC_SPI_Config_Struct* sis3305_ADC_SPI_configuration_struct) { unsigned int addr, data, read_loop; sis3305_ADC_SPI_configuration_struct->uintChipID[0] = data ; data = sis3305_ADC_SPI_configuration_struct->uintControl[0] & 0xffff ; return 0; } #endif