otsdaq_components  v2_04_01
FSSRFirmwareBase.h
1 #ifndef _ots_FSSRFirmware_h_
2 #define _ots_FSSRFirmware_h_
3 
4 #include <string>
5 
6 #include "otsdaq-components/DAQHardware/FirmwareSequence.h" /* for FirmwareSequence */
7 #include "otsdaq-components/DetectorConfiguration/ROCStream.h" /* for ROCStream */
8 
9 //#include "otsdaq-components/DAQHardware/PurdueFirmwareCore.h"
10 
11 namespace ots
12 {
13 // - FrontEndFirmwareBase (all virtual read, write, setDest, init) *functions are not
14 // pure virtual, rather throw exceptions if not overridden to allow setDest to go unused,
15 // for example.
16 // - OtsUDPFirmwareCore (inherits and implements FrontEndFirmwareBase)
17 // - PurdueFirmwareCore (inherits and implements FrontEndFirmwareBase)
18 //
19 // - FSSRFirmwareBase (takes ONLY parameter for communication type. Does not inherit
20 // from anything). *Implements 90-100% base fssr functionality:
21 // - FSSROtsFirmware (inherits from FSSRApplicationFirmwareBase only and overrides
22 // any 10% special functions)
23 // - FSSRPurdueFirmware (inherits from FSSRApplicationFirmwareBase only and overrides
24 // any 10% special functions) FSSRFirmwareBase::setCSR()
25 // {
26 // Communication->write(CSR);
27 // }
28 //
29 // - At PLUGIN level (takes parameter for communication AND application firmware
30 // type. ALSO -PRESTON WAS partially RIGHT - inherit from FrontEndFirmwareBase AND
31 // FSSRFirmwareBase. ) * implement all the base functions using the pointers:
32 //
33 // PLUGIN::PLUGIN(commType,appType)
34 // {
35 // If(appType == otsApp)
36 // FSSFirmware = FSSROtsFirmware(commType); //IMPORTANT pass comm
37 // type Else FSSFirmware =
38 // FSSRPurdueFirmware(commType); //IMPORTANT pass comm type
39 // }
40 //
41 // PLUGIN::whatever()
42 // {
43 // FSSFirmware->read();
44 // FSSFirmware->setCSR(); //will call override version if implemented
45 // }
46 //
47 // * This way the FE interface plugin code is exactly the same for both cases, just
48 // modified by type strings.
49 // * Since only modified by type strings, this means there only needs to be one FE
50 // plugin class! Types controlled by configuration.
51 
52 class FrontEndFirmwareBase;
53 
55 {
56  public:
57  FSSRFirmwareBase(const std::string& communicationFirmwareType,
58  unsigned int communicationFirmwareVersion = -1,
59  unsigned int version = -1);
60  virtual ~FSSRFirmwareBase(void);
61  void init(void);
62 
63  std::string universalRead(char* address);
64  std::string universalWrite(char* address, char* data);
65 
66  // virtual void setDataDestination (std::string& buffer,
67  // const std::string& ip, const uint16_t port);// {__SS__;
68  // __THROW__(ss.str() + "Illegal call to undefined base class member function");
69  // return;};
70  uint32_t createRegisterFromValue(std::string& readBuffer, std::string& receivedValue);
71 
72  // FEW specific methods
73  std::string configureClocks(std::string source, double frequency);
74  std::string resetDetector(int channel = -1);
75  std::string enableTrigger(void);
76  // virtual void setDataDestination (std::string& buffer, const std::string& ip, const
77  // uint16_t port); std::string setDataDestination (std::string ip, uint32_t port);
78 
79  void resetDCM(std::string& buffer);
80  void alignReadOut(std::string& buffer, unsigned int sensor, unsigned int chip);
81  void makeDACSequence(FirmwareSequence<uint64_t>& sequence,
82  unsigned int channel,
83  const ROCStream& rocStream);
84  void makeDACSequence(FirmwareSequence<uint32_t>& sequence,
85  unsigned int channel,
86  const ROCStream& rocStream);
87  void makeMaskSequence(FirmwareSequence<uint64_t>& sequence,
88  unsigned int channel,
89  const ROCStream& rocStream);
90  void makeMaskSequence(FirmwareSequence<uint32_t>& sequence,
91  unsigned int channel,
92  const ROCStream& rocStream);
93 
94  void makeDACBuffer(std::string& buffer,
95  unsigned int channel,
96  const ROCStream& rocStream);
97  void makeDACBuffer(std::vector<std::string>& buffer,
98  unsigned int channel,
99  const ROCStream& rocStream);
100  void makeMaskBuffer(std::string& buffer,
101  unsigned int channel,
102  const ROCStream& rocStream);
103  void setFrequencyFromClockState(std::string& buffer, double frequency);
104  bool isClockStateExternal(void);
105 
106  std::string readFromAddress(uint64_t address);
107 
108  // FER specific methods
109  std::string resetBCO(void);
110  std::string armBCOReset(void);
111  std::string startStream(bool channel0,
112  bool channel1,
113  bool channel2,
114  bool channel3,
115  bool channel4,
116  bool channel5);
117  std::string stopStream(void);
118 
119  void makeMaskSequence(FirmwareSequence<uint64_t>& sequence,
120  unsigned int channel,
121  const ROCStream& rocStream,
122  const std::string& registerName);
123  void makeMaskSequence(FirmwareSequence<uint32_t>& sequence,
124  unsigned int channel,
125  const ROCStream& rocStream,
126  const std::string& registerName);
127  void makeMaskBuffer(std::string& buffer,
128  unsigned int channel,
129  const ROCStream& rocStream,
130  const std::string& registerName);
131 
132  void setCSRRegister(uint32_t total);
133 
134  // Set values for register STRIP_CSR (Strip Control Register)
135  // STRIP_CSR = 0xc4000000
136  // Byte 4-------------------
137  // 31 DCM_RESET
138  // 30 BCO_LOCKED
139  // 29 MCCLK_LOCKED
140  // 28 unused
142  // 27 STREAM_ENABLE
143  // 26 SEND_BCO
144  // 25 SEND_TRIG_NUM
145  // 24 SEND_TRIG
146  // Byte 3-------------------
147  // 23 TRIG_ENABLE
148  // 22 BCO_CLEAR
149  // 21 TRIG_NUM_CLEAR
150  // 20 FLUSH
152  // 19 ARM_BCO_RESET
153  // 18-17 unused
154  // 16 EXT_BCO
155  // Byte 2-------------------
156  // 15-14 IDLE_COUNT
157  // 13-8 MODULE_ENABLE
158  // Byte 1-------------------
159  // 7-3 PACKET_SIZE
160  // 2-0 N_CHANNELS
161 
162  uint32_t stripCSRRegisterValue_;
163  void setPacketSizeStripCSR(uint32_t size);
164  void enableChannelsStripCSR(bool channel0,
165  bool channel1,
166  bool channel2,
167  bool channel3,
168  bool channel4,
169  bool channel5);
170  void setExternalBCOClockSourceStripCSR(std::string clockSource);
171  // void setHaltStripCSR (bool set);//2018-10-24
172  // Doesn't exist????
173  void armBCOResetCSR(void);
174  void flushBuffersStripCSR(void);
175  void resetTriggerCounterStripCSR(std::string& buffer);
176  void resetBCOCounterStripCSR(void);
177  void enableTriggerStripCSR(bool enable);
178  void sendTriggerDataStripCSR(bool send);
179  void sendTriggerNumberStripCSR(bool send);
180  void sendBCOStripCSR(bool send);
181  void enableStreamStripCSR(bool enable);
182  void resetDCMStripCSR(bool clear);
183  uint32_t waitDCMResetStripCSR(void);
184  std::string readCSRRegister(void);
185 
186  std::string readSCCSRRegister(void);
187 
188  uint32_t stripResetRegisterValue_;
189  // Set values for register STRIP_RESET (Strip Reset)
190  void resetStripResetRegisterValue(void) { stripResetRegisterValue_ = 0; }
191  void resetDAC(void);
192  void resetLink(bool channel0,
193  bool channel1,
194  bool channel2,
195  bool channel3,
196  bool channel4,
197  bool channel5);
198  void clearErrors(bool channel0,
199  bool channel1,
200  bool channel2,
201  bool channel3,
202  bool channel4,
203  bool channel5);
204  void clearFIFO(bool channel0,
205  bool channel1,
206  bool channel2,
207  bool channel3,
208  bool channel4,
209  bool channel5);
210  void resetChip(bool channel0,
211  bool channel1,
212  bool channel2,
213  bool channel3,
214  bool channel4,
215  bool channel5);
216 
217  uint32_t stripBCODCMRegisterValue_;
218  void setFrequencyRatio(std::string& buffer, int numerator, int denominator);
219 
220  void configureStripTriggerUnbiased(std::string& buffer);
221  void configureTriggerInputs(std::string& buffer);
222 
223  // STRIP_TRIG_CSR = 0xc40000060
224  uint32_t stripTriggerCSRRegisterValue_;
225 
226  // Registers setters
227  void BCOOffset(uint32_t offset);
228  void selectSpyFIFO(uint32_t input);
229  void halt(bool halt);
230 
231  std::string resetSlaveBCO(void);
232 
233  static const std::string PURDUE_FIRMWARE_NAME;
234  static const std::string OTS_FIRMWARE_NAME;
235 
236  FrontEndFirmwareBase* communicationFirmwareInstance_;
237 
238  protected:
239  unsigned int version_;
240  const std::string communicationFirmwareType_;
241 };
242 }
243 
244 #endif
void makeDACBuffer(std::string &buffer, unsigned int channel, const ROCStream &rocStream)