scc  2024.06
SystemC components library
socket_width_adapter.h
1 /*******************************************************************************
2  * Copyright 2024 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_SOCKET_WIDTH_ADAPTER_H_
18 #define _SCC_SOCKET_WIDTH_ADAPTER_H_
19 
20 #include <tlm>
21 
23 namespace scc {
24 
25 template <unsigned int TGT_WIDTH = 32, unsigned int INTOR_BUSWIDTH = 32, typename TYPES = tlm::tlm_base_protocol_types, int N = 1,
26  sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND>
27 class socket_width_adapter : public sc_core::sc_module, public tlm::tlm_fw_transport_if<TYPES>, public tlm::tlm_bw_transport_if<TYPES> {
28 public:
29  using tlm_payload_type = typename TYPES::tlm_payload_type;
30  using tlm_phase_type = typename TYPES::tlm_phase_type;
31  using target_socket_type = tlm::tlm_target_socket<TGT_WIDTH, TYPES, N, POL>;
32  using initiator_socket_type = tlm::tlm_initiator_socket<INTOR_BUSWIDTH, TYPES, N, POL>;
33 
34  target_socket_type tsck{"tsck"};
35 
36  initiator_socket_type isck{"isck"};
37 
38  socket_width_adapter(sc_core::sc_module_name const& nm)
39  : sc_core::sc_module(nm) {
40  tsck.bind(*this);
41  isck.bind(*this);
42  }
43 
44  socket_width_adapter() = delete;
45 
47 
49 
50  virtual ~socket_width_adapter() = default;
51 
52 private:
53  tlm::tlm_sync_enum nb_transport_fw(tlm_payload_type& trans, tlm_phase_type& phase, sc_core::sc_time& t) override {
54  return isck->nb_transport_fw(trans, phase, t);
55  };
56 
57  void b_transport(tlm_payload_type& trans, sc_core::sc_time& t) override { isck->b_transport(trans, t); }
58 
59  bool get_direct_mem_ptr(tlm_payload_type& trans, tlm::tlm_dmi& dmi_data) override { return isck->get_direct_mem_ptr(trans, dmi_data); }
60 
61  unsigned int transport_dbg(tlm_payload_type& trans) override { return isck->transport_dbg(trans); }
62 
63  tlm::tlm_sync_enum nb_transport_bw(tlm_payload_type& trans, tlm_phase_type& phase, sc_core::sc_time& t) override {
64  return tsck->nb_transport_bw(trans, phase, t);
65  }
66 
67  void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) override {
68  tsck->invalidate_direct_mem_ptr(start_range, end_range);
69  }
70 };
71 } // namespace scc
72 #endif // _SCC_SOCKET_WIDTH_ADAPTER_H_
SCC TLM utilities.