#ifdef CF__LINUX #elif defined __VISUALC__ #include "stdafx.h" #endif #include "USBpix.h" // do not use namespace if not needed //using namespace std; USBpix::USBpix(int chip_add_0, int mod_add, SiUSBDevice * Handle0, bool isFEI4B, SiUSBDevice * Handle1, int chip_add_1)// : ConfigRegister(Handle)//, ConfigFEMemory(chip_add, mod_add, Handle) { myUSB0 = Handle0; myUSB1 = Handle1; myChipAdd0 = (chip_add_1 == 999)?chip_add_0:chip_add_1; // dirty hack as 2ChipAdapter connectes master board to FE1 myChipAdd1 = (chip_add_1 == 999)?chip_add_1:chip_add_0; // dirty hack as 2ChipAdapter connectes slave board to FE0 FEI4B = isFEI4B; myModAdd = mod_add; FEI4Aexisting = false; FEI4Bexisting = false; confReg1 = new ConfigRegister(Handle0, FEI4B); confReg0 = new ConfigRegister(Handle1, FEI4B); confFEMem1 = new ConfigFEMemory(myChipAdd1, mod_add, Handle0, confReg1, isFEI4B); // in single chip module, this MUST be the addressed chip! confFEMem0 = new ConfigFEMemory(myChipAdd0, mod_add, Handle0, confReg0, isFEI4B); // Handle == Handle0 is correct! One board cfgs all chips! FEI4Aexisting = !isFEI4B; FEI4Bexisting = isFEI4B; } USBpix::~USBpix(){ delete confReg1; delete confReg0; delete confFEMem1; delete confFEMem0; } void USBpix::SetUSBHandles(SiUSBDevice * hUSB0, SiUSBDevice * hUSB1) // sets pointer hUSB to correct instance SiUSBDevice. Needed for Plug'n'Play { // USB handle must be the same for both instances of ConfigFEMemory, but NOT for ConfigRegister... confFEMem1->SetUSBHandle(hUSB0); confFEMem0->SetUSBHandle(hUSB0); confReg1->SetUSBHandle(hUSB0); confReg0->SetUSBHandle(hUSB1); } bool USBpix::MakeMeFEI4A() { FEI4B = false; if (FEI4Aexisting) { return false; } if (FEI4Bexisting) { FEI4Bexisting = false; delete confReg1; delete confReg0; confReg1 = new ConfigRegister(myUSB0, FEI4B); confReg0 = new ConfigRegister(myUSB1, FEI4B); delete confFEMem1; delete confFEMem0; confFEMem1 = new ConfigFEMemory(myChipAdd0, myModAdd, myUSB0, confReg1, FEI4B); // in single chip module, this MUST be the addressed chip! confFEMem0 = new ConfigFEMemory(myChipAdd1, myModAdd, myUSB0, confReg0, FEI4B); // Handle == myUSB0 is correct! One board cfgs all chips! } FEI4Aexisting = true; return true; } bool USBpix::MakeMeFEI4B() { FEI4B = true; if (FEI4Bexisting) { return false; } if (FEI4Aexisting) { FEI4Aexisting = false; delete confReg1; delete confReg0; confReg1 = new ConfigRegister(myUSB0, FEI4B); confReg0 = new ConfigRegister(myUSB1, FEI4B); delete confFEMem1; delete confFEMem0; confFEMem1 = new ConfigFEMemory(myChipAdd0, myModAdd, myUSB0, confReg1, FEI4B); // in single chip module, this MUST be the addressed chip! confFEMem0 = new ConfigFEMemory(myChipAdd1, myModAdd, myUSB0, confReg0, FEI4B); // Handle == Handle0 is correct! One board cfgs all chips! } FEI4Bexisting = true; return true; } bool USBpix::FEisFEI4B() { return FEI4B; } bool USBpix::StartScan(int ScanVarIndex, int ScanStartVal, int ScanStopVal, int ScanValStepSize, int InjCount, int MaskStepSize, int MaskStepCount, int ShiftMask, bool all_DCs, bool special_dc_loop, bool singleDCloop) { // check for inconsistencies, if not true then scan error flag is set if ((ScanVarIndex >= 0) && /*(ScanVarIndex < GLOBAL_REG_ITEMS) && */(ScanStartVal >= 0) && (ScanStopVal >= 0) && (ScanValStepSize >= 0) && (ScanStartVal <= ScanStopVal) && (((ScanStopVal - ScanStartVal) == 0) || (((ScanStopVal - ScanStartVal)%ScanValStepSize) == 0)) && ((ScanValStepSize == 0) || (((ScanStopVal - ScanStartVal)/ScanValStepSize) < 1024)) && (InjCount >= 0) && (InjCount < 256) && (MaskStepSize >= 0) && (MaskStepCount >= 0) && (ShiftMask >= 0) && (ShiftMask < 16)) { // turn on scan LED (LED 3) WriteRegister(CS_SCAN_LED, 1); int add, size, colpr_mode, colpr_addr, old_chip_add; old_chip_add = myChipAdd0; SetChipAdd((int)8, old_chip_add); // scans all FEs at the same time... // clear SRAM and histograms // do not delete here // this is done in USBPixController for reasons //ClearSRAM(old_chip_add); //ClearConfHisto(); //ClearTOTHisto(); if(FEI4B) { GetGlobalVarAddVal(B_COLPR_MODE, add, size, colpr_mode, myChipAdd0); GetGlobalVarAddVal(B_COLPR_ADDR, add, size, colpr_addr, myChipAdd0); } else { GetGlobalVarAddVal(COLPR_MODE, add, size, colpr_mode, myChipAdd0); GetGlobalVarAddVal(COLPR_ADDR, add, size, colpr_addr, myChipAdd0); } // read out length of LVL1 //m_lengthLVL1 = ReadRegister(CS_L_LV1); //WriteRegister(CS_QUANTITY, 1); WriteRegister(CS_QUANTITY, InjCount); // set scanStep to zero confReg1->m_scanStep = 0; WriteRegister(CS_CONFIGURATION_NR, confReg1->m_scanStep); // automatically sets the same for slave board... //for (int maskStep = 0; (maskStep < MaskStepCount) && (m_scanCancelled == false) && (m_scanError == false); maskStep++) //{ //int ScanVal = ScanStartVal; // configuration parameter loop // total number of steps is ((ScanStopVal - ScanStartVal) / ScanValStepSize) + 1 for (int ScanVal = ScanStartVal; (ScanVal <= ScanStopVal) && (confReg1->m_scanCancelled == false) && (confReg1->m_scanError == false); ScanVal += ScanValStepSize, confReg1->m_scanStep++) { WriteRegister(CS_CONFIGURATION_NR, (confReg1->m_scanStep%32)); // set configuration step in FPGA, do not crop to 5 bit value for interrupt readout // set scan variable to start value SetGlobalVal(ScanVarIndex, ScanVal, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(ScanVarIndex), myChipAdd0); // pixel mask loop for (int maskStep = 0; (maskStep < MaskStepCount) && (confReg1->m_scanCancelled == false) && (confReg1->m_scanError == false); maskStep++) { if (all_DCs) // ((colpr_mode == 1) | (colpr_mode == 2))) // for debugging one might want to use other settings also??? { if (!special_dc_loop && !singleDCloop) { //scan loop for COLPR_ADDR. Scans every 8th (FE-I4A) DC at once! for (int col_add = 1; (col_add <= 8/*colpr_mode * 4*/) && (confReg1->m_scanCancelled == false) && (confReg1->m_scanError == false); col_add++) { if(FEI4B) { SetGlobalVal(B_COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(B_COLPR_MODE, 2, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(B_COLPR_ADDR), myChipAdd0); } else { SetGlobalVal(COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(COLPR_MODE, 2, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(COLPR_ADDR), myChipAdd0); } // enable data take mode // WriteCommand(FE_EN_DATA_TAKE); //for (int injection = 0; injection < InjCount; injection++) { // start injections int received_DH = 0; //reset event counter WriteRegister(CS_STATUS_REG, received_DH); WriteRegister(CS_TRIGGER_STRB_LV1, 1); while ((myUSB0->HandlePresent() == true) && (confReg1->ReadRegister(CS_TRIGGER_STRB_LV1) != 0)) { ; } /*// wait for chip to send data int timeout = 0; while ((received_DH != m_lengthLVL1))//!= m_lengthLVL1) && (received_DH != (m_lengthLVL1 - 1)) && (received_DH != (m_lengthLVL1 + 1))) { received_DH = ReadRegister(CS_STATUS_REG); timeout++; if (timeout == 1000) // to be adjusted... { //SetGlobalVal(COLPR_ADDR, 0); //SetGlobalVal(COLPR_MODE, 3); //WriteGlobal(IndexToRegisterNumber(COLPR_ADDR)); //SetGlobalVal(COLPR_MODE, colpr_mode); //SetGlobalVal(COLPR_ADDR, colpr_addr); //WriteGlobal(IndexToRegisterNumber(COLPR_MODE)); break; //return false; } }*/ } } } else if (!special_dc_loop && singleDCloop) { //scan loop for COLPR_ADDR. Scans single DCs! Needed for ToT scans like FDAC-Tuning for (int col_add = 0; col_add <= 39; col_add++) { if(FEI4B) { SetGlobalVal(B_COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(B_COLPR_MODE, 0, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(B_COLPR_ADDR), myChipAdd0); } else { SetGlobalVal(COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(COLPR_MODE, 0, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(COLPR_ADDR), myChipAdd0); } // enable data take mode // WriteCommand(FE_EN_DATA_TAKE); //for (int injection = 0; injection < InjCount; injection++) { // start injections int received_DH = 0; //reset event counter WriteRegister(CS_STATUS_REG, received_DH); WriteRegister(CS_TRIGGER_STRB_LV1, 1); while ((myUSB0->HandlePresent() == true) && (confReg1->ReadRegister(CS_TRIGGER_STRB_LV1) != 0)) { ; } /*// wait for chip to send data int timeout = 0; while ((received_DH != m_lengthLVL1))//!= m_lengthLVL1) && (received_DH != (m_lengthLVL1 - 1)) && (received_DH != (m_lengthLVL1 + 1))) { received_DH = ReadRegister(CS_STATUS_REG); timeout++; if (timeout == 1000) // to be adjusted... { //SetGlobalVal(COLPR_ADDR, 0); //SetGlobalVal(COLPR_MODE, 3); //WriteGlobal(IndexToRegisterNumber(COLPR_ADDR)); //SetGlobalVal(COLPR_MODE, colpr_mode); //SetGlobalVal(COLPR_ADDR, colpr_addr); //WriteGlobal(IndexToRegisterNumber(COLPR_MODE)); break; //return false; } }*/ } } } else { for (int col_add = 1; col_add <= 6/*8*//*colpr_mode * 4*/; col_add++) { if(FEI4B) { SetGlobalVal(B_COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(B_COLPR_MODE, 2, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(B_COLPR_ADDR), myChipAdd0); } else { SetGlobalVal(COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(COLPR_MODE, 2, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(COLPR_ADDR), myChipAdd0); } // enable data take mode // WriteCommand(FE_EN_DATA_TAKE); //for (int injection = 0; injection < InjCount; injection++) { // start injections int received_DH = 0; //reset event counter WriteRegister(CS_STATUS_REG, received_DH); WriteRegister(CS_TRIGGER_STRB_LV1, 1); while ((myUSB0->HandlePresent() == true) && (confReg1->ReadRegister(CS_TRIGGER_STRB_LV1) != 0)) { ; } /*// wait for chip to send data int timeout = 0; while ((received_DH != m_lengthLVL1))//!= m_lengthLVL1) && (received_DH != (m_lengthLVL1 - 1)) && (received_DH != (m_lengthLVL1 + 1))) { received_DH = ReadRegister(CS_STATUS_REG); timeout++; if (timeout == 1000) // to be adjusted... { //SetGlobalVal(COLPR_ADDR, 0); //SetGlobalVal(COLPR_MODE, 3); //WriteGlobal(IndexToRegisterNumber(COLPR_ADDR)); //SetGlobalVal(COLPR_MODE, colpr_mode); //SetGlobalVal(COLPR_ADDR, colpr_addr); //WriteGlobal(IndexToRegisterNumber(COLPR_MODE)); break; //return false; } }*/ } } for (int col_add = 0; col_add <= 39; col_add = col_add + 8) { if(FEI4B) { SetGlobalVal(B_COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(B_COLPR_MODE, 0, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(B_COLPR_ADDR), myChipAdd0); } else { SetGlobalVal(COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(COLPR_MODE, 0, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(COLPR_ADDR), myChipAdd0); } // enable data take mode // WriteCommand(FE_EN_DATA_TAKE); //for (int injection = 0; injection < InjCount; injection++) { // start injections int received_DH = 0; //reset event counter WriteRegister(CS_STATUS_REG, received_DH); WriteRegister(CS_TRIGGER_STRB_LV1, 1); while ((myUSB0->HandlePresent() == true) && (ReadRegister(CS_TRIGGER_STRB_LV1) != 0)) { ; } /*// wait for chip to send data int timeout = 0; while ((received_DH != m_lengthLVL1))//!= m_lengthLVL1) && (received_DH != (m_lengthLVL1 - 1)) && (received_DH != (m_lengthLVL1 + 1))) { received_DH = ReadRegister(CS_STATUS_REG); timeout++; if (timeout == 1000) // to be adjusted... { //SetGlobalVal(COLPR_ADDR, 0); //SetGlobalVal(COLPR_MODE, 3); //WriteGlobal(IndexToRegisterNumber(COLPR_ADDR)); //SetGlobalVal(COLPR_MODE, colpr_mode); //SetGlobalVal(COLPR_ADDR, colpr_addr); //WriteGlobal(IndexToRegisterNumber(COLPR_MODE)); break; //return false; } }*/ } } for (int col_add = 7; col_add <= 39; col_add = col_add + 8) { if(FEI4B) { SetGlobalVal(B_COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(B_COLPR_MODE, 0, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(B_COLPR_ADDR), myChipAdd0); } else { SetGlobalVal(COLPR_ADDR, col_add, myChipAdd0); SetGlobalVal(COLPR_MODE, 0, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(COLPR_ADDR), myChipAdd0); } // enable data take mode // WriteCommand(FE_EN_DATA_TAKE); //for (int injection = 0; injection < InjCount; injection++) { // start injections int received_DH = 0; //reset event counter WriteRegister(CS_STATUS_REG, received_DH); WriteRegister(CS_TRIGGER_STRB_LV1, 1); while ((myUSB0->HandlePresent() == true) && (ReadRegister(CS_TRIGGER_STRB_LV1) != 0)) { ; } /*// wait for chip to send data int timeout = 0; while ((received_DH != m_lengthLVL1))//!= m_lengthLVL1) && (received_DH != (m_lengthLVL1 - 1)) && (received_DH != (m_lengthLVL1 + 1))) { received_DH = ReadRegister(CS_STATUS_REG); timeout++; if (timeout == 100) // to be adjusted... { //SetGlobalVal(COLPR_ADDR, 0); //SetGlobalVal(COLPR_MODE, 3); //WriteGlobal(IndexToRegisterNumber(COLPR_ADDR)); //SetGlobalVal(COLPR_MODE, colpr_mode); //SetGlobalVal(COLPR_ADDR, colpr_addr); //WriteGlobal(IndexToRegisterNumber(COLPR_MODE)); break; //return false; } }*/ } } } if(FEI4B) { SetGlobalVal(B_COLPR_ADDR, 0, myChipAdd0); SetGlobalVal(B_COLPR_MODE, 3, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(B_COLPR_ADDR), myChipAdd0); } else { SetGlobalVal(COLPR_ADDR, 0, myChipAdd0); SetGlobalVal(COLPR_MODE, 3, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(COLPR_ADDR), myChipAdd0); } } //} else // (!all_DCs) { //for (int injection = 0; injection < InjCount; injection++) { // start injections int received_DH = 0; // reset event counter WriteRegister(CS_STATUS_REG, received_DH); WriteRegister(CS_TRIGGER_STRB_LV1, 1); while ((myUSB0->HandlePresent() == true) && (ReadRegister(CS_TRIGGER_STRB_LV1) != 0)) { ; } /*// wait for chip to send data int timeout = 0; while ((received_DH != m_lengthLVL1))//!= m_lengthLVL1) && (received_DH != (m_lengthLVL1 - 1)) && (received_DH != (m_lengthLVL1 + 1))) { received_DH = ReadRegister(CS_STATUS_REG); timeout++; if (timeout == 100) // to be adjusted... { //SetGlobalVal(COLPR_ADDR, 0); //SetGlobalVal(COLPR_MODE, 3); //WriteGlobal(IndexToRegisterNumber(COLPR_ADDR)); //SetGlobalVal(COLPR_MODE, colpr_mode); //SetGlobalVal(COLPR_ADDR, colpr_addr); //WriteGlobal(IndexToRegisterNumber(COLPR_MODE)); break; //return false; } }*/ } } //WriteCommand(FE_CONF_MODE, myChipAdd0); // needed to avoid triggering while chip gets configured in hitbus triggering modes... int oldtriggermode = ReadRegister(CS_TRIGGER_MODE); // needed to avoid triggering while chip gets configured in hitbus triggering modes... setTriggerMode(0); if(ShiftMask & 0x01) ShiftPixMask(HITBUS, MaskStepSize, myChipAdd0, true); if(ShiftMask & 0x02) ShiftPixMask(CAP0, MaskStepSize, myChipAdd0); if(ShiftMask & 0x04) ShiftPixMask(CAP1, MaskStepSize, myChipAdd0); if(ShiftMask & 0x08) ShiftPixMask(ENABLE, MaskStepSize, myChipAdd0); setTriggerMode(oldtriggermode);// needed to avoid triggering while chip gets configured in hitbus triggering modes... //WriteCommand(FE_EN_DATA_TAKE, myChipAdd0); // needed to avoid triggering while chip gets configured in hitbus triggering modes... } // end for masksteps // reload Mask after 32 Masksteps... //WriteCommand(FE_CONF_MODE, myChipAdd0); // needed to avoid triggering while chip gets configured in hitbus triggering modes... int oldtriggermode = ReadRegister(CS_TRIGGER_MODE); // needed to avoid triggering while chip gets configured in hitbus triggering modes... setTriggerMode(0); if(ShiftMask & 0x01) WritePixelSingleLatch(HITBUS, myChipAdd0); if(ShiftMask & 0x02) WritePixelSingleLatch(CAP0, myChipAdd0); if(ShiftMask & 0x04) WritePixelSingleLatch(CAP1, myChipAdd0); if(ShiftMask & 0x08) WritePixelSingleLatch(ENABLE, myChipAdd0); setTriggerMode(oldtriggermode);// needed to avoid triggering while chip gets configured in hitbus triggering modes... //WriteCommand(FE_EN_DATA_TAKE, myChipAdd0); // needed to avoid triggering while chip gets configured in hitbus triggering modes... // read SRAM if CONF_NR[4:0] == 5'b11111 or if last step is reached if ((confReg1->m_scanStep%32 == 31) || (confReg1->m_scanStep == ((ScanStopVal - ScanStartVal) / ScanValStepSize))) { // to be sure that FSM is not working WriteRegister(CS_TRIGGER_STRB_LV1, 0); //while ((USB->HandlePresent() == true) && (ReadRegister(CS_SRAM_READOUT_READY) == 0)) // TODO //{ // ; //} ReadSRAM(confReg1->m_scanStep, myChipAdd0); ClearSRAM(myChipAdd0); if (myChipAdd1 != 999) { ReadSRAM(confReg1->m_scanStep, myChipAdd1); ClearSRAM(myChipAdd1); } } // this is needed to avoid wrong m_scanStep value that is read out by GetScanStatus() // expression m_scanStep is updated before tested by for loop entry condition // so GetScanStatus() will read wrong value for the last step (increased by one which is not the case) if (confReg1->m_scanStep == ((ScanStopVal - ScanStartVal) / ScanValStepSize)) { break; } //int scanStep = 0; //bool scanBusy = true; //bool scanCancelled = true; //GetScanStatus(scanBusy, scanCancelled, scanStep); //if (m_scanCancelled) //{ // WriteRegister(CS_TRIGGER_STRB_LV1, 0); // ResetScanStatus(); // return false; //} } // end for scanstep //} // reset uC status bits //ResetScanStatus(); // you never know... WriteRegister(CS_TRIGGER_STRB_LV1, 0); //while ((USB->HandlePresent() == true) && (ReadRegister(CS_SRAM_READOUT_READY) == 0)) // TODO //{ // ; //} if(FEI4B) { SetGlobalVal(B_COLPR_MODE, colpr_mode, myChipAdd0); SetGlobalVal(B_COLPR_ADDR, colpr_addr, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(B_COLPR_MODE), myChipAdd0); } else { SetGlobalVal(COLPR_MODE, colpr_mode, myChipAdd0); SetGlobalVal(COLPR_ADDR, colpr_addr, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(COLPR_MODE), myChipAdd0); } // turn off scan LED (LED 3) WriteRegister(CS_SCAN_LED, 0); // setting of scan status bits if (confReg1->m_scanCancelled) // scan externally cancelled { //SetScanCancelled(); // not needed this has to be set externally SetScanReady(); SetChipAdd(old_chip_add, (int)8); // scans all FEs at the same time... return false; } else if (confReg1->m_scanError) // internal scan abort, e.g. timeout, ... { SetScanError(); SetScanReady(); SetChipAdd(old_chip_add, (int)8); // scans all FEs at the same time... return false; } else { SetScanReady(); SetChipAdd(old_chip_add, (int)8); // scans all FEs at the same time... return true; } } else // scan cancelled due to wrong parameters { SetScanError(); SetScanReady(); return false; } } void USBpix::StartHitORScan() { //int old_chip_add = myChipAdd0; //SetChipAdd((int)8, old_chip_add); // scans all FEs at the same time... // resetting scan status bits // this should be done *before* calling StartHitORScan() ResetScanStatus(); // turn on scan LED (LED 3) WriteRegister(CS_SCAN_LED, 1); SetCalibrationMode(); if(FEI4B) { SetGlobalVal(DIGHITIN_SEL, 1, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(DIGHITIN_SEL), myChipAdd0); } else { SetGlobalVal(B_DIGHITIN_SEL, 1, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(B_DIGHITIN_SEL), myChipAdd0); } WriteCommand(FE_EN_DATA_TAKE, myChipAdd0); WriteRegister(CS_CONFIGURATION_NR, 0); if (myChipAdd1 != 999) confReg0->WriteRegister(CS_CONFIGURATION_NR, 0); ClearSRAM(myChipAdd0); ClearConfHisto(myChipAdd0); ClearTOTHisto(myChipAdd0); if (myChipAdd1 != 999) { ClearSRAM(myChipAdd1); ClearConfHisto(myChipAdd1); ClearTOTHisto(myChipAdd1); } //WriteRegister(CS_QUANTITY, 1); WriteRegister(CS_QUANTITY, 10); for (int DC = 0; (DC < 40) && (confReg1->m_scanCancelled == false); DC++) { for (int pixel = PIXEL26880; (pixel <= PIXEL26240) && (confReg1->m_scanCancelled == false); pixel++) { int pixelmask = 0xffffffff; for (int i = PIXEL26880; i <= PIXEL32; i++) { SetPixelVal(i, pixelmask, HITBUS, myChipAdd0); SetPixelVal(i, ~pixelmask, ENABLE, myChipAdd0); } WritePixelSingleLatch(HITBUS, myChipAdd0); WritePixelSingleLatch(ENABLE, myChipAdd0); SetPixelVal(HITBUS, DC, pixel, 0xfffffffe, myChipAdd0); WritePixelSingleLatchDC(HITBUS, DC, myChipAdd0); SetPixelVal(ENABLE, DC, pixel, ~0xfffffffe, myChipAdd0); WritePixelSingleLatchDC(ENABLE, DC, myChipAdd0); if(FEI4B) { SetGlobalVal(B_COLPR_MODE, 0, myChipAdd0); SetGlobalVal(B_COLPR_ADDR, DC, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(B_COLPR_MODE), myChipAdd0); } else { SetGlobalVal(COLPR_MODE, 0, myChipAdd0); SetGlobalVal(COLPR_ADDR, DC, myChipAdd0); WriteGlobalSingleReg(IndexToRegisterNumber(COLPR_MODE), myChipAdd0); } WriteRegister(CS_TRIGGER_STRB_LV1, 1); while ((myUSB0->HandlePresent() == true) && (ReadRegister(CS_TRIGGER_STRB_LV1) != 0)) { ; } } } // to be sure that FSM is not working WriteRegister(CS_TRIGGER_STRB_LV1, 0); //while ((USB->HandlePresent() == true) && (ReadRegister(CS_SRAM_READOUT_READY) == 0)) // TODO //{ // ; //} ReadSRAM(myChipAdd0); ClearSRAM(myChipAdd0); if (myChipAdd1 != 999) { ReadSRAM(myChipAdd1); ClearSRAM(myChipAdd1); } SetRunMode(); // turn off LED 3 WriteRegister(CS_SCAN_LED, 0); //SetChipAdd(old_chip_add, (int)8); // scans all FEs at the same time... SetScanReady(); } void USBpix::SetSlowControlMode() // sets system to bypass-mode { confFEMem1->SetSlowControlMode(); } void USBpix::setSelAltBus(bool on_off) // toggels SelAltBus_P { confFEMem1->setSelAltBus(on_off); } void USBpix::setSelCMD(bool on_off) { confFEMem1->setSelCMD(on_off); } void USBpix::SetCMDMode() // sets system to default mode (use CMD...) { confFEMem1->SetCMDMode(); } void USBpix::WriteCommand(int the_command, int chip_addr) // sends command to FE, command definition given in defines.h { // only slow commands send FE by FE. Fast commands are accepted by both... if (the_command == FE_LV1_TRIGGER || the_command == FE_BCR || the_command == FE_ECR || the_command == FE_CAL) // fast commands, accepted by all chips... confFEMem1->WriteCommand(the_command); else { if (chip_addr == myChipAdd0) confFEMem1->WriteCommand(the_command); else if (chip_addr == myChipAdd1) confFEMem0->WriteCommand(the_command); } } void USBpix::WriteGlobal(int chip_addr) // writes complete global configuration { if (chip_addr == myChipAdd0) confFEMem1->WriteGlobal(); else if (chip_addr == myChipAdd1) confFEMem0->WriteGlobal(); } void USBpix::WriteGlobalSingleReg(int RegisterNumber, int chip_addr) // writes global register number RegisterNumber { if (chip_addr == myChipAdd0) confFEMem1->WriteGlobal(RegisterNumber); else if (chip_addr == myChipAdd1) confFEMem0->WriteGlobal(RegisterNumber); } void USBpix::WritePixel(int chip_addr) // writes complete pixel configuration { if (chip_addr == myChipAdd0) confFEMem1->WritePixel(); else if (chip_addr == myChipAdd1) confFEMem0->WritePixel(); } void USBpix::WritePixelSingleLatch(int latch, int chip_addr) // writes one latch in all DCs. Will be overloaded later to write variable DCs { if (chip_addr == myChipAdd0) confFEMem1->WritePixel(latch); else if (chip_addr == myChipAdd1) confFEMem0->WritePixel(latch); } void USBpix::WritePixelSingleLatchDC(int latch, int DC, int chip_addr) // writes one latch in given DCs. { if (chip_addr == myChipAdd0) confFEMem1->WritePixel(latch, DC); else if (chip_addr == myChipAdd1) confFEMem0->WritePixel(latch, DC); } void USBpix::ShiftPixMask(int latch, int steps, int chip_addr, bool fillOnes) // shifts pixel masks - last parameter allows to fill with ones, not zeros { if (chip_addr == myChipAdd0) confFEMem1->ShiftPixMask(latch, steps, fillOnes); else if (chip_addr == myChipAdd1) confFEMem0->ShiftPixMask(latch, steps, fillOnes); } void USBpix::ReadGlobal(int chip_addr) // reads complete global configuration, will be overloaded later to read just one global register { if (chip_addr == myChipAdd0) confFEMem1->ReadGlobal(); else if (chip_addr == myChipAdd1) confFEMem0->ReadGlobal(); } int USBpix::ReadGlobalSingleReg(int RegisterNumber, int chip_addr) // reads global register number RegisterNumber { if (chip_addr == myChipAdd0) return confFEMem1->ReadGlobal(RegisterNumber); else if (chip_addr == myChipAdd1) return confFEMem0->ReadGlobal(RegisterNumber); else return 0; } void USBpix::ReadPixel(int chip_addr) // reads complete pixel configuration { if (chip_addr == myChipAdd0) confFEMem1->ReadPixel(); else if (chip_addr == myChipAdd1) confFEMem0->ReadPixel(); } //void USBpix::ReadPixelSingleLatch(int latch, int chip_addr) // reads one latch of all DCs. Will be overloaded later to read variable DCs //{ // if (chip_addr == myChipAdd0) // confFEMem1->ReadPixel(latch); // // else if (chip_addr == myChipAdd1) // confFEMem0->ReadPixel(latch); //} void USBpix::ReadPixelSingleLatch(int latch, bool bypass, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->ReadPixel(latch, bypass); else if (chip_addr == myChipAdd1 && bypass == false) confFEMem0->ReadPixel(latch, false); } void USBpix::ReadPixelSingleLatchDC(int latch, int DC, int chip_addr) // reads one latch of the given DC. { if (chip_addr == myChipAdd0) confFEMem1->ReadPixel(latch, DC); else if (chip_addr == myChipAdd1) confFEMem0->ReadPixel(latch, DC); } void USBpix::ReadPixelSingleLatchDC(int latch, int DC, bool bypass, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->ReadPixel(latch, DC, bypass); else if (chip_addr == myChipAdd1 && bypass == false) confFEMem0->ReadPixel(latch, DC, false); } void USBpix::SetGlobalVal(int the_index, int the_value, int chip_addr) // sets one item in global configuration { if (chip_addr == myChipAdd0) confFEMem1->SetGlobalVal(the_index, the_value); else if (chip_addr == myChipAdd1) confFEMem0->SetGlobalVal(the_index, the_value); } void USBpix::SetPixelVal(int the_index, int the_value, int latch, int chip_addr) // sets one item in pixel configuration { if (chip_addr == myChipAdd0) confFEMem1->SetPixelVal(the_index, the_value, latch); else if (chip_addr == myChipAdd1) confFEMem0->SetPixelVal(the_index, the_value, latch); } void USBpix::SetPixelVal(int latch, int theDC, int the_DCindex, int the_value, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->SetPixelVal(latch, theDC, the_DCindex, the_value); else if (chip_addr == myChipAdd1) confFEMem0->SetPixelVal(latch, theDC, the_DCindex, the_value); } bool USBpix::ReadGlobalFile(const char * globalfilename, int chip_addr) // reads global configuration from file { if (chip_addr == myChipAdd0) return confFEMem1->ReadGlobalFile(globalfilename); else if (chip_addr == myChipAdd1) return confFEMem0->ReadGlobalFile(globalfilename); else return false; } void USBpix::ReadPixelFile(const char * pixelfilename, int latch, int chip_addr) //reads pixel configuration for one latch from file { if (chip_addr == myChipAdd0) confFEMem1->ReadPixelFile(pixelfilename, latch); else if (chip_addr == myChipAdd1) confFEMem0->ReadPixelFile(pixelfilename, latch); } void USBpix::SaveGlobal(const char * newfilename, int chip_addr) // saves global configuration to file { if (chip_addr == myChipAdd0) confFEMem1->SaveGlobal(newfilename); else if (chip_addr == myChipAdd1) confFEMem0->SaveGlobal(newfilename); } void USBpix::SaveGlobalRB(const char * newfilename, int chip_addr) // saves read-back global configuration to file { if (chip_addr == myChipAdd0) confFEMem1->SaveGlobalRB(newfilename); else if (chip_addr == myChipAdd1) confFEMem0->SaveGlobalRB(newfilename); } void USBpix::LoadGlobalDefault(int chip_addr) // loads default configuration { if (chip_addr == myChipAdd0) confFEMem1->LoadGlobalDefault(); else if (chip_addr == myChipAdd1) confFEMem0->LoadGlobalDefault(); } void USBpix::SavePixel(const char * newfilename, int latch, int doublecolumn, int chip_addr) //saves pixel configuration for one latch/DC to file { if (chip_addr == myChipAdd0) confFEMem1->SavePixel(newfilename, latch, doublecolumn); else if (chip_addr == myChipAdd1) confFEMem0->SavePixel(newfilename, latch, doublecolumn); } void USBpix::SavePixelRB(const char * newfilename, int latch, int doublecolumn, int chip_addr) // saves read-back pixel configuration for one latch/DC to file { if (chip_addr == myChipAdd0) confFEMem1->SavePixelRB(newfilename, latch, doublecolumn); else if (chip_addr == myChipAdd1) confFEMem0->SavePixelRB(newfilename, latch, doublecolumn); } void USBpix::GetGlobalVarAddVal(int Variable, int& Address, int& Size, int& Value, int chip_addr) // writes value, bitsize and address of one item of global configuration to given addresses { if (chip_addr == myChipAdd0) confFEMem1->GetGlobalVarAddVal(Variable, Address, Size, Value); else if (chip_addr == myChipAdd1) confFEMem0->GetGlobalVarAddVal(Variable, Address, Size, Value); } void USBpix::GetGlobalRBVarAddVal(int Variable, int& Address, int& Size, int& Value, int chip_addr) // writes value, bitsize and address of one item of read-back global configuration to given addresses { if (chip_addr == myChipAdd0) confFEMem1->GetGlobalRBVarAddVal(Variable, Address, Size, Value); else if (chip_addr == myChipAdd1) confFEMem0->GetGlobalRBVarAddVal(Variable, Address, Size, Value); } void USBpix::GetPixelVarAddVal(int Variable, int& Address, int& Size, int& Value, int latch, int chip_addr) // writes value, bitsize and address of one item of pixel configuration to given addresses { if (chip_addr == myChipAdd0) confFEMem1->GetPixelVarAddVal(Variable, Address, Size, Value, latch); else if (chip_addr == myChipAdd1) confFEMem0->GetPixelVarAddVal(Variable, Address, Size, Value, latch); } //void USBpix::GetPixelRBVarAddVal(int Variable, int& Address, int& Size, int& Value, int latch, int chip_addr) // writes value, bitsize and address of one item of read-back pixel configuration to given addresses //{ // if (chip_addr == myChipAdd0) // confFEMem1->GetPixelRBVarAddVal(Variable, Address, Size, Value, latch); // // else if (chip_addr == myChipAdd1) // confFEMem0->GetPixelRBVarAddVal(Variable, Address, Size, Value, latch); //} void USBpix::GetPixelRBVarAddVal(int Variable, int& Address, int& Size, int& Value, int latch, bool bypass, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->GetPixelRBVarAddVal(Variable, Address, Size, Value, latch, bypass); else if (chip_addr == myChipAdd1 && bypass == false) confFEMem0->GetPixelRBVarAddVal(Variable, Address, Size, Value, latch, false); } void USBpix::SetChipAdd(int new_chip_add, int chip_addr) // sets chip address { if (chip_addr == myChipAdd0) { myChipAdd0 = new_chip_add; confFEMem1->SetChipAdd(new_chip_add); } else if (chip_addr == myChipAdd1) { myChipAdd1 = new_chip_add; confFEMem0->SetChipAdd(new_chip_add); } } void USBpix::SendReadErrors(int chip_addr) // sends a global pulse to read error counters { if (chip_addr == myChipAdd0) confFEMem1->SendReadErrors(); else if (chip_addr == myChipAdd1) confFEMem0->SendReadErrors(); } void USBpix::ReadEPROMvalues(int chip_addr) // Sends global pulse to read the values from EPROM to GR. { if (chip_addr == myChipAdd0) confFEMem1->ReadEPROMvalues(); else if (chip_addr == myChipAdd1) confFEMem0->ReadEPROMvalues(); } void USBpix::BurnEPROMvalues() // Burns to the EPROM whatever is stored in GR. Note that burning a 1 is non reversibel! Does not respect chip ID. { confFEMem1->BurnEPROMvalues(); } void USBpix::SendBitstream(unsigned char * bitstream, int bitsize, int chip_addr) // sends bitsream to FE { if (chip_addr == myChipAdd0) confFEMem1->SendBitstream(bitstream, bitsize); else if (chip_addr == myChipAdd1) confFEMem0->SendBitstream(bitstream, bitsize); } std::string USBpix::getGlobalVarName(int Variable) { return confFEMem1->getGlobalVarName(Variable); } void USBpix::sendBitstreamToAB(int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->sendBitstreamToAB(); } void USBpix::sendBitstreamToC(int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->sendBitstreamToC(); } //ScanChain void USBpix::SetScanChainValue (int BlockSelect,int index, int val, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->SetScanChainValue(BlockSelect, index, val); } void USBpix::GetScanChainValue (int BlockSelect,int index, int& size, int& add, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->GetScanChainValue(BlockSelect, index, size, add, Value); else { size = 0; Value = 0; } } void USBpix::GetScanChainValueRB(int BlockSelect,int index, int& size, int& add, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->GetScanChainValueRB(BlockSelect, index, size, add, Value); else { size = 0; Value = 0; } } void USBpix::RunScanChain(int ScanChainSelect, USBPixDCS* dcs, double& current_before, double& current_after, bool shift_only, bool se_while_pulse, bool si_while_pulse, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->RunScanChain(ScanChainSelect, dcs, current_before, current_after, shift_only, se_while_pulse, si_while_pulse); } void USBpix::LoadFileToScanChain(int ScanChainSelect, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->LoadFileToScanChain(ScanChainSelect); } void USBpix::SaveFileFromScanChain(int ScanChainSelect, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->SaveFileFromScanChain(ScanChainSelect); } void USBpix::SaveFileFromScanChainRB(int ScanChainSelect, int chip_addr) { if (chip_addr == myChipAdd0) confFEMem1->SaveFileFromScanChainRB(ScanChainSelect); } //void USBpix::ReadScanChainFromFE(int ScanChainSelect, int chip_addr) //{ // if (chip_addr == myChipAdd0) // confFEMem1->ReadScanChainFromFE(ScanChainSelect); //} int USBpix::IndexToRegisterNumber(int the_index) // needed to hide FE-I4 / FE-I3 structure differences to outside world { return confFEMem1->IndexToRegisterNumber(the_index); } void USBpix::ResetAll() // sets all registers in the fpga to zero { confReg1->ResetAll(); } // access to FPGA configuration registers int USBpix::ReadRegister(int CS) // read 8bit register, wrapper for ReadXilinx() to protect against accidental misuse { return confReg1->ReadRegister(CS); // also for board 1 needed? Very likely not... } void USBpix::WriteRegister(int CS, int data) // write 8bit register, wrapper for WriteXilinx() to protect against accidental misuse { confReg1->WriteRegister(CS, data); // Needed for both boards, as needed for histogramming if (myChipAdd1 != 999) confReg0->WriteRegister(CS, data); } //---write strb & LV1 registers--------------- void USBpix::WriteStrbSave(unsigned char *data) // saves all parameters for injection / LV1 generating state machine { confReg1->WriteStrbSave(data); // only board 0 can inject or trigger... if (myChipAdd1 != 999) confReg0->WriteStrbSave(data); // but board 1 needs to know also!!! } void USBpix::WriteStrbStart() // start measurements / LV1 FSM { confReg1->WriteStrbStart(); // only board 0 can trigger and inject } void USBpix::WriteStrbStop() // stop measurements / LV1 FSM { confReg1->WriteStrbStop(); // only board 0 can trigger and inject } //---write ConfigSM registers----------------- void USBpix::SetCableLengthReg(int value) { confReg1->SetCableLengthReg(value); // only in single chip mode CMOS is used... if (myChipAdd1 != 999) confReg0->SetCableLengthReg(value); } //void USBpix::WriteFEMemBlockRAMReset() // resets BlockRAM. FE-configurations are stored in the BlockRAM //{ // confReg1->WriteFEMemBlockRAMReset(); // only board 0 can cfg chips... //} void USBpix::resetRunModeAdd() { confReg1->resetRunModeAdd(); if (myChipAdd1 != 999) confReg0->resetRunModeAdd(); } void USBpix::SetCalibrationMode() // sets system to calibration mode (HIT-HISTOGRAMMING) { confReg1->SetCalibrationMode(); if (myChipAdd1 != 999) confReg0->SetCalibrationMode(); } void USBpix::SetRunMode() // sets system to run mode (FULL DATA STORAGE) { confReg1->SetRunMode(); if (myChipAdd1 != 999) confReg0->SetRunMode(); } void USBpix::SetTOTMode() // sets system to tot mode (TOT-HISTOGRAMMING) { confReg1->SetTOTMode(); if (myChipAdd1 != 999) confReg0->SetTOTMode(); } void USBpix::SetTLUMode() // sets system to TLU Mode (FULL DATA Storage + Trigger Number recieved from TLU) { confReg1->SetTLUMode(); // NEEDS WORK FOR 2nd BOARD !!! DATA SYNCHRONISATION WITH FIRST BOARD... if (myChipAdd1 != 999) confReg0->SetTLUMode(); } void USBpix::WriteStrbQuantity(int value) // writes quantity of generated strobe and LV1 signals { confReg1->WriteStrbQuantity(value); // only board 0 can strobe or trigger, but board 1 needs to know also... if (myChipAdd1 != 999) confReg0->WriteStrbQuantity(value); } void USBpix::enableExtLV1() // sets TriggerMode to 2 => simple external trigger via LEMO or RJ45 { // both boards need to know for FE selftriggering confReg1->enableExtLV1(); if (myChipAdd1 != 999) confReg0->enableExtLV1(); } void USBpix::disableExtLV1() // disables external triggers via LEMO (TX0) or ethernet connector { // both boards need to know for FE selftriggering confReg1->disableExtLV1(); if (myChipAdd1 != 999) confReg0->disableExtLV1(); } void USBpix::setTriggerMode(int TriggerMode) // sets mode for external triggers via LEMO, RJ45 or MULTI_IO pins: enum TriggerType {STROBE_SCAN=0, USBPIX_SELF_TRG=1, EXT_TRG=2,TLU_SIMPLE=3, TLU_DATA_HANDSHAKE=4, USBPIX_REPLICATION_SLAVE=5}; { confReg1->setTriggerMode(TriggerMode); // Use Trigger Repli for second 2nd BOARD !!! if (myChipAdd1 != 999) confReg0->setTriggerMode(TriggerMode); // ToDo: Define good mode here... } void USBpix::enableTriggerReplicationMaster() // enables forwarding of triggers via MULTI_IO pins { confReg1->enableTriggerReplicationMaster(); // Board one should be master... if (myChipAdd1 != 999) confReg0->disableTriggerReplicationMaster(); // Board two should always be slave. disable call correct??? } void USBpix::disableTriggerReplicationMaster() // disables forwarding of triggers via MULTI_IO pins { confReg1->disableTriggerReplicationMaster(); // Board one should be master... if (myChipAdd1 != 999) confReg0->disableTriggerReplicationMaster(); // Board two should always be slave. disable call correct??? } void USBpix::enable_8b10_Decoding() // enables decoding { confReg1->enable_8b10_Decoding(); // MUST be the same for all Boards... if (myChipAdd1 != 999) confReg0->enable_8b10_Decoding(); } void USBpix::disable_8b10_Decoding() // disables decoding { confReg1->enable_8b10_Decoding(); // MUST be the same for all Boards... if (myChipAdd1 != 999) confReg0->enable_8b10_Decoding(); } void USBpix::enableCMDLV1() // sets LV1 generating state machine to CMD mode { confReg1->enableCMDLV1(); // Can be the same for all Boards... if (myChipAdd1 != 999) confReg0->enableCMDLV1(); } void USBpix::disableCMDLV1() // sets LV1 generating state machine to external pad mode { confReg1->disableCMDLV1(); // Can be the same for all Boards... if (myChipAdd1 != 999) confReg0->disableCMDLV1(); } void USBpix::enable_160Mbps_data_rate() // sets system to 160 Mbps data rate { confReg1->enable_160Mbps_data_rate(); // decided to be the same for all Boards, although chip cfg dependent... if (myChipAdd1 != 999) confReg0->enable_160Mbps_data_rate(); } void USBpix::disable_160Mbps_data_rate() // sets system to 40 Mbps data rate { confReg1->disable_160Mbps_data_rate(); // decided to be the same for all Boards, although chip cfg dependent... if (myChipAdd1 != 999) confReg0->disable_160Mbps_data_rate(); } void USBpix::EnablePowerChannel(bool on_off, int channel) // disables/enables power channel number "channel", channel defined in defines.h { confReg1->EnablePowerChannel(on_off, channel); // Should it be the same for all Boards? Powering still an open question... if (myChipAdd1 != 999) confReg0->EnablePowerChannel(on_off, channel); } void USBpix::stopXCK(bool status) { confReg1->stopXCK(status); // only board 0 provides module clk... } void USBpix::SetAuxClkFreq(int freq) { confReg1->SetAuxClkFreq(freq); // No AuxClk on modules anyway... } void USBpix::incr_phase_shift(int chip_addr) // increments incoming data synchronization by 1/256 clock duration { if (chip_addr == myChipAdd0) // needs to be set for both boards independently for sure!!! confReg1->incr_phase_shift(); else if (chip_addr == myChipAdd1) confReg0->incr_phase_shift(); } void USBpix::decr_phase_shift(int chip_addr) // decrements incoming data synchronization by 1/256 clock duration { if (chip_addr == myChipAdd0) // needs to be set for both boards independently for sure!!! confReg1->decr_phase_shift(); else if (chip_addr == myChipAdd1) confReg0->decr_phase_shift(); } bool USBpix::check_phase_shift_overflow(int chip_addr) // checks for overflow of phase shift { if (chip_addr == myChipAdd0) // needs to be checked for both boards independently for sure!!! return confReg1->check_phase_shift_overflow(); else if (chip_addr == myChipAdd1) return confReg0->check_phase_shift_overflow(); else return false; } double USBpix::StartSyncCheck(double min_BitErrorRate, int chip_addr) // starts synchro checker until min_BitErrorRate was achieved { if (chip_addr == myChipAdd0) // needs to be checked for both boards independently for sure!!! return confReg1->StartSyncCheck(min_BitErrorRate); else if (chip_addr == myChipAdd1) return confReg0->StartSyncCheck(min_BitErrorRate); else return -1; } bool USBpix::StartSyncScan(double min_BitErrorRate, int chip_addr) // Scans for opimal Sync clk-phase { if (chip_addr == myChipAdd0) // needs to be checked for both boards independently for sure!!! return confReg1->StartSyncScan(min_BitErrorRate); else if (chip_addr == myChipAdd1) return confReg0->StartSyncScan(min_BitErrorRate); else return false; } void USBpix::StoreSyncCheckPattern(int chip_addr) // stores new SyncCheckPattern { if (chip_addr == myChipAdd0) // needs to be set for both boards independently for sure!!! confReg1->StoreSyncCheckPattern(); else if (chip_addr == myChipAdd1) confReg0->StoreSyncCheckPattern(); } void USBpix::ResetSyncCheckPattern(int chip_addr) // resets SyncCheckPattern { if (chip_addr == myChipAdd0) // needs to be set for both boards independently for sure!!! confReg1->ResetSyncCheckPattern(); else if (chip_addr == myChipAdd1) confReg0->ResetSyncCheckPattern(); } void USBpix::ResetSRAMCounter(int chip_addr) // set SRAM address to 0 { if (chip_addr == myChipAdd0) // needs to be set for both boards independently for sure!!! confReg1->ResetSRAMCounter(); else if (chip_addr == myChipAdd1) confReg0->ResetSRAMCounter(); } void USBpix::SetSRAMCounter(int startadd, int chip_addr) // set RAM address to any value { if (chip_addr == myChipAdd0) // needs to be set for both boards independently for sure!!! confReg1->SetSRAMCounter(startadd); else if (chip_addr == myChipAdd1) confReg0->SetSRAMCounter(startadd); } void USBpix::ReadSRAM(int chip_addr) // reads complete SRAM, further data handling dependent on system mode { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ReadSRAM(); else if (chip_addr == myChipAdd1) confReg0->ReadSRAM(); } void USBpix::ReadSRAM(int scan_nr, int chip_addr) // reads complete SRAM, further data handling dependent on system mode and fills correct scansteps of ConfData { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ReadSRAM(scan_nr); else if (chip_addr == myChipAdd1) confReg0->ReadSRAM(scan_nr); } void USBpix::ReadSRAM(int StartAdd, int NumberOfWords, int chip_addr) // reads SRAM partially { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ReadSRAM(StartAdd, NumberOfWords); else if (chip_addr == myChipAdd1) confReg0->ReadSRAM(StartAdd, NumberOfWords); } void USBpix::ClearSRAM(int chip_addr) // clears SRAM { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearSRAM(); else if (chip_addr == myChipAdd1) confReg0->ClearSRAM(); } void USBpix::WriteSRAM(int StartAdd, int NumberOfWords, int chip_addr) // writes SRAM, only for debugging purposes needed { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->WriteSRAM(StartAdd, NumberOfWords); else if (chip_addr == myChipAdd1) confReg0->WriteSRAM(StartAdd, NumberOfWords); } void USBpix::GetConfHisto(int col, int row, int confstep, int &Value, int chip_addr) // writes histogram-value for col, row, step to &Value (needs calibration mode) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetConfHisto(col, row, confstep, Value); else if (chip_addr == myChipAdd1) confReg0->GetConfHisto(col, row, confstep, Value); } void USBpix::GetTOTHisto(int col, int row, int tot, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetTOTHisto(col, row, tot, Value); else if (chip_addr == myChipAdd1) confReg0->GetTOTHisto(col, row, tot, Value); } void USBpix::ClearTOTHisto(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearTOTHisto(); else if (chip_addr == myChipAdd1) confReg0->ClearTOTHisto(); } void USBpix::ClearConfHisto(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearConfHisto(); else if (chip_addr == myChipAdd1) confReg0->ClearConfHisto(); } void USBpix::GetHitTOTHistoFromRawData(int col, int row, int TOT, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetHitTOTHistoFromRawData(col, row, TOT, Value); else if (chip_addr == myChipAdd1) confReg0->GetHitTOTHistoFromRawData(col, row, TOT, Value); } void USBpix::GetHitHistoFromRawData(int col, int row, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetHitHistoFromRawData(col, row, Value); else if (chip_addr == myChipAdd1) confReg0->GetHitHistoFromRawData(col, row, Value); } void USBpix::GetHitLV1HistoFromRawData(int LV1ID, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetHitLV1HistoFromRawData(LV1ID, Value); else if (chip_addr == myChipAdd1) confReg0->GetHitLV1HistoFromRawData(LV1ID, Value); } void USBpix::ClearHitTOTHistoFromRawData(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearHitTOTHistoFromRawData(); else if (chip_addr == myChipAdd1) confReg0->ClearHitTOTHistoFromRawData(); } void USBpix::ClearHitHistoFromRawData(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearHitHistoFromRawData(); else if (chip_addr == myChipAdd1) confReg0->ClearHitHistoFromRawData(); } void USBpix::ClearHitLV1HistoFromRawData(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearHitLV1HistoFromRawData(); else if (chip_addr == myChipAdd1) confReg0->ClearHitLV1HistoFromRawData(); } // cluster histograms void USBpix::GetClusterSizeHistoFromRawData(int Size, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetClusterSizeHistoFromRawData(Size, Value); else if (chip_addr == myChipAdd1) confReg0->GetClusterSizeHistoFromRawData(Size, Value); } void USBpix::GetClusterTOTHistoFromRawData(int TOT, int Size, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetClusterTOTHistoFromRawData(TOT, Size, Value); else if (chip_addr == myChipAdd1) confReg0->GetClusterTOTHistoFromRawData(TOT, Size, Value); } void USBpix::GetClusterSeedTOTHistoFromRawData(/*int col, int row, */int TOT, int Size, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetClusterSeedTOTHistoFromRawData(TOT, Size, Value); else if (chip_addr == myChipAdd1) confReg0->GetClusterSeedTOTHistoFromRawData(TOT, Size, Value); } void USBpix::GetClusterSeedLV1HistoFromRawData(int LV1ID, int Size, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetClusterSeedLV1HistoFromRawData(LV1ID, Size, Value); else if (chip_addr == myChipAdd1) confReg0->GetClusterSeedLV1HistoFromRawData(LV1ID, Size, Value); } void USBpix::GetClusterSeedHistoFromRawData(int col, int row, int Size, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetClusterSeedHistoFromRawData(col, row, Size, Value); else if (chip_addr == myChipAdd1) confReg0->GetClusterSeedHistoFromRawData(col, row, Size, Value); } void USBpix::GetClusterSeedPerTriggerHistoFromRawData(int Amount, int& Value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetClusterSeedPerTriggerHistoFromRawData(Amount, Value); else if (chip_addr == myChipAdd1) confReg0->GetClusterSeedPerTriggerHistoFromRawData(Amount, Value); } void USBpix::ClearClusterSizeHistoFromRawData(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearClusterSizeHistoFromRawData(); else if (chip_addr == myChipAdd1) confReg0->ClearClusterSizeHistoFromRawData(); } void USBpix::ClearClusterTOTHistoFromRawData(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearClusterTOTHistoFromRawData(); else if (chip_addr == myChipAdd1) confReg0->ClearClusterTOTHistoFromRawData(); } void USBpix::ClearClusterSeedTOTHistoFromRawData(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearClusterSeedTOTHistoFromRawData(); else if (chip_addr == myChipAdd1) confReg0->ClearClusterSeedTOTHistoFromRawData(); } void USBpix::ClearClusterSeedLV1HistoFromRawData(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearClusterSeedLV1HistoFromRawData(); else if (chip_addr == myChipAdd1) confReg0->ClearClusterSeedLV1HistoFromRawData(); } void USBpix::ClearClusterSeedHistoFromRawData(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearClusterSeedHistoFromRawData(); else if (chip_addr == myChipAdd1) confReg0->ClearClusterSeedHistoFromRawData(); } void USBpix::ClearClusterSeedPerTriggerHistoFromRawData(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->ClearClusterSeedPerTriggerHistoFromRawData(); else if (chip_addr == myChipAdd1) confReg0->ClearClusterSeedPerTriggerHistoFromRawData(); } bool USBpix::WriteFileFromRawData(std::string filename, int chip_addr, bool new_file, bool close_file, bool fillSourceScanHistograms, bool fillClusterHistograms, int max_cluster_col_distance, int max_cluster_row_distance, int max_cluster_depth, int timewalk_threshold_max) // new raw data format, human & machine readable file format { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->WriteFileFromRawData(filename, new_file, close_file, fillSourceScanHistograms, fillClusterHistograms, max_cluster_col_distance, max_cluster_row_distance, max_cluster_depth, timewalk_threshold_max); else if (chip_addr == myChipAdd1) return confReg0->WriteFileFromRawData(filename, new_file, close_file, fillSourceScanHistograms, fillClusterHistograms, max_cluster_col_distance, max_cluster_row_distance, max_cluster_depth, timewalk_threshold_max); else return false; } bool USBpix::FileSaveRB(const char *filename, int event_quant, bool attach_data, int chip_addr) // old raw data format { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->FileSaveRB(filename, event_quant, attach_data); else if (chip_addr == myChipAdd1) return confReg0->FileSaveRB(filename, event_quant, attach_data); else return false; } bool USBpix::CheckDataConsisty(const char * filename, bool attach_data, bool write_summary, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->CheckDataConsisty(filename, attach_data, write_summary); else if (chip_addr == myChipAdd1) return confReg0->CheckDataConsisty(filename, attach_data, write_summary); else return false; } bool USBpix::WriteToTHisto(const char *filename, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->WriteToTHisto(filename); else if (chip_addr == myChipAdd1) return confReg0->WriteToTHisto(filename); else return false; } bool USBpix::WriteConfHisto(const char *filename, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->WriteConfHisto(filename); else if (chip_addr == myChipAdd1) return confReg0->WriteConfHisto(filename); return false; } void USBpix::GetSourceScanStatus(bool &SRAMFull, bool &MeasurementRunning, int &SRAMFillLevel, int &CollectedEvents, int &TriggerRate, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->GetSourceScanStatus(SRAMFull, MeasurementRunning, SRAMFillLevel, CollectedEvents, TriggerRate); else if (chip_addr == myChipAdd1) confReg0->GetSourceScanStatus(SRAMFull, MeasurementRunning, SRAMFillLevel, CollectedEvents, TriggerRate); } void USBpix::BuildWords(int chip_addr) // in run mode: makes array of words out of character array { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->BuildWords(); else if (chip_addr == myChipAdd1) confReg0->BuildWords(); } bool USBpix::WriteSRAMWords(char* filename, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->WriteSRAMWords(filename); else if (chip_addr == myChipAdd1) return confReg0->WriteSRAMWords(filename); return false; } bool USBpix::WriteSRAMBitsFromWords(char *filename, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->WriteSRAMBitsFromWords(filename); else if (chip_addr == myChipAdd1) return confReg0->WriteSRAMBitsFromWords(filename); return false; } bool USBpix::WriteSRAMBytes(char* filename, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->WriteSRAMBytes(filename); else if (chip_addr == myChipAdd1) return confReg0->WriteSRAMBytes(filename); return false; } bool USBpix::WriteSRAMBitsFromBytes(char *filename, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->WriteSRAMBitsFromBytes(filename); else if (chip_addr == myChipAdd1) return confReg0->WriteSRAMBitsFromBytes(filename); return false; } void USBpix::GetSystemMode(bool &CalMode, bool &TOTMode) { confReg1->GetSystemMode(CalMode, TOTMode); // both systems MUST always be in the same mode... } void USBpix::SetMeasurementMode(int mode) // selects which events to count (LV1, DH, DR...) { confReg1->SetMeasurementMode(mode); // both systems MUST always be in the same mode... if (myChipAdd1 != 999) confReg0->SetMeasurementMode(mode); } void USBpix::StartMeasurement() { confReg1->StartMeasurement(); // MUST be the same for all Boards... if (myChipAdd1 != 999) confReg0->StartMeasurement(); // both systems MUST always be started at the same time... } void USBpix::StopMeasurement() { confReg1->StopMeasurement(); // MUST be the same for all Boards... if (myChipAdd1 != 999) confReg0->StopMeasurement(); // both systems MUST always be stopped at the same time... } void USBpix::PauseMeasurement() { confReg1->PauseMeasurement(); // MUST be the same for all Boards... if (myChipAdd1 != 999) confReg0->PauseMeasurement(); // both systems MUST always be stopped at the same time... } void USBpix::ResumeMeasurement() { confReg1->ResumeMeasurement(); // MUST be the same for all Boards... if (myChipAdd1 != 999) confReg0->ResumeMeasurement(); // both systems MUST always be stopped at the same time... } void USBpix::SetNumberOfEvents(int data) { confReg1->SetNumberOfEvents(data); // Counts only #events for chip 0, except Lv1 triggers. Just to be sure, real stop will be done in software. if (myChipAdd1 != 999) confReg0->SetNumberOfEvents(data); // both systems MUST always be started at the same time... } int USBpix::GetCountedEvents() { int events = confReg1->GetCountedEvents(); if (myChipAdd1 != 999) events += confReg0->GetCountedEvents(); return events; } void USBpix::GetScanStatus(bool & scanReady, bool & scanCancelled, bool & scanError, int & scanStep) { confReg1->GetScanStatus(scanReady, scanCancelled, scanError, scanStep); // Scan status only in board 0... } void USBpix::SetScanReady() { confReg1->SetScanReady(); // Scan status only in board 0... } void USBpix::SetScanCancelled() { confReg1->SetScanCancelled(); // Scan status only in board 0... } void USBpix::SetScanError() { confReg1->SetScanError(); // Scan status only in board 0... } void USBpix::ResetScanStatus() { confReg1->ResetScanStatus(); // Scan status only in board 0... } int USBpix::GetCurrentPhaseshift(int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! return confReg1->GetCurrentPhaseshift(); else if (chip_addr == myChipAdd1) return confReg0->GetCurrentPhaseshift(); return -1; } void USBpix::SetCurrentPhaseshift(int value, int chip_addr) { if (chip_addr == myChipAdd0) // needs to be called for both boards independently for sure!!! confReg1->SetCurrentPhaseshift(value); else if (chip_addr == myChipAdd1) confReg0->SetCurrentPhaseshift(value); } bool USBpix::CheckRX0State() { return confReg1->CheckRX0State(); // Status only in board 0... } bool USBpix::CheckRX1State() { return confReg1->CheckRX1State(); // Status only in board 0... } bool USBpix::CheckRX2State() { return confReg1->CheckRX2State(); // Status only in board 0... } bool USBpix::CheckExtTriggerState() { return confReg1->CheckExtTriggerState(); // Status only in board 0... } void USBpix::GetSyncScanResult(double* dataX, double* dataY, int size, int chip_addr) { if (chip_addr == myChipAdd0) confReg1->GetSyncScanResult(dataX, dataY, size); else if (chip_addr == myChipAdd1) confReg0->GetSyncScanResult(dataX, dataY, size); } void USBpix::GetSRAMWordsRB(unsigned int* data, int size, int chip_addr) { if (chip_addr == myChipAdd0) confReg1->GetSRAMWordsRB(data, size); else if (chip_addr == myChipAdd1) confReg0->GetSRAMWordsRB(data, size); }