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 "sysc/kernel/sc_time.h"
15#include "target-signal-socket.h"
16template <typename T = bool>
18 : public sc_core::sc_port<sc_core::sc_signal_inout_if<T>, 0, sc_core::SC_ZERO_OR_MORE_BOUND>,
19 public sc_core::sc_module
20{
21 SCP_LOGGER();
22 std::vector<T> vals;
23 bool vals_valid = false;
24 sc_core::sc_event ev;
25
26public:
27 MultiInitiatorSignalSocket(const char* name = "MultiInitiatorSignalSocket")
28 : sc_core::sc_port<sc_core::sc_signal_inout_if<T>, 0, sc_core::SC_ZERO_OR_MORE_BOUND>(name)
29 , sc_core::sc_module(sc_core::sc_module_name((std::string(name) + "_thread").c_str()))
30 {
31 SCP_DEBUG(())("Constructor");
32 SC_THREAD(writer);
33 }
34 void writer()
35 {
36 while (1) {
37 while (vals_valid == false) {
38 wait(ev);
39 }
40 std::vector<T> vs = vals; // No race conditions, we are single threaded. COPY the vector
41 vals_valid = false;
42 for (auto v : vs) {
43 for (int i = 0; i < this->size(); i++) {
44 if (auto t = dynamic_cast<TargetSignalSocketProxy<bool>*>(this->operator[](i))) {
45 SCP_DEBUG(())("Writing {} to {}", v, t->get_parent().name());
46 }
47 this->operator[](i)->write(v);
48 }
49 wait(sc_core::SC_ZERO_TIME); // ensure all immediate events have been processed
50 }
51 }
52 }
53 void async_write_vector(const std::vector<T>& vs)
54 {
55 vals.insert(vals.end(), vs.begin(), vs.end()); // COPY the vector to the end.
56 vals_valid = true;
57 ev.notify();
58 }
59};
60
61#endif
Definition multiinitiator-signal-socket.h:20
Definition target.h:160