otsdaq_components  v2_01_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 std::runtime_error(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, uint32_t value);
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  uint32_t stripCSRRegisterValue_;
99  //Set values for register STRIP_CSR (Strip Control Register)
100  void setPacketSizeStripCSR (uint32_t size);
101  void enableChannelsStripCSR (bool channel0, bool channel1, bool channel2, bool channel3, bool channel4, bool channel5);
102  void setExternalBCOClockSourceStripCSR(std::string clockSource);
103  void setHaltStripCSR (bool set);
104  void enableBCOStripCSR (bool enable);
105  void flushBuffersStripCSR (void);
106  void resetTriggerCounterStripCSR (std::string& buffer);
107  void resetBCOCounterStripCSR (void);
108  void enableTriggerStripCSR (bool enable);
109  void sendTriggerDataStripCSR (bool send);
110  void sendTriggerNumberStripCSR (bool send);
111  void sendBCOStripCSR (bool send);
112  void enableStreamStripCSR (bool enable);
113  void resetDCMStripCSR (bool clear);
114  uint32_t waitDCMResetStripCSR (void);
115  std::string readCSRRegister (void);
116 
117  std::string readSCCSRRegister (void);
118 
119  uint32_t stripResetRegisterValue_;
120  //Set values for register STRIP_RESET (Strip Reset)
121  void resetStripResetRegisterValue(void)
122  {
123  stripResetRegisterValue_ = 0;
124  }
125  void resetDAC (void);
126  void resetLink (bool channel0, bool channel1, bool channel2, bool channel3, bool channel4, bool channel5);
127  void clearErrors (bool channel0, bool channel1, bool channel2, bool channel3, bool channel4, bool channel5);
128  void clearFIFO (bool channel0, bool channel1, bool channel2, bool channel3, bool channel4, bool channel5);
129  void resetChip (bool channel0, bool channel1, bool channel2, bool channel3, bool channel4, bool channel5);
130 
131  uint32_t stripBCODCMRegisterValue_;
132  void setFrequencyRatio (std::string& buffer, int numerator, int denominator);
133 
134  void configureStripTriggerUnbiased (std::string& buffer);
135  void configureTriggerInputs (std::string& buffer);
136 
137  uint32_t stripTriggerCSRRegisterValue_;
138 
139  //Registers setters
140  void BCOOffset (uint32_t offset);
141  void selectSpyFIFO (uint32_t input);
142  void halt (bool halt);
143 
144 
145  std::string resetSlaveBCO(void);
146 
147  static const std::string PURDUE_FIRMWARE_NAME;
148  static const std::string OTS_FIRMWARE_NAME;
149 
150  FrontEndFirmwareBase* communicationFirmwareInstance_;
151 
152 protected:
153  unsigned int version_;
154  const std::string communicationFirmwareType_;
155 };
156 
157 }
158 
159 #endif