scc 2025.09
SystemC components library
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 _TLM_SCC_INITIATOR_MIXIN_H_
18#define _TLM_SCC_INITIATOR_MIXIN_H_
19
20#include "scc/utilities.h"
21#include <functional>
22#include <sstream>
23#include <tlm>
24
26namespace tlm {
28namespace scc {
38template <typename BASE_TYPE, typename TYPES = tlm::tlm_base_protocol_types> class initiator_mixin : public BASE_TYPE {
39public:
40 using transaction_type = typename TYPES::tlm_payload_type;
41 using phase_type = typename TYPES::tlm_phase_type;
42 using sync_enum_type = tlm::tlm_sync_enum;
43 using fw_interface_type = tlm::tlm_fw_transport_if<TYPES>;
44 using bw_interface_type = tlm::tlm_bw_transport_if<TYPES>;
45
46public:
51 : initiator_mixin(sc_core::sc_gen_unique_name("initiator_mixin_socket")) {}
52
57 explicit initiator_mixin(const sc_core::sc_module_name& name)
58 : BASE_TYPE(name)
59 , bw_if(this->name()) {
60 this->m_export.bind(bw_if);
61 }
62
67 void register_nb_transport_bw(std::function<sync_enum_type(transaction_type&, phase_type&, sc_core::sc_time&)> cb) {
68 bw_if.set_transport_function(cb);
69 }
70
75 void register_invalidate_direct_mem_ptr(std::function<void(sc_dt::uint64, sc_dt::uint64)> cb) {
76 bw_if.set_invalidate_direct_mem_function(cb);
77 }
78
79private:
80 class bw_transport_if : public tlm::tlm_bw_transport_if<TYPES> {
81 public:
82 using transport_fct = std::function<sync_enum_type(transaction_type&, phase_type&, sc_core::sc_time&)>;
83 using invalidate_dmi_fct = std::function<void(sc_dt::uint64, sc_dt::uint64)>;
84
85 bw_transport_if(const std::string& name)
86 : m_name(name)
87 , m_transport_ptr(0)
88 , m_invalidate_direct_mem_ptr(0) {}
89
90 void set_transport_function(transport_fct p) {
91 if(m_transport_ptr) {
92 std::stringstream s;
93 s << m_name << ": non-blocking callback allready registered";
94 SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket", s.str().c_str());
95 } else {
96 m_transport_ptr = p;
97 }
98 }
99
100 void set_invalidate_direct_mem_function(invalidate_dmi_fct p) {
101 if(m_invalidate_direct_mem_ptr) {
102 std::stringstream s;
103 s << m_name << ": invalidate DMI callback allready registered";
104 SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket", s.str().c_str());
105 } else {
106 m_invalidate_direct_mem_ptr = p;
107 }
108 }
109
110 sync_enum_type nb_transport_bw(transaction_type& trans, phase_type& phase, sc_core::sc_time& t) {
111 if(m_transport_ptr)
112 return m_transport_ptr(trans, phase, t);
113 std::stringstream s;
114 s << m_name << ": no transport callback registered";
115 SC_REPORT_ERROR("/OSCI_TLM-2/initiator_mixin", s.str().c_str());
116 return tlm::TLM_ACCEPTED;
117 }
118
119 void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) {
120 if(m_invalidate_direct_mem_ptr) // forward call
121 m_invalidate_direct_mem_ptr(start_range, end_range);
122 }
123
124 private:
125 const std::string m_name;
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 //_TLM_SCC_INITIATOR_MIXIN_H__
void register_invalidate_direct_mem_ptr(std::function< void(sc_dt::uint64, sc_dt::uint64)> cb)
initiator_mixin(const sc_core::sc_module_name &name)
void register_nb_transport_bw(std::function< sync_enum_type(transaction_type &, phase_type &, sc_core::sc_time &)> cb)
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19