otsdaq_components  v2_05_02_indev
OtsUDPFirmwareCore.h
1 #ifndef _ots_OtsUDPFirmwareCore_h_
2 #define _ots_OtsUDPFirmwareCore_h_
3 
4 //#include "otsdaq-fermilabtestbeam/DAQHardware/FirmwareSequence.h"
5 #include "otsdaq-components/DAQHardware/FrontEndFirmwareBase.h"
6 
7 #include <string>
8 #include <vector>
9 
10 namespace ots
11 {
13 {
14  //===============================================
15  // OtsUDPFirmwareCore
16  //
17  // The intent of this class is to be the core UDP firmware functionality.
18  // This should handle everything except the user block 0x0 of the address space.
19  //
20  //
21  // Note: Currently there are these other blocks of the address space:
22  // block 0x1 -- UDP core
23  // block 0x2 -- Programming over Ethernet core
24 
25  public:
26  OtsUDPFirmwareCore(unsigned int version);
27  virtual ~OtsUDPFirmwareCore(void);
28  virtual void init(void);
29 
31  // implementation of base class virtual functionality
32 
33  // std::string read (char* address);
34  virtual std::string write(char* address, char* data);
35  virtual void write(std::string& buffer,
36  char* address,
37  char* data,
38  bool clearBuffer = true);
39  virtual void write(std::string& buffer,
40  uint32_t address,
41  uint32_t data,
42  bool clearBuffer = true);
43  virtual void write(std::string& buffer,
44  uint64_t address,
45  uint64_t data,
46  bool clearBuffer = true);
47  virtual void waitClear(std::string& /*buffer*/,
48  uint32_t /*address*/,
49  uint32_t /*data*/,
50  uint32_t /*timeout*/ = 255,
51  bool /*clearBuffer*/ = true)
52  {
53  }
54 
55  virtual std::string read(char* address);
56  virtual void read(std::string& buffer, char* address, bool clearBuffer = true);
57  virtual void read(std::string& buffer, uint64_t address, bool clearBuffer = true);
58  virtual void read(std::string& buffer, uint32_t address, bool clearBuffer = true);
59 
60  virtual void setDataDestination(std::string& buffer,
61  const std::string& ip,
62  const uint16_t port,
63  bool clearBuffer = true);
64 
65  virtual uint32_t createRegisterFromValue(std::string& readBuffer,
66  std::string& receivedValue);
68  // low level functionality
69  void writeAdvanced(std::string& buffer,
70  const char* address,
71  const char* data,
72  uint8_t size = 1,
73  uint8_t commandTypeOptions = 0,
74  bool clearBuffer = true);
75  void writeAdvanced(std::string& buffer,
76  const uint64_t& address,
77  const char* data,
78  uint8_t size,
79  uint8_t commandTypeOptions = 0,
80  bool clearBuffer = true); // size is required, to remove ambiguity
81  // when calling write with data=0
82  void writeAdvanced(std::string& buffer,
83  const uint64_t& address,
84  const uint64_t& data,
85  uint8_t commandTypeOptions = 0,
86  bool clearBuffer = true);
87  void writeAdvanced(std::string& buffer,
88  const uint64_t& address,
89  const std::vector<uint64_t>& data,
90  uint8_t commandTypeOptions = 0,
91  bool clearBuffer = true);
92  void readAdvanced(std::string& buffer,
93  char* address,
94  uint8_t size = 1,
95  uint8_t commandTypeOptions = 0,
96  bool clearBuffer = true);
97  void readAdvanced(std::string& buffer,
98  const uint64_t& address,
99  uint8_t size = 1,
100  uint8_t commandTypeOptions = 0,
101  bool clearBuffer = true);
102 
104  // next level functionality
105 
106  // data destination read/write
107  void writeDataDestinationIP(std::string& buffer,
108  const uint64_t value,
109  bool clearBuffer = true);
110  void writeDataDestinationMAC(std::string& buffer,
111  const uint64_t value,
112  bool clearBuffer = true);
113  void writeDataDestinationPort(std::string& buffer,
114  const uint64_t value,
115  bool clearBuffer = true);
116 
117  void readDataDestinationIP(std::string& buffer);
118  void readDataDestinationMAC(std::string& buffer);
119  void readDataDestinationPort(std::string& buffer);
120 
121  void setDataDestinationAsSelf(std::string& buffer)
122  {
123  buffer.resize(0);
124  buffer += (char)2; /* special one-byte packet, sets data destination as sender */
125  }
126 
127  // control destination read/write
128  virtual void setControlDestination(std::string& buffer,
129  const std::string& ip,
130  const uint16_t port);
131 
132  void writeControlDestinationIP(std::string& buffer, const uint64_t value);
133  void writeControlDestinationMAC(std::string& buffer, const uint64_t value);
134  void writeControlDestinationPort(std::string& buffer, const uint64_t value);
135 
136  void readControlDestinationIP(std::string& buffer);
137  void readControlDestinationMAC(std::string& buffer);
138  void readControlDestinationPort(std::string& buffer);
139 
140  void setControlDestinationAsSelf(std::string& buffer)
141  {
142  buffer.resize(0);
143  buffer +=
144  (char)1; /* special one-byte packet, sets control destination as sender */
145  }
146 
147  // other
148  void UDPFirmwareSpecialPing(std::string& buffer)
149  {
150  buffer.resize(0);
151  buffer += (char)0; /* special one-byte packet, returns OEI version (16-bits) */
152  }
153  void UDPFirmwareSpecialNoOp(std::string& buffer)
154  {
155  buffer.resize(0);
156  buffer += (char)3; /* special one-byte packet, is ignored at OIE - could be used
157  to keep connection alive */
158  }
159 
160  void readUDPFirmwareVersion(std::string& buffer);
161  void softEthernetReset(std::string& buffer);
162  void hardEthernetReset(std::string& buffer);
163  void clearEthernetReset(std::string& buffer);
164 
165  void startBurst(std::string& buffer);
166  void stopBurst(std::string& buffer);
167 
168  // command type options that can be OR'd
169  static const uint8_t FIFO_ADDRESS_CMD_TYPE;
170 };
171 }
172 
173 #endif