69struct tcp4tlm_bridge :
public sc_core::sc_module,
70 protected tcp4tlm::server<tcp4tlm::request_message, tcp4tlm::response_message>,
71 protected tcp4tlm::client<tcp4tlm::request_message, tcp4tlm::response_message> {
72 SC_HAS_PROCESS(tcp4tlm_bridge);
79 cci::cci_param<std::string> other_host_name{
"other_host_name",
""};
80 cci::cci_param<unsigned> other_host_port{
"other_host_port", 0};
81 cci::cci_param<unsigned> this_host_port{
"this_host_port", 32000u};
82 cci::cci_param<bool> wall_time_simulation_speed{
"wall_time_simulation_speed",
false};
83 cci::cci_param<bool> write_no_response{
"write_no_response",
false};
84 cci::cci_param<bool> no_systemc_sync{
"no_systemc_sync",
false};
86 tlm_utils::simple_target_socket<tcp4tlm_bridge, ::scc::LT> tsckt;
88 tlm_utils::simple_initiator_socket<tcp4tlm_bridge, ::scc::LT> isckt;
90 sc_core::sc_vector<sc_core::sc_out<bool>> signals{
"signals"};
92 tcp4tlm_bridge(sc_core::sc_module_name name,
size_t no_of_ports = 0);
94 virtual ~tcp4tlm_bridge();
96 typedef tcp4tlm::connection<tcp4tlm::response_message, tcp4tlm::request_message> connection_type;
97 typedef std::shared_ptr<connection_type> con_ptr;
99 void server_send_completed(con_ptr& con,
bool established =
false)
override {
105 void server_receive_completed(con_ptr& con,
const tcp4tlm::request_message*
const result)
override;
107 void start_server() {
108 using namespace std::chrono_literals;
109 server::start_server(this_host_port.get_value());
112 void wait4connection() {
113 using namespace std::chrono_literals;
115 std::unique_lock<std::mutex> lock(con_est_mtx);
116 while(!con_est.load())
117 con_est_sig.wait_for(lock, 100ms, [
this]() {
return con_est.load(); });
120 bool is_connection_established() {
return con_est; }
122 void end_connection();
124 sc_core::sc_event
const& get_shutdown_event()
const {
return shutdown_evt; }
127 using callback_task = std::packaged_task<bool(
void)>;
130 sc_core::sc_time timepoint;
134 std::mutex con_est_mtx;
135 std::condition_variable con_est_sig;
136 std::atomic<bool> con_est{
false};
137 sc_core::sc_event shutdown_evt;
139 unsigned long long sync;
140 void btransport_cb(tlm::tlm_generic_payload&, sc_core::sc_time&);
141 unsigned transport_dbg_cb(tlm::tlm_generic_payload&);
142 virtual void do_access(tlm::tlm_generic_payload& gp, sc_core::sc_time& delay,
bool debug =
false);
143 void timing_thread();
144 void process_task_que();
145 void process_timed_task_que();
146 void end_of_elaboration()
override;
147 void start_of_simulation()
override;
148 void end_of_simulation()
override;
149 std::shared_ptr<tcp4tlm::response_message> resp_msg;
150 tlm_utils::tlm_quantumkeeper quantumkeeper;
154 tlm::scc::tlm_gp_shared_ptr init_gp(
const tcp4tlm::BusOpMsg*
const msg);
155#ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS
156 tcp4tlm::request_message get_notify_endpoint_msg(boost::asio::local::stream_protocol::endpoint& ep) {
157 return tcp4tlm::make_notify_endpoint_msg(ep.path(), 0);
160 tcp4tlm::request_message get_notify_endpoint_msg(boost::asio::ip::tcp::endpoint& ep) {
161 boost::asio::ip::address addr = ep.address();
162 return tcp4tlm::make_notify_endpoint_msg(addr.is_unspecified() ? boost::asio::ip::host_name() : addr.to_string(), ep.port());
164#ifdef GENERATE_STATISTICS
165 std::vector<unsigned long> rtto, txt, rxt;
169 std::vector<unsigned long> histogram;
170 unsigned long min, max;
171 unsigned long long sum;
172 tlm_genip::addr_decoder_if& indexer;
174 bool print_histogram;
175 statistics(tlm_genip::addr_decoder_if& indexer_,
size_t hsize,
unsigned long initval)
176 : histogram(hsize, 0)
182 , print_histogram(false) {}
183 void updateStat(
unsigned long rt);