37void WIB::ConfigFEMB(uint8_t iFEMB, std::vector<uint32_t> fe_config, std::vector<uint16_t> clk_phases,
38 uint8_t pls_mode, uint8_t pls_dac_val, uint8_t start_frame_mode_sel, uint8_t start_frame_swap){
40 if (iFEMB < 1 || iFEMB > 4)
42 BUException::WIB_BAD_ARGS e;
43 std::stringstream expstr;
44 expstr <<
"ConfigFEMB: iFEMB should be between 1 and 4: "
46 e.Append(expstr.str().c_str());
51 BUException::WIB_BAD_ARGS e;
52 std::stringstream expstr;
53 expstr <<
"ConfigFEMB: pls_dac_mode is allowed to be 0 (off), 1 (FPGA), 2 (internal), but is: "
55 e.Append(expstr.str().c_str());
58 if (start_frame_mode_sel > 1 || start_frame_swap > 1)
60 BUException::WIB_BAD_ARGS e;
61 std::stringstream expstr;
62 expstr <<
"ConfigFEMB: start_frame_mode_sel and start_frame_swap must be 0 or 1";
63 e.Append(expstr.str().c_str());
67 if(fe_config.size() != 8){
69 BUException::WIB_BAD_ARGS e;
70 std::stringstream expstr;
71 expstr <<
"Error: Expecting 9 Front End configuration options:" << std::endl <<
72 "\t0: Gain" << std::endl <<
73 "\t1: Shaping Time" << std::endl <<
74 "\t2: High Baseline" << std::endl <<
75 "\t3: High Leakage" << std::endl <<
76 "\t4: Leakage x 10" << std::endl <<
77 "\t5: AC Coupling" << std::endl <<
78 "\t6: Buffer" << std::endl <<
79 "\t7: Use External Clock" << std::endl;
80 e.Append(expstr.str().c_str());
84 std::cout <<
"Front End configuration options:" << std::endl <<
85 "\t0:" << std::setw(22) << std::setfill(
' ') <<
"Gain " << fe_config[0] << std::endl <<
86 "\t1:" << std::setw(22) << std::setfill(
' ') <<
"Shaping Time " << fe_config[1] << std::endl <<
87 "\t2:" << std::setw(22) << std::setfill(
' ') <<
"High Baseline " << fe_config[2] << std::endl <<
88 "\t3:" << std::setw(22) << std::setfill(
' ') <<
"High Leakage " << fe_config[3] << std::endl <<
89 "\t4:" << std::setw(22) << std::setfill(
' ') <<
"Leakage x 10 " << fe_config[4] << std::endl <<
90 "\t5:" << std::setw(22) << std::setfill(
' ') <<
"AC Coupling " << fe_config[5] << std::endl <<
91 "\t6:" << std::setw(22) << std::setfill(
' ') <<
"Buffer " << fe_config[6] << std::endl <<
92 "\t8:" << std::setw(22) << std::setfill(
' ') <<
"Use External Clock " << fe_config[7] << std::endl;
95 std::cout <<
"Pulser Mode: " << int(pls_mode) <<
" and DAC Value: " << int(pls_dac_val) << std::endl;
98 uint32_t slow_control_dnd =
Read(
"SYSTEM.SLOW_CONTROL_DND");
99 Write(
"SYSTEM.SLOW_CONTROL_DND",1);
103 std::cout <<
"Error: Can't read registers from FEMB " << int(iFEMB) << std::endl;
106 BUException::FEMB_REG_READ_ERROR e;
107 std::stringstream expstr;
108 expstr <<
" for FEMB: " << int(iFEMB);
109 e.Append(expstr.str().c_str());
116 WriteFEMB(iFEMB,
"START_FRAME_MODE_SELECT", start_frame_mode_sel);
118 WriteFEMB(iFEMB,
"START_FRAME_SWAP", start_frame_swap);
154 uint32_t REG_LATCHLOC1_4_data = 0x04040404;
155 uint32_t REG_LATCHLOC5_8_data = 0x04040404;
157 WriteFEMB(iFEMB,
"ADC_LATCH_LOC_0TO3", REG_LATCHLOC1_4_data);
158 WriteFEMB(iFEMB,
"ADC_LATCH_LOC_4TO7", REG_LATCHLOC5_8_data);
161 uint8_t internal_daq_value = 0;
164 if (pls_dac_val >= 63)
166 BUException::WIB_BAD_ARGS e;
167 std::stringstream expstr;
168 expstr <<
"ConfigFEMB: pls_dac_val is 6 bits for internal DAC, must be 0-63, but is: "
170 e.Append(expstr.str().c_str());
173 internal_daq_value = pls_dac_val;
176 else if (pls_mode == 2)
178 if (pls_dac_val >= 32)
180 BUException::WIB_BAD_ARGS e;
181 std::stringstream expstr;
182 expstr <<
"ConfigFEMB: pls_dac_val is 5 bits for FPGA DAC, must be 0-31, but is: "
184 e.Append(expstr.str().c_str());
191 SetupFEMBASICs(iFEMB, fe_config[0], fe_config[1], fe_config[2], fe_config[3], fe_config[4], fe_config[5], fe_config[6], fe_config[7], pls_mode, internal_daq_value);
192 std::cout <<
"FEMB " << int(iFEMB) <<
" Successful SPI config" << std::endl;
195 if (clk_phases.size() == 0)
197 clk_phases.push_back(0xFFFF);
201 std::cout <<
"Warning: FEMB " << int(iFEMB) <<
" ADC FIFO not synced from expected phases, trying to hunt for phases" << std::endl;
204 std::cout <<
"Error: FEMB " << int(iFEMB) <<
" ADC FIFO could not be synced even after hunting" << std::endl;
207 uint16_t adc_fifo_sync = (
ReadFEMB(iFEMB, 6) & 0xFFFF0000) >> 16;
208 BUException::FEMB_ADC_SYNC_ERROR e;
209 std::stringstream expstr;
210 expstr <<
" after hunting. ";
211 expstr <<
" FEMB: " << int(iFEMB);
212 expstr <<
" sync: " << std::bitset<16>(adc_fifo_sync);
213 expstr <<
" phases: ";
214 expstr << std::hex << std::setfill (
'0') << std::setw(2) <<
ReadFEMB(iFEMB,
"ADC_ASIC_CLK_PHASE_SELECT");
215 expstr << std::hex << std::setfill (
'0') << std::setw(2) <<
ReadFEMB(iFEMB,
"ADC_ASIC_CLK_PHASE_SELECT_2");
216 e.Append(expstr.str().c_str());
223 uint16_t adc_fifo_sync = (
ReadFEMB(iFEMB, 6) & 0xFFFF0000) >> 16;
224 BUException::FEMB_ADC_SYNC_ERROR e;
225 std::stringstream expstr;
226 expstr <<
" after trying all in list. ";
227 expstr <<
" FEMB: " << int(iFEMB);
228 expstr <<
" sync: " << std::bitset<16>(adc_fifo_sync);
229 expstr <<
" phases tried: " << std::endl;
230 for (
size_t iclk_phase = 0;iclk_phase < clk_phases.size();iclk_phase++)
233 << std::hex << std::setfill (
'0') << std::setw(4) << clk_phases[iclk_phase] << std::endl;
235 e.Append(expstr.str().c_str());
239 uint16_t adc_fifo_sync = (
ReadFEMB(iFEMB, 6) & 0xFFFF0000) >> 16;
240 std::cout <<
"FEMB " << int(iFEMB) <<
" Final ADC FIFO sync: " << std::bitset<16>(adc_fifo_sync) << std::endl;
241 std::cout <<
"FEMB " << int(iFEMB) <<
" Final Clock Phases: "
242 << std::hex << std::setfill (
'0') << std::setw(2) <<
ReadFEMB(iFEMB,
"ADC_ASIC_CLK_PHASE_SELECT")
243 << std::hex << std::setfill (
'0') << std::setw(2) <<
ReadFEMB(iFEMB,
"ADC_ASIC_CLK_PHASE_SELECT_2")
263 Write(
"SYSTEM.SLOW_CONTROL_DND",slow_control_dnd);
276 std::vector<uint32_t> fake_samples, uint8_t start_frame_mode_sel, uint8_t start_frame_swap){
278 if (iFEMB < 1 || iFEMB > 4)
280 BUException::WIB_BAD_ARGS e;
281 std::stringstream expstr;
282 expstr <<
"ConfigFEMBFakeData: iFEMB should be between 1 and 4: "
284 e.Append(expstr.str().c_str());
287 if (start_frame_mode_sel > 1 || start_frame_swap > 1)
289 BUException::WIB_BAD_ARGS e;
290 std::stringstream expstr;
291 expstr <<
"ConfigFEMBFakeData: start_frame_mode_sel and start_frame_swap must be 0 or 1";
292 e.Append(expstr.str().c_str());
295 if (fake_mode == 1 && fake_word > 0xFFF)
297 BUException::WIB_BAD_ARGS e;
298 std::stringstream expstr;
299 expstr <<
"ConfigFEMBFakeData: fake_word must be only 12 bits i.e. <= 4095, is: "
301 e.Append(expstr.str().c_str());
304 if (fake_mode == 2 && fake_samples.size() != 256)
306 BUException::WIB_BAD_ARGS e;
307 std::stringstream expstr;
308 expstr <<
"ConfigFEMBFakeData: femb_samples must be 255 long, is: "
309 << fake_samples.size();
310 e.Append(expstr.str().c_str());
313 if (fake_mode == 3 && femb_number > 0xF)
315 BUException::WIB_BAD_ARGS e;
316 std::stringstream expstr;
317 expstr <<
"ConfigFEMBFakeData: femb_number must be only 4 bits i.e. <= 15, is: "
319 e.Append(expstr.str().c_str());
324 uint32_t slow_control_dnd =
Read(
"SYSTEM.SLOW_CONTROL_DND");
325 Write(
"SYSTEM.SLOW_CONTROL_DND",1);
330 WriteFEMB(iFEMB,
"STREAM_AND_ADC_DATA_EN", 0);
333 WriteFEMB(iFEMB,
"START_FRAME_MODE_SELECT", start_frame_mode_sel);
335 WriteFEMB(iFEMB,
"START_FRAME_SWAP", start_frame_swap);
345 WriteFEMB(iFEMB,
"DATA_TEST_PATTERN", fake_word);
350 for (
size_t iSample=0; iSample < 256; iSample++)
352 WriteFEMB(iFEMB,0x300+iSample,fake_samples.at(iSample));
358 WriteFEMB(iFEMB,
"FEMB_NUMBER", femb_number);
360 WriteFEMB(iFEMB,
"FEMB_TST_SEL", fake_mode);
366 WriteFEMB(iFEMB,
"STREAM_AND_ADC_DATA_EN", 9);
368 Write(
"SYSTEM.SLOW_CONTROL_DND",slow_control_dnd);
378 uint32_t clk_period = 5;
379 uint32_t clk_dis = 0;
380 uint32_t d14_rst_oft = 0 / clk_period;
381 uint32_t d14_rst_wdt = (45 / clk_period ) ;
382 uint32_t d14_rst_inv = 1;
383 uint32_t d14_read_oft = 480 / clk_period;
384 uint32_t d14_read_wdt = 20 / clk_period;
385 uint32_t d14_read_inv = 1;
386 uint32_t d14_idxm_oft = 230 / clk_period;
387 uint32_t d14_idxm_wdt = 270 / clk_period;
388 uint32_t d14_idxm_inv = 0;
389 uint32_t d14_idxl_oft = 480 / clk_period;
390 uint32_t d14_idxl_wdt = 20 / clk_period;
391 uint32_t d14_idxl_inv = 0;
392 uint32_t d14_idl0_oft = 50 / clk_period;
393 uint32_t d14_idl0_wdt = (190 / clk_period ) -1;
394 uint32_t d14_idl1_oft = 480 / clk_period;
395 uint32_t d14_idl1_wdt = 20 / clk_period;
396 uint32_t d14_idl_inv = 0;
398 uint32_t d58_rst_oft = 0 / clk_period;
399 uint32_t d58_rst_wdt = (45 / clk_period );
400 uint32_t d58_rst_inv = 1;
401 uint32_t d58_read_oft = 480 / clk_period;
402 uint32_t d58_read_wdt = 20 / clk_period;
403 uint32_t d58_read_inv = 1;
404 uint32_t d58_idxm_oft = 230 / clk_period;
405 uint32_t d58_idxm_wdt = 270 / clk_period;
406 uint32_t d58_idxm_inv = 0;
407 uint32_t d58_idxl_oft = 480 / clk_period;
408 uint32_t d58_idxl_wdt = 20 / clk_period;
409 uint32_t d58_idxl_inv = 0;
410 uint32_t d58_idl0_oft = 50 / clk_period;
411 uint32_t d58_idl0_wdt = (190 / clk_period ) -1;
412 uint32_t d58_idl1_oft = 480 / clk_period;
413 uint32_t d58_idl1_wdt = 20 / clk_period;
414 uint32_t d58_idl_inv = 0;
441 uint32_t d14_read_step = 11;
442 uint32_t d14_read_ud = 0;
443 uint32_t d14_idxm_step = 9;
444 uint32_t d14_idxm_ud = 0;
445 uint32_t d14_idxl_step = 7;
446 uint32_t d14_idxl_ud = 0;
447 uint32_t d14_idl0_step = 12;
448 uint32_t d14_idl0_ud = 0;
449 uint32_t d14_idl1_step = 10;
450 uint32_t d14_idl1_ud = 0;
451 uint32_t d14_phase_en = 1;
453 uint32_t d58_read_step = 0;
454 uint32_t d58_read_ud = 0;
455 uint32_t d58_idxm_step = 5;
456 uint32_t d58_idxm_ud = 0;
457 uint32_t d58_idxl_step = 4;
458 uint32_t d58_idxl_ud = 1;
459 uint32_t d58_idl0_step = 3;
460 uint32_t d58_idl0_ud = 0;
461 uint32_t d58_idl1_step = 4;
462 uint32_t d58_idl1_ud = 0;
463 uint32_t d58_phase_en = 1;
468 uint32_t d14_inv = (d14_rst_inv<<0) + (d14_read_inv<<1)+ (d14_idxm_inv<<2)+ (d14_idxl_inv<<3)+ (d14_idl_inv<<4);
469 uint32_t d58_inv = (d58_rst_inv<<0) + (d58_read_inv<<1)+ (d58_idxm_inv<<2)+ (d58_idxl_inv<<3)+ (d58_idl_inv<<4);
470 uint32_t d_inv = d58_inv + ( d14_inv<<5);
474 addr_data = clk_dis + (d_inv << 16);
477 addr_data = d58_rst_oft + (d14_rst_oft << 16);
480 addr_data = d58_rst_wdt + (d14_rst_wdt << 16);
483 addr_data = d58_read_oft + (d14_read_oft << 16);
486 addr_data = d58_read_wdt + (d14_read_wdt << 16);
489 addr_data = d58_idxm_oft + (d14_idxm_oft << 16);
492 addr_data = d58_idxm_wdt + (d14_idxm_wdt << 16);
495 addr_data = d58_idxl_oft + (d14_idxl_oft << 16);
498 addr_data = d58_idxl_wdt + (d14_idxl_wdt << 16);
501 addr_data = d58_idl0_oft + (d14_idl0_oft << 16);
504 addr_data = d58_idl0_wdt + (d14_idl0_wdt << 16);
507 addr_data = d58_idl1_oft + (d14_idl1_oft << 16);
510 addr_data = d58_idl1_wdt + (d14_idl1_wdt << 16);
514 for(
size_t i=0; i<4; i++)
516 addr_data = d14_read_step + (d14_idxm_step <<16);
519 addr_data = d14_idxl_step + (d14_idl0_step <<16);
522 d14_phase_en = d14_phase_en ^ 1;
523 uint32_t d14_ud = d14_read_ud + (d14_idxm_ud<<1) + (d14_idxl_ud<<2)+ (d14_idl0_ud<<3)+ (d14_idl1_ud<<4) + (d14_phase_en <<15);
524 addr_data = d14_idl1_step + (d14_ud<<16);
527 addr_data = d58_read_step + (d58_idxm_step <<16);
530 addr_data = d58_idxl_step + (d58_idl0_step <<16);
533 d58_phase_en = d58_phase_en ^ 1;
534 uint32_t d58_ud = d58_read_ud + (d58_idxm_ud<<1) + (d58_idxl_ud<<2)+ (d58_idl0_ud<<3)+ (d58_idl1_ud<<4) + (d58_phase_en <<15);
535 addr_data = d58_idl1_step + (d58_ud <<16);
622 bool highLeakage,
bool leakagex10,
bool acCoupling,
bool buffer,
bool useExtClock,
623 uint8_t internalDACControl, uint8_t internalDACValue){
629 BUException::WIB_BAD_ARGS e;
630 std::stringstream expstr;
631 expstr <<
"gain should be between 0 and 3, but is: "
633 e.Append(expstr.str().c_str());
638 BUException::WIB_BAD_ARGS e;
639 std::stringstream expstr;
640 expstr <<
"shape should be between 0 and 3, but is: "
642 e.Append(expstr.str().c_str());
646 const size_t REG_SPI_BASE_WRITE = 0x200;
647 const size_t REG_SPI_BASE_READ = 0x250;
650 bool bypassOutputBuffer=
true;
651 bool useOutputMonitor=
false;
652 bool useCh16HighPassFilter=
false;
653 bool monitorBandgapNotTemp=
false;
654 bool monitorTempBandgapNotSignal=
false;
655 bool useTestCapacitance = (bool) internalDACControl;
658 if (gain == 0x1) gain = 0x2;
659 else if (gain== 0x2) gain = 0x1;
662 if (shape == 0x0) shape = 0x2;
663 else if (shape == 0x1) shape = 0x0;
664 else if (shape == 0x2) shape = 0x3;
665 else if (shape == 0x3) shape = 0x1;
668 if (highBaseline > 1)
671 fe_map.
set_board(useTestCapacitance,0,gain,shape,
672 useOutputMonitor,!bypassOutputBuffer,!highLeakage,
673 monitorBandgapNotTemp,monitorTempBandgapNotSignal,useCh16HighPassFilter,
674 leakagex10,acCoupling,internalDACControl,internalDACValue
681 fe_map.
set_board(useTestCapacitance,~highBaseline,gain,shape,
682 useOutputMonitor,!bypassOutputBuffer,!highLeakage,
683 monitorBandgapNotTemp,monitorTempBandgapNotSignal,useCh16HighPassFilter,
684 leakagex10,acCoupling,internalDACControl,internalDACValue
688 uint8_t offsetCurrentValue=0;
692 bool useADCTestInput=0;
695 bool lsbCurrentStearingPartialNotFull=0;
697 if (useExtClock) clk0=1;
700 bool enableOffsetCurrent=0;
705 adc_map.
set_board(offsetCurrentValue, pcsr, pdsr,
706 adcSleep, useADCTestInput, f4, f5,
707 lsbCurrentStearingPartialNotFull,0,0,
710 enableOffsetCurrent,f0,f1,
715 const std::vector<uint32_t> regs = map.
get_regs();
716 const size_t nRegs = regs.size();
718 uint16_t adc_sync_status = 0xFFFF;
720 for(
unsigned iSPIWrite=0; iSPIWrite < 2; iSPIWrite++)
722 WriteFEMB(iFEMB,
"STREAM_AND_ADC_DATA_EN", 0 );
725 std::cout <<
"ASIC SPI Write Registers..." << std::endl;
726 for (
size_t iReg=0; iReg<nRegs; iReg++)
728 WriteFEMB(iFEMB,REG_SPI_BASE_WRITE+iReg,regs[iReg]);
741 bool spi_mismatch =
false;
742 for (
unsigned iSPIRead = 0; iSPIRead < 2; iSPIRead++)
744 std::cout <<
"ASIC SPI Readback..." << std::endl;
745 std::vector<uint32_t> regsReadback(nRegs);
746 for (
size_t iReg=0; iReg<nRegs; iReg++)
748 uint32_t regReadback =
ReadFEMB(iFEMB,REG_SPI_BASE_READ+iReg);
749 regsReadback[iReg] = regReadback;
753 bool verbose =
false;
754 if (verbose) std::cout <<
"ASIC SPI register number, write val, read val:" << std::endl;
755 spi_mismatch =
false;
756 for (
size_t iReg=0; iReg<nRegs; iReg++)
760 std::cout << std::dec << std::setfill (
' ') << std::setw(3) << iReg
762 << std::hex << std::setfill (
'0') << std::setw(8) << regs[iReg]
764 << std::hex << std::setfill (
'0') << std::setw(8) << regsReadback[iReg]
767 if (regs[iReg] != regsReadback[iReg])
770 size_t asicFailNum = 0;
771 if (iReg > 0) asicFailNum = (iReg-1) / 9;
772 std::cout <<
"FE-ADC ASIC " << asicFailNum <<
" SPI faled" << std::endl;
775 if (!spi_mismatch)
break;
781 std::cout <<
"FEMB ASIC SPI readback mismatch--problems communicating with ASICs for FEMB: " << int(iFEMB) << std::endl;
785 BUException::FEMB_SPI_READBACK_MISMATCH e;
786 std::stringstream expstr;
787 expstr <<
" for FEMB: " << int(iFEMB);
788 e.Append(expstr.str().c_str());
795 WriteFEMB(iFEMB,
"STREAM_AND_ADC_DATA_EN", 9 );
797 WriteFEMB(iFEMB,
"STREAM_AND_ADC_DATA_EN", 9 );
800 adc_sync_status = (uint16_t)
ReadFEMB(iFEMB,
"ADC_ASIC_SYNC_STATUS");
806 return adc_sync_status;
811 const uint32_t REG_SPI_BASE_WRITE = 0x200;
812 const uint32_t REG_SPI_BASE_READ = 0x250;
813 uint16_t adc_sync_status = 0xFFFF;
819 for(
unsigned iSPIWrite=0; iSPIWrite < nTries; iSPIWrite++)
821 WriteFEMB(iFEMB,
"STREAM_AND_ADC_DATA_EN", 0 );
824 std::cout <<
"ASIC SPI Write Registers..." << std::endl;
829 std::vector<uint32_t> vals(nASICs);
830 for (
size_t iASIC=0; iASIC<nASICs; iASIC++)
832 uint32_t address = (REG_SPI_BASE_WRITE + 9*iASIC + 8);
833 std::cout <<
"Writing address " << std::hex << std::setfill (
'0') << std::setw(8) << address << std::endl;
837 uint32_t shiftVal = value & mask;
838 uint32_t regMask = (mask << pos);
839 uint32_t initVal =
ReadFEMB(iFEMB,address);
840 uint32_t newVal = ( (initVal & ~(regMask)) | (shiftVal << pos) );
841 vals[iASIC] = newVal;
854 if (iSPIWrite == nTries - 1)
857 bool spi_mismatch =
false;
858 for (
unsigned iSPIRead = 0; iSPIRead < 2; iSPIRead++)
860 std::cout <<
"ASIC SPI Readback..." << std::endl;
861 std::vector<uint32_t> regsReadback(nASICs);
862 for (
size_t iASIC=0; iASIC<nASICs; iASIC++)
864 uint32_t regReadback =
ReadFEMB(iFEMB, (REG_SPI_BASE_READ + 9*iASIC + 8));
865 regsReadback[iASIC] = regReadback;
869 std::cout <<
"ASIC SPI register number, write val, read val:" << std::endl;
870 spi_mismatch =
false;
871 for (
size_t iASIC=0; iASIC<nASICs; iASIC++)
873 std::cout << std::dec << std::setfill (
' ') << std::setw(3) << iASIC
875 << std::hex << std::setfill (
'0') << std::setw(8) << vals[iASIC]
877 << std::hex << std::setfill (
'0') << std::setw(8) << regsReadback[iASIC]
879 if (vals[iASIC] != regsReadback[iASIC])
882 size_t asicFailNum = 0;
883 if (iASIC > 0) asicFailNum = (iASIC-1);
884 std::cout <<
"FE-ADC ASIC " << asicFailNum <<
" SPI faled" << std::endl;
887 if (!spi_mismatch)
break;
891 BUException::WIB_ERROR e;
892 e.Append(
"SPI programming failure");
898 WriteFEMB(iFEMB,
"STREAM_AND_ADC_DATA_EN", 9 );
900 WriteFEMB(iFEMB,
"STREAM_AND_ADC_DATA_EN", 9 );
903 adc_sync_status = (uint16_t)
ReadFEMB(iFEMB,
"ADC_ASIC_SYNC_STATUS");
909 return adc_sync_status;
1062 uint32_t clk_phase_data0 = (clk_phase_data_start >> 8) & 0xFF;
1063 uint32_t clk_phase_data1 = clk_phase_data_start & 0xFF;
1064 uint32_t adc_fifo_sync = 1;
1066 uint32_t a_cs[8] = {
1067 0xc000, 0x3000, 0x0c00, 0x0300,
1068 0x00c0, 0x0030, 0x000c, 0x0003};
1070 uint32_t a_mark[8] = {
1071 0x80, 0x40, 0x20, 0x10,
1072 0x08, 0x04, 0x02, 0x01};
1074 uint32_t a_cnt[8] = {
1078 while (adc_fifo_sync){
1080 adc_fifo_sync = (
ReadFEMB(iFEMB, 6) & 0xFFFF0000) >> 16;
1082 adc_fifo_sync = (
ReadFEMB(iFEMB, 6) & 0xFFFF0000) >> 16;
1085 std::cout <<
"FEMB " << int(iFEMB) <<
" ADC FIFO sync: " << std::bitset<16>(adc_fifo_sync) << std::endl;
1087 if (adc_fifo_sync == 0){
1088 std::cout <<
"FEMB " << int(iFEMB) <<
" Successful SPI config and ADC FIFO synced" << std::endl;
1091 std::cout <<
" phase: " << std::hex << std::setw(2) << std::setfill(
'0') << clk_phase_data0;
1092 std::cout << std::hex << std::setw(2) << std::setfill(
'0') << clk_phase_data1 << std::endl;
1096 std::cout <<
"ERROR: sync not zero: " << std::bitset<16>(adc_fifo_sync) << std::endl;
1097 for(
int i = 0; i < 8; ++i){
1098 uint32_t a = adc_fifo_sync & a_cs[i];
1099 uint32_t a_mark_xor = 0;
1102 a_mark_xor = a_mark[i] ^ 0xFF;
1103 if (a_cnt[i] == 1 || a_cnt[i] == 3){
1104 clk_phase_data0 = ((clk_phase_data0 & a_mark[i]) ^ a_mark[i]) + (clk_phase_data0 & a_mark_xor);
1106 else if (a_cnt[i] == 2 || a_cnt[i] == 4){
1107 clk_phase_data1 = ((clk_phase_data1 & a_mark[i]) ^ a_mark[i]) + (clk_phase_data1 & a_mark_xor);
1109 else if (a_cnt[i] >= 5){
1117 uint16_t clk_phase_to_write=0;
1118 clk_phase_to_write |= (clk_phase_data0 & 0xFF) << 8;
1119 clk_phase_to_write |= clk_phase_data1;
void set_board(uint8_t d=0, uint8_t pcsr=0, uint8_t pdsr=0, uint8_t slp=0, uint8_t tstin=0, uint8_t f4=0, uint8_t f5=0, uint8_t slsb=0, uint8_t res4=0, uint8_t res3=0, uint8_t res2=0, uint8_t res1=0, uint8_t res0=0, uint8_t clk0=0, uint8_t clk1=0, uint8_t frqc=0, uint8_t engr=0, uint8_t f0=0, uint8_t f1=0, uint8_t f2=0, uint8_t f3=0)