rogue
Loading...
Searching...
No Matches
Xvc.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_PROTOCOLS_XILINX_XVC_H__
18#define __ROGUE_PROTOCOLS_XILINX_XVC_H__
19#include "rogue/Directives.h"
20
21#include <atomic>
22#include <cstdint>
23#include <memory>
24#include <thread>
25
26#include "rogue/GeneralError.h"
27#include "rogue/Logging.h"
28#include "rogue/Queue.h"
33
34namespace rogue {
35namespace protocols {
36namespace xilinx {
37
54 protected:
55 unsigned mtu_;
56
57 // Use rogue frames to exchange data with other rogue objects
59
60 // Log (named xvcLog_ to avoid shadowing JtagDriver::log_)
61 std::shared_ptr<rogue::Logging> xvcLog_;
62
63 // Background server thread.
64 std::unique_ptr<std::thread> thread_;
65 std::atomic<bool> threadEn_;
66
67 // One-shot start guard. rogue::Queue::stop() is irreversible (see
68 // rogue/Queue.h: stop() sets run_=false with no restart API), so a
69 // restarted Xvc would have a permanently-non-blocking queue and a
70 // dirty wake-fd. start() asserts this flag is false; once set, it
71 // stays set for the lifetime of the instance.
72 std::atomic<bool> started_;
73
74 // Lock
75 std::mutex mtx_;
76
77 // Shutdown wake-fd (self-pipe). wakeFd_[0]=read end (consumed by
78 // XvcServer/XvcConnection select()); wakeFd_[1]=write end (one byte
79 // written in Xvc::stop()).
80 int wakeFd_[2] = {-1, -1};
81
82 // Cached bound port (atomic so getPort() is safe during stop()).
83 std::atomic<uint32_t> boundPort_{0};
84
85 // Owned XvcServer: constructed in start() so port is synchronously
86 // known before the server thread races.
87 std::unique_ptr<rogue::protocols::xilinx::XvcServer> server_;
88
89 // TCP server thread entry point for Vivado clients.
90 void runThread();
91
92 public:
106 static std::shared_ptr<rogue::protocols::xilinx::Xvc> create(uint16_t port);
107
109 static void setup_python();
110
120 explicit Xvc(uint16_t port);
121
123 ~Xvc();
124
128 void start();
129
133 void stop();
134
143 void acceptFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
144
153 uint64_t getMaxVectorSize() final;
154
170 int xfer(uint8_t* txBuffer,
171 unsigned txBytes,
172 uint8_t* hdBuffer,
173 unsigned hdBytes,
174 uint8_t* rxBuffer,
175 unsigned rxBytes) final;
176
187 uint32_t getPort() const;
188};
189
190// Convenience
191typedef std::shared_ptr<rogue::protocols::xilinx::Xvc> XvcPtr;
192} // namespace xilinx
193} // namespace protocols
194} // namespace rogue
195
196#endif
Thread-safe bounded queue with optional busy threshold.
Definition Queue.h:39
Stream master endpoint.
Definition Master.h:65
static std::shared_ptr< rogue::interfaces::stream::Master > create()
Creates a stream master.
Definition Master.cpp:40
Stream slave endpoint and default frame pool.
Definition Slave.h:72
Base transport driver for the AxisToJtag firmware protocol.
Definition JtagDriver.h:60
Rogue XVC bridge between TCP XVC clients and Rogue stream transport.
Definition Xvc.h:53
std::unique_ptr< rogue::protocols::xilinx::XvcServer > server_
Definition Xvc.h:87
rogue::Queue< std::shared_ptr< rogue::interfaces::stream::Frame > > queue_
Definition Xvc.h:58
uint64_t getMaxVectorSize() final
Returns maximum vector size supported by this XVC bridge.
Definition Xvc.cpp:299
std::atomic< bool > threadEn_
Definition Xvc.h:65
int xfer(uint8_t *txBuffer, unsigned txBytes, uint8_t *hdBuffer, unsigned hdBytes, uint8_t *rxBuffer, unsigned rxBytes) final
Executes one protocol transfer over Rogue frame transport.
Definition Xvc.cpp:313
void runThread()
Run driver initialization and XVC thread.
Definition Xvc.cpp:224
~Xvc()
Destroys the XVC bridge instance.
Definition Xvc.cpp:91
std::shared_ptr< rogue::Logging > xvcLog_
Definition Xvc.h:61
void start()
Starts XVC server thread and enables bridge operation.
Definition Xvc.cpp:112
std::unique_ptr< std::thread > thread_
Definition Xvc.h:64
void acceptFrame(std::shared_ptr< rogue::interfaces::stream::Frame > frame)
Receives reply frame from downstream Rogue transport.
Definition Xvc.cpp:289
void stop()
Stops XVC server thread and drains frame queue.
Definition Xvc.cpp:169
std::atomic< bool > started_
Definition Xvc.h:72
std::atomic< uint32_t > boundPort_
Definition Xvc.h:83
uint32_t getPort() const
Returns the TCP port the XVC server is bound to.
Definition Xvc.cpp:308
static void setup_python()
Registers Python bindings for this class.
Definition Xvc.cpp:403
std::shared_ptr< rogue::protocols::xilinx::Xvc > XvcPtr
Definition Xvc.h:191