$treeview $search $mathjax $extrastylesheet
otsdaq_components
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-components/DAQHardware/FSSRFirmwareBase.h" 00002 00003 #include "otsdaq-core/Macros/CoutMacros.h" 00004 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00005 00006 #include "otsdaq-components/DAQHardware/FSSRFirmwareDefinitions.h" 00007 #include "otsdaq-components/DetectorHardware/FSSRROCDefinitions.h" 00008 #include "otsdaq-core/BitManipulator/BitManipulator.h" 00009 00010 #include <arpa/inet.h> 00011 #include <netinet/in.h> 00012 #include <sys/socket.h> 00013 00014 #include <cstdlib> 00015 #include <iostream> 00016 00017 #include "otsdaq-components/DAQHardware/FrontEndFirmwareBase.h" 00018 #include "otsdaq-components/DAQHardware/OtsUDPFirmwareCore.h" 00019 #include "otsdaq-components/DAQHardware/PurdueFirmwareCore.h" 00020 00021 using namespace ots; 00022 00023 const std::string FSSRFirmwareBase::PURDUE_FIRMWARE_NAME = "PurdueFSSRFirmware"; 00024 const std::string FSSRFirmwareBase::OTS_FIRMWARE_NAME = "OtsUDPFSSRFirmware"; 00025 00026 //======================================================================================================================== 00027 FSSRFirmwareBase::FSSRFirmwareBase(const std::string& communicationFirmwareType, 00028 unsigned int communicationFirmwareVersion, 00029 unsigned int version) 00030 : stripCSRRegisterValue_(0), communicationFirmwareType_(communicationFirmwareType) 00031 { 00032 // choose: OtsUDPFirmwareCore or PurdueFirmwareCore 00033 if(communicationFirmwareType == 00034 FSSRFirmwareBase::PURDUE_FIRMWARE_NAME) // could also use string and: if(choice == 00035 // "purdue") etc. 00036 communicationFirmwareInstance_ = 00037 new PurdueFirmwareCore(communicationFirmwareVersion); 00038 else if(communicationFirmwareType == 00039 FSSRFirmwareBase::OTS_FIRMWARE_NAME) // AUG-17-2017 RAR dissociated because 00040 // function calls are entirely 00041 // independent from PURDUE firmware 00042 // calls 00043 // // 00044 communicationFirmwareInstance_ = 00045 new OtsUDPFirmwareCore(communicationFirmwareVersion); 00046 else 00047 { 00048 __SS__ << "Unknown communication firmware type choice: " 00049 << communicationFirmwareType << std::endl; 00050 __COUT_ERR__ << ss.str(); 00051 __SS_THROW__; 00052 } 00053 00054 // now we can call write/read etc with 00055 // communicationFirmwareInstance_->write, 00056 // communicationFirmwareInstance_->read, etc 00057 } 00058 00059 //======================================================================================================================== 00060 FSSRFirmwareBase::~FSSRFirmwareBase(void) 00061 { 00062 delete communicationFirmwareInstance_; 00063 communicationFirmwareInstance_ = NULL; 00064 } 00065 00066 //======================================================================================================================== 00067 void FSSRFirmwareBase::init(void) {} 00068 00069 //======================================================================================================================== 00070 std::string FSSRFirmwareBase::universalRead(char* address) 00071 { 00072 __COUT__ << "universalRead communicationFirmwareType_ " << communicationFirmwareType_ 00073 << std::endl; 00074 return communicationFirmwareInstance_->read(address); 00075 } 00076 00077 //======================================================================================================================== 00078 std::string FSSRFirmwareBase::universalWrite(char* address, char* data) 00079 { 00080 __COUT__ << "universalWrite communicationFirmwareType_ " << communicationFirmwareType_ 00081 << std::endl; 00082 return communicationFirmwareInstance_->write(address, data); 00083 } 00084 00085 //======================================================================================================================== 00086 uint32_t FSSRFirmwareBase::createRegisterFromValue(std::string& readBuffer, 00087 std::string& receivedValue) 00088 { 00089 return communicationFirmwareInstance_->createRegisterFromValue(readBuffer, 00090 receivedValue); 00091 } 00092 00093 //======================================================================================================================== 00094 std::string FSSRFirmwareBase::configureClocks(std::string source, double frequency) 00095 { 00096 // std::cout << __COUT_HDR_FL__ << "Writing Clock configuration!" << std::endl; 00097 00098 std::string buffer; 00099 // NoNeedNowwrite(buffer, ETHIO_DESTINATION_PORT, 0x0000b798); // Listen port for 00100 // ethio stuff 00101 00102 setPacketSizeStripCSR(6); 00103 setExternalBCOClockSourceStripCSR(source); //(source) 00104 communicationFirmwareInstance_->write( 00105 buffer, STRIP_CSR, stripCSRRegisterValue_); // Reset CSR - reset trigger 00106 // counter, external 27 MHz clock 00107 00108 resetDCM(buffer); 00109 // alignReadOut(buffer,0x3000);//0x3000 00110 00111 setFrequencyFromClockState(buffer, frequency); 00112 communicationFirmwareInstance_->write( 00113 buffer, STRIP_CSR, stripCSRRegisterValue_, false /*clearBuffer*/); 00114 00115 resetDCM(buffer); 00116 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue :" << std::hex << 00117 // stripCSRRegisterValue_ << std::dec << std::endl; 00118 00119 return buffer; 00120 } 00121 00122 //======================================================================================================================== 00123 void FSSRFirmwareBase::resetDCM(std::string& buffer) 00124 { 00125 // 31 DCM_RESET 00126 resetDCMStripCSR(true); // Set bit 31 00127 communicationFirmwareInstance_->write(buffer, 00128 STRIP_CSR, 00129 stripCSRRegisterValue_, 00130 false /*clearBuffer*/); // Set reset to DCM 00131 00132 resetDCMStripCSR(false); // unset bit 31 00133 communicationFirmwareInstance_->write(buffer, 00134 STRIP_CSR, 00135 stripCSRRegisterValue_, 00136 false /*clearBuffer*/); // Clear reset to DCM 00137 00138 // 2018-10-24 Lorenzo in OtsUDPFirmware is doing nothing so I am commenting it out 00139 // communicationFirmwareInstance_->waitClear(buffer, STRIP_CSR, 00140 // waitDCMResetStripCSR(),false/*clearBuffer*/); // Wait for DCM to lock 00141 } 00142 00143 //======================================================================================================================== 00144 void FSSRFirmwareBase::alignReadOut(std::string& buffer, 00145 unsigned int sensor, 00146 unsigned int chip) 00147 { 00148 //(2:0) sensor 00149 //(7:3) chip 00150 // 28 up/down (-> here we always move up) 00151 // 31 must be set 1 00152 // It shifts the readout every time is called by few picosends (likely) if bit 31 is 00153 // set 00154 communicationFirmwareInstance_->write( 00155 buffer, 00156 STRIP_TRIM_CSR, 00157 (0x9 << 28) + ((chip & 0xf) << 3) + 00158 (sensor & 0x7)); // MCLKB edge for channel 5 // was 0x00002000 00159 } 00160 //======================================================================================================================== 00161 std::string FSSRFirmwareBase::resetDetector(int channel) 00162 { 00163 // std::cout << __COUT_HDR_FL__ << "Resetting detector!" << std::endl; 00164 // Byte 4------------------- 00165 // 31 CHIP_RESET 00166 // 30 CLEAR_FIFO 00167 // 29 CLEAR_ERRORS 00168 // 28 LINK_RESET 00170 // 27 DAC_RESET 00171 // 26 unused 00172 // 25 unused 00173 // 24 unused 00174 // Byte 3------------------- 00175 // 23-16 unused 00176 // Byte 2------------------- 00177 // 15-8 unused 00178 // Byte 1------------------- 00179 // 7-0 CHANNEL_MASK ->Reset signals are sent to all channels with bits set in 00180 // CHANNEL_MASK field 00181 00182 std::string buffer; 00183 if(channel == -1) // reset all channels 00184 { 00185 // write(buffer,STRIP_RESET,0xd000003f); // Issue reset 00186 communicationFirmwareInstance_->write( 00187 buffer, 00188 STRIP_RESET, 00189 0xf000003f); // Issue reset // was 0xf000003f 00190 // 2018-10-24 Lorenzo in OtsUDPFirmware is doing nothing so I am 00191 // commenting it out 00192 // communicationFirmwareInstance_->waitClear(buffer, 00193 // STRIP_RESET, 0xf0000000); // Wait for reset to complete // 00194 // was 0xf0000000 00195 } 00196 else 00197 { 00198 communicationFirmwareInstance_->write( 00199 buffer, 00200 STRIP_RESET, 00201 0xf000003f); // Issue reset 00202 // 2018-10-24 Lorenzo in OtsUDPFirmware is doing nothing so I am 00203 // commenting it out 00204 // communicationFirmwareInstance_->waitClear(buffer, 00205 // STRIP_RESET, 0xf0000000); // Wait for reset to complete 00206 } 00207 00208 return buffer; 00209 } 00210 00211 //======================================================================================================================== 00212 std::string FSSRFirmwareBase::enableTrigger(void) 00213 { 00214 std::string buffer; 00215 // std::cout << __COUT_HDR_FL__ << "Enabling Trigger!!!" << std::endl; 00216 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue in :" << std::hex << 00217 // stripCSRRegisterValue_ << std::dec << std::endl; 00218 00219 // setHaltStripCSR(1);//WARNING THIS IS CLEARED BY THE MASTER BUT IF THERE IS NO 00220 // MASTER NOTHING WORKS UNLESS THE BIT IS UNSET 00221 sendTriggerDataStripCSR(false); // STRIP_CSR -> Bit 24 -> SEND_TRIG 00222 communicationFirmwareInstance_->write( 00223 buffer, STRIP_CSR, stripCSRRegisterValue_, false /*clearBuffer*/); 00224 resetTriggerCounterStripCSR(buffer); 00225 sendTriggerDataStripCSR(true); // STRIP_CSR -> Bit 24 -> SEND_TRIG 00226 sendTriggerNumberStripCSR(true); // STRIP_CSR -> Bit 25 -> SEND_TRIGNUM 00227 sendBCOStripCSR(true); // STRIP_CSR -> Bit 26 -> SEND_BCO 00228 communicationFirmwareInstance_->write( 00229 buffer, STRIP_CSR, stripCSRRegisterValue_, false /*clearBuffer*/); 00230 00231 stripTriggerCSRRegisterValue_ = 0; 00232 BCOOffset(4); 00233 communicationFirmwareInstance_->write( 00234 buffer, 00235 STRIP_TRIG_CSR, 00236 stripTriggerCSRRegisterValue_, 00237 false /*clearBuffer*/); // BCO offset // was 0x00000004 00238 00239 // write(buffer,STRIP_TRIG_INPUT_0,0x1f060040); // FSSR GOTHIT trigger input - 00240 // timed in for the 27 MHz external clock 00241 // write(buffer,STRIP_TRIG_INPUT_3,0x3f874040); // Unbiased trigger input + 00242 // external trigger 00243 00244 configureStripTriggerUnbiased(buffer); 00245 00246 configureTriggerInputs(buffer); 00247 00248 // FIXME for IP .36 the number to set is 0x20401000 00249 00250 // if (1 || communicationFirmwareInstance_->getVersion() == 1) 00251 communicationFirmwareInstance_->write( 00252 buffer, STRIP_TRIG_INPUT_3, 0x20401000, false /*clearBuffer*/); 00253 // else if (communicationFirmwareInstance_->getVersion() == 2) 00254 // communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_3, 0x20301000, 00255 // false/*clearBuffer*/); else 00256 //{ 00257 // __SS__ << "what version is this?" << communicationFirmwareInstance_->getVersion() 00258 //<< std::endl; 00259 // __COUT__ << ss.str(); 00260 // __SS_THROW__; 00261 //} 00262 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue out:" << std::hex << 00263 // stripCSRRegisterValue_ << std::dec << std::endl; std::cout << __COUT_HDR_FL__ << 00264 // "Done enabling Trigger!!!" << std::endl; 00265 00266 return buffer; 00267 } 00268 // 00270 // void FSSRFirmwareBase::setDataDestination(std::string& buffer, const std::string& ip, 00271 // const uint16_t port) 00273 //{ 00274 // std::cout << __COUT_HDR_FL__ << "Set data destination!" << std::endl; 00275 // 00276 // struct sockaddr_in socketAddress; 00277 // inet_pton(AF_INET, ip.c_str(), &(socketAddress.sin_addr)); 00278 // std::cout << __COUT_HDR_FL__ << "ADDRESS: " << std::hex << 00279 // ntohl(socketAddress.sin_addr.s_addr) << std::dec << std::endl; 00280 // communicationFirmwareInstance_->write(buffer, DATA_DESTINATION_IP, 00281 // ntohl(socketAddress.sin_addr.s_addr)); // Set data destination IP 192.168.133.1 00282 // std::cout << __COUT_HDR_FL__ << "PORT: " << std::hex << port << std::dec << 00283 // std::endl; communicationFirmwareInstance_->write(buffer, 00284 // DATA_SOURCE_DESTINATION_PORT, port); // Set data destination port std::cout << 00285 // __COUT_HDR_FL__ << "THIS IS THE BUFFER: " << buffer << std::endl; 00286 // 00287 // for(uint32_t i=0; i<buffer.size(); i++) 00288 // printf("%2.2X-",(uint8_t)buffer[i]); 00289 // std::cout << std::dec << std::endl; 00290 // 00291 //} 00292 00293 //======================================================================================================================== 00294 std::string FSSRFirmwareBase::resetBCO(void) 00295 { 00296 std::cout << __COUT_HDR_PL__ << "Reset BCO!!!" << std::endl; 00297 std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue in :" << std::hex 00298 << stripCSRRegisterValue_ << std::dec << std::endl; 00299 std::string buffer; 00300 00301 // resetTriggerCounterStripCSR(buffer); 00302 // write(buffer, STRIP_CSR, stripCSRRegisterValue_);//the write is done in the reset 00303 // std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue :" << std::hex << 00304 // stripCSRRegisterValue_ << std::dec << std::endl; 00305 00306 // msg->Write(STRIP_SC_CSR,0x90000b95|(chmask<<16)); 00307 00308 // Byte 4------------------- 00309 // 31 SC_BUSY 00310 // 30 RAW 00311 // 29 BCO_SYNC 00312 // 28 BCO_ZERO 00314 // 27 unused 00315 // 26-24 LENGTH 00316 // Byte 3------------------- 00317 // 23-16 CHANNEL_MASK 00318 // Byte 2------------------- 00319 // 15-13 READ_SELECT 00320 // 12-10 INSTRUCTION 00321 // 9-5 ADDRESS 00322 // Byte 1------------------- 00323 // 9-5 ADDRESS 00324 // 4-0 CHIP_ID 00325 // 0x 9 0 3 f 0 b 9 5 00326 // 1001-0000-0011-1111-0000-1011-1001-0101 00327 // CHIP_ID 1-0101 -> 21 wild chip id ->all chips will get the command 00328 // ADDRESS 11-100 -> 28 00329 // INSTRUCTION 010 -> 2 00330 // READ_SELECT 000 -> 0 00331 // CHANNEL_MASK 0011-1111 -> all Channels 00332 // LENGTH 000 -> 0 00333 // unused 00334 // BCO_SYNC 1 00335 // BCO_ZERO 0 00336 // RAW 0 00337 // SC_BUSY 1 00338 // When BCO SYNC is set the transaction is delayed until the internal BCO counter has 00339 // a value of 240. This allow the AqBCO command to be synchronized 00340 communicationFirmwareInstance_->write( 00341 buffer, STRIP_SC_CSR, 0x903f0b95, false /*clearBuffer*/); // This is the 00342 // <SCR,set> command 00343 // with the bit set to 00344 // sync SHIFT with 00345 // BCO=0. 00346 00347 // enableBCOStripCSR(true); 00348 // communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_); 00349 00350 std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue out:" << std::hex 00351 << stripCSRRegisterValue_ << std::dec << std::endl; 00352 std::cout << __COUT_HDR_FL__ << "Done reset BCO!!!" << std::endl; 00353 00354 return buffer; 00355 } 00356 00357 //======================================================================================================================== 00358 std::string FSSRFirmwareBase::armBCOReset(void) 00359 { 00360 std::string buffer; 00361 armBCOResetCSR(); 00362 communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_); 00363 return buffer; 00364 } 00365 00366 //======================================================================================================================== 00367 std::string FSSRFirmwareBase::startStream(bool channel0, 00368 bool channel1, 00369 bool channel2, 00370 bool channel3, 00371 bool channel4, 00372 bool channel5) 00373 { 00374 // std::cout << __COUT_HDR_FL__ << "Start Stream!" << std::endl; 00375 // std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue in:" << std::hex << 00376 // stripCSRRegisterValue_ << std::dec << std::endl; 00377 std::string buffer; 00378 00379 // std::cout << __COUT_HDR_PL__ << " channel0 " << channel0 << " channel1 " << 00380 // channel1 << " channel2 " << channel2 << " channel3 " << channel3 << " channel4 " << 00381 // channel4 << " channel5 " << channel5 << std::endl; 00382 00383 enableChannelsStripCSR(channel0, channel1, channel2, channel3, channel4, channel5); 00384 // if (version_ == 1) 00385 // enableChannelsStripCSR(true, true, true, true, false, false); 00386 // else if (version_ == 2) 00387 // enableChannelsStripCSR(true, true, true, true, true, true); 00388 00389 enableStreamStripCSR( 00390 true); // Turn on streaming hits along with BCO data // was 0x0f000f30 00391 communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_); 00392 00393 // std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue out:" << std::hex << 00394 // stripCSRRegisterValue_ << std::dec << std::endl; std::cout << __COUT_HDR_PL__ 00395 // << "Done start Stream!" << std::endl; 00396 00397 return buffer; 00398 } 00399 00400 //======================================================================================================================== 00401 std::string FSSRFirmwareBase::stopStream(void) 00402 { 00403 std::string buffer; 00404 enableStreamStripCSR(false); 00405 enableChannelsStripCSR(false, false, false, false, false, false); 00406 communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_); 00407 return buffer; 00408 } 00409 00410 //======================================================================================================================== 00411 void FSSRFirmwareBase::makeDACSequence(FirmwareSequence<uint64_t>& sequence, 00412 unsigned int channel, 00413 const ROCStream& rocStream) 00414 { 00415 const ROCDACs& rocDACs = rocStream.getROCDACs(); 00416 for(DACList::const_iterator it = rocDACs.getDACList().begin(); 00417 it != rocDACs.getDACList().end(); 00418 it++) 00419 { 00420 // if(it->first != "SendData" && it->first != "RejectHits") continue; 00421 uint64_t data = FSSRROCDefinitions::makeDACWriteCommand( 00422 rocStream.getFEWROCAddress(), it->first, it->second.second); 00423 sequence.pushBack(ChannelFIFOAddress[channel], data); 00424 sequence.pushBack(ChannelFIFOAddress[channel], 00425 BitManipulator::insertBits(data, (uint64_t)0x48, 56, 8)); 00426 // set WRITE 00427 sequence.pushBack(ChannelFIFOAddress[channel], 00428 BitManipulator::insertBits(data, (uint64_t)1, 60, 1)); 00429 // clr WRITE 00430 sequence.pushBack(ChannelFIFOAddress[channel], 00431 BitManipulator::insertBits(data, (uint64_t)0, 60, 1)); 00432 // clr TALK 00433 sequence.pushBack(ChannelFIFOAddress[channel], 00434 BitManipulator::insertBits(data, (uint64_t)0, 62, 1)); 00435 sequence.pushBack(ChannelFIFOAddress[channel], 00436 BitManipulator::insertBits(data, (uint64_t)0x40, 56, 8)); 00437 // break; 00438 } 00439 } 00440 00441 //======================================================================================================================== 00442 void FSSRFirmwareBase::makeDACSequence(FirmwareSequence<uint32_t>& sequence, 00443 unsigned int channel, 00444 const ROCStream& rocStream) 00445 { 00446 const ROCDACs& rocDACs = rocStream.getROCDACs(); 00447 for(DACList::const_iterator it = rocDACs.getDACList().begin(); 00448 it != rocDACs.getDACList().end(); 00449 it++) 00450 { 00451 /*RYAN 00452 //if(it->first != "SendData" && it->first != "RejectHits") continue; 00453 uint64_t data = 00454 FSSRROCDefinitions::makeDACWriteCommand(rocStream.getFEWROCAddress(), it->first, 00455 it->second.second); sequence.pushBack(ChannelFIFOAddress[channel], data); 00456 sequence.pushBack(ChannelFIFOAddress[channel], 00457 BitManipulator::insertBits(data,(uint32_t)0x48,56,8)); 00458 //set WRITE 00459 sequence.pushBack(ChannelFIFOAddress[channel], 00460 BitManipulator::insertBits(data,(uint32_t)1,60,1)); 00461 //clr WRITE 00462 sequence.pushBack(ChannelFIFOAddress[channel], 00463 BitManipulator::insertBits(data,(uint32_t)0,60,1)); 00464 //clr TALK 00465 sequence.pushBack(ChannelFIFOAddress[channel], 00466 BitManipulator::insertBits(data,(uint32_t)0,62,1)); 00467 sequence.pushBack(ChannelFIFOAddress[channel], 00468 BitManipulator::insertBits(data,(uint32_t)0x40,56,8)); 00469 */ 00470 00471 // if(it->first != "SendData" && it->first != "RejectHits") continue; 00472 uint32_t data = FSSRROCDefinitions::makeDACWriteHeader( 00473 rocStream.getFEWROCAddress(), it->first); 00474 // Insert channel 00475 BitManipulator::insertBits(data, 1, 16 + channel, 1); 00476 sequence.pushBack(ChannelFIFOAddress[channel], it->second.second); 00477 std::cout << __COUT_HDR_FL__ << "Register: " << it->first 00478 << " value: " << it->second.second << std::hex << " -> Data: " << data 00479 << std::dec << std::endl; 00480 sequence.pushBack(STRIP_SC_CSR, data); 00481 } 00482 } 00483 00484 //======================================================================================================================== 00485 void FSSRFirmwareBase::makeDACBuffer(std::string& buffer, 00486 unsigned int channel, 00487 const ROCStream& rocStream) 00488 { 00489 std::cout << __COUT_HDR_FL__ << "Channel: " << channel << std::endl; 00490 std::cout << __COUT_HDR_FL__ << "BufferINsize: " << buffer.size() << std::endl; 00491 const ROCDACs& rocDACs = rocStream.getROCDACs(); 00492 // for (DACList::const_iterator it = rocDACs.getDACList().begin(); it != 00493 // rocDACs.getDACList().end(); it++) 00494 // { 00495 // std::string bufferElement; 00496 // communicationFirmwareInstance_->waitClear(bufferElement, STRIP_SC_CSR, 00497 // 0x80000000); uint32_t registerHeader = 0; 00498 // //FIXME This must go in the FSSRROCDefinitions stuff 00499 // //if (it->first != "RejectHits" && it->first != "SendData") 00500 // if (it->first == "VTp0") 00501 // { 00502 // //communicationFirmwareInstance_->write(bufferElement, 00503 // ChannelFIFOAddress[channel], it->second.second); registerHeader = 00504 // FSSRROCDefinitions::makeDACReadHeader(rocStream.getFEWROCAddress(), it->first); 00505 // //Insert channel 00506 // BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1); 00526 // 00527 // std::cout << __COUT_HDR_FL__ << "Register: " << it->first << " value: " << 00528 // it->second.second << std::hex << " -> Data: " << registerHeader << std::dec << 00529 // std::endl; communicationFirmwareInstance_->write(bufferElement, STRIP_SC_CSR, 00530 // registerHeader); communicationFirmwareInstance_->waitClear(bufferElement, 00531 // STRIP_SC_CSR, 0x80000000); 00532 // 00533 // //buffer.push_back(bufferElement); 00534 // buffer += bufferElement; 00535 // } 00536 // //break; 00537 // } 00538 for(DACList::const_iterator it = rocDACs.getDACList().begin(); 00539 it != rocDACs.getDACList().end(); 00540 it++) 00541 { 00542 std::string bufferElement; 00543 communicationFirmwareInstance_->waitClear( 00544 bufferElement, STRIP_SC_CSR, 0x80000000, false); 00545 uint32_t registerHeader = 0; 00546 // FIXME This must go in the FSSRROCDefinitions stuff 00547 if(it->first != "RejectHits" && it->first != "SendData") 00548 { 00549 communicationFirmwareInstance_->write( 00550 bufferElement, ChannelFIFOAddress[channel], it->second.second, false); 00551 registerHeader = FSSRROCDefinitions::makeDACWriteHeader( 00552 rocStream.getFEWROCAddress(), it->first); 00553 // Insert channel 00554 BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1); 00555 } 00556 else 00557 { 00558 if(it->second.second == 1 || it->second.second == 2) 00559 { 00560 registerHeader = FSSRROCDefinitions::makeDACSetHeader( 00561 rocStream.getFEWROCAddress(), it->first); 00562 // Insert channel 00563 BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1); 00564 } 00565 else if(it->second.second == 0 || it->second.second == 5) 00566 { 00567 registerHeader = FSSRROCDefinitions::makeDACResetHeader( 00568 rocStream.getFEWROCAddress(), it->first); 00569 // Insert channel 00570 BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1); 00571 } 00572 else 00573 std::cout << __COUT_HDR_FL__ << "Register value for : " << it->first 00574 << " doesn't have a value I expect -> value = " 00575 << it->second.second << std::endl; 00576 } 00577 00578 // std::cout << __COUT_HDR_FL__ << "Register: " << it->first << " value: " << 00579 // it->second.second << std::hex << " -> Data: " << registerHeader << std::dec << 00580 // std::endl; 00581 communicationFirmwareInstance_->write( 00582 bufferElement, STRIP_SC_CSR, registerHeader, false); 00583 communicationFirmwareInstance_->waitClear( 00584 bufferElement, STRIP_SC_CSR, 0x80000000, false); 00585 00586 // buffer.push_back(bufferElement); 00587 buffer += bufferElement; 00588 // break; 00589 } 00590 std::cout << __COUT_HDR_FL__ << "BufferOUTsize: " << buffer.size() << std::endl; 00591 } 00592 00593 //======================================================================================================================== 00594 void FSSRFirmwareBase::makeDACBuffer(std::vector<std::string>& buffer, 00595 unsigned int channel, 00596 const ROCStream& rocStream) 00597 { 00598 // std::cout << __COUT_HDR_FL__ << "\tMaking DAC Buffer" << std::endl; 00599 00600 int limitCount = 0; 00601 unsigned int singleVectorCount = 0; 00602 00603 std::string alternateBuffer; 00604 00605 // std::cout << __COUT_HDR_FL__ << "Channel: " << channel << std::endl; 00606 const ROCDACs& rocDACs = rocStream.getROCDACs(); 00607 // std::cout << __COUT_HDR_FL__ << "Number of DACs: " << rocDACs.getDACList().size() 00608 // << std::endl; 00609 std::string bufferElement; 00610 // FIXME My 00611 // for (const auto it: rocDACs.getDACList()) 00612 for(const std::pair<std::string, std::pair<unsigned int, unsigned int> >& it : 00613 rocDACs.getDACList()) 00614 // for (std::map<std::string, std::pair<unsigned int, unsigned int> >::const_iterator 00615 // it = rocDACs.getDACList().begin(); it != rocDACs.getDACList().end(); it++) 00616 { 00617 // std::cout << __COUT_HDR_FL__ << "Register?" << std::endl; 00618 // if (it.first != "ActiveLines") continue; 00619 // std::cout << __COUT_HDR_FL__ << "Register-1: " << it->first << " val: " << 00620 // it->second.first << " = " << it->second.second << std::endl; 00621 communicationFirmwareInstance_->waitClear( 00622 bufferElement, STRIP_SC_CSR, 0x80000000, false); 00623 uint32_t registerHeader = 0; 00624 // FIXME This must go in the FSSRROCDefinitions stuff 00625 // std::cout << __COUT_HDR_FL__ << "Register0: " << it.first << std::endl; 00626 if(it.first != "RejectHits" && it.first != "SendData") 00627 { 00628 // std::cout << __COUT_HDR_FL__ << "Register1: " << it.first << "Channel: " << 00629 // channel << " fifo address: " << ChannelFIFOAddress[channel] << std::endl; 00630 communicationFirmwareInstance_->write( 00631 bufferElement, ChannelFIFOAddress[channel], it.second.second, false); 00632 registerHeader = FSSRROCDefinitions::makeDACWriteHeader( 00633 rocStream.getFEWROCAddress(), it.first); 00634 // Insert channel 00635 BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1); 00636 } 00637 else 00638 { 00639 // std::cout << __COUT_HDR_FL__ << "Register2: " << it.first << std::endl; 00640 if(it.second.second == 1 || it.second.second == 2) 00641 { 00642 registerHeader = FSSRROCDefinitions::makeDACSetHeader( 00643 rocStream.getFEWROCAddress(), it.first); 00644 // Insert channel 00645 BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1); 00646 } 00647 else if(it.second.second == 0 || it.second.second == 5) 00648 { 00649 registerHeader = FSSRROCDefinitions::makeDACResetHeader( 00650 rocStream.getFEWROCAddress(), it.first); 00651 // Insert channel 00652 BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1); 00653 } 00654 else 00655 std::cout << __COUT_HDR_FL__ << "Register value for : " << it.first 00656 << " doesn't have a value I expect -> value = " 00657 << it.second.second << std::endl; 00658 } 00659 // std::cout << __COUT_HDR_FL__ << "Register: " << it.first << " value: " << 00660 // it.second.second << std::hex << " -> Data: " << registerHeader << std::dec << 00661 // std::endl; 00662 communicationFirmwareInstance_->write( 00663 bufferElement, STRIP_SC_CSR, registerHeader, false); 00664 communicationFirmwareInstance_->waitClear( 00665 bufferElement, STRIP_SC_CSR, 0x80000000, false); 00666 00667 // std::cout << __COUT_HDR_FL__ << "Register3: " << it.first << std::endl; 00668 // alternateBuffer += bufferElement; 00669 limitCount++; 00670 singleVectorCount++; 00671 00672 if(limitCount == STIB_DAC_WRITE_MAX) 00673 { 00674 std::cout << __COUT_HDR_FL__ << "\tBuffer length:" << bufferElement.size() 00675 << std::endl; 00676 buffer.push_back(bufferElement); 00677 limitCount = 0; 00678 bufferElement.clear(); 00679 } 00680 else if(singleVectorCount == 00681 rocDACs.getDACList().size()) // case for incomplete packet 00682 { 00683 buffer.push_back(bufferElement); 00684 } 00685 00686 // buffer.push_back(bufferElement); 00687 // break; 00688 } 00689 // std::cout << __COUT_HDR_FL__ << "\tDone making DAC Buffer" << std::endl; 00690 } 00691 00692 //======================================================================================================================== 00693 void FSSRFirmwareBase::makeMaskBuffer(std::string& buffer, 00694 unsigned int channel, 00695 const ROCStream& rocStream) 00696 { 00697 // std::cout << __COUT_HDR_FL__ << "Making mask! " << std::endl; 00698 makeMaskBuffer(buffer, channel, rocStream, "Kill"); 00699 // makeMaskSequence(buffer, channel, rocStream, "Inject"); 00700 } 00701 00702 //======================================================================================================================== 00703 void FSSRFirmwareBase::makeMaskBuffer(std::string& buffer, 00704 unsigned int channel, 00705 const ROCStream& rocStream, 00706 const std::string& registerName) 00707 { 00708 int chipId = rocStream.getFEWROCAddress(); 00709 const std::string& mask = rocStream.getROCMask(); 00710 // std::cout << __COUT_HDR_FL__ << "\tMaking mask! Length = " << mask.length() << 00711 // std::endl; std::cout << __COUT_HDR_FL__ << "\tMask length: " << mask.length() << 00712 // std::endl; std::cout << __COUT_HDR_FL__ << "\tMask: " << mask << std::endl; 00713 00714 unsigned int data[4] = {0, 0, 0, 0}; 00715 00716 char val; 00717 // int j = 0; 00718 for(unsigned int d = 0; d < 4; d++) 00719 { // d goes from 0 to 4. 4 bytes 00720 // std::cout << __COUT_HDR_FL__ << "---------------------" << d << 00721 // "-------------------" << std::endl; 00722 for(unsigned int m = 0; m < 8 * 4; m++) 00723 { // m goes from 0 to 31, since each byte has 8 bits, there are 32 bits 00724 val = mask[(8 * 4 * d) + m]; // assigns to val the value of the corresponding 00725 // bit. 0-31, 32-63, 64-95, 96-127. it goes 00726 // through each of the 128 bits 00727 // std::cout << __COUT_HDR_FL__ << "---------------------" << j++ << 00728 // std::endl; std::cout << __COUT_HDR_FL__ << "data[" << d << "] before: " << 00729 // std::hex << data[d] << std::dec << std::endl; 00730 data[d] |= (unsigned int)atoi(&val) << (8 * 4 - 1 - m); 00731 // std::cout << __COUT_HDR_FL__ << "(unsigned int) atoi(&val): " << (unsigned 00732 // int) atoi(&val) << std::endl; std::cout << __COUT_HDR_FL__ << "data[" << d 00733 // << "] after: " << std::hex << data[d] << std::dec << std::endl; std::cout 00734 // << 00735 // __COUT_HDR_FL__ << std::hex << "D: " << data[d] << " Val: " << (unsigned 00736 // int)atoi(&val) << " index: " << std::dec << (8*4-1-m) << " bit: " << 00737 // mask[(8*4*d)+m] << std::dec << std::endl; 00738 } 00739 // 00740 } 00741 00742 int i; 00743 unsigned int w; 00744 unsigned char len = 4; 00745 unsigned char addr = 17; // Kill 00746 unsigned char bitMask = 1 << channel; 00747 unsigned char inst = WRITE; 00748 00749 communicationFirmwareInstance_->waitClear(buffer, STRIP_SC_CSR, 0x80000000, false); 00750 00751 for(i = 0; i < 4; i++) 00752 // write(buffer, STRIP_SCI + 4 * i, data[i]); 00753 communicationFirmwareInstance_->write( 00754 buffer, STRIP_SCI + 4 * (4 - i - 1), data[i], false); 00755 00756 w = 0x80000000 | (len << 24) | (bitMask << 16) | (inst << 10) | (addr << 5) | chipId; 00757 00758 communicationFirmwareInstance_->write(buffer, STRIP_SC_CSR, w, false); 00759 00760 communicationFirmwareInstance_->waitClear(buffer, STRIP_SC_CSR, 0x80000000, false); 00761 } 00762 00763 //======================================================================================================================== 00764 void FSSRFirmwareBase::makeMaskSequence(FirmwareSequence<uint64_t>& sequence, 00765 unsigned int channel, 00766 const ROCStream& rocStream) 00767 { 00768 std::cout << __COUT_HDR_FL__ << "Making mask! " << std::endl; 00769 makeMaskSequence(sequence, channel, rocStream, "Kill"); 00770 // makeMaskSequence(sequence, channel, rocStream, "Inject"); 00771 } 00772 00773 //======================================================================================================================== 00774 void FSSRFirmwareBase::makeMaskSequence(FirmwareSequence<uint32_t>& sequence, 00775 unsigned int channel, 00776 const ROCStream& rocStream) 00777 { 00778 std::cout << __COUT_HDR_FL__ << "Making mask! " << std::endl; 00779 makeMaskSequence(sequence, channel, rocStream, "Kill"); 00780 // makeMaskSequence(channel,rocStream,sequence,"Inject"); 00781 } 00782 00783 //======================================================================================================================== 00784 void FSSRFirmwareBase::makeMaskSequence(FirmwareSequence<uint64_t>& sequence, 00785 unsigned int channel, 00786 const ROCStream& rocStream, 00787 const std::string& registerName) 00788 { 00789 int chipId = rocStream.getFEWROCAddress(); // 9, 14 or 21 bcast 00790 std::string mask = rocStream.getROCMask(); 00791 std::cout << __COUT_HDR_FL__ << "Mask length: " << mask.length() << std::endl; 00792 00793 uint64_t uInt64Data = 0; 00794 std::string stringData = ""; 00795 00796 // have to manually set every bit for mask writes. 00797 // reset fifo 00798 // download every bit (shift_in and shift_ctrl) to fifo (setup muxes and control 00799 // lines) configure muxes for readout commence readout 00800 00801 // FIFO Controls - byte 5 (7:0) 00802 // 7 - FIFO Clock 00803 // 6 - Shift Ctrl bit 00804 // MASK_CELL_H - Shift In bit 00805 // MUX Controls - byte 0 (7:0) 00806 // 7 - Read En/Output MUX sel (1 for masks) 00807 // 1 - Write En for mux 00808 // 0 - Reset Fifo 00809 00810 // reset fifo 00811 BitManipulator::insertBits(uInt64Data, 0x1, 56, 8); 00812 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00813 00814 // configure fifo for write 00815 BitManipulator::insertBits(uInt64Data, 0x2, 56, 8); 00816 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00817 00818 // Download every bit (shift_in and shift_control) to fifo (setup muxes and control 00819 // lines) Bit 7 of data is FIFO clock, bit 6 is shift_control, bit 5 is shift_in 00820 // start bits (ctrl 0, data 0 => ctrl 1, data 0) 00821 00822 BitManipulator::insertBits(uInt64Data, 0x40, 16, 8); //(0<<7) | (1<<6) | (0<<5) 00823 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00824 BitManipulator::insertBits( 00825 uInt64Data, 00826 0xc0, 00827 16, 00828 8); //(1<<7) | (1<<6) | (0<<5) -> clock the data in the fifo 00829 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00830 00831 stringData = FSSRROCDefinitions::makeMaskWriteCommand(chipId, registerName, mask); 00832 00833 uint8_t data; 00834 for(unsigned int s = 0; s < stringData.length(); s++) 00835 for(int b = 8 - 1; b >= 0 && (s * 8 + 8 - b < 13 + 128); b--) 00836 { 00837 // std::cout << __COUT_HDR_FL__ << "S: " << s << " val: " << 00838 // stringData.data()[s] << " b: " << b << " bit: " << 00839 // ((stringData.data()[s]>>b)&1) << std::endl; 00840 data = 0x40 | (((stringData.data()[s] >> b) & 1) << 5); 00841 BitManipulator::insertBits(uInt64Data, (uint64_t)data, 16, 8); 00842 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00843 data |= 0x80; 00844 BitManipulator::insertBits(uInt64Data, (uint64_t)data, 16, 8); 00845 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00846 } 00847 00848 // reset Shift Control 00849 BitManipulator::insertBits(uInt64Data, 0x0, 16, 8); 00850 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00851 BitManipulator::insertBits(uInt64Data, 0x80, 16, 8); 00852 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00853 00854 // configure muxes for readout 00855 BitManipulator::insertBits(uInt64Data, 0x0, 56, 8); 00856 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00857 00858 // commence readout 00859 BitManipulator::insertBits(uInt64Data, 0x80, 56, 8); 00860 sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data); 00861 } 00862 00863 //======================================================================================================================== 00864 void FSSRFirmwareBase::makeMaskSequence(FirmwareSequence<uint32_t>& sequence, 00865 unsigned int channel, 00866 const ROCStream& rocStream, 00867 const std::string& registerName) 00868 { 00869 } 00870 00871 //======================================================================================================================== 00872 std::string FSSRFirmwareBase::readCSRRegister() 00873 { 00874 std::string buffer; 00875 // std::cout << __COUT_HDR_FL__ << "FSSR readCSRRegister" << std::endl; 00876 communicationFirmwareInstance_->read(buffer, STRIP_CSR); 00877 return buffer; 00878 } 00879 00880 //======================================================================================================================== 00881 std::string FSSRFirmwareBase::readSCCSRRegister() 00882 { 00883 std::string buffer; 00884 std::cout << __COUT_HDR_FL__ << "FSSR readCSRRegister" << std::endl; 00885 communicationFirmwareInstance_->read(buffer, STRIP_SC_CSR); 00886 return buffer; 00887 } 00888 00889 //======================================================================================================================== 00890 void FSSRFirmwareBase::setFrequencyFromClockState(std::string& buffer, double frequency) 00891 { 00892 // std::cout << __COUT_HDR_FL__ << "Setting up clock frequency!!!" << std::endl; 00893 00894 int quotient; 00895 int numerator; 00896 int denominator; 00897 double realClockFrequency; 00898 00899 if(BitManipulator::readBits(stripCSRRegisterValue_, 17, 1) == 00900 1) // if fastBCO is enabled 00901 quotient = 4; 00902 else // normal cases 00903 quotient = 8; 00904 00905 if(isClockStateExternal()) // base freq: 54MHz 00906 { 00907 realClockFrequency = 00908 EXTERNAL_CLOCK_FREQUENCY / quotient; // this is the REAL frequency being used 00909 } 00910 else // base freq: 66.667MHz 00911 { 00912 realClockFrequency = 00913 INTERNAL_CLOCK_FREQUENCY / quotient; // this is the REAL frequency being used 00914 } 00915 00916 double factor = frequency / realClockFrequency; 00917 00918 // The device needs the denominator and the denominator to be load into a 5 bit 00919 // register It will take two initial numerator and denominator bigger than necessary 00920 // (to do not loose precision) and divide them for their gcd. If they still do not 00921 // fit in 5 bit, they are trunked (divided by 2) untill they are less than 32 00922 numerator = 00923 factor * 100; // we will work with 2 digits precision after the decimal point 00924 denominator = 100; 00925 00926 do 00927 { 00928 // We will need the GCD at some point in order to simplify fractions //taken from 00929 // other sources 00930 int gcd = numerator; 00931 int rest = denominator; 00932 int tmp; 00933 00934 while(rest != 0) 00935 { 00936 tmp = rest; 00937 rest = gcd % tmp; 00938 gcd = tmp; 00939 } 00940 // Done finding the GCD 00941 00942 if(gcd == 1) // if there's no GCD, just divide by 2 to find the nearest 00943 // approximation with less bits 00944 { 00945 numerator /= 2; 00946 denominator /= 2; 00947 } 00948 else 00949 { 00950 numerator /= gcd; 00951 denominator /= gcd; 00952 } 00953 00954 } while(denominator >= 32 || numerator >= 32); 00955 00956 // numerator = 2; 00957 // denominator = 1; 00958 // std::cout << __COUT_HDR_FL__ << "Numerator: " << numerator << std::endl; 00959 // std::cout << __COUT_HDR_FL__ << "Denominator: " << denominator << std::endl; 00960 setFrequencyRatio(buffer, numerator, denominator); 00961 // std::cout << __COUT_HDR_FL__ << "Done with clock frequency setup!!!" << std::endl; 00962 } 00963 //======================================================================================================================== 00964 bool FSSRFirmwareBase::isClockStateExternal() // returns true if the clock state is 00965 // External 00966 { 00967 if(BitManipulator::readBits(stripCSRRegisterValue_, 16, 1) == 1) 00968 return true; 00969 else 00970 return false; 00971 } 00972 00973 //======================================================================================================================== 00974 void FSSRFirmwareBase::setCSRRegister(uint32_t total) { stripCSRRegisterValue_ = total; } 00975 00976 //======================================================================================================================== 00977 void FSSRFirmwareBase::setPacketSizeStripCSR(uint32_t size) 00978 { 00979 if(size > 31) 00980 std::cout << __COUT_HDR_FL__ 00981 << "ERROR: Maximum packet size is 31 while here you are trying to set " 00982 << size << " packets!" << std::endl; 00983 BitManipulator::insertBits(stripCSRRegisterValue_, size, 3, 5); 00984 // write(buffer,STRIP_CSR, stripSCRRegisterValue_); 00985 } 00986 00987 //======================================================================================================================== 00988 void FSSRFirmwareBase::enableChannelsStripCSR(bool channel0, 00989 bool channel1, 00990 bool channel2, 00991 bool channel3, 00992 bool channel4, 00993 bool channel5) 00994 { 00995 BitManipulator::insertBits(stripCSRRegisterValue_, 00996 ((uint32_t)channel0) + ((uint32_t)channel1 << 1) + 00997 ((uint32_t)channel2 << 2) + ((uint32_t)channel3 << 3) + 00998 ((uint32_t)channel4 << 4) + ((uint32_t)channel5 << 5), 00999 8, 01000 6); 01001 } 01002 01003 //======================================================================================================================== 01004 void FSSRFirmwareBase::setExternalBCOClockSourceStripCSR(std::string clockSource) 01005 { 01006 if(clockSource == "External") 01007 BitManipulator::insertBits(stripCSRRegisterValue_, 1, 16, 1); 01008 else if(clockSource == "Internal") 01009 BitManipulator::insertBits(stripCSRRegisterValue_, 0, 16, 1); 01010 } 01011 01012 //======================================================================================================================== 01013 // void FSSRFirmwareBase::setHaltStripCSR(bool set) 01014 //{ 01015 // BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) set, 17, 1); 01016 //} 01017 01018 //======================================================================================================================== 01019 void FSSRFirmwareBase::armBCOResetCSR(void) 01020 { 01021 BitManipulator::insertBits(stripCSRRegisterValue_, 1, 19, 1); 01022 } 01023 01024 //======================================================================================================================== 01025 void FSSRFirmwareBase::flushBuffersStripCSR(void) 01026 { 01027 BitManipulator::insertBits(stripCSRRegisterValue_, 1, 20, 1); 01028 } 01029 01030 //======================================================================================================================== 01031 void FSSRFirmwareBase::resetTriggerCounterStripCSR(std::string& buffer) 01032 { 01033 // Ryan's firmware is too fast so I need to make sure he understand the 1!!!! 01034 BitManipulator::insertBits(stripCSRRegisterValue_, 1, 21, 1); 01035 communicationFirmwareInstance_->write( 01036 buffer, STRIP_CSR, stripCSRRegisterValue_, false /*clearBuffer*/); 01037 BitManipulator::insertBits(stripCSRRegisterValue_, 1, 21, 1); 01038 communicationFirmwareInstance_->write( 01039 buffer, STRIP_CSR, stripCSRRegisterValue_, false /*clearBuffer*/); 01040 BitManipulator::insertBits(stripCSRRegisterValue_, 1, 21, 1); 01041 communicationFirmwareInstance_->write( 01042 buffer, STRIP_CSR, stripCSRRegisterValue_, false /*clearBuffer*/); 01043 BitManipulator::insertBits(stripCSRRegisterValue_, 1, 21, 1); 01044 communicationFirmwareInstance_->write( 01045 buffer, STRIP_CSR, stripCSRRegisterValue_, false /*clearBuffer*/); 01046 BitManipulator::insertBits(stripCSRRegisterValue_, 1, 21, 1); 01047 communicationFirmwareInstance_->write( 01048 buffer, STRIP_CSR, stripCSRRegisterValue_, false /*clearBuffer*/); 01049 01050 BitManipulator::insertBits(stripCSRRegisterValue_, 0, 21, 1); 01051 communicationFirmwareInstance_->write( 01052 buffer, STRIP_CSR, stripCSRRegisterValue_, false /*clearBuffer*/); 01053 } 01054 01055 //======================================================================================================================== 01056 void FSSRFirmwareBase::resetBCOCounterStripCSR(void) 01057 { 01058 BitManipulator::insertBits(stripCSRRegisterValue_, 1, 22, 1); 01059 } 01060 01061 //======================================================================================================================== 01062 void FSSRFirmwareBase::enableTriggerStripCSR(bool enable) 01063 { 01064 BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t)enable, 23, 1); 01065 } 01066 01067 //======================================================================================================================== 01068 void FSSRFirmwareBase::sendTriggerDataStripCSR(bool send) 01069 { 01070 BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t)send, 24, 1); 01071 } 01072 01073 //======================================================================================================================== 01074 void FSSRFirmwareBase::sendTriggerNumberStripCSR(bool send) 01075 { 01076 BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t)send, 25, 1); 01077 } 01078 01079 //======================================================================================================================== 01080 void FSSRFirmwareBase::sendBCOStripCSR(bool send) 01081 { 01082 BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t)send, 26, 1); 01083 } 01084 01085 //======================================================================================================================== 01086 void FSSRFirmwareBase::enableStreamStripCSR(bool enable) 01087 { 01088 BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t)enable, 27, 1); 01089 } 01090 01091 //======================================================================================================================== 01092 void FSSRFirmwareBase::resetDCMStripCSR(bool clear) 01093 { 01094 BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t)clear, 31, 1); 01095 } 01096 01097 //======================================================================================================================== 01098 uint32_t FSSRFirmwareBase::waitDCMResetStripCSR(void) 01099 { 01100 uint32_t bitToCheck = 0; 01101 BitManipulator::insertBits(bitToCheck, 1, 31, 2); 01102 return bitToCheck; 01103 } 01104 01105 //======================================================================================================================== 01106 void FSSRFirmwareBase::resetDAC(void) 01107 { 01108 BitManipulator::insertBits(stripResetRegisterValue_, 1, 27, 1); 01109 } 01110 01111 //======================================================================================================================== 01112 void FSSRFirmwareBase::resetLink(bool channel0, 01113 bool channel1, 01114 bool channel2, 01115 bool channel3, 01116 bool channel4, 01117 bool channel5) 01118 { 01119 stripResetRegisterValue_ = 0; 01120 BitManipulator::insertBits(stripResetRegisterValue_, 01121 ((uint32_t)channel0) + ((uint32_t)channel1 << 1) + 01122 ((uint32_t)channel2 << 2) + ((uint32_t)channel3 << 3) + 01123 ((uint32_t)channel4 << 4) + ((uint32_t)channel5 << 5), 01124 0, 01125 6); 01126 BitManipulator::insertBits(stripResetRegisterValue_, 1, 29, 1); 01127 /* 01128 write(buffer, STRIP_RESET, (1<<28) + 01129 ((uint32_t)channel0) + 01130 ((uint32_t)channel1<<1) + 01131 ((uint32_t)channel2<<2) + 01132 ((uint32_t)channel3<<3) + 01133 ((uint32_t)channel4<<4) + 01134 ((uint32_t)channel5<<5) 01135 ); 01136 */ 01137 } 01138 01139 //======================================================================================================================== 01140 void FSSRFirmwareBase::clearErrors(bool channel0, 01141 bool channel1, 01142 bool channel2, 01143 bool channel3, 01144 bool channel4, 01145 bool channel5) 01146 { 01147 stripResetRegisterValue_ = 0; 01148 BitManipulator::insertBits(stripResetRegisterValue_, 01149 ((uint32_t)channel0) + ((uint32_t)channel1 << 1) + 01150 ((uint32_t)channel2 << 2) + ((uint32_t)channel3 << 3) + 01151 ((uint32_t)channel4 << 4) + ((uint32_t)channel5 << 5), 01152 0, 01153 6); 01154 BitManipulator::insertBits(stripResetRegisterValue_, 1, 29, 1); 01155 } 01156 01157 //======================================================================================================================== 01158 void FSSRFirmwareBase::clearFIFO(bool channel0, 01159 bool channel1, 01160 bool channel2, 01161 bool channel3, 01162 bool channel4, 01163 bool channel5) 01164 { 01165 stripResetRegisterValue_ = 0; 01166 BitManipulator::insertBits(stripResetRegisterValue_, 01167 ((uint32_t)channel0) + ((uint32_t)channel1 << 1) + 01168 ((uint32_t)channel2 << 2) + ((uint32_t)channel3 << 3) + 01169 ((uint32_t)channel4 << 4) + ((uint32_t)channel5 << 5), 01170 0, 01171 6); 01172 BitManipulator::insertBits(stripResetRegisterValue_, 1, 30, 1); 01173 } 01174 01175 //======================================================================================================================== 01176 void FSSRFirmwareBase::resetChip(bool channel0, 01177 bool channel1, 01178 bool channel2, 01179 bool channel3, 01180 bool channel4, 01181 bool channel5) 01182 { 01183 stripResetRegisterValue_ = 0; 01184 BitManipulator::insertBits(stripResetRegisterValue_, 01185 ((uint32_t)channel0) + ((uint32_t)channel1 << 1) + 01186 ((uint32_t)channel2 << 2) + ((uint32_t)channel3 << 3) + 01187 ((uint32_t)channel4 << 4) + ((uint32_t)channel5 << 5), 01188 0, 01189 6); 01190 BitManipulator::insertBits(stripResetRegisterValue_, 1, 31, 1); 01191 } 01192 01193 //======================================================================================================================== 01194 void FSSRFirmwareBase::setFrequencyRatio(std::string& buffer, 01195 int numerator, 01196 int denominator) 01197 { 01198 // The device need to load numerator minus one and denominator minus one, with an 01199 // internal address of 0x50 and 052 respectively 01200 communicationFirmwareInstance_->write( 01201 buffer, 01202 STRIP_BCO_DCM, 01203 0x80500000 + (numerator - 1)); // Set BCOCLK numerator // was 0x80500003 01204 communicationFirmwareInstance_->waitClear( 01205 buffer, 01206 STRIP_BCO_DCM, 01207 0xf0000000); // Wait DCM write to finish // was 0x80000000 01208 01209 communicationFirmwareInstance_->write( 01210 buffer, 01211 STRIP_BCO_DCM, 01212 0x80520000 + (denominator - 1)); // Set BCOCLK denominator // was 0x80520001 01213 communicationFirmwareInstance_->waitClear( 01214 buffer, STRIP_BCO_DCM, 0xf0000000); // Wait DCM write to finish - BCO frequency 01215 // should be 13.513 MHz // was 0x80000000 01216 } 01217 01218 //======================================================================================================================== 01219 void FSSRFirmwareBase::BCOOffset(uint32_t offset) 01220 { 01221 BitManipulator::insertBits(stripTriggerCSRRegisterValue_, offset, 0, 4); 01222 } 01223 01224 //======================================================================================================================== 01225 void FSSRFirmwareBase::selectSpyFIFO(uint32_t input) 01226 { 01227 BitManipulator::insertBits(stripTriggerCSRRegisterValue_, input, 4, 3); 01228 } 01229 01230 //======================================================================================================================== 01231 void FSSRFirmwareBase::halt(bool halt) 01232 { 01233 BitManipulator::insertBits(stripTriggerCSRRegisterValue_, (uint32_t)halt, 7, 1); 01234 } 01235 01236 //======================================================================================================================== 01237 void FSSRFirmwareBase::configureStripTriggerUnbiased(std::string& buffer) 01238 { 01239 communicationFirmwareInstance_->write( 01240 buffer, 01241 STRIP_TRIG_UNBIASED, 01242 0x002805c, 01243 false /*clearBuffer*/); // Configure unbiased trigger 01244 } 01245 01246 //======================================================================================================================== 01247 void FSSRFirmwareBase::configureTriggerInputs(std::string& buffer) 01248 { 01249 // communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_0, 0x3f440000); // 01250 // FSSR GOTHIT trigger input channel 0,1 01251 // communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_1, 0x3f440000); // 01252 // FSSR GOTHIT trigger input channel 2,3 01253 communicationFirmwareInstance_->write( 01254 buffer, 01255 STRIP_TRIG_INPUT_0, 01256 0x0, 01257 false /*clearBuffer*/); // FSSR GOTHIT trigger input channel 0,1 01258 communicationFirmwareInstance_->write( 01259 buffer, 01260 STRIP_TRIG_INPUT_1, 01261 0x0, 01262 false /*clearBuffer*/); // FSSR GOTHIT trigger input channel 2,3 01263 communicationFirmwareInstance_->write( 01264 buffer, 01265 STRIP_TRIG_INPUT_2, 01266 0x0, 01267 false /*clearBuffer*/); // FSSR GOTHIT trigger input channel 4,5 01268 } 01269 01270 //======================================================================================================================== 01271 std::string FSSRFirmwareBase::resetSlaveBCO(void) 01272 { 01273 std::string buffer; 01274 /*TODO:make unambiguous by casting to uint32_t*/ 01275 communicationFirmwareInstance_->write( 01276 buffer, (uint32_t)0xc5000000, (uint32_t)0x00000008); 01277 return buffer; 01278 } 01279 01280 /* 01281 //======================================================================================================================== 01282 void FSSRFirmwareBase::chipID(uint32_t size) 01283 { 01284 BitManipulator::insertBits(stripSCRegisterValue_, size, 0, 5); 01285 } 01286 01287 //======================================================================================================================== 01288 void FSSRFirmwareBase::addressSlowControls(uint32_t size) 01289 { 01290 BitManipulator::insertBits(stripSCRegisterValue_, size, 5, 5); 01291 } 01292 01293 //======================================================================================================================== 01294 void FSSRFirmwareBase::instructionSlowControls(uint32_t size) 01295 { 01296 BitManipulator::insertBits(stripSCRegisterValue_, size, 10, 3); 01297 } 01298 01299 //======================================================================================================================== 01300 void FSSRFirmwareBase::channelreadSelect(uint32_t size) 01301 { 01302 BitManipulator::insertBits(stripSCRegisterValue_, size, 13, 3); 01303 } 01304 01305 //======================================================================================================================== 01306 void FSSRFirmwareBase::channelMask(uint32_t size) 01307 { 01308 BitManipulator::insertBits(stripSCRegisterValue_, size, 16, 8); 01309 } 01310 01311 //======================================================================================================================== 01312 void FSSRFirmwareBase::bitsLength(uint32_t length) 01313 { 01314 BitManipulator::insertBits(stripSCRegisterValue_, length, 26, 3); 01315 } 01316 01317 01318 //======================================================================================================================== 01319 void FSSRFirmwareBase::syncFallingBCO(bool sync) 01320 { 01321 BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)sync, 28, 1); 01322 } 01323 01324 //======================================================================================================================== 01325 void FSSRFirmwareBase::syncRisingBCO(bool sync) 01326 { 01327 BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)sync, 29, 1); 01328 } 01329 01330 //======================================================================================================================== 01331 void FSSRFirmwareBase::setRaw(bool set) 01332 { 01333 BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)set, 30, 1); 01334 } 01335 01336 //======================================================================================================================== 01337 void FSSRFirmwareBase::initSlowControls(bool init) 01338 { 01339 BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)init, 31, 1); 01340 } 01341 01342 //======================================================================================================================== 01343 void FSSRFirmwareBase::resetCount(bool reset) 01344 { 01345 BitManipulator::insertBits(stripAnalysisCSRRegisterValue_, (uint32_t)reset, 30, 1); 01346 } 01347 01348 //======================================================================================================================== 01349 void FSSRFirmwareBase::setBCO_0(uint32_t void FSSRFirmwareBase::BCOOffset(uint32_t 01350 offset) 01351 { 01352 BitManipulator::insertBits(stripTrigCSRRegisterValue_, offset, 0, 4); 01353 }input) 01354 { 01355 BitManipulator::insertBits(trigInputRegisterValue_, input, 0, 8); 01356 } 01357 01358 //======================================================================================================================== 01359 void FSSRFirmwareBase::setBCO_1(uint32_t input) 01360 { 01361 BitManipulator::insertBits(trigInputRegisterValue_, input, 8, 8); 01362 } 01363 01364 //======================================================================================================================== 01365 void FSSRFirmwareBase::trimFracBCO_0(uint32_t input) 01366 { 01367 BitManipulator::insertBits(trigInputRegisterValue_, input, 16, 4); 01368 } 01369 01370 //======================================================================================================================== 01371 void FSSRFirmwareBase::trimFracBCO_1(uint32_t input) 01372 { 01373 BitManipulator::insertBits(trigInputRegisterValue_, input, 20, 4); 01374 } 01375 01376 //======================================================================================================================== 01377 void FSSRFirmwareBase::enable_0(bool enable) 01378 { 01379 BitManipulator::insertBits(trigInputRegisterValue_, (uint32_t)enable, 28, 1); 01380 } 01381 01382 //======================================================================================================================== 01383 void FSSRFirmwareBase::enable_1(bool enable) 01384 { 01385 BitManipulator::insertBits(trigInputRegisterValue_, (uint32_t)enable, 29, 1); 01386 } 01387 01388 */