scc 2025.09
SystemC components library
tagged_initiator_mixin.h
1/*******************************************************************************
2 * Copyright 2016, 2018 MINRES Technologies GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17#ifndef _SCC_TAGGED_INITIATOR_MIXIN_H__
18#define _SCC_TAGGED_INITIATOR_MIXIN_H__
19
20#include <functional>
21#include <scc/utilities.h>
22#include <sstream>
23#include <tlm>
24
26namespace tlm {
28namespace scc {
32template <typename BASE_TYPE, typename TYPES = tlm::tlm_base_protocol_types> class tagged_initiator_mixin : public BASE_TYPE {
33public:
34 using transaction_type = typename TYPES::tlm_payload_type;
35 using phase_type = typename TYPES::tlm_phase_type;
36 using sync_enum_type = tlm::tlm_sync_enum;
37 using fw_interface_type = tlm::tlm_fw_transport_if<TYPES>;
38 using bw_interface_type = tlm::tlm_bw_transport_if<TYPES>;
39
40public:
44 tagged_initiator_mixin()
45 : BASE_TYPE(sc_core::sc_gen_unique_name("tagged_initiator_socket"))
46 , bw_if(this->name()) {
47 this->m_export.bind(bw_if);
48 }
53 explicit tagged_initiator_mixin(const char* n)
54 : BASE_TYPE(n)
55 , bw_if(this->name()) {
56 this->m_export.bind(bw_if);
57 }
58
63 void register_nb_transport_bw(std::function<sync_enum_type(unsigned int, transaction_type&, phase_type&, sc_core::sc_time&)> cb,
64 unsigned int tag) {
65 bw_if.set_transport_function(cb, tag);
66 }
67
72 void register_invalidate_direct_mem_ptr(std::function<void(unsigned int, sc_dt::uint64, sc_dt::uint64)> cb, unsigned int tag) {
73 bw_if.set_invalidate_direct_mem_function(cb, tag);
74 }
75
76private:
77 class bw_transport_if : public tlm::tlm_bw_transport_if<TYPES> {
78 public:
79 using transport_fct = std::function<sync_enum_type(unsigned int, transaction_type&, phase_type&, sc_core::sc_time&)>;
80 using invalidate_dmi_fct = std::function<void(unsigned int, sc_dt::uint64, sc_dt::uint64)>;
81
82 bw_transport_if(const std::string& name)
83 : m_name(name)
84 , m_transport_ptr(0)
85 , m_invalidate_direct_mem_ptr(0) {}
86
87 void set_transport_function(transport_fct p, unsigned int tag) {
88 if(m_transport_ptr) {
89 std::stringstream s;
90 s << m_name << ": non-blocking callback allready registered";
91 SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket", s.str().c_str());
92 } else {
93 m_transport_ptr = p;
94 tags[0] = tag;
95 }
96 }
97
98 void set_invalidate_direct_mem_function(invalidate_dmi_fct p, unsigned int tag) {
99 if(m_invalidate_direct_mem_ptr) {
100 std::stringstream s;
101 s << m_name << ": invalidate DMI callback allready registered";
102 SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket", s.str().c_str());
103 } else {
104 m_invalidate_direct_mem_ptr = p;
105 tags[1] = tag;
106 }
107 }
108
109 sync_enum_type nb_transport_bw(transaction_type& trans, phase_type& phase, sc_core::sc_time& t) {
110 if(m_transport_ptr)
111 return m_transport_ptr(tags[0], trans, phase, t);
112 std::stringstream s;
113 s << m_name << ": no transport callback registered";
114 SC_REPORT_ERROR("/OSCI_TLM-2/tagged_initiator_mixin", s.str().c_str());
115 return tlm::TLM_ACCEPTED;
116 }
117
118 void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) {
119 if(m_invalidate_direct_mem_ptr) // forward call
120 m_invalidate_direct_mem_ptr(tags[1], start_range, end_range);
121 }
122
123 private:
124 const std::string m_name;
125 unsigned int tags[2]; // dbg, dmi
126 transport_fct m_transport_ptr;
127 invalidate_dmi_fct m_invalidate_direct_mem_ptr;
128 };
129
130private:
131 bw_transport_if bw_if;
132};
133} // namespace scc
134} // namespace tlm
135
136#endif //_SCC_TAGGED_INITIATOR_MIXIN_H__
void register_nb_transport_bw(std::function< sync_enum_type(unsigned int, transaction_type &, phase_type &, sc_core::sc_time &)> cb, unsigned int tag)
void register_invalidate_direct_mem_ptr(std::function< void(unsigned int, sc_dt::uint64, sc_dt::uint64)> cb, unsigned int tag)
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19