scc  2022.4.0
SystemC components library
tlm_rec_initiator_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_INITIATOR_SOCKET_H_
18 #define TLM_REC_INITIATOR_SOCKET_H_
19 
20 #include <tlm/scc/scv/tlm_recorder.h>
21 #include <tlm>
22 
24 namespace tlm {
26 namespace scc {
28 namespace scv {
29 template <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  >
35 class tlm_rec_initiator_socket : public tlm::tlm_initiator_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 
47 public:
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<fw_interface_type, N
51 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
52  ,
53  POL
54 #endif
55  >;
56  using export_type = sc_core::sc_export<bw_interface_type>;
57  using base_target_socket_type = tlm::tlm_base_target_socket_b<BUSWIDTH, fw_interface_type, bw_interface_type>;
58  using base_type = tlm::tlm_base_initiator_socket_b<BUSWIDTH, fw_interface_type, bw_interface_type>;
59 
60  tlm_rec_initiator_socket()
61  : tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N
62 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
63  ,
64  POL
65 #endif
66  >()
67  , recorder(this->name(), fw_port, bw_port) {
68  }
69 
70  explicit tlm_rec_initiator_socket(const char* name)
71  : tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N
72 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
73  ,
74  POL
75 #endif
76  >(name)
77  , fw_port(sc_core::sc_gen_unique_name("$$$_fw"))
78  , bw_port(sc_core::sc_gen_unique_name("$$$_bw"))
79  , recorder(this->name(), fw_port, bw_port) {
80  }
81 
82  virtual ~tlm_rec_initiator_socket() {}
83 
84  virtual const char* kind() const { return "tlm_rec_target_socket"; }
85  //
86  // Bind initiator socket to target socket
87  // - Binds the port of the initiator socket to the export of the target
88  // socket
89  // - Binds the port of the target socket to the export of the initiator
90  // socket
91  //
92  virtual void bind(base_target_socket_type& s) {
93  // initiator.port -> target.export
94  (this->get_base_port())(recorder);
95  fw_port(s.get_base_interface());
96  // target.port -> initiator.export
97  (s.get_base_port())(recorder);
98  bw_port(this->get_base_interface());
99  }
100  //
101  // Bind initiator socket to initiator socket (hierarchical bind)
102  // - Binds both the export and the port
103  //
104  virtual void bind(base_type& s) {
105  // port
106  (this->get_base_port())(recorder);
107  fw_port(s.get_base_port());
108  // export
109  (s.get_base_export())(recorder);
110  bw_port(this->get_base_export());
111  }
112 
113  //
114  // Bind interface to socket
115  // - Binds the interface to the export of this socket
116  //
117  virtual void bind(bw_interface_type& ifs) { (this->get_base_export())(ifs); }
118 
119  void setExtensionRecording(tlm_extensions_recording_if<TYPES>* extensionRecording) {
120  recorder.setExtensionRecording(extensionRecording);
121  }
122 
123 protected:
124  sc_core::sc_port<tlm::tlm_fw_transport_if<TYPES>> fw_port{sc_core::sc_gen_unique_name("$$$__rec_fw__$$$")};
125  sc_core::sc_port<tlm::tlm_bw_transport_if<TYPES>> bw_port{sc_core::sc_gen_unique_name("$$$__rec_bw__$$$")};
126  scv::tlm_recorder<TYPES> recorder;
127 };
128 } // namespace scv
129 } // namespace scc
130 } // namespace tlm
131 
132 #endif /* TLM_REC_TARGET_SOCKET_H_ */
SCC SystemC utilities.
SystemC TLM.