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