otsdaq_components  v2_02_00
OtsUDPFirmwareCore.h
1 #ifndef _ots_OtsUDPFirmwareCore_h_
2 #define _ots_OtsUDPFirmwareCore_h_
3 
4 //#include "otsdaq-components/DAQHardware/FirmwareSequence.h"
5 #include "otsdaq-components/DAQHardware/FrontEndFirmwareBase.h"
6 
7 
8 #include <string>
9 #include <vector>
10 
11 
12 namespace ots
13 {
14 
16 {
17  //===============================================
18  //OtsUDPFirmwareCore
19  //
20  // The intent of this class is to be the core UDP firmware functionality.
21  // This should handle everything except the user block 0x0 of the address space.
22  //
23  //
24  // Note: Currently there are these other blocks of the address space:
25  // block 0x1 -- UDP core
26  // block 0x2 -- Programming over Ethernet core
27 
28 public:
29 
30  OtsUDPFirmwareCore (unsigned int version);
31  virtual ~OtsUDPFirmwareCore (void);
32  virtual void init (void);
33 
34 
36  //implementation of base class virtual functionality
37 
38  //std::string read (char* address);
39  virtual std::string write (char* address, char* data);
40  virtual void write (std::string& buffer, char* address, char* data, bool clearBuffer=true);
41  virtual void write (std::string& buffer, uint32_t address, uint32_t data, bool clearBuffer=true);
42  virtual void write (std::string& buffer, uint64_t address, uint64_t data, bool clearBuffer=true);
43  virtual void waitClear (std::string& buffer, uint32_t address, uint32_t data, uint32_t timeout = 255, bool clearBuffer=true){}
44 
45  virtual std::string read (char* address);
46  virtual void read (std::string& buffer, char* address, bool clearBuffer=true);
47  virtual void read (std::string& buffer, uint64_t address, bool clearBuffer=true);
48  virtual void read (std::string& buffer, uint32_t address, bool clearBuffer=true);
49 
50 
51  virtual void setDataDestination (std::string& buffer, const std::string& ip, const uint16_t port, bool clearBuffer=true);
52 
53  virtual uint32_t createRegisterFromValue (std::string& readBuffer, std::string& receivedValue);
55  //low level functionality
56  void writeAdvanced (std::string& buffer, const char* address, const char* data, uint8_t size = 1, uint8_t commandTypeOptions = 0, bool clearBuffer=true);
57  void writeAdvanced (std::string& buffer, const uint64_t& address, const char* data, uint8_t size, uint8_t commandTypeOptions = 0, bool clearBuffer=true); //size is required, to remove ambiguity when calling write with data=0
58  void writeAdvanced (std::string& buffer, const uint64_t& address, const uint64_t& data, uint8_t commandTypeOptions = 0, bool clearBuffer=true);
59  void writeAdvanced (std::string& buffer, const uint64_t& address, const std::vector<uint64_t>& data, uint8_t commandTypeOptions = 0, bool clearBuffer=true);
60  void readAdvanced (std::string& buffer, char* address, uint8_t size = 1, uint8_t commandTypeOptions = 0, bool clearBuffer=true);
61  void readAdvanced (std::string& buffer, const uint64_t& address, uint8_t size = 1, uint8_t commandTypeOptions = 0, bool clearBuffer=true);
62 
64  //next level functionality
65 
66  //data destination read/write
67  void writeDataDestinationIP (std::string& buffer, const uint64_t value, bool clearBuffer=true);
68  void writeDataDestinationMAC (std::string& buffer, const uint64_t value, bool clearBuffer=true);
69  void writeDataDestinationPort (std::string& buffer, const uint64_t value, bool clearBuffer=true);
70 
71  void readDataDestinationIP (std::string& buffer);
72  void readDataDestinationMAC (std::string& buffer);
73  void readDataDestinationPort (std::string& buffer);
74 
75  void setDataDestinationAsSelf (std::string& buffer) { buffer.resize(0); buffer += (char)2; /* special one-byte packet, sets data destination as sender */}
76 
77 
78  //control destination read/write
79  virtual void setControlDestination (std::string& buffer, const std::string& ip, const uint16_t port);
80 
81  void writeControlDestinationIP (std::string& buffer, const uint64_t value);
82  void writeControlDestinationMAC (std::string& buffer, const uint64_t value);
83  void writeControlDestinationPort (std::string& buffer, const uint64_t value);
84 
85  void readControlDestinationIP (std::string& buffer);
86  void readControlDestinationMAC (std::string& buffer);
87  void readControlDestinationPort (std::string& buffer);
88 
89  void setControlDestinationAsSelf (std::string& buffer) { buffer.resize(0); buffer += (char)1; /* special one-byte packet, sets control destination as sender */ }
90 
91  //other
92  void UDPFirmwareSpecialPing (std::string& buffer) { buffer.resize(0); buffer += (char)0; /* special one-byte packet, returns OEI version (16-bits) */ }
93  void UDPFirmwareSpecialNoOp (std::string& buffer) { buffer.resize(0); buffer += (char)3; /* special one-byte packet, is ignored at OIE - could be used to keep connection alive */ }
94 
95  void readUDPFirmwareVersion (std::string& buffer);
96  void softEthernetReset (std::string& buffer);
97  void hardEthernetReset (std::string& buffer);
98  void clearEthernetReset (std::string& buffer);
99 
100  void startBurst (std::string& buffer);
101  void stopBurst (std::string& buffer);
102 
103  //command type options that can be OR'd
104  static const uint8_t FIFO_ADDRESS_CMD_TYPE;
105 };
106 
107 }
108 
109 #endif