otsdaq_components  v2_02_00
PSI46DigFirmware.cc
1 //#include "otsdaq-components/DAQHardware/PSI46DigFirmware.h"
2 //#include "otsdaq-components/DAQHardware/PSI46DigFirmwareDefinitions.h"
3 //#include "otsdaq-core/BitManipulator/BitManipulator.h"
4 //#include "otsdaq-components/DetectorHardware/PSI46DigROCDefinitions.h"
5 //#include "otsdaq-core/MessageFacility/MessageFacility.h"
6 //#include "otsdaq-core/Macros/CoutMacros.h"
7 //#include <sys/socket.h>
8 //#include <netinet/in.h>
9 //#include <arpa/inet.h>
10 //#include <iostream>
11 //#include <cstdlib>
12 //
13 //using namespace ots;
14 //
15 //
17 //PSI46DigFirmware::PSI46DigFirmware(unsigned int version, std::string type) :
18 // FrontEndFirmwareBase(version),
19 // stripCSRRegisterValue_(0)
20 //{
21 // protocolInstance_ = FrontEndFirmwareBase::getInstance(type,version);
22 // assert(protocolInstance_ != NULL);
23 // //returns either new OtsUDPFirmware or new PurdueFirmwareCore,
24 // //now we can call write/read etc with protocol->write, protocol->read, etc
25 //}
26 //
28 //PSI46DigFirmware::~PSI46DigFirmware(void)
29 //{
30 // delete protocolInstance_;
31 // protocolInstance_= NULL;
32 //}
33 //
35 //int PSI46DigFirmware::init(void)
36 //{
37 // return 0;
38 //}
39 //
41 //std::string PSI46DigFirmware::configureClocks(std::string source, double frequency)
42 //{
43 // std::cout << __COUT_HDR_FL__ << "Writing Clock configuration!" << std::endl;
44 //
45 // std::string buffer;
46 // //NoNeedNowwrite(buffer, ETHIO_DESTINATION_PORT, 0x0000b798); // Listen port for ethio stuff
47 //
48 // setPacketSizeStripCSR(6);
49 // setExternalBCOClockSourceStripCSR(source); //(source)
50 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_); // Reset CSR - reset trigger counter, external 27 MHz clock
51 //
52 // resetDCMStripCSR(true);
53 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_); // Set reset to DCM
54 //
55 // resetDCMStripCSR(false);
56 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_); // Clear reset to DCM
57 //
58 // ;
59 // protocolInstance_->waitClear(buffer, STRIP_CSR, waitDCMResetStripCSR()); // Wait for DCM to lock
60 //
61 // protocolInstance_->write(buffer, STRIP_TRIM_CSR, 0x00002000); // MCLKB edge for channel 5 // was 0x00002000
62 //
63 // setFrequencyFromClockState(buffer, frequency);
64 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
65 //
66 // resetDCMStripCSR(true);
67 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
68 //
69 // resetDCMStripCSR(false);
70 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
71 //
72 // protocolInstance_->waitClear(buffer, STRIP_CSR, waitDCMResetStripCSR()); // Wait for DCM to lock
73 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue :" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
74 //
75 // return buffer;
76 //}
77 //
79 //std::string PSI46DigFirmware::resetDetector(int channel)
80 //{
81 // std::cout << __COUT_HDR_FL__ << "Resetting detector!" << std::endl;
82 // std::string buffer;
83 // if (channel == -1)//reset all channels
84 // {
85 // //protocolInstance_->write(buffer,STRIP_RESET,0xd000003f); // Issue reset
86 // protocolInstance_->write(buffer, STRIP_RESET, 0xf000003f); // Issue reset // was 0xf000003f
87 // protocolInstance_->waitClear(buffer, STRIP_RESET, 0xf0000000); // Wait for reset to complete // was 0xf0000000
88 // } else
89 // {
90 // protocolInstance_->write(buffer, STRIP_RESET, 0xf000003f); // Issue reset
91 // protocolInstance_->waitClear(buffer, STRIP_RESET, 0xf0000000); // Wait for reset to complete
92 // }
93 //
94 // return buffer;
95 //}
96 //
98 //std::string PSI46DigFirmware::enableTrigger(void)
99 //{
100 // std::string buffer;
101 // std::cout << __COUT_HDR_FL__ << "Enabling Trigger!!!" << std::endl;
102 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue in :" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
103 //
104 // setHaltStripCSR(1);//WARNING THIS IS CLEARED BY THE MASTER BUT IF THERE IS NO MASTER NOTHING WORKS UNLESS THE BIT IS UNSET
105 // //setHaltStripCSR(0);//WARNING THIS IS CLEARED BY THE MASTER BUT IF THERE IS NO MASTER NOTHING WORKS UNLESS THE BIT IS UNSET
106 // sendTriggerDataStripCSR(true);
107 // sendTriggerNumberStripCSR(true);
108 // sendBCOStripCSR(true);
109 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
110 //
111 // stripTriggerCSRRegisterValue_ = 0;
112 // BCOOffset(4);
113 // protocolInstance_->write(buffer, STRIP_TRIG_CSR, stripTriggerCSRRegisterValue_); // BCO offset // was 0x00000004
114 //
115 // // write(buffer,STRIP_TRIG_INPUT_0,0x1f060040); // PSI46Dig GOTHIT trigger input - timed in for the 27 MHz external clock
116 // // write(buffer,STRIP_TRIG_INPUT_3,0x3f874040); // Unbiased trigger input + external trigger
117 //
118 // configureStripTriggerUnbiased(buffer);
119 //
120 // configureTriggerInputs(buffer);
121 //
122 // //FIXME for IP .36 the number to set is 0x20401000
123 //
124 // if (version_ == 1)
125 // protocolInstance_->write(buffer, STRIP_TRIG_INPUT_3, 0x20401000); // Turn on streaming hits along with BCO data
126 // else if (version_ == 2)
127 // protocolInstance_->write(buffer, STRIP_TRIG_INPUT_3, 0x20301000); // Turn on streaming hits along with BCO data
128 // else
129 // {
130 // std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "what version is this?" << version_ << std::endl;
131 // assert(0);
132 // }
133 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue out:" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
134 // std::cout << __COUT_HDR_FL__ << "Done enabling Trigger!!!" << std::endl;
135 //
136 // return buffer;
137 //}
138 //
140 //std::string PSI46DigFirmware::resetBCO(void)
141 //{
142 // std::cout << __COUT_HDR_FL__ << "Reset BCO!!!" << std::endl;
143 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue in :" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
144 // std::string buffer;
145 //
146 // resetTriggerCounterStripCSR(buffer);
147 // //write(buffer, STRIP_CSR, stripCSRRegisterValue_);//the write is done in the reset
148 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue :" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
149 //
150 // //msg->Write(STRIP_SC_CSR,0x90000b95|(chmask<<16));
151 // //write(buffer,STRIP_SC_CSR,0x900f0b95);// This is the <SCR,set> command with the bit set to sync SHIFT with BCO=0.
152 //
153 //
154 // enableBCOStripCSR(true);
155 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
156 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue out:" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
157 // std::cout << __COUT_HDR_FL__ << "Done reset BCO!!!" << std::endl;
158 //
159 // return buffer;
160 //}
161 //
163 //std::string PSI46DigFirmware::startStream(bool channel0, bool channel1, bool channel2, bool channel3, bool channel4, bool channel5)
164 //{
165 // std::cout << __COUT_HDR_FL__ << "Start Stream!" << std::endl;
166 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue in:" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
167 // std::string buffer;
168 //
169 // std::cout << __COUT_HDR_FL__ << " channel0 " << channel0 << " channel1 " << channel1 << " channel2 " << channel2 << " channel3 " << channel3 << " channel4 " << channel4 << " channel5 " << channel5 << std::endl;
170 //
171 // enableChannelsStripCSR(channel0, channel1, channel2, channel3, channel4, channel5);
172 // // if (version_ == 1)
173 // // enableChannelsStripCSR(true, true, true, true, false, false);
174 // // else if (version_ == 2)
175 // // enableChannelsStripCSR(true, true, true, true, true, true);
176 //
177 // enableStreamStripCSR(true); // Turn on streaming hits along with BCO data // was 0x0f000f30
178 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
179 //
180 // std::cout << __COUT_HDR_FL__ << "stripCSRRegisterValue out:" << std::hex << stripCSRRegisterValue_ << std::dec << std::endl;
181 // std::cout << __COUT_HDR_FL__ << "Done start Stream!" << std::endl;
182 //
183 // return buffer;
184 //}
185 //
187 //std::string PSI46DigFirmware::stopStream(void)
188 //{
189 // std::string buffer;
190 // enableChannelsStripCSR(false, false, false, false, false, false);
191 // enableStreamStripCSR(false);
192 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
193 // return buffer;
194 //}
195 //
197 //void PSI46DigFirmware::makeDACSequence(FirmwareSequence<uint64_t>& sequence,
198 // unsigned int channel, const ROCStream& rocStream)
199 //{
200 // const ROCDACs& rocDACs = rocStream.getROCDACs();
201 // for (DACList::const_iterator it = rocDACs.getDACList().begin(); it
202 // != rocDACs.getDACList().end(); it++)
203 // {
204 // //if(it->first != "SendData" && it->first != "RejectHits") continue;
205 // uint64_t data = PSI46DigROCDefinitions::makeDACWriteCommand(
206 // rocStream.getFEWROCAddress(), it->first, it->second.second);
207 // sequence.pushBack(ChannelFIFOAddress[channel], data);
208 // sequence.pushBack(ChannelFIFOAddress[channel],
209 // BitManipulator::insertBits(data, (uint64_t) 0x48, 56, 8));
210 // //set WRITE
211 // sequence.pushBack(ChannelFIFOAddress[channel],
212 // BitManipulator::insertBits(data, (uint64_t) 1, 60, 1));
213 // //clr WRITE
214 // sequence.pushBack(ChannelFIFOAddress[channel],
215 // BitManipulator::insertBits(data, (uint64_t) 0, 60, 1));
216 // //clr TALK
217 // sequence.pushBack(ChannelFIFOAddress[channel],
218 // BitManipulator::insertBits(data, (uint64_t) 0, 62, 1));
219 // sequence.pushBack(ChannelFIFOAddress[channel],
220 // BitManipulator::insertBits(data, (uint64_t) 0x40, 56, 8));
221 // //break;
222 // }
223 //}
224 //
226 //void PSI46DigFirmware::makeDACSequence(FirmwareSequence<uint32_t>& sequence,
227 // unsigned int channel, const ROCStream& rocStream)
228 //{
229 // const ROCDACs& rocDACs = rocStream.getROCDACs();
230 // for (DACList::const_iterator it = rocDACs.getDACList().begin(); it
231 // != rocDACs.getDACList().end(); it++)
232 // {
233 // /*RYAN
234 // //if(it->first != "SendData" && it->first != "RejectHits") continue;
235 // uint64_t data = PSI46DigROCDefinitions::makeDACWriteCommand(rocStream.getFEWROCAddress(), it->first, it->second.second);
236 // sequence.pushBack(ChannelFIFOAddress[channel], data);
237 // sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)0x48,56,8));
238 // //set WRITE
239 // sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)1,60,1));
240 // //clr WRITE
241 // sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)0,60,1));
242 // //clr TALK
243 // sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)0,62,1));
244 // sequence.pushBack(ChannelFIFOAddress[channel], BitManipulator::insertBits(data,(uint32_t)0x40,56,8));
245 // */
246 //
247 // //if(it->first != "SendData" && it->first != "RejectHits") continue;
248 // uint32_t data = PSI46DigROCDefinitions::makeDACWriteHeader(
249 // rocStream.getFEWROCAddress(), it->first);
250 // //Insert channel
251 // BitManipulator::insertBits(data, 1, 16 + channel, 1);
252 // sequence.pushBack(ChannelFIFOAddress[channel], it->second.second);
253 // std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Register: " << it->first << " value: "
254 // << it->second.second << std::hex << " -> Data: " << data << std::dec
255 // << std::endl;
256 // sequence.pushBack(STRIP_SC_CSR, data);
257 // }
258 //}
259 //
261 //void PSI46DigFirmware::makeDACBuffer(std::string& buffer,
262 // unsigned int channel, const ROCStream& rocStream)
263 //{
264 // std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Channel: " << channel << std::endl;
265 // const ROCDACs& rocDACs = rocStream.getROCDACs();
266 // for (DACList::const_iterator it = rocDACs.getDACList().begin(); it != rocDACs.getDACList().end(); it++)
267 // {
268 // std::string bufferElement;
269 // protocolInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000);
270 // uint32_t registerHeader = 0;
271 // //FIXME This must go in the PSI46DigROCDefinitions stuff
272 // if (it->first != "RejectHits" && it->first != "SendData")
273 // {
274 // protocolInstance_->write(bufferElement, ChannelFIFOAddress[channel], it->second.second);
275 // registerHeader = PSI46DigROCDefinitions::makeDACWriteHeader(
276 // rocStream.getFEWROCAddress(), it->first);
277 // //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Register: " << it->first << " value: " << it->second.second << hex << " -> Data: " << registerHeader << dec << std::endl;
278 // //Insert channel
279 // BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
280 // }
281 // else
282 // {
283 // if (it->second.second == 1 || it->second.second == 2)
284 // {
285 // registerHeader = PSI46DigROCDefinitions::makeDACSetHeader(
286 // rocStream.getFEWROCAddress(), it->first);
287 // //Insert channel
288 // BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
289 // }
290 // else if (it->second.second == 0 || it->second.second == 5)
291 // {
292 // registerHeader = PSI46DigROCDefinitions::makeDACResetHeader(
293 // rocStream.getFEWROCAddress(), it->first);
294 // //Insert channel
295 // BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
296 // }
297 // else
298 // std::cout << __COUT_HDR_FL__ << "Register value for : " << it->first
299 // << " doesn't have a value I expect -> value = "
300 // << it->second.second << std::endl;
301 //
302 // }
303 // //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Register: " << it->first << " value: " << it->second.second << hex << " -> Data: " << registerHeader << dec << std::endl;
304 // protocolInstance_->write(bufferElement, STRIP_SC_CSR, registerHeader);
305 // protocolInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000);
306 //
307 // //buffer.push_back(bufferElement);
308 // buffer += bufferElement;
309 // //break;
310 // }
311 //}
312 //
314 //void PSI46DigFirmware:: makeDACBuffer(std::vector<std::string>& buffer, unsigned int channel, const ROCStream& rocStream)
315 //{
316 //
317 // std::cout << __COUT_HDR_FL__ << "\tMaking DAC Buffer" << std::endl;
318 //
319 // int limitCount = 0;
320 // unsigned int singleVectorCount = 0;
321 //
322 // std::string alternateBuffer;
323 //
324 // std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Channel: " << channel << std::endl;
325 // const ROCDACs& rocDACs = rocStream.getROCDACs();
326 // //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Number of DACs: " << rocDACs.getDACList().size() << std::endl;
327 // std::string bufferElement;
328 // for (DACList::const_iterator it = rocDACs.getDACList().begin(); it != rocDACs.getDACList().end(); it++)
329 // {
330 // protocolInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000);
331 // uint32_t registerHeader = 0;
332 // //FIXME This must go in the PSI46DigROCDefinitions stuff
333 // if (it->first != "RejectHits" && it->first != "SendData")
334 // {
335 // protocolInstance_->write(bufferElement, ChannelFIFOAddress[channel], it->second.second);
336 // registerHeader = PSI46DigROCDefinitions::makeDACWriteHeader(
337 // rocStream.getFEWROCAddress(), it->first);
338 // std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Register: " << it->first << " value: " << it->second.second << std::hex << " -> Data: " << registerHeader << std::dec << std::endl;
339 // //Insert channel
340 // BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
341 // }
342 // else
343 // {
344 // if (it->second.second == 1 || it->second.second == 2)
345 // {
346 // registerHeader = PSI46DigROCDefinitions::makeDACSetHeader(
347 // rocStream.getFEWROCAddress(), it->first);
348 // //Insert channel
349 // BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
350 // }
351 // else if (it->second.second == 0 || it->second.second == 5)
352 // {
353 // registerHeader = PSI46DigROCDefinitions::makeDACResetHeader(
354 // rocStream.getFEWROCAddress(), it->first);
355 // //Insert channel
356 // BitManipulator::insertBits(registerHeader, 1, 16 + channel, 1);
357 // }
358 // else
359 // std::cout << __COUT_HDR_FL__ << "Register value for : " << it->first
360 // << " doesn't have a value I expect -> value = "
361 // << it->second.second << std::endl;
362 //
363 // }
364 // //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Register: " << it->first << " value: " << it->second.second << hex << " -> Data: " << registerHeader << dec << std::endl;
365 // protocolInstance_->write(bufferElement, STRIP_SC_CSR, registerHeader);
366 // protocolInstance_->waitClear(bufferElement, STRIP_SC_CSR, 0x80000000);
367 //
368 // //alternateBuffer += bufferElement;
369 // limitCount++;
370 // singleVectorCount++;
371 //
372 // if (limitCount == STIB_DAC_WRITE_MAX)
373 // {
374 // std::cout << __COUT_HDR_FL__ << "\tBuffer lenght:" << bufferElement.size() << std::endl;
375 // buffer.push_back(bufferElement);
376 // limitCount = 0;
377 // bufferElement.clear();
378 // }
379 // else if (singleVectorCount == rocDACs.getDACList().size()) //case for imcomplete packet
380 // {
381 // buffer.push_back(bufferElement);
382 // }
383 //
384 // //buffer.push_back(bufferElement);
385 // //break;
386 // }
387 // std::cout << __COUT_HDR_FL__ << "\tDone making DAC Buffer" << std::endl;
388 //
389 //}
390 //
392 //void PSI46DigFirmware::makeMaskBuffer(std::string& buffer, unsigned int channel,
393 // const ROCStream& rocStream)
394 //{
395 // std::cout << __COUT_HDR_FL__ << "Making mask! " << std::endl;
396 // makeMaskBuffer(buffer, channel, rocStream, "Kill");
397 // // makeMaskSequence(buffer, channel, rocStream, "Inject");
398 //}
399 //
401 //void PSI46DigFirmware::makeMaskBuffer(std::string& buffer, unsigned int channel, const ROCStream& rocStream, const std::string& registerName)
402 //{
403 // std::cout << __COUT_HDR_FL__ << "\tMaking mask! " << std::endl;
404 // int chipId = rocStream.getFEWROCAddress();
405 // std::string mask = rocStream.getROCMask();
406 // std::cout << __COUT_HDR_FL__ << "\tMask length: " << mask.length() << std::endl;
407 //
408 // unsigned int data[4] = { 0, 0, 0, 0 };
409 //
410 // char val;
411 // //int j = 0;
412 // for (unsigned int d = 0; d < 4; d++)
413 // { //d goes from 0 to 4. 4 bytes
414 // //std::cout << __COUT_HDR_FL__ << "---------------------" << d << "-------------------" << std::endl;
415 // for (unsigned int m = 0; m < 8 * 4; m++)
416 // { //m goes from 0 to 31, since each byte has 8 bits, there are 32 bits
417 // 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
418 // //std::cout << __COUT_HDR_FL__ << "---------------------" << j++ << std::endl;
419 // //std::cout << __COUT_HDR_FL__ << "data[" << d << "] before: " << hex << data[d] << dec << std::endl;
420 // data[d] |= (unsigned int) atoi(&val) << (8 * 4 - 1 - m);
421 // //std::cout << __COUT_HDR_FL__ << "(unsigned int) atoi(&val): " << (unsigned int) atoi(&val) << std::endl;
422 // //std::cout << __COUT_HDR_FL__ << "data[" << d << "] after: " << hex << data[d] << dec << std::endl;
423 // //std::cout << __COUT_HDR_FL__ << hex << "D: " << data[d] << " Val: " << (unsigned int)atoi(&val) << " index: " << dec << (8*4-1-m) << " bit: " << mask[(8*4*d)+m] << dec << std::endl;
424 // }
425 // //
426 // }
427 //
428 // int i, ierr;
429 // unsigned int w;
430 // unsigned char len = 4;
431 // unsigned char addr = 17;//Kill
432 // unsigned char bitMask = 1 << channel;
433 // unsigned char inst = WRITE;
434 //
435 // protocolInstance_->waitClear(buffer, STRIP_SC_CSR, 0x80000000);
436 //
437 // for (i = 0; i < 4; i++)
438 // //write(buffer, STRIP_SCI + 4 * i, data[i]);
439 // protocolInstance_->write(buffer, STRIP_SCI + 4 * (4 - i - 1), data[i]);
440 //
441 // w = 0x80000000 | (len << 24) | (bitMask << 16) | (inst << 10) | (addr << 5) | chipId;
442 //
443 // ierr = protocolInstance_->write(buffer, STRIP_SC_CSR, w);
444 //
445 // protocolInstance_->waitClear(buffer, STRIP_SC_CSR, 0x80000000);
446 //}
447 //
449 //void PSI46DigFirmware::makeMaskSequence(FirmwareSequence<uint64_t>& sequence,
450 // unsigned int channel, const ROCStream& rocStream)
451 //{
452 // std::cout << __COUT_HDR_FL__ << "Making mask! " << std::endl;
453 // makeMaskSequence(sequence, channel, rocStream, "Kill");
454 // // makeMaskSequence(sequence, channel, rocStream, "Inject");
455 //}
456 //
458 //void PSI46DigFirmware::makeMaskSequence(FirmwareSequence<uint32_t>& sequence,
459 // unsigned int channel, const ROCStream& rocStream)
460 //{
461 // std::cout << __COUT_HDR_FL__ << "Making mask! " << std::endl;
462 // makeMaskSequence(sequence, channel, rocStream, "Kill");
463 // // makeMaskSequence(channel,rocStream,sequence,"Inject");
464 //}
465 //
467 //void PSI46DigFirmware::makeMaskSequence(FirmwareSequence<uint64_t>& sequence,
468 // unsigned int channel, const ROCStream& rocStream,
469 // const std::string& registerName)
470 //{
471 // int chipId = rocStream.getFEWROCAddress();//9, 14 or 21 bcast
472 // std::string mask = rocStream.getROCMask();
473 // std::cout << __COUT_HDR_FL__ << "Mask length: " << mask.length() << std::endl;
474 //
475 // uint64_t uInt64Data = 0;
476 // std::string stringData = "";
477 //
478 // //have to manually set every bit for mask writes.
479 // //reset fifo
480 // //download every bit (shift_in and shift_ctrl) to fifo (setup muxes and control lines)
481 // //configure muxes for readout
482 // //commence readout
483 //
484 // //FIFO Controls - byte 5 (7:0)
485 // //7 - FIFO Clock
486 // //6 - Shift Ctrl bit
487 // //MASK_CELL_H - Shift In bit
488 // //MUX Controls - byte 0 (7:0)
489 // //7 - Read En/Output MUX sel (1 for masks)
490 // //1 - Write En for mux
491 // //0 - Reset Fifo
492 //
493 // //reset fifo
494 // BitManipulator::insertBits(uInt64Data, 0x1, 56, 8);
495 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
496 //
497 // //configure fifo for write
498 // BitManipulator::insertBits(uInt64Data, 0x2, 56, 8);
499 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
500 //
501 // //Download every bit (shift_in and shift_control) to fifo (setup muxes and control lines)
502 // //Bit 7 of data is FIFO clock, bit 6 is shift_control, bit 5 is shift_in
503 // //start bits (ctrl 0, data 0 => ctrl 1, data 0)
504 //
505 // BitManipulator::insertBits(uInt64Data, 0x40, 16, 8);//(0<<7) | (1<<6) | (0<<5)
506 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
507 // BitManipulator::insertBits(uInt64Data, 0xc0, 16, 8);//(1<<7) | (1<<6) | (0<<5) -> clock the data in the fifo
508 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
509 //
510 // stringData = PSI46DigROCDefinitions::makeMaskWriteCommand(chipId,
511 // registerName, mask);
512 //
513 // uint8_t data;
514 // for (unsigned int s = 0; s < stringData.length(); s++)
515 // for (int b = 8 - 1; b >= 0 && (s * 8 + 8 - b < 13 + 128); b--)
516 // {
517 // //std::cout << __COUT_HDR_FL__ << "S: " << s << " val: " << std::stringData.data()[s] << " b: " << b << " bit: " << ((stringData.data()[s]>>b)&1) << std::endl;
518 // data = 0x40 | (((stringData.data()[s] >> b) & 1) << 5);
519 // BitManipulator::insertBits(uInt64Data, (uint64_t) data, 16, 8);
520 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
521 // data |= 0x80;
522 // BitManipulator::insertBits(uInt64Data, (uint64_t) data, 16, 8);
523 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
524 // }
525 //
526 // //reset Shift Control
527 // BitManipulator::insertBits(uInt64Data, 0x0, 16, 8);
528 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
529 // BitManipulator::insertBits(uInt64Data, 0x80, 16, 8);
530 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
531 //
532 // //configure muxes for readout
533 // BitManipulator::insertBits(uInt64Data, 0x0, 56, 8);
534 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
535 //
536 // //commence readout
537 // BitManipulator::insertBits(uInt64Data, 0x80, 56, 8);
538 // sequence.pushBack(ChannelFIFOAddress[channel], uInt64Data);
539 //
540 //}
541 //
543 //void PSI46DigFirmware::makeMaskSequence(FirmwareSequence<uint32_t>& sequence,
544 // unsigned int channel, const ROCStream& rocStream,
545 // const std::string& registerName)
546 //{}
547 //
549 //std::string PSI46DigFirmware::readCSRRegister()
550 //{
551 // std::string buffer;
552 // read(buffer,STRIP_CSR);
553 // return buffer;
554 //}
555 //
557 //void PSI46DigFirmware::setFrequencyFromClockState(std::string& buffer, double frequency)
558 //{
559 // std::cout << __COUT_HDR_FL__ << "Setting up clock frequency!!!" << std::endl;
560 //
561 // int quotient;
562 // int numerator;
563 // int denominator;
564 // double realClockFrequency;
565 //
566 // if (BitManipulator::readBits(stripCSRRegisterValue_, 17, 1) == 1) //if fastBCO is enabled
567 // quotient = 4;
568 // else //normal cases
569 // quotient = 8;
570 //
571 // if (isClockStateExternal()) //base freq: 54MHz
572 // {
573 // realClockFrequency = EXTERNAL_CLOCK_FREQUENCY / quotient; //this is the REAL frequency being used
574 // }
575 // else //base freq: 66.667MHz
576 // {
577 // realClockFrequency = INTERNAL_CLOCK_FREQUENCY / quotient; //this is the REAL frequency being used
578 // }
579 //
580 // double factor = frequency / realClockFrequency;
581 //
582 // //The device needs the denominator and the denominator to be load into a 5 bit register
583 // //It will take two initial numerator and denominator bigger than necessary (to do not loose precision)
584 // //and divide them for their gcd. If they still do not fit in 5 bit, they are trunked (divided by 2)
585 // //untill they are less than 32
586 // numerator = factor * 100; //we will work with 2 digits precision after the decimal point
587 // denominator = 100;
588 //
589 // do
590 // {
591 // //We will need the GCD at some point in order to simplify fractions //taken from other sources
592 // int gcd = numerator;
593 // int rest = denominator;
594 // int tmp;
595 //
596 // while (rest != 0)
597 // {
598 // tmp = rest;
599 // rest = gcd % tmp;
600 // gcd = tmp;
601 // }
602 // //Done finding the GCD
603 //
604 // if (gcd == 1) //if there's no GCD, just divide by 2 to find the nearest approssimation with less bits
605 // {
606 // numerator /= 2;
607 // denominator /= 2;
608 // }
609 // else
610 // {
611 // numerator /= gcd;
612 // denominator /= gcd;
613 // }
614 //
615 // }
616 // while (denominator >= 32 || numerator >= 32);
617 // std::cout << __COUT_HDR_FL__ << "Numerator: " << numerator << std::endl;
618 // std::cout << __COUT_HDR_FL__ << "Denominator: " << denominator << std::endl;
619 // setFrequencyRatio(buffer, numerator, denominator);
620 // std::cout << __COUT_HDR_FL__ << "Done with clock frequency setup!!!" << std::endl;
621 //}
623 //bool PSI46DigFirmware::isClockStateExternal() //returns true if the clock state is External
624 //{
625 // if (BitManipulator::readBits(stripCSRRegisterValue_, 16, 1) == 1)
626 // return true;
627 // else
628 // return false;
629 //}
630 //
632 //void PSI46DigFirmware::setCSRRegister(uint32_t total)
633 //{
634 // stripCSRRegisterValue_ = total;
635 //}
636 //
638 //void PSI46DigFirmware::setPacketSizeStripCSR(uint32_t size)
639 //{
640 // if (size > 31)
641 // std::cout << __COUT_HDR_FL__
642 // << "ERROR: Maximum packet size is 31 while here you are trying to set "
643 // << size << " packets!" << std::endl;
644 // BitManipulator::insertBits(stripCSRRegisterValue_, size, 3, 5);
645 // //write(buffer,STRIP_CSR, stripSCRRegisterValue_);
646 //}
647 //
649 //void PSI46DigFirmware::enableChannelsStripCSR(bool channel0, bool channel1,
650 // bool channel2, bool channel3, bool channel4, bool channel5)
651 //{
652 // BitManipulator::insertBits(stripCSRRegisterValue_, ((uint32_t) channel0)
653 // + ((uint32_t) channel1 << 1) + ((uint32_t) channel2 << 2)
654 // + ((uint32_t) channel3 << 3) + ((uint32_t) channel4 << 4)
655 // + ((uint32_t) channel5 << 5), 8, 6);
656 //}
657 //
659 //void PSI46DigFirmware::setExternalBCOClockSourceStripCSR(std::string clockSource)
660 //{
661 // if (clockSource == "External")
662 // BitManipulator::insertBits(stripCSRRegisterValue_, 1, 16, 1);
663 // else if (clockSource == "Internal")
664 // BitManipulator::insertBits(stripCSRRegisterValue_, 0, 16, 1);
665 //}
666 //
668 //void PSI46DigFirmware::setHaltStripCSR(bool set)
669 //{
670 // BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) set, 17, 1);
671 //}
672 //
674 //void PSI46DigFirmware::enableBCOStripCSR(bool enable)
675 //{
676 // BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) enable, 19, 1);
677 //}
678 //
680 //void PSI46DigFirmware::flushBuffersStripCSR(void)
681 //{
682 // BitManipulator::insertBits(stripCSRRegisterValue_, 1, 20, 1);
683 //}
684 //
686 //void PSI46DigFirmware::resetTriggerCounterStripCSR(std::string& buffer)
687 //{
688 // BitManipulator::insertBits(stripCSRRegisterValue_, 1, 21, 1);
689 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
690 //
691 // BitManipulator::insertBits(stripCSRRegisterValue_, 0, 21, 1);
692 // protocolInstance_->write(buffer, STRIP_CSR, stripCSRRegisterValue_);
693 //}
694 //
696 //void PSI46DigFirmware::resetBCOCounterStripCSR(void)
697 //{
698 // BitManipulator::insertBits(stripCSRRegisterValue_, 1, 22, 1);
699 //}
700 //
702 //void PSI46DigFirmware::enableTriggerStripCSR(bool enable)
703 //{
704 // BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) enable, 23, 1);
705 //}
706 //
708 //void PSI46DigFirmware::sendTriggerDataStripCSR(bool send)
709 //{
710 // BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) send, 24, 1);
711 //}
712 //
714 //void PSI46DigFirmware::sendTriggerNumberStripCSR(bool send)
715 //{
716 // BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) send, 25, 1);
717 //}
718 //
720 //void PSI46DigFirmware::sendBCOStripCSR(bool send)
721 //{
722 // BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) send, 26, 1);
723 //}
724 //
726 //void PSI46DigFirmware::enableStreamStripCSR(bool enable)
727 //{
728 // BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) enable, 27, 1);
729 //}
730 //
732 //void PSI46DigFirmware::resetDCMStripCSR(bool clear)
733 //{
734 // BitManipulator::insertBits(stripCSRRegisterValue_, (uint32_t) clear, 31, 1);
735 //}
736 //
738 //uint32_t PSI46DigFirmware::waitDCMResetStripCSR(void)
739 //{
740 // uint32_t bitToCheck = 0;
741 // BitManipulator::insertBits(bitToCheck, 1, 31, 2);
742 // return bitToCheck;
743 //}
744 //
746 //void PSI46DigFirmware::resetDAC(void)
747 //{
748 // BitManipulator::insertBits(stripResetRegisterValue_, 1, 27, 1);
749 //}
750 //
752 //void PSI46DigFirmware::resetLink(bool channel0, bool channel1, bool channel2,
753 // bool channel3, bool channel4, bool channel5)
754 //{
755 // stripResetRegisterValue_ = 0;
756 // BitManipulator::insertBits(stripResetRegisterValue_,
757 // ((uint32_t) channel0) + ((uint32_t) channel1 << 1)
758 // + ((uint32_t) channel2 << 2) + ((uint32_t) channel3 << 3)
759 // + ((uint32_t) channel4 << 4) + ((uint32_t) channel5 << 5),
760 // 0, 6);
761 // BitManipulator::insertBits(stripResetRegisterValue_, 1, 29, 1);
762 // /*
763 // write(buffer, STRIP_RESET, (1<<28) +
764 // ((uint32_t)channel0) +
765 // ((uint32_t)channel1<<1) +
766 // ((uint32_t)channel2<<2) +
767 // ((uint32_t)channel3<<3) +
768 // ((uint32_t)channel4<<4) +
769 // ((uint32_t)channel5<<5)
770 // );
771 // */
772 //}
773 //
775 //void PSI46DigFirmware::clearErrors(bool channel0, bool channel1, bool channel2,
776 // bool channel3, bool channel4, bool channel5)
777 //{
778 // stripResetRegisterValue_ = 0;
779 // BitManipulator::insertBits(stripResetRegisterValue_,
780 // ((uint32_t) channel0) + ((uint32_t) channel1 << 1)
781 // + ((uint32_t) channel2 << 2) + ((uint32_t) channel3 << 3)
782 // + ((uint32_t) channel4 << 4) + ((uint32_t) channel5 << 5),
783 // 0, 6);
784 // BitManipulator::insertBits(stripResetRegisterValue_, 1, 29, 1);
785 //}
786 //
788 //void PSI46DigFirmware::clearFIFO(bool channel0, bool channel1, bool channel2,
789 // bool channel3, bool channel4, bool channel5)
790 //{
791 // stripResetRegisterValue_ = 0;
792 // BitManipulator::insertBits(stripResetRegisterValue_,
793 // ((uint32_t) channel0) + ((uint32_t) channel1 << 1)
794 // + ((uint32_t) channel2 << 2) + ((uint32_t) channel3 << 3)
795 // + ((uint32_t) channel4 << 4) + ((uint32_t) channel5 << 5),
796 // 0, 6);
797 // BitManipulator::insertBits(stripResetRegisterValue_, 1, 30, 1);
798 //}
799 //
801 //void PSI46DigFirmware::resetChip(bool channel0, bool channel1, bool channel2,
802 // bool channel3, bool channel4, bool channel5)
803 //{
804 // stripResetRegisterValue_ = 0;
805 // BitManipulator::insertBits(stripResetRegisterValue_,
806 // ((uint32_t) channel0) + ((uint32_t) channel1 << 1)
807 // + ((uint32_t) channel2 << 2) + ((uint32_t) channel3 << 3)
808 // + ((uint32_t) channel4 << 4) + ((uint32_t) channel5 << 5),
809 // 0, 6);
810 // BitManipulator::insertBits(stripResetRegisterValue_, 1, 31, 1);
811 //}
812 //
814 //void PSI46DigFirmware::setFrequencyRatio(std::string& buffer, int numerator, int denominator)
815 //{
816 // //The device need to load numerator minus one and denominator minus one, with an internal address of 0x50 and 052 respectively
817 // protocolInstance_->write(buffer, STRIP_BCO_DCM, 0x80500000 + (numerator - 1)); // Set BCOCLK numerator // was 0x80500003
818 // protocolInstance_->waitClear(buffer, STRIP_BCO_DCM, 0xf0000000); // Wait DCM write to finish // was 0x80000000
819 //
820 // protocolInstance_->write(buffer, STRIP_BCO_DCM, 0x80520000 + (denominator - 1)); // Set BCOCLK denominator // was 0x80520001
821 // protocolInstance_->waitClear(buffer, STRIP_BCO_DCM, 0xf0000000); // Wait DCM write to finish - BCO frequency should be 13.513 MHz // was 0x80000000
822 //}
823 //
825 //void PSI46DigFirmware::BCOOffset(uint32_t offset)
826 //{
827 // BitManipulator::insertBits(stripTriggerCSRRegisterValue_, offset, 0, 4);
828 //}
829 //
831 //void PSI46DigFirmware::selectSpyFIFO(uint32_t input)
832 //{
833 // BitManipulator::insertBits(stripTriggerCSRRegisterValue_, input, 4, 3);
834 //}
835 //
837 //void PSI46DigFirmware::halt(bool halt)
838 //{
839 // BitManipulator::insertBits(stripTriggerCSRRegisterValue_, (uint32_t) halt, 7, 1);
840 //}
841 //
843 //void PSI46DigFirmware::configureStripTriggerUnbiased(std::string& buffer)
844 //{
845 // protocolInstance_->write(buffer, STRIP_TRIG_UNBIASED, 0x002805c); // Configure unbiased trigger
846 //}
847 //
849 //void PSI46DigFirmware::configureTriggerInputs(std::string& buffer)
850 //{
851 // protocolInstance_->write(buffer, STRIP_TRIG_INPUT_0, 0x3f440000); // PSI46Dig GOTHIT trigger input channel 0,1
852 // protocolInstance_->write(buffer, STRIP_TRIG_INPUT_1, 0x3f440000); // PSI46Dig GOTHIT trigger input channel 2,3
853 // protocolInstance_->write(buffer, STRIP_TRIG_INPUT_2, 0x0); // PSI46Dig GOTHIT trigger input channel 4,5
854 //}
855 //
857 // //========================================================================================================================
858 // void PSI46DigFirmware::chipID(uint32_t size)
859 // {
860 // BitManipulator::insertBits(stripSCRegisterValue_, size, 0, 5);
861 // }
862 //
863 // //========================================================================================================================
864 // void PSI46DigFirmware::addressSlowControls(uint32_t size)
865 // {
866 // BitManipulator::insertBits(stripSCRegisterValue_, size, 5, 5);
867 // }
868 //
869 // //========================================================================================================================
870 // void PSI46DigFirmware::instructionSlowControls(uint32_t size)
871 // {
872 // BitManipulator::insertBits(stripSCRegisterValue_, size, 10, 3);
873 // }
874 //
875 // //========================================================================================================================
876 // void PSI46DigFirmware::channelreadSelect(uint32_t size)
877 // {
878 // BitManipulator::insertBits(stripSCRegisterValue_, size, 13, 3);
879 // }
880 //
881 // //========================================================================================================================
882 // void PSI46DigFirmware::channelMask(uint32_t size)
883 // {
884 // BitManipulator::insertBits(stripSCRegisterValue_, size, 16, 8);
885 // }
886 //
887 // //========================================================================================================================
888 // void PSI46DigFirmware::bitsLength(uint32_t length)
889 // {
890 // BitManipulator::insertBits(stripSCRegisterValue_, length, 26, 3);
891 // }
892 //
893 //
894 // //========================================================================================================================
895 // void PSI46DigFirmware::syncFallingBCO(bool sync)
896 // {
897 // BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)sync, 28, 1);
898 // }
899 //
900 // //========================================================================================================================
901 // void PSI46DigFirmware::syncRisingBCO(bool sync)
902 // {
903 // BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)sync, 29, 1);
904 // }
905 //
906 // //========================================================================================================================
907 // void PSI46DigFirmware::setRaw(bool set)
908 // {
909 // BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)set, 30, 1);
910 // }
911 //
912 // //========================================================================================================================
913 // void PSI46DigFirmware::initSlowControls(bool init)
914 // {
915 // BitManipulator::insertBits(stripSCRegisterValue_, (uint32_t)init, 31, 1);
916 // }
917 //
918 // //========================================================================================================================
919 // void PSI46DigFirmware::resetCount(bool reset)
920 // {
921 // BitManipulator::insertBits(stripAnalysisCSRRegisterValue_, (uint32_t)reset, 30, 1);
922 // }
923 //
924 // //========================================================================================================================
925 // void PSI46DigFirmware::setBCO_0(uint32_t void PSI46DigFirmware::BCOOffset(uint32_t offset)
926 // {
927 // BitManipulator::insertBits(stripTrigCSRRegisterValue_, offset, 0, 4);
928 // }input)
929 // {
930 // BitManipulator::insertBits(trigInputRegisterValue_, input, 0, 8);
931 // }
932 //
933 // //========================================================================================================================
934 // void PSI46DigFirmware::setBCO_1(uint32_t input)
935 // {
936 // BitManipulator::insertBits(trigInputRegisterValue_, input, 8, 8);
937 // }
938 //
939 // //========================================================================================================================
940 // void PSI46DigFirmware::trimFracBCO_0(uint32_t input)
941 // {
942 // BitManipulator::insertBits(trigInputRegisterValue_, input, 16, 4);
943 // }
944 //
945 // //========================================================================================================================
946 // void PSI46DigFirmware::trimFracBCO_1(uint32_t input)
947 // {
948 // BitManipulator::insertBits(trigInputRegisterValue_, input, 20, 4);
949 // }
950 //
951 // //========================================================================================================================
952 // void PSI46DigFirmware::enable_0(bool enable)
953 // {
954 // BitManipulator::insertBits(trigInputRegisterValue_, (uint32_t)enable, 28, 1);
955 // }
956 //
957 // //========================================================================================================================
958 // void PSI46DigFirmware::enable_1(bool enable)
959 // {
960 // BitManipulator::insertBits(trigInputRegisterValue_, (uint32_t)enable, 29, 1);
961 // }
962 //
963 // */
964 //
965 //
966 //
967 //
973 //#include "otsdaq-core/Macros/CoutMacros.h"
2196 //