scc 2025.09
SystemC components library
tlm_rec_target_socket.h
1/*******************************************************************************
2 * Copyright 2016, 2017 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_REC_TARGET_SOCKET_H_
18#define TLM_REC_TARGET_SOCKET_H_
19
20#include <tlm/scc/scv/tlm_recorder.h>
21#include <tlm>
22
24namespace tlm {
26namespace scc {
28namespace scv {
29template <unsigned int BUSWIDTH = 32, typename TYPES = tlm::tlm_base_protocol_types, int N = 1
30#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
31 ,
32 sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND
33#endif
34 >
35class tlm_rec_target_socket : public tlm::tlm_target_socket<BUSWIDTH, TYPES, N
36#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
37 ,
38 POL
39#endif
40 > {
41 static std::string gen_name(const char* first, const char* second) {
42 std::stringstream ss;
43 ss << first << "_" << second;
44 return ss.str();
45 }
46
47public:
48 using fw_interface_type = tlm::tlm_fw_transport_if<TYPES>;
49 using bw_interface_type = tlm::tlm_bw_transport_if<TYPES>;
50 using port_type = sc_core::sc_port<bw_interface_type, N
51#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
52 ,
53 POL
54#endif
55 >;
56
57 using export_type = sc_core::sc_export<fw_interface_type>;
58 using base_initiator_socket_type = tlm::tlm_base_initiator_socket_b<BUSWIDTH, fw_interface_type, bw_interface_type>;
59 using base_type = tlm::tlm_base_target_socket_b<BUSWIDTH, fw_interface_type, bw_interface_type>;
60
61 tlm_rec_target_socket()
62 : tlm::tlm_target_socket<BUSWIDTH, TYPES, N
63#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
64 ,
65 POL
66#endif
67 >()
68 , recorder(this->name(), fw_port, this->get_base_port()) {
69 }
70
71 explicit tlm_rec_target_socket(const char* name)
72 : tlm::tlm_target_socket<BUSWIDTH, TYPES, N
73#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
74 ,
75 POL
76#endif
77 >(name)
78 , recorder(this->name(), fw_port, this->get_base_port()) {
79 }
80
81 virtual ~tlm_rec_target_socket() = default; // NOLINT
82
83 virtual const char* kind() const { return "tlm_rec_target_socket"; }
84 //
85 // Bind target socket to target socket (hierarchical bind)
86 // - Binds both the export and the port
87 //
88 virtual void bind(base_type& s) {
89 // export
90 (this->get_base_export())(s.get_base_export()); // will be handled by bind(fw_interface_type& ifs)
91 // port
92 (s.get_base_port())(recorder); // bind the recording interface to the port,
93 // recording will use the m_port
94 }
95 //
96 // Bind interface to socket
97 // - Binds the interface to the export
98 //
99 virtual void bind(fw_interface_type& ifs) {
100 export_type* exp = &this->get_base_export();
101 if(this == exp) {
102 export_type::bind(recorder); // non-virtual function call
103 fw_port(ifs);
104 } else {
105 exp->bind(ifs);
106 }
107 }
108 //
109 // Forward to 'operator->()' of port class
110 //
111 bw_interface_type* operator->() { return &recorder; }
112
113 void setExtensionRecording(tlm_extensions_recording_if<TYPES>* extensionRecording) {
114 recorder.setExtensionRecording(extensionRecording);
115 }
116
117protected:
118 sc_core::sc_port<fw_interface_type> fw_port{sc_core::sc_gen_unique_name("$$$__rec_fw__$$$")};
119 scv::tlm_recorder<TYPES> recorder;
120};
121} // namespace scv
122} // namespace scc
123} // namespace tlm
124
125#endif /* TLM_REC_TARGET_SOCKET_H_ */
SCC SCV4TLM classes and functions.
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19