quic/qbox
Loading...
Searching...
No Matches
multiinitiator-signal-socket.h
1/*
2 * This file is part of libgsutils
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * Author: GreenSocs 2022
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _LIBGSUTILS_PORTS_MULTIINITIATOR_SIGNAL_SOCKET_H
10#define _LIBGSUTILS_PORTS_MULTIINITIATOR_SIGNAL_SOCKET_H
11
12#include <systemc>
13#include <scp/report.h>
14#include "target-signal-socket.h"
15template <typename T = bool>
17 : public sc_core::sc_port<sc_core::sc_signal_inout_if<T>, 0, sc_core::SC_ZERO_OR_MORE_BOUND>,
18 public sc_core::sc_module
19{
20 SCP_LOGGER();
21 std::vector<T> vals;
22 bool vals_valid = false;
23 sc_core::sc_event ev;
24
25public:
26 MultiInitiatorSignalSocket(const char* name = "MultiInitiatorSignalSocket")
27 : sc_core::sc_port<sc_core::sc_signal_inout_if<T>, 0, sc_core::SC_ZERO_OR_MORE_BOUND>(name)
28 , sc_core::sc_module(sc_core::sc_module_name((std::string(name) + "_thread").c_str()))
29 {
30 SCP_DEBUG(())("Constructor");
31 SC_THREAD(writer);
32 }
33 void writer()
34 {
35 while (1) {
36 while (vals_valid == false) {
37 wait(ev);
38 }
39 std::vector<T> vs = vals; // No race conditions, we are single threaded. COPY the vector
40 vals_valid = false;
41 for (auto v : vs) {
42 for (int i = 0; i < this->size(); i++) {
43 if (auto t = dynamic_cast<TargetSignalSocketProxy<bool>*>(this->operator[](i))) {
44 SCP_DEBUG(())("Writing {} to {}", v, t->get_parent().name());
45 }
46 this->operator[](i)->write(v);
47 }
48 wait(sc_core::SC_ZERO_TIME); // ensure all immediate events have been processed
49 }
50 }
51 }
52 void async_write_vector(const std::vector<T>& vs)
53 {
54 assert(vals_valid == false);
55 vals = vs; // COPY the vector.
56 vals_valid = true;
57 ev.notify();
58 }
59};
60
61#endif
Definition multiinitiator-signal-socket.h:19
Definition target.h:160