otsdaq_components  v2_01_00
FSSRFirmwareBase.cc
1 #include "otsdaq-components/DAQHardware/FSSRFirmwareBase.h"
2 
3 #include "otsdaq-core/MessageFacility/MessageFacility.h"
4 #include "otsdaq-core/Macros/CoutMacros.h"
5 
6 #include "otsdaq-components/DAQHardware/FSSRFirmwareDefinitions.h"
7 #include "otsdaq-core/BitManipulator/BitManipulator.h"
8 #include "otsdaq-components/DetectorHardware/FSSRROCDefinitions.h"
9 
10 #include <sys/socket.h>
11 #include <netinet/in.h>
12 #include <arpa/inet.h>
13 
14 #include <iostream>
15 #include <cstdlib>
16 
17 #include "otsdaq-components/DAQHardware/FrontEndFirmwareBase.h"
18 #include "otsdaq-components/DAQHardware/PurdueFirmwareCore.h"
19 #include "otsdaq-components/DAQHardware/OtsUDPFirmwareCore.h"
20 
21 using namespace ots;
22 
23 const std::string FSSRFirmwareBase::PURDUE_FIRMWARE_NAME = "PurdueFSSRFirmware";
24 const std::string FSSRFirmwareBase::OTS_FIRMWARE_NAME = "OtsUDPFSSRFirmware";
25 
26 
27 //========================================================================================================================
28 FSSRFirmwareBase::FSSRFirmwareBase(
29  const std::string& communicationFirmwareType,
30  unsigned int communicationFirmwareVersion,
31  unsigned int version)
32 : stripCSRRegisterValue_(0)
33 , communicationFirmwareType_(communicationFirmwareType)
34 {
35  //choose: OtsUDPFirmwareCore or PurdueFirmwareCore
36  if(communicationFirmwareType == FSSRFirmwareBase::PURDUE_FIRMWARE_NAME) //could also use string and: if(choice == "purdue") etc.
37  communicationFirmwareInstance_ = new PurdueFirmwareCore(communicationFirmwareVersion);
38  else if(communicationFirmwareType == FSSRFirmwareBase::OTS_FIRMWARE_NAME) //AUG-17-2017 RAR dissociated because function calls are entirely independent from PURDUE firmware calls //
39  communicationFirmwareInstance_ = new OtsUDPFirmwareCore(communicationFirmwareVersion);
40  else
41  {
42  __SS__ << "Unknown communication firmware type choice: " <<
43  communicationFirmwareType << std::endl;
44  __COUT_ERR__ << ss.str();
45  throw std::runtime_error(ss.str());
46  }
47 
48 
49  //now we can call write/read etc with
50  // communicationFirmwareInstance_->write,
51  // communicationFirmwareInstance_->read, etc
52 
53 }
54 
55 //========================================================================================================================
56 FSSRFirmwareBase::~FSSRFirmwareBase(void)
57 {
58  delete communicationFirmwareInstance_;
59  communicationFirmwareInstance_= NULL;
60 }
61 
62 //========================================================================================================================
63 void FSSRFirmwareBase::init(void)
64 {}
65 
66 
67 //========================================================================================================================
68 std::string FSSRFirmwareBase::universalRead(char* address)
69 {
70  __COUT__ << "universalRead communicationFirmwareType_ " << communicationFirmwareType_ << std::endl;
71  return communicationFirmwareInstance_->read(address);
72 }
73 
74 //========================================================================================================================
75 std::string FSSRFirmwareBase::universalWrite(char* address, char* data)
76 {
77  __COUT__ << "universalWrite communicationFirmwareType_ " << communicationFirmwareType_ << std::endl;
78  return communicationFirmwareInstance_->write(address, data);
79 }
80 
81 //========================================================================================================================
82 uint32_t FSSRFirmwareBase::createRegisterFromValue (std::string& readBuffer, std::string& receivedValue)
83 {
84  return communicationFirmwareInstance_->createRegisterFromValue(readBuffer,receivedValue);
85 }
86 
87 //========================================================================================================================
88 std::string FSSRFirmwareBase::configureClocks(std::string source, double frequency)
89 {
90  std::cout << __COUT_HDR_FL__ << "Writing Clock configuration!" << std::endl;
91 
92  std::string buffer;
93  //NoNeedNowwrite(buffer, ETHIO_DESTINATION_PORT, 0x0000b798); // Listen port for ethio stuff
94 
95  setPacketSizeStripCSR(6);
96  setExternalBCOClockSourceStripCSR(source); //(source)
97  communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_); // Reset CSR - reset trigger counter, external 27 MHz clock
98 
99  resetDCM(buffer);
100  alignReadOut(buffer,0x3000);//0x3000
101 
102  setFrequencyFromClockState(buffer, frequency);
103  communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_,false/*clearBuffer*/);
104 
105  resetDCM(buffer);
106  std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue :" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
107 
108  return buffer;
109 }
110 
111 //========================================================================================================================
112 void FSSRFirmwareBase::resetDCM(std::string& buffer)
113 {
114  __COUT__ << communicationFirmwareInstance_ << std::endl;
115  resetDCMStripCSR(true);
116  __COUT__ << communicationFirmwareInstance_ << std::endl;
117 
118  communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_,false/*clearBuffer*/); // Set reset to DCM
119 
120  __COUT__ << communicationFirmwareInstance_ << std::endl;
121 
122  resetDCMStripCSR(false);
123  communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_,false/*clearBuffer*/); // Clear reset to DCM
124 
125  communicationFirmwareInstance_->waitClear(buffer, STRIP_CSR, waitDCMResetStripCSR(),false/*clearBuffer*/); // Wait for DCM to lock
126 }
127 
128 
129 //========================================================================================================================
130 void FSSRFirmwareBase::alignReadOut(std::string& buffer, uint32_t value)
131 {
132  communicationFirmwareInstance_->write(buffer, STRIP_TRIM_CSR, value); // MCLKB edge for channel 5 // was 0x00002000
133 }
134 //========================================================================================================================
135 std::string FSSRFirmwareBase::resetDetector(int channel)
136 {
137  std::cout << __COUT_HDR_FL__ << "Resetting detector!" << std::endl;
138  std::string buffer;
139  if (channel == -1)//reset all channels
140  {
141  //write(buffer,STRIP_RESET,0xd000003f); // Issue reset
142  communicationFirmwareInstance_->write(buffer, STRIP_RESET, 0xf000003f); // Issue reset // was 0xf000003f
143  communicationFirmwareInstance_->waitClear(buffer, STRIP_RESET, 0xf0000000); // Wait for reset to complete // was 0xf0000000
144  } else
145  {
146  communicationFirmwareInstance_->write(buffer, STRIP_RESET, 0xf000003f); // Issue reset
147  communicationFirmwareInstance_->waitClear(buffer, STRIP_RESET, 0xf0000000); // Wait for reset to complete
148  }
149 
150  return buffer;
151 }
152 
153 //========================================================================================================================
154 std::string FSSRFirmwareBase::enableTrigger(void)
155 {
156  std::string buffer;
157  std::cout << __COUT_HDR_FL__ << "Enabling Trigger!!!" << std::endl;
158  std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue in :" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
159 
160  //setHaltStripCSR(1);//WARNING THIS IS CLEARED BY THE MASTER BUT IF THERE IS NO MASTER NOTHING WORKS UNLESS THE BIT IS UNSET
161  sendTriggerDataStripCSR(true);
162  sendTriggerNumberStripCSR(true);
163  sendBCOStripCSR(true);
164  communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_, false/*clearBuffer*/);
165 
166  stripTriggerCSRRegisterValue_ = 0;
167  BCOOffset(4);
168  communicationFirmwareInstance_->write(buffer, STRIP_TRIG_CSR, stripTriggerCSRRegisterValue_, false/*clearBuffer*/); // BCO offset // was 0x00000004
169 
170  // write(buffer,STRIP_TRIG_INPUT_0,0x1f060040); // FSSR GOTHIT trigger input - timed in for the 27 MHz external clock
171  // write(buffer,STRIP_TRIG_INPUT_3,0x3f874040); // Unbiased trigger input + external trigger
172 
173  configureStripTriggerUnbiased(buffer);
174 
175  configureTriggerInputs(buffer);
176 
177  //FIXME for IP .36 the number to set is 0x20401000
178 
179  if (1 || communicationFirmwareInstance_->getVersion() == 1)
180  communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_3, 0x20401000, false/*clearBuffer*/); // Turn on streaming hits along with BCO data
181  else if (communicationFirmwareInstance_->getVersion() == 2)
182  communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_3, 0x20301000, false/*clearBuffer*/); // Turn on streaming hits along with BCO data
183  else
184  {
185  __SS__ << "what version is this?" << communicationFirmwareInstance_->getVersion() << std::endl;
186  __COUT__ << ss.str();
187  throw std::runtime_error(ss.str());
188  }
189  std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue out:" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
190  std::cout << __COUT_HDR_FL__ << "Done enabling Trigger!!!" << std::endl;
191 
192  return buffer;
193 }
194 //
196 //void FSSRFirmwareBase::setDataDestination(std::string& buffer, const std::string& ip, const uint16_t port)
198 //{
199 // std::cout << __COUT_HDR_FL__ << "Set data destination!" << std::endl;
200 //
201 // struct sockaddr_in socketAddress;
202 // inet_pton(AF_INET, ip.c_str(), &(socketAddress.sin_addr));
203 // std::cout << __COUT_HDR_FL__ << "ADDRESS: " << std::hex << ntohl(socketAddress.sin_addr.s_addr) << std::dec << std::endl;
204 // communicationFirmwareInstance_->write(buffer, DATA_DESTINATION_IP, ntohl(socketAddress.sin_addr.s_addr)); // Set data destination IP 192.168.133.1
205 // std::cout << __COUT_HDR_FL__ << "PORT: " << std::hex << port << std::dec << std::endl;
206 // communicationFirmwareInstance_->write(buffer, DATA_SOURCE_DESTINATION_PORT, port); // Set data destination port
207 // std::cout << __COUT_HDR_FL__ << "THIS IS THE BUFFER: " << buffer << std::endl;
208 //
209 // for(uint32_t i=0; i<buffer.size(); i++)
210 // printf("%2.2X-",(uint8_t)buffer[i]);
211 // std::cout << std::dec << std::endl;
212 //
213 //}
214 
215 
216 
217 
218 //========================================================================================================================
219 std::string FSSRFirmwareBase::resetBCO(void)
220 {
221  std::cout << __COUT_HDR_PL__ << "Reset BCO!!!" << std::endl;
222  std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue in :" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
223  std::string buffer;
224 
225  resetTriggerCounterStripCSR(buffer);
226  //write(buffer, STRIP_CSR, stripCSRRegisterValue_);//the write is done in the reset
227  std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue :" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
228 
229  //msg->Write(STRIP_SC_CSR,0x90000b95|(chmask<<16));
230  communicationFirmwareInstance_->write(buffer,STRIP_SC_CSR,0x903f0b95, false/*clearBuffer*/);// This is the <SCR,set> command with the bit set to sync SHIFT with BCO=0.
231 
232  //enableBCOStripCSR(true);
233  //communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
234 
235  std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue out:" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
236  std::cout << __COUT_HDR_FL__ << "Done reset BCO!!!" << std::endl;
237 
238  return buffer;
239 }
240 
241 //========================================================================================================================
242 std::string FSSRFirmwareBase::armBCOReset(void)
243 {
244  std::cout << __COUT_HDR_FL__ << std::endl;
245  std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue in :" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
246  std::string buffer;
247 
248  enableBCOStripCSR(true);
249  communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
250  std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue out:" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
251  std::cout << __COUT_HDR_FL__ << "Done!" << std::endl;
252 
253  return buffer;
254 }
255 
256 //========================================================================================================================
257 std::string FSSRFirmwareBase::startStream(bool channel0, bool channel1, bool channel2, bool channel3, bool channel4, bool channel5)
258 {
259  std::cout << __COUT_HDR_FL__ << "Start Stream!" << std::endl;
260  std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue in:" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
261  std::string buffer;
262 
263  std::cout << __COUT_HDR_PL__ << " channel0 " << channel0 << " channel1 " << channel1 << " channel2 " << channel2 << " channel3 " << channel3 << " channel4 " << channel4 << " channel5 " << channel5 << std::endl;
264 
265  enableChannelsStripCSR(channel0, channel1, channel2, channel3, channel4, channel5);
266  // if (version_ == 1)
267  // enableChannelsStripCSR(true, true, true, true, false, false);
268  // else if (version_ == 2)
269  // enableChannelsStripCSR(true, true, true, true, true, true);
270 
271  enableStreamStripCSR(true); // Turn on streaming hits along with BCO data // was 0x0f000f30
272  communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
273 
274  std::cout << __COUT_HDR_PL__ << "stripCSRRegisterValue out:" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
275  std::cout << __COUT_HDR_PL__ << "Done start Stream!" << std::endl;
276 
277  return buffer;
278 }
279 
280 //========================================================================================================================
281 std::string FSSRFirmwareBase::stopStream(void)
282 {
283  std::string buffer;
284  enableChannelsStripCSR(false, false, false, false, false, false);
285  enableStreamStripCSR(false);
286  communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
287  return buffer;
288 }
289 
290 //========================================================================================================================
291 void FSSRFirmwareBase::makeDACSequence(FirmwareSequence<uint64_t>& sequence, unsigned int channel, const ROCStream& rocStream)
292 {
293  const ROCDACs& rocDACs = rocStream.getROCDACs();
294  for (DACList::const_iterator it = rocDACs.getDACList().begin(); it != rocDACs.getDACList().end(); it++)
295  {
296  //if(it->first != "SendData" && it->first != "RejectHits") continue;
297  uint64_t data = FSSRROCDefinitions::makeDACWriteCommand(
298  rocStream.getFEWROCAddress(), it->first, it->second.second);
299  sequence.pushBack(ChannelFIFOAddress[channel], data);
300  sequence.pushBack(ChannelFIFOAddress[channel],
301  BitManipulator::insertBits(data, (uint64_t) 0x48, 56, 8));
302  //set WRITE
303  sequence.pushBack(ChannelFIFOAddress[channel],
304  BitManipulator::insertBits(data, (uint64_t) 1, 60, 1));
305  //clr WRITE
306  sequence.pushBack(ChannelFIFOAddress[channel],
307  BitManipulator::insertBits(data, (uint64_t) 0, 60, 1));
308  //clr TALK
309  sequence.pushBack(ChannelFIFOAddress[channel],
310  BitManipulator::insertBits(data, (uint64_t) 0, 62, 1));
311  sequence.pushBack(ChannelFIFOAddress[channel],
312  BitManipulator::insertBits(data, (uint64_t) 0x40, 56, 8));
313  //break;
314  }
315 }
316 
317 //========================================================================================================================
318 void FSSRFirmwareBase::makeDACSequence(FirmwareSequence<uint32_t>& sequence,
319  unsigned int channel, const ROCStream& rocStream)
320 {
321  const ROCDACs& rocDACs = rocStream.getROCDACs();
322  for (DACList::const_iterator it = rocDACs.getDACList().begin(); it
323  != rocDACs.getDACList().end(); it++)
324  {
325  /*RYAN
326  //if(it->first != "SendData" && it->first != "RejectHits") continue;
327  uint64_t data = FSSRROCDefinitions::makeDACWriteCommand(rocStream.getFEWROCAddress(), it->first, it->second.second);
328  sequence.pushBack(ChannelFIFOAddress[channel], data);
329  sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)0x48,56,8));
330  //set WRITE
331  sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)1,60,1));
332  //clr WRITE
333  sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)0,60,1));
334  //clr TALK
335  sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)0,62,1));
336  sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)0x40,56,8));
337  */
338 
339  //if(it->first != "SendData" && it->first != "RejectHits") continue;
340  uint32_t data = FSSRROCDefinitions::makeDACWriteHeader(
341  rocStream.getFEWROCAddress(), it->first);
342  //Insert channel
343  BitManipulator::insertBits(data, 1, 16 + channel, 1);
344  sequence.pushBack(ChannelFIFOAddress[channel], it->second.second);
345  std::cout << __COUT_HDR_FL__ << "Register: " << it->first << " value: "
346  << it->second.second << std::hex << " -> Data: " << data << std::dec
347  << std::endl;
348  sequence.pushBack(STRIP_SC_CSR, data);
349  }
350 }
351 
352 //========================================================================================================================
353 void FSSRFirmwareBase::makeDACBuffer(std::string& buffer, unsigned int channel, const ROCStream& rocStream)
354 {
355  std::cout << __COUT_HDR_FL__ << "Channel: " << channel << std::endl;
356  std::cout << __COUT_HDR_FL__ << "BufferINsize: " << buffer.size() << std::endl;
357  const ROCDACs& rocDACs = rocStream.getROCDACs();
358 // for (DACList::const_iterator it = rocDACs.getDACList().begin(); it != rocDACs.getDACList().end(); it++)
359 // {
360 // std::string bufferElement;
361 // communicationFirmwareInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000);
362 // uint32_t registerHeader = 0;
363 // //FIXME This must go in the FSSRROCDefinitions stuff
364 // //if (it->first != "RejectHits" && it->first != "SendData")
365 // if (it->first == "VTp0")
366 // {
367 // //communicationFirmwareInstance_->write(bufferElement, ChannelFIFOAddress[channel], it->second.second);
368 // registerHeader = FSSRROCDefinitions::makeDACReadHeader(rocStream.getFEWROCAddress(), it->first);
369 // //Insert channel
370 // BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
393 //
394 // std::cout << __COUT_HDR_FL__ << "Register: " << it->first << " value: " << it->second.second << std::hex << " -> Data: " << registerHeader << std::dec << std::endl;
395 // communicationFirmwareInstance_->write(bufferElement, STRIP_SC_CSR, registerHeader);
396 // communicationFirmwareInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000);
397 //
398 // //buffer.push_back(bufferElement);
399 // buffer += bufferElement;
400 // }
401 // //break;
402 // }
403  for (DACList::const_iterator it = rocDACs.getDACList().begin(); it != rocDACs.getDACList().end(); it++)
404  {
405  std::string bufferElement;
406  communicationFirmwareInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000, false);
407  uint32_t registerHeader = 0;
408  //FIXME This must go in the FSSRROCDefinitions stuff
409  if (it->first != "RejectHits" && it->first != "SendData")
410  {
411  communicationFirmwareInstance_->write(bufferElement, ChannelFIFOAddress[channel], it->second.second, false);
412  registerHeader = FSSRROCDefinitions::makeDACWriteHeader(rocStream.getFEWROCAddress(), it->first);
413  //Insert channel
414  BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
415  }
416  else
417  {
418  if (it->second.second == 1 || it->second.second == 2)
419  {
420  registerHeader = FSSRROCDefinitions::makeDACSetHeader(rocStream.getFEWROCAddress(), it->first);
421  //Insert channel
422  BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
423  }
424  else if (it->second.second == 0 || it->second.second == 5)
425  {
426  registerHeader = FSSRROCDefinitions::makeDACResetHeader(rocStream.getFEWROCAddress(), it->first);
427  //Insert channel
428  BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
429  }
430  else
431  std::cout << __COUT_HDR_FL__ << "Register value for : " << it->first
432  << " doesn't have a value I expect -> value = "
433  << it->second.second << std::endl;
434 
435  }
436 
437  //std::cout << __COUT_HDR_FL__ << "Register: " << it->first << " value: " << it->second.second << std::hex << " -> Data: " << registerHeader << std::dec << std::endl;
438  communicationFirmwareInstance_->write(bufferElement, STRIP_SC_CSR, registerHeader, false);
439  communicationFirmwareInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000, false);
440 
441  //buffer.push_back(bufferElement);
442  buffer += bufferElement;
443  //break;
444  }
445  std::cout << __COUT_HDR_FL__ << "BufferOUTsize: " << buffer.size() << std::endl;
446 }
447 
448 //========================================================================================================================
449 void FSSRFirmwareBase::makeDACBuffer(std::vector<std::string>& buffer, unsigned int channel, const ROCStream& rocStream)
450 {
451 
452  std::cout << __COUT_HDR_FL__ << "\tMaking DAC Buffer" << std::endl;
453 
454  int limitCount = 0;
455  unsigned int singleVectorCount = 0;
456 
457  std::string alternateBuffer;
458 
459  std::cout << __COUT_HDR_FL__ << "Channel: " << channel << std::endl;
460  const ROCDACs& rocDACs = rocStream.getROCDACs();
461  //std::cout << __COUT_HDR_FL__ << "Number of DACs: " << rocDACs.getDACList().size() << std::endl;
462  std::string bufferElement;
463  //FIXME My
464  // for (const auto it: rocDACs.getDACList())
465  for (const std::pair<std::string, std::pair<unsigned int, unsigned int> >& it: rocDACs.getDACList())
466 // for (std::map<std::string, std::pair<unsigned int, unsigned int> >::const_iterator it = rocDACs.getDACList().begin(); it != rocDACs.getDACList().end(); it++)
467  {
468  //std::cout << __COUT_HDR_FL__ << "Register?" << std::endl;
469 // if (it.first != "ActiveLines") continue;
470 // std::cout << __COUT_HDR_FL__ << "Register-1: " << it->first << " val: " << it->second.first << " = " << it->second.second << std::endl;
471  communicationFirmwareInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000, false);
472  uint32_t registerHeader = 0;
473  //FIXME This must go in the FSSRROCDefinitions stuff
474  //std::cout << __COUT_HDR_FL__ << "Register0: " << it.first << std::endl;
475  if (it.first != "RejectHits" && it.first != "SendData")
476  {
477  //std::cout << __COUT_HDR_FL__ << "Register1: " << it.first << "Channel: " << channel << " fifo address: " << ChannelFIFOAddress[channel] << std::endl;
478  communicationFirmwareInstance_->write(bufferElement, ChannelFIFOAddress[channel], it.second.second, false);
479  registerHeader = FSSRROCDefinitions::makeDACWriteHeader(rocStream.getFEWROCAddress(), it.first);
480  //Insert channel
481  BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
482  }
483  else
484  {
485  //std::cout << __COUT_HDR_FL__ << "Register2: " << it.first << std::endl;
486  if (it.second.second == 1 || it.second.second == 2)
487  {
488  registerHeader = FSSRROCDefinitions::makeDACSetHeader(rocStream.getFEWROCAddress(), it.first);
489  //Insert channel
490  BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
491  }
492  else if (it.second.second == 0 || it.second.second == 5)
493  {
494  registerHeader = FSSRROCDefinitions::makeDACResetHeader(rocStream.getFEWROCAddress(), it.first);
495  //Insert channel
496  BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
497  }
498  else
499  std::cout << __COUT_HDR_FL__ << "Register value for : " << it.first
500  << " doesn't have a value I expect -> value = "
501  << it.second.second << std::endl;
502 
503  }
504  //std::cout << __COUT_HDR_FL__ << "Register: " << it.first << " value: " << it.second.second << std::hex << " -> Data: " << registerHeader << std::dec << std::endl;
505  communicationFirmwareInstance_->write(bufferElement, STRIP_SC_CSR, registerHeader, false);
506  communicationFirmwareInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000, false);
507 
508  //std::cout << __COUT_HDR_FL__ << "Register3: " << it.first << std::endl;
509  //alternateBuffer += bufferElement;
510  limitCount++;
511  singleVectorCount++;
512 
513  if (limitCount == STIB_DAC_WRITE_MAX)
514  {
515  std::cout << __COUT_HDR_FL__ << "\tBuffer length:" << bufferElement.size() << std::endl;
516  buffer.push_back(bufferElement);
517  limitCount = 0;
518  bufferElement.clear();
519  }
520  else if (singleVectorCount == rocDACs.getDACList().size()) //case for incomplete packet
521  {
522  buffer.push_back(bufferElement);
523  }
524 
525  //buffer.push_back(bufferElement);
526  //break;
527  }
528  std::cout << __COUT_HDR_FL__ << "\tDone making DAC Buffer" << std::endl;
529 
530 }
531 
532 //========================================================================================================================
533 void FSSRFirmwareBase::makeMaskBuffer(std::string& buffer, unsigned int channel,
534  const ROCStream& rocStream)
535 {
536  std::cout << __COUT_HDR_FL__ << "Making mask! " << std::endl;
537  makeMaskBuffer(buffer, channel, rocStream, "Kill");
538  // makeMaskSequence(buffer, channel, rocStream, "Inject");
539 }
540 
541 //========================================================================================================================
542 void FSSRFirmwareBase::makeMaskBuffer(std::string& buffer, unsigned int channel, const ROCStream& rocStream, const std::string& registerName)
543 {
544  int chipId = rocStream.getFEWROCAddress();
545  const std::string& mask = rocStream.getROCMask();
546  std::cout << __COUT_HDR_FL__ << "\tMaking mask! Length = " << mask.length() << std::endl;
547 // std::cout << __COUT_HDR_FL__ << "\tMask length: " << mask.length() << std::endl;
548 // std::cout << __COUT_HDR_FL__ << "\tMask: " << mask << std::endl;
549 
550  unsigned int data[4] = { 0, 0, 0, 0 };
551 
552  char val;
553  //int j = 0;
554  for (unsigned int d = 0; d < 4; d++)
555  { //d goes from 0 to 4. 4 bytes
556  //std::cout << __COUT_HDR_FL__ << "---------------------" << d << "-------------------" << std::endl;
557  for (unsigned int m = 0; m < 8 * 4; m++)
558  { //m goes from 0 to 31, since each byte has 8 bits, there are 32 bits
559  val = mask[(8 * 4 * d) + m]; //assigns to val the value of the corresponding bit. 0-31, 32-63, 64-95, 96-127. it goes through each of the 128 bits
560  //std::cout << __COUT_HDR_FL__ << "---------------------" << j++ << std::endl;
561  //std::cout << __COUT_HDR_FL__ << "data[" << d << "] before: " << std::hex << data[d] << std::dec << std::endl;
562  data[d] |= (unsigned int) atoi(&val) << (8 * 4 - 1 - m);
563  //std::cout << __COUT_HDR_FL__ << "(unsigned int) atoi(&val): " << (unsigned int) atoi(&val) << std::endl;
564  //std::cout << __COUT_HDR_FL__ << "data[" << d << "] after: " << std::hex << data[d] << std::dec << std::endl;
565  //std::cout << __COUT_HDR_FL__ << std::hex << "D: " << data[d] << " Val: " << (unsigned int)atoi(&val) << " index: " << std::dec << (8*4-1-m) << " bit: " << mask[(8*4*d)+m] << std::dec << std::endl;
566  }
567  //
568  }
569 
570  int i;
571  unsigned int w;
572  unsigned char len = 4;
573  unsigned char addr = 17;//Kill
574  unsigned char bitMask = 1 << channel;
575  unsigned char inst = WRITE;
576 
577  communicationFirmwareInstance_->waitClear(buffer, STRIP_SC_CSR, 0x80000000, false);
578 
579  for (i = 0; i < 4; i++)
580  //write(buffer, STRIP_SCI + 4 * i, data[i]);
581  communicationFirmwareInstance_->write(buffer, STRIP_SCI + 4 * (4 - i - 1), data[i], false);
582 
583  w = 0x80000000 | (len << 24) | (bitMask << 16) | (inst << 10) | (addr << 5) | chipId;
584 
585  communicationFirmwareInstance_->write(buffer, STRIP_SC_CSR, w, false);
586 
587  communicationFirmwareInstance_->waitClear(buffer, STRIP_SC_CSR, 0x80000000, false);
588 }
589 
590 //========================================================================================================================
591 void FSSRFirmwareBase::makeMaskSequence(FirmwareSequence<uint64_t>& sequence,
592  unsigned int channel, const ROCStream& rocStream)
593 {
594  std::cout << __COUT_HDR_FL__ << "Making mask! " << std::endl;
595  makeMaskSequence(sequence, channel, rocStream, "Kill");
596  // makeMaskSequence(sequence, channel, rocStream, "Inject");
597 }
598 
599 //========================================================================================================================
600 void FSSRFirmwareBase::makeMaskSequence(FirmwareSequence<uint32_t>& sequence,
601  unsigned int channel, const ROCStream& rocStream)
602 {
603  std::cout << __COUT_HDR_FL__ << "Making mask! " << std::endl;
604  makeMaskSequence(sequence, channel, rocStream, "Kill");
605  // makeMaskSequence(channel,rocStream,sequence,"Inject");
606 }
607 
608 //========================================================================================================================
609 void FSSRFirmwareBase::makeMaskSequence(FirmwareSequence<uint64_t>& sequence,
610  unsigned int channel, const ROCStream& rocStream,
611  const std::string& registerName)
612 {
613  int chipId = rocStream.getFEWROCAddress();//9, 14 or 21 bcast
614  std::string mask = rocStream.getROCMask();
615  std::cout << __COUT_HDR_FL__ << "Mask length: " << mask.length() << std::endl;
616 
617  uint64_t uInt64Data = 0;
618  std::string stringData = "";
619 
620  //have to manually set every bit for mask writes.
621  //reset fifo
622  //download every bit (shift_in and shift_ctrl) to fifo (setup muxes and control lines)
623  //configure muxes for readout
624  //commence readout
625 
626  //FIFO Controls - byte 5 (7:0)
627  //7 - FIFO Clock
628  //6 - Shift Ctrl bit
629  //MASK_CELL_H - Shift In bit
630  //MUX Controls - byte 0 (7:0)
631  //7 - Read En/Output MUX sel (1 for masks)
632  //1 - Write En for mux
633  //0 - Reset Fifo
634 
635  //reset fifo
636  BitManipulator::insertBits(uInt64Data, 0x1, 56, 8);
637  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
638 
639  //configure fifo for write
640  BitManipulator::insertBits(uInt64Data, 0x2, 56, 8);
641  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
642 
643  //Download every bit (shift_in and shift_control) to fifo (setup muxes and control lines)
644  //Bit 7 of data is FIFO clock, bit 6 is shift_control, bit 5 is shift_in
645  //start bits (ctrl 0, data 0 => ctrl 1, data 0)
646 
647  BitManipulator::insertBits(uInt64Data, 0x40, 16, 8);//(0<<7) | (1<<6) | (0<<5)
648  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
649  BitManipulator::insertBits(uInt64Data, 0xc0, 16, 8);//(1<<7) | (1<<6) | (0<<5) -> clock the data in the fifo
650  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
651 
652  stringData = FSSRROCDefinitions::makeMaskWriteCommand(chipId,
653  registerName, mask);
654 
655  uint8_t data;
656  for (unsigned int s = 0; s < stringData.length(); s++)
657  for (int b = 8 - 1; b >= 0 && (s * 8 + 8 - b < 13 + 128); b--)
658  {
659  //std::cout << __COUT_HDR_FL__ << "S: " << s << " val: " << stringData.data()[s] << " b: " << b << " bit: " << ((stringData.data()[s]>>b)&1) << std::endl;
660  data = 0x40 | (((stringData.data()[s] >> b) & 1) << 5);
661  BitManipulator::insertBits(uInt64Data, (uint64_t) data, 16, 8);
662  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
663  data |= 0x80;
664  BitManipulator::insertBits(uInt64Data, (uint64_t) data, 16, 8);
665  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
666  }
667 
668  //reset Shift Control
669  BitManipulator::insertBits(uInt64Data, 0x0, 16, 8);
670  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
671  BitManipulator::insertBits(uInt64Data, 0x80, 16, 8);
672  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
673 
674  //configure muxes for readout
675  BitManipulator::insertBits(uInt64Data, 0x0, 56, 8);
676  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
677 
678  //commence readout
679  BitManipulator::insertBits(uInt64Data, 0x80, 56, 8);
680  sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
681 
682 }
683 
684 //========================================================================================================================
685 void FSSRFirmwareBase::makeMaskSequence(FirmwareSequence<uint32_t>& sequence,
686  unsigned int channel, const ROCStream& rocStream,
687  const std::string& registerName)
688 {}
689 
690 //========================================================================================================================
691 std::string FSSRFirmwareBase::readCSRRegister()
692 {
693  std::string buffer;
694  std::cout << __COUT_HDR_FL__ << "FSSR readCSRRegister" << std::endl;
695  communicationFirmwareInstance_->read(buffer,STRIP_CSR);
696  return buffer;
697 }
698 
699 //========================================================================================================================
700 std::string FSSRFirmwareBase::readSCCSRRegister()
701 {
702  std::string buffer;
703  std::cout << __COUT_HDR_FL__ << "FSSR readCSRRegister" << std::endl;
704  communicationFirmwareInstance_->read(buffer,STRIP_SC_CSR);
705  return buffer;
706 }
707 
708 //========================================================================================================================
709 void FSSRFirmwareBase::setFrequencyFromClockState(std::string& buffer, double frequency)
710 {
711  std::cout << __COUT_HDR_FL__ << "Setting up clock frequency!!!" << std::endl;
712 
713  int quotient;
714  int numerator;
715  int denominator;
716  double realClockFrequency;
717 
718  if (BitManipulator::readBits(stripCSRRegisterValue_, 17, 1) == 1) //if fastBCO is enabled
719  quotient = 4;
720  else //normal cases
721  quotient = 8;
722 
723  if (isClockStateExternal()) //base freq: 54MHz
724  {
725  realClockFrequency = EXTERNAL_CLOCK_FREQUENCY / quotient; //this is the REAL frequency being used
726  }
727  else //base freq: 66.667MHz
728  {
729  realClockFrequency = INTERNAL_CLOCK_FREQUENCY / quotient; //this is the REAL frequency being used
730  }
731 
732  double factor = frequency / realClockFrequency;
733 
734  //The device needs the denominator and the denominator to be load into a 5 bit register
735  //It will take two initial numerator and denominator bigger than necessary (to do not loose precision)
736  //and divide them for their gcd. If they still do not fit in 5 bit, they are trunked (divided by 2)
737  //untill they are less than 32
738  numerator = factor * 100; //we will work with 2 digits precision after the decimal point
739  denominator = 100;
740 
741  do
742  {
743  //We will need the GCD at some point in order to simplify fractions //taken from other sources
744  int gcd = numerator;
745  int rest = denominator;
746  int tmp;
747 
748  while (rest != 0)
749  {
750  tmp = rest;
751  rest = gcd % tmp;
752  gcd = tmp;
753  }
754  //Done finding the GCD
755 
756  if (gcd == 1) //if there's no GCD, just divide by 2 to find the nearest approximation with less bits
757  {
758  numerator /= 2;
759  denominator /= 2;
760  }
761  else
762  {
763  numerator /= gcd;
764  denominator /= gcd;
765  }
766 
767  }
768  while (denominator >= 32 || numerator >= 32);
769 
770  //numerator = 2;
771  //denominator = 1;
772  std::cout << __COUT_HDR_FL__ << "Numerator: " << numerator << std::endl;
773  std::cout << __COUT_HDR_FL__ << "Denominator: " << denominator << std::endl;
774  setFrequencyRatio(buffer, numerator, denominator);
775  std::cout << __COUT_HDR_FL__ << "Done with clock frequency setup!!!" << std::endl;
776 }
777 //========================================================================================================================
778 bool FSSRFirmwareBase::isClockStateExternal() //returns true if the clock state is External
779 {
780  if (BitManipulator::readBits(stripCSRRegisterValue_, 16, 1) == 1)
781  return true;
782  else
783  return false;
784 }
785 
786 //========================================================================================================================
787 void FSSRFirmwareBase::setCSRRegister(uint32_t total)
788 {
789  stripCSRRegisterValue_ = total;
790 }
791 
792 //========================================================================================================================
793 void FSSRFirmwareBase::setPacketSizeStripCSR(uint32_t size)
794 {
795  if (size > 31)
796  std::cout << __COUT_HDR_FL__
797  << "ERROR: Maximum packet size is 31 while here you are trying to set "
798  << size << " packets!" << std::endl;
799  BitManipulator::insertBits(stripCSRRegisterValue_, size, 3, 5);
800  //write(buffer,STRIP_CSR, stripSCRRegisterValue_);
801 }
802 
803 //========================================================================================================================
804 void FSSRFirmwareBase::enableChannelsStripCSR(bool channel0, bool channel1,
805  bool channel2, bool channel3, bool channel4, bool channel5)
806 {
807  BitManipulator::insertBits(stripCSRRegisterValue_, ((uint32_t) channel0)
808  + ((uint32_t) channel1 << 1) + ((uint32_t) channel2 << 2)
809  + ((uint32_t) channel3 << 3) + ((uint32_t) channel4 << 4)
810  + ((uint32_t) channel5 << 5), 8, 6);
811 }
812 
813 //========================================================================================================================
814 void FSSRFirmwareBase::setExternalBCOClockSourceStripCSR(std::string clockSource)
815 {
816  if (clockSource == "External")
817  BitManipulator::insertBits(stripCSRRegisterValue_, 1, 16, 1);
818  else if (clockSource == "Internal")
819  BitManipulator::insertBits(stripCSRRegisterValue_, 0, 16, 1);
820 }
821 
822 //========================================================================================================================
823 void FSSRFirmwareBase::setHaltStripCSR(bool set)
824 {
825  BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) set, 17, 1);
826 }
827 
828 //========================================================================================================================
829 void FSSRFirmwareBase::enableBCOStripCSR(bool enable)
830 {
831  BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) enable, 19, 1);
832 }
833 
834 //========================================================================================================================
835 void FSSRFirmwareBase::flushBuffersStripCSR(void)
836 {
837  BitManipulator::insertBits(stripCSRRegisterValue_, 1, 20, 1);
838 }
839 
840 //========================================================================================================================
841 void FSSRFirmwareBase::resetTriggerCounterStripCSR(std::string& buffer)
842 {
843  //Ryan's firmware is too fast so I need to make sure he understand the 1!!!!
844  BitManipulator::insertBits(stripCSRRegisterValue_, 1, 21, 1);
845  communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_, false/*clearBuffer*/);
846 
847  //BitManipulator::insertBits(stripCSRRegisterValue_, 0, 21, 1);
848  //communicationFirmwareInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_, false/*clearBuffer*/);
849 }
850 
851 //========================================================================================================================
852 void FSSRFirmwareBase::resetBCOCounterStripCSR(void)
853 {
854  BitManipulator::insertBits(stripCSRRegisterValue_, 1, 22, 1);
855 }
856 
857 //========================================================================================================================
858 void FSSRFirmwareBase::enableTriggerStripCSR(bool enable)
859 {
860  BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) enable, 23, 1);
861 }
862 
863 //========================================================================================================================
864 void FSSRFirmwareBase::sendTriggerDataStripCSR(bool send)
865 {
866  BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) send, 24, 1);
867 }
868 
869 //========================================================================================================================
870 void FSSRFirmwareBase::sendTriggerNumberStripCSR(bool send)
871 {
872  BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) send, 25, 1);
873 }
874 
875 //========================================================================================================================
876 void FSSRFirmwareBase::sendBCOStripCSR(bool send)
877 {
878  BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) send, 26, 1);
879 }
880 
881 //========================================================================================================================
882 void FSSRFirmwareBase::enableStreamStripCSR(bool enable)
883 {
884  BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) enable, 27, 1);
885 }
886 
887 //========================================================================================================================
888 void FSSRFirmwareBase::resetDCMStripCSR(bool clear)
889 {
890  BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) clear, 31, 1);
891 }
892 
893 //========================================================================================================================
894 uint32_t FSSRFirmwareBase::waitDCMResetStripCSR(void)
895 {
896  uint32_t bitToCheck = 0;
897  BitManipulator::insertBits(bitToCheck, 1, 31, 2);
898  return bitToCheck;
899 }
900 
901 //========================================================================================================================
902 void FSSRFirmwareBase::resetDAC(void)
903 {
904  BitManipulator::insertBits(stripResetRegisterValue_, 1, 27, 1);
905 }
906 
907 //========================================================================================================================
908 void FSSRFirmwareBase::resetLink(bool channel0, bool channel1, bool channel2,
909  bool channel3, bool channel4, bool channel5)
910 {
911  stripResetRegisterValue_ = 0;
912  BitManipulator::insertBits(stripResetRegisterValue_,
913  ((uint32_t) channel0) + ((uint32_t) channel1 << 1)
914  + ((uint32_t) channel2 << 2) + ((uint32_t) channel3 << 3)
915  + ((uint32_t) channel4 << 4) + ((uint32_t) channel5 << 5),
916  0, 6);
917  BitManipulator::insertBits(stripResetRegisterValue_, 1, 29, 1);
918  /*
919  write(buffer, STRIP_RESET, (1<<28) +
920  ((uint32_t)channel0) +
921  ((uint32_t)channel1<<1) +
922  ((uint32_t)channel2<<2) +
923  ((uint32_t)channel3<<3) +
924  ((uint32_t)channel4<<4) +
925  ((uint32_t)channel5<<5)
926  );
927  */
928 }
929 
930 //========================================================================================================================
931 void FSSRFirmwareBase::clearErrors(bool channel0, bool channel1, bool channel2,
932  bool channel3, bool channel4, bool channel5)
933 {
934  stripResetRegisterValue_ = 0;
935  BitManipulator::insertBits(stripResetRegisterValue_,
936  ((uint32_t) channel0) + ((uint32_t) channel1 << 1)
937  + ((uint32_t) channel2 << 2) + ((uint32_t) channel3 << 3)
938  + ((uint32_t) channel4 << 4) + ((uint32_t) channel5 << 5),
939  0, 6);
940  BitManipulator::insertBits(stripResetRegisterValue_, 1, 29, 1);
941 }
942 
943 //========================================================================================================================
944 void FSSRFirmwareBase::clearFIFO(bool channel0, bool channel1, bool channel2,
945  bool channel3, bool channel4, bool channel5)
946 {
947  stripResetRegisterValue_ = 0;
948  BitManipulator::insertBits(stripResetRegisterValue_,
949  ((uint32_t) channel0) + ((uint32_t) channel1 << 1)
950  + ((uint32_t) channel2 << 2) + ((uint32_t) channel3 << 3)
951  + ((uint32_t) channel4 << 4) + ((uint32_t) channel5 << 5),
952  0, 6);
953  BitManipulator::insertBits(stripResetRegisterValue_, 1, 30, 1);
954 }
955 
956 //========================================================================================================================
957 void FSSRFirmwareBase::resetChip(bool channel0, bool channel1, bool channel2,
958  bool channel3, bool channel4, bool channel5)
959 {
960  stripResetRegisterValue_ = 0;
961  BitManipulator::insertBits(stripResetRegisterValue_,
962  ((uint32_t) channel0) + ((uint32_t) channel1 << 1)
963  + ((uint32_t) channel2 << 2) + ((uint32_t) channel3 << 3)
964  + ((uint32_t) channel4 << 4) + ((uint32_t) channel5 << 5),
965  0, 6);
966  BitManipulator::insertBits(stripResetRegisterValue_, 1, 31, 1);
967 }
968 
969 //========================================================================================================================
970 void FSSRFirmwareBase::setFrequencyRatio(std::string& buffer, int numerator, int denominator)
971 {
972  //The device need to load numerator minus one and denominator minus one, with an internal address of 0x50 and 052 respectively
973  communicationFirmwareInstance_->write(buffer, STRIP_BCO_DCM, 0x80500000 + (numerator - 1)); // Set BCOCLK numerator // was 0x80500003
974  communicationFirmwareInstance_->waitClear(buffer, STRIP_BCO_DCM, 0xf0000000); // Wait DCM write to finish // was 0x80000000
975 
976  communicationFirmwareInstance_->write(buffer, STRIP_BCO_DCM, 0x80520000 + (denominator - 1)); // Set BCOCLK denominator // was 0x80520001
977  communicationFirmwareInstance_->waitClear(buffer, STRIP_BCO_DCM, 0xf0000000); // Wait DCM write to finish - BCO frequency should be 13.513 MHz // was 0x80000000
978 }
979 
980 //========================================================================================================================
981 void FSSRFirmwareBase::BCOOffset(uint32_t offset)
982 {
983  BitManipulator::insertBits(stripTriggerCSRRegisterValue_, offset, 0, 4);
984 }
985 
986 //========================================================================================================================
987 void FSSRFirmwareBase::selectSpyFIFO(uint32_t input)
988 {
989  BitManipulator::insertBits(stripTriggerCSRRegisterValue_, input, 4, 3);
990 }
991 
992 //========================================================================================================================
993 void FSSRFirmwareBase::halt(bool halt)
994 {
995  BitManipulator::insertBits(stripTriggerCSRRegisterValue_, (uint32_t) halt, 7, 1);
996 }
997 
998 //========================================================================================================================
999 void FSSRFirmwareBase::configureStripTriggerUnbiased(std::string& buffer)
1000 {
1001  communicationFirmwareInstance_->write(buffer, STRIP_TRIG_UNBIASED, 0x002805c, false/*clearBuffer*/); // Configure unbiased trigger
1002 }
1003 
1004 //========================================================================================================================
1005 void FSSRFirmwareBase::configureTriggerInputs(std::string& buffer)
1006 {
1007 // communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_0, 0x3f440000); // FSSR GOTHIT trigger input channel 0,1
1008 // communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_1, 0x3f440000); // FSSR GOTHIT trigger input channel 2,3
1009  communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_0, 0x0, false/*clearBuffer*/); // FSSR GOTHIT trigger input channel 0,1
1010  communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_1, 0x0, false/*clearBuffer*/); // FSSR GOTHIT trigger input channel 2,3
1011  communicationFirmwareInstance_->write(buffer, STRIP_TRIG_INPUT_2, 0x0, false/*clearBuffer*/); // FSSR GOTHIT trigger input channel 4,5
1012 }
1013 
1014 //========================================================================================================================
1015 std::string FSSRFirmwareBase::resetSlaveBCO(void)
1016 {
1017  std::string buffer;
1018  /*TODO:make unambiguous by casting to uint32_t*/
1019  communicationFirmwareInstance_->write(buffer, (uint32_t)0xc5000000, (uint32_t)0x00000008);
1020  return buffer;
1021 }
1022 
1023 /*
1024  //========================================================================================================================
1025  void FSSRFirmwareBase::chipID(uint32_t size)
1026  {
1027  BitManipulator::insertBits(stripSCRegisterValue_, size, 0, 5);
1028  }
1029 
1030  //========================================================================================================================
1031  void FSSRFirmwareBase::addressSlowControls(uint32_t size)
1032  {
1033  BitManipulator::insertBits(stripSCRegisterValue_, size, 5, 5);
1034  }
1035 
1036  //========================================================================================================================
1037  void FSSRFirmwareBase::instructionSlowControls(uint32_t size)
1038  {
1039  BitManipulator::insertBits(stripSCRegisterValue_, size, 10, 3);
1040  }
1041 
1042  //========================================================================================================================
1043  void FSSRFirmwareBase::channelreadSelect(uint32_t size)
1044  {
1045  BitManipulator::insertBits(stripSCRegisterValue_, size, 13, 3);
1046  }
1047 
1048  //========================================================================================================================
1049  void FSSRFirmwareBase::channelMask(uint32_t size)
1050  {
1051  BitManipulator::insertBits(stripSCRegisterValue_, size, 16, 8);
1052  }
1053 
1054  //========================================================================================================================
1055  void FSSRFirmwareBase::bitsLength(uint32_t length)
1056  {
1057  BitManipulator::insertBits(stripSCRegisterValue_, length, 26, 3);
1058  }
1059 
1060 
1061  //========================================================================================================================
1062  void FSSRFirmwareBase::syncFallingBCO(bool sync)
1063  {
1064  BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)sync, 28, 1);
1065  }
1066 
1067  //========================================================================================================================
1068  void FSSRFirmwareBase::syncRisingBCO(bool sync)
1069  {
1070  BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)sync, 29, 1);
1071  }
1072 
1073  //========================================================================================================================
1074  void FSSRFirmwareBase::setRaw(bool set)
1075  {
1076  BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)set, 30, 1);
1077  }
1078 
1079  //========================================================================================================================
1080  void FSSRFirmwareBase::initSlowControls(bool init)
1081  {
1082  BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)init, 31, 1);
1083  }
1084 
1085  //========================================================================================================================
1086  void FSSRFirmwareBase::resetCount(bool reset)
1087  {
1088  BitManipulator::insertBits(stripAnalysisCSRRegisterValue_, (uint32_t)reset, 30, 1);
1089  }
1090 
1091  //========================================================================================================================
1092  void FSSRFirmwareBase::setBCO_0(uint32_t void FSSRFirmwareBase::BCOOffset(uint32_t offset)
1093  {
1094  BitManipulator::insertBits(stripTrigCSRRegisterValue_, offset, 0, 4);
1095  }input)
1096  {
1097  BitManipulator::insertBits(trigInputRegisterValue_, input, 0, 8);
1098  }
1099 
1100  //========================================================================================================================
1101  void FSSRFirmwareBase::setBCO_1(uint32_t input)
1102  {
1103  BitManipulator::insertBits(trigInputRegisterValue_, input, 8, 8);
1104  }
1105 
1106  //========================================================================================================================
1107  void FSSRFirmwareBase::trimFracBCO_0(uint32_t input)
1108  {
1109  BitManipulator::insertBits(trigInputRegisterValue_, input, 16, 4);
1110  }
1111 
1112  //========================================================================================================================
1113  void FSSRFirmwareBase::trimFracBCO_1(uint32_t input)
1114  {
1115  BitManipulator::insertBits(trigInputRegisterValue_, input, 20, 4);
1116  }
1117 
1118  //========================================================================================================================
1119  void FSSRFirmwareBase::enable_0(bool enable)
1120  {
1121  BitManipulator::insertBits(trigInputRegisterValue_, (uint32_t)enable, 28, 1);
1122  }
1123 
1124  //========================================================================================================================
1125  void FSSRFirmwareBase::enable_1(bool enable)
1126  {
1127  BitManipulator::insertBits(trigInputRegisterValue_, (uint32_t)enable, 29, 1);
1128  }
1129 
1130  */