Line data Source code
1 : ///////////////////////////////////////////////////////////////////////////////
2 : // Author: Eric Flumerfelt, FNAL RSI
3 : // Date: 8/13/2015
4 : ///////////////////////////////////////////////////////////////////////////////
5 :
6 : #ifndef DTCSOFTWARECFO_H
7 : #define DTCSOFTWARECFO_H 1
8 :
9 : #include "DTC.h"
10 : // #include "artdaq-core-mu2e/Overlays/DTC_Types.h"
11 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_CharacterNotInTableError.h"
12 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_DCSOperationType.h"
13 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_DDRFlags.h"
14 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_DebugType.h"
15 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_EVBStatus.h"
16 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_EventMode.h"
17 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_EventWindowTag.h"
18 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_FIFOFullErrorFlags.h"
19 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_IICDDRBusAddress.h"
20 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_IICSERDESBusAddress.h"
21 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_LinkEnableMode.h"
22 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_LinkStatus.h"
23 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_Link_ID.h"
24 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_OscillatorType.h"
25 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_PLL_ID.h"
26 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_PRBSMode.h"
27 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_ROC_Emulation_Type.h"
28 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_RXBufferStatus.h"
29 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_RXStatus.h"
30 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_SERDESLoopbackMode.h"
31 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_SERDESRXDisparityError.h"
32 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_SerdesClockSpeed.h"
33 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_SimMode.h"
34 : #include "artdaq-core-mu2e/Overlays/DTC_Types/DTC_Subsystem.h"
35 : #include "artdaq-core-mu2e/Overlays/DTC_Types/Exceptions.h"
36 : #include "artdaq-core-mu2e/Overlays/DTC_Types/Utilities.h"
37 :
38 : #include <atomic>
39 : #include <set>
40 : #include <thread>
41 :
42 : namespace DTCLib
43 : {
44 : /// <summary>
45 : /// The DTCSoftwareCFO class is responsible for sending ReadoutRequest and
46 : /// DataRequest packets to the DTC in the absence of a functioning CFO.
47 : /// Requests are sent asynchronously, and the overall behaviour is meant to
48 : /// emulate a system with a CFO as closely as possible.
49 : /// </summary>
50 : class DTCSoftwareCFO
51 : {
52 : public:
53 : /// <summary>
54 : /// Construct an instance of the DTCSoftwareCFO class
55 : /// </summary>
56 : /// <param name="dtc">Pointer to DTC object to use for sending requests</param>
57 : /// <param name="useCFOEmulator">Whether to use the DTC CFO emulator</param>
58 : /// <param name="debugPacketCount">Number of debug packets to request</param>
59 : /// <param name="debugType">Flag for the debug packets</param>
60 : /// <param name="stickyDebugType">Whether the debug type should stay as the flag or revert to default</param>
61 : /// <param name="quiet">When true, don't print debug information to screen</param>
62 : /// <param name="asyncRR">Whether to send ReadoutRequests asynchronously</param>
63 : /// <param name="forceNoDebugMode">Do NOT set the Debug flag in Data Request</param>
64 : /// <param name="useCFODRP">Send DRPs from the CFO Emulator</param>
65 : DTCSoftwareCFO(DTC* dtc, bool useCFOEmulator, uint16_t debugPacketCount = 0, DTC_DebugType debugType = DTC_DebugType_ExternalSerialWithReset, bool stickyDebugType = false, bool quiet = false, bool asyncRR = false, bool forceNoDebugMode = false, bool useCFODRP = false);
66 : /// <summary>
67 : /// DTCSoftwareCFO Destructor
68 : /// </summary>
69 : ~DTCSoftwareCFO();
70 :
71 : /// <summary>
72 : /// Send a Heartbeat Packet and data request for a given timestamp
73 : /// </summary>
74 : /// <param name="ts">Timestamp for requests</param>
75 : /// <param name="heartbeatsAfter">Number of heartbeats after reqeust to drive DTC state machine</param>
76 : void SendRequestForTimestamp(DTC_EventWindowTag ts = DTC_EventWindowTag(static_cast<uint64_t>(0)), uint32_t heartbeatsAfter = 16, bool sendHeartbeats = true);
77 : /// <summary>
78 : /// Send Heartbeat Packets and Data Requests for a range of timestamps.
79 : /// </summary>
80 : /// <param name="count">Number of requests</param>
81 : /// <param name="start">Starting timestamp (Default: 0)</param>
82 : /// <param name="increment">Whether to increment the timestamp for each request (Default: true)</param>
83 : /// <param name="delayBetweenDataRequests">Number of microseconds to wait between requests</param>
84 : /// <param name="requestsAhead">Number of Heartbeat Packets to send ahead of data requests</param>
85 : /// <param name="heartbeatsAfter">How many Heartbeat Packets to send after all Data Requests have been sent to flush the system</param>
86 : void SendRequestsForRange(int count, DTC_EventWindowTag start = DTC_EventWindowTag(static_cast<uint64_t>(0)), bool increment = true, uint32_t delayBetweenDataRequests = 0, int requestsAhead = 1, uint32_t heartbeatsAfter = 16, bool sendHeartbeats = true);
87 :
88 : /// <summary>
89 : /// Send requests for a list of timestamps.
90 : /// </summary>
91 : /// <param name="timestamps">List of timestamps to send</param>
92 : /// <param name="delayBetweenDataRequests">Number of microseconds to wait between requests</param>
93 : /// <param name="heartbeatsAfter">Number of heartbeats after reqeust to drive DTC state machine</param>
94 : void SendRequestsForList(std::set<DTC_EventWindowTag> timestamps, uint32_t delayBetweenDataRequests = 0, uint32_t heartbeatsAfter = 16);
95 :
96 : /// <summary>
97 : /// Enable quiet mode.
98 : ///
99 : /// When in quiet mode, DTCSoftwareCFO will not print ReadoutRequest packets or DataRequest packets to screen.
100 : /// </summary>
101 : /// <param name="quiet">Whether to enable quiet mode.</param>
102 0 : void setQuiet(bool quiet) { quiet_ = quiet; }
103 :
104 : /// <summary>
105 : /// Set the number of packets requested
106 : /// </summary>
107 : /// <param name="dbc">Packet count</param>
108 0 : void setDebugPacketCount(uint16_t dbc) { debugPacketCount_ = dbc; }
109 :
110 : /// <summary>
111 : /// Blocks until all ReadoutRequest packets have been sent
112 : /// </summary>
113 : void WaitForRequestsToBeSent() const;
114 :
115 : /// <summary>
116 : /// Get a pointer to the DTC instance
117 : /// </summary>
118 : /// <returns>Pointer to the DTC instance</returns>
119 : DTC* GetDTC() const { return theDTC_; }
120 :
121 : private:
122 : void SendRequestsForRangeImplAsync(DTC_EventWindowTag start, int count, bool increment = true, uint32_t delayBetweenDataRequests = 0, uint32_t heartbeatsAfter = 16, bool sendHeartbeats = true);
123 : void SendRequestsForRangeImplSync(DTC_EventWindowTag start, int count, bool increment = true, uint32_t delayBetweenDataRequests = 0, int requestsAhead = 1, uint32_t heartbeatsAfter = 16, bool sendHeartbeats = true);
124 :
125 : void SendRequestsForListImplAsync(std::set<DTC_EventWindowTag> timestamps, uint32_t delayBetweenDataRequests = 0, uint32_t heartbeatsAfter = 16);
126 :
127 : // Request Parameters
128 : bool useCFOEmulator_;
129 : uint16_t debugPacketCount_;
130 : DTC_DebugType debugType_;
131 : bool stickyDebugType_;
132 : bool quiet_; // Don't print as much
133 : bool asyncRR_;
134 : bool forceNoDebug_;
135 :
136 : // Object basic properties (not accessible)
137 : DTC* theDTC_;
138 : DTC_LinkEnableMode linkMode_[6];
139 : std::unique_ptr<std::thread> theThread_;
140 : std::atomic<bool> requestsSent_;
141 : std::atomic<bool> abort_;
142 : };
143 : } // namespace DTCLib
144 : #endif // ifndef DTCSOFTWARECFO_H
|