qualcomm/qbox
Loading...
Searching...
No Matches
monitor.h
1/*
2 * Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _GREENSOCS_MONITOR_H
8#define _GREENSOCS_MONITOR_H
9
10#include <cci_configuration>
11#include <systemc>
12#include <tlm>
13#include <scp/report.h>
14#include <scp/helpers.h>
15#include <tlm_utils/simple_initiator_socket.h>
16#include <tlm_utils/simple_target_socket.h>
17#include <ports/initiator-signal-socket.h>
18#include <ports/target-signal-socket.h>
19#include <tlm_sockets_buswidth.h>
20#include <libgssync.h>
21#include "crow.h"
22#include <thread>
23#include <future>
24#include <qkmultithread.h>
25#include <mcips-plugin.h>
26#include <chrono>
27#include <atomic>
28#include <ports/biflow-socket.h>
29
30#define MAX_ASIO_BUF_LEN (1024ULL * 16ULL)
31#define MAX_BUFFER 1000
32
33namespace gs {
34
35template <unsigned int BUSWIDTH = DEFAULT_TLM_BUSWIDTH>
36class monitor : public sc_core::sc_module
37{
38 SCP_LOGGER();
39
40 class biflow_ws
41 {
42 public:
43 std::vector<crow::websocket::connection*> m_conns;
45 std::string buffer;
46 const char* name;
47
48 public:
49 void bind(biflow_bindable& other)
50 {
51 socket.bind(other);
52 socket.can_receive_any();
53 }
54 void b_transport(tlm::tlm_generic_payload& txn, sc_core::sc_time& t)
55 {
56 /* NB we are ignoring the templated type here, as we're simply sending strings, if the type is not a
57 * character, this will produce some sort of rubbish! */
58 char* ptr = (char*)txn.get_data_ptr();
59 std::string data(ptr, txn.get_data_length());
60 buffer = (buffer + data);
61 if (buffer.size() > MAX_BUFFER) buffer = buffer.substr(buffer.size() - MAX_BUFFER);
62 for (auto conn : m_conns) {
63 conn->send_text(data);
64 }
65 }
66 void enqueue(std::string data)
67 {
68 for (auto c : data) {
69 socket.enqueue(c);
70 }
71 }
72 biflow_ws(gs::biflow_multibindable& o, const char* n)
73 : socket(sc_core::sc_gen_unique_name("monitor_biflow_backend")), name(n)
74 {
75 socket.register_b_transport(this, &biflow_ws::b_transport);
76 bind(o);
77 }
78 void set_conn(crow::websocket::connection* c)
79 {
80 m_conns.push_back(c);
81 c->send_text(buffer);
82 }
83 void clear_conn(crow::websocket::connection* c)
84 {
85 auto i = std::find(m_conns.begin(), m_conns.end(), c);
86 if (i != m_conns.end()) {
87 m_conns.erase(i);
88 }
89 }
90 };
91 std::map<std::string, std::unique_ptr<biflow_ws>> biflows;
92
93public:
94 monitor(const sc_core::sc_module_name& nm);
95
96 ~monitor();
97
98private:
99 void init_monitor();
100
101 void before_end_of_elaboration() override;
102
103 void end_of_elaboration() override;
104
105 void end_of_simulation() override;
106
107public:
108 cci::cci_param<uint32_t> p_server_port;
109 cci::cci_param<std::string> p_html_doc_template_dir_path;
110 cci::cci_param<std::string> p_html_doc_name;
111 cci::cci_param<bool> p_use_html_presentation;
112 cci::cci_param<uint32_t> p_refresh_interval_ms;
113
114private:
115 crow::SimpleApp m_app;
116 std::future<void> m_app_future;
117 gs::runonsysc m_sc;
118 std::vector<tlm_quantumkeeper_multithread*> m_qks;
119 std::vector<McipsPlugin*> m_mcips_plugins;
120};
121} // namespace gs
122
123extern "C" void module_register();
124
125#endif
Definition biflow-socket.h:73
void bind(biflow_bindable &other)
Bind method to connect two biflow sockets.
Definition biflow-socket.h:203
void can_receive_any()
can_receive_any Allow unlimited items to arrive.
Definition biflow-socket.h:263
void enqueue(T data)
enqueue Enqueue data to be sent (unlimited queue size) NOTE: Thread safe.
Definition biflow-socket.h:276
void register_b_transport(MODULE *mod, void(MODULE::*cb)(tlm::tlm_generic_payload &, sc_core::sc_time &))
Register b_transport to be called whenever data is received from the socket.
Definition biflow-socket.h:226
Definition runonsysc.h:23
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10
Definition biflow-socket.h:55
Definition biflow-socket.h:68