quic/qbox
Loading...
Searching...
No Matches
qk_extendedif.h
1/*
2 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 * Author: GreenSocs 2022
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef QK_EXTENDEDIF_H
9#define QK_EXTENDEDIF_H
10
11#ifndef SC_INCLUDE_DYNAMIC_PROCESSES
12#define SC_INCLUDE_DYNAMIC_PROCESSES
13#endif
14
15#include <systemc>
16#include <tlm>
17#include <tlm_utils/tlm_quantumkeeper.h>
18
19#include <scp/report.h>
20
21#include <libgsutils.h>
22
23namespace gs {
24
25/* this quantumkeeper is inteded as an interface for other more
26 * sophisticated QKs. However if provides a trivial implementation making it
27 * identicle to a standard tlm-2.0 QK
28 */
29namespace SyncPolicy {
30enum Type { SYSTEMC_THREAD, OS_THREAD };
31}
32
33class tlm_quantumkeeper_extended : public tlm_utils::tlm_quantumkeeper, public sc_core::sc_object
34{
35public:
36 tlm_quantumkeeper_extended(): sc_object("qk") {}
37
38 /*
39 * Additional functions
40 */
41
42 // based on standard tlm2 QK.
43 virtual sc_core::sc_time time_to_sync()
44 {
45 if (m_next_sync_point > (m_local_time + sc_core::sc_time_stamp()))
46 return m_next_sync_point - (m_local_time + sc_core::sc_time_stamp());
47 else
48 return sc_core::SC_ZERO_TIME;
49 }
50
51 // stop trying to syncronise
52 virtual void stop() {}
53
54 // start trying to syncronise, (and start job for convenience)
55 virtual void start(std::function<void()> job = nullptr)
56 {
57 if (job) sc_core::sc_spawn(job);
58 }
59
60 virtual SyncPolicy::Type get_thread_type() const { return SyncPolicy::SYSTEMC_THREAD; }
61
62 // non-const need_sync as some sync policies need a non-const version
63 virtual bool need_sync() { return tlm_utils::tlm_quantumkeeper::need_sync(); }
64
65 virtual bool need_sync() const override
66 {
67 SCP_INFO("Libgssync") << "const need_sync called, probably wanted to call non-const version";
68 return tlm_utils::tlm_quantumkeeper::need_sync();
69 }
70
71 // NB, the following function is only for the convenience of
72 // the 'old' sync policys. This can/should be removed.
73 virtual void run_on_systemc(std::function<void()> job) { job(); }
74};
75} // namespace gs
76
77#endif // QK_EXTENDEDIF_H
Definition target.h:160
Definition qk_extendedif.h:34
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10