/* * BusConfigurator.cpp * * Created on: Dec 15, 2017 * Author: Hovanes Egiyan */ #include "BusConfigurator.hh" using namespace std; const int VETROC::BusConfigurator::blockLevel = 1; double VETROC::BusConfigurator::pulseFrequency = 2048; //double VETROC::BusConfigurator::pulseFrequency = 4; double VETROC::BusConfigurator::dutyCycle = 0.5; unsigned VETROC::BusConfigurator::pulseWidth = 8000; unsigned VETROC::BusConfigurator::coincidenceWindow = 31; namespace VETROC { void BusConfigurator::setupBoards() { std::cout << "Setting up boards" << std::endl; unsigned smallestSlot = *min_element( slotsWithBoards.begin(), slotsWithBoards.end() ); firstBoardAddress = (smallestSlot << 19); /* 0 = software synch-reset, FP input 1, internal clock */ int iflag = 0x00; int nBoardsFound = vetrocInit( firstBoardAddress, addressIncrement, 1, iflag ); if ( nBoardsFound <= 0 ) { stringstream errMsg; errMsg << "BusConfigurator::setupBoards : no VETROC board found. Bye ! \n"; throw runtime_error( errMsg.str() ); } else if ( nBoardsFound != static_cast( slotsWithBoards.size() ) ) { stringstream errMsg; errMsg << "BusConfigurator::setupBoards : Number of VETROC boards found is " << dec << nBoardsFound << " but requested " << slotsWithBoards.size(); throw runtime_error( errMsg.str() ); } vetrocGSetProcMode( /*4000*/2000,/*4000*/2000 ); /* Maybe ? pick one of these 2 ? */ /* vetrocEnableMultiBlock(1); */ /* vetrocDisableMultiBlock(); */ /* Construct SlotMask Here you'd want to loop over slots if you had more than 1 slot, using vetrocSlot(index) to find slot numbers */ uint32_t slotMask = 0; for ( unsigned slotIndex = 0; slotIndex < slotsWithBoards.size(); slotIndex++ ) { slotMask |= (1 << slotsWithBoards[slotIndex]); cout << "Initializing VETROC in slot " << dec << slotsWithBoards[slotIndex] << " , mask is " << hex << showbase << slotMask << endl; vetrocSetBlockLevel( slotsWithBoards[slotIndex], blockLevel ); vetrocTriggerPulseWidth( slotsWithBoards[slotIndex], pulseWidth ); vetrocLinkReset( slotsWithBoards[slotIndex] ); vetrocClear( slotsWithBoards[slotIndex] ); // This command sets up the internal pulser frequency and duty factor. vetrocPulserSetup( slotsWithBoards[slotIndex], pulseFrequency, dutyCycle, 0xffffffff ); // This line sets the latching to happen on internal trigger. vetrocSetTrigSource( slotsWithBoards[slotIndex], VETROC_SD_MUX_PULSER ); // Set the coincidence window between X and Y planes vetrocSetCoincidenceWindow( slotsWithBoards[slotIndex], coincidenceWindow ); } cout << "BusConfigurator::setupBoards: Final slot Mask is " << hex << showbase << slotMask << endl; } } /* namespace VETROC */