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