target_socket.hh revision 13523
113521Sgabeblack@google.com/***************************************************************************** 213521Sgabeblack@google.com 313521Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 413521Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 513521Sgabeblack@google.com with this work for additional information regarding copyright ownership. 613521Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 713521Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 813521Sgabeblack@google.com License. You may obtain a copy of the License at 913521Sgabeblack@google.com 1013521Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1113521Sgabeblack@google.com 1213521Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1313521Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1413521Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1513521Sgabeblack@google.com implied. See the License for the specific language governing 1613521Sgabeblack@google.com permissions and limitations under the License. 1713521Sgabeblack@google.com 1813521Sgabeblack@google.com *****************************************************************************/ 1913521Sgabeblack@google.com 2013521Sgabeblack@google.com#ifndef __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_TARGET_SOCKET_HH__ 2113521Sgabeblack@google.com#define __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_TARGET_SOCKET_HH__ 2213521Sgabeblack@google.com 2313521Sgabeblack@google.com#include <typeindex> 2413521Sgabeblack@google.com 2513521Sgabeblack@google.com#include "tlm_core/2/interfaces/fw_bw_ifs.hh" 2613521Sgabeblack@google.com#include "tlm_core/2/sockets/base_socket_if.hh" 2713521Sgabeblack@google.com 2813521Sgabeblack@google.comnamespace tlm 2913521Sgabeblack@google.com{ 3013521Sgabeblack@google.com 3113521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>, 3213521Sgabeblack@google.com typename BW_IF=tlm_bw_transport_if<>> 3313521Sgabeblack@google.comclass tlm_base_target_socket_b 3413521Sgabeblack@google.com{ 3513521Sgabeblack@google.com public: 3613521Sgabeblack@google.com virtual ~tlm_base_target_socket_b() {} 3713521Sgabeblack@google.com 3813521Sgabeblack@google.com virtual sc_core::sc_port_b<BW_IF> &get_base_port() = 0; 3913521Sgabeblack@google.com virtual sc_core::sc_export<FW_IF> &get_base_export() = 0; 4013521Sgabeblack@google.com virtual FW_IF &get_base_interface() = 0; 4113521Sgabeblack@google.com}; 4213521Sgabeblack@google.com 4313521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF> 4413521Sgabeblack@google.comclass tlm_base_initiator_socket_b; 4513521Sgabeblack@google.com 4613521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N, 47 sc_core::sc_port_policy POL> 48class tlm_base_initiator_socket; 49 50template <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>, 51 typename BW_IF=tlm_bw_transport_if<>, int N=1, 52 sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 53class tlm_base_target_socket : 54 public tlm_base_socket_if, 55 public tlm_base_target_socket_b<BUSWIDTH, FW_IF, BW_IF>, 56 public sc_core::sc_export<FW_IF> 57{ 58 public: 59 typedef FW_IF fw_interface_type; 60 typedef BW_IF bw_interface_type; 61 typedef sc_core::sc_port<bw_interface_type, N, POL> port_type; 62 63 typedef sc_core::sc_export<fw_interface_type> export_type; 64 typedef tlm_base_initiator_socket_b< 65 BUSWIDTH, fw_interface_type, bw_interface_type> 66 base_initiator_socket_type; 67 68 typedef tlm_base_target_socket_b< 69 BUSWIDTH, fw_interface_type, bw_interface_type> base_type; 70 71 template <unsigned int, typename, typename, int, sc_core::sc_port_policy> 72 friend class tlm_base_initiator_socket; 73 74 public: 75 tlm_base_target_socket() : 76 export_type(sc_core::sc_gen_unique_name("tlm_base_target_socket")), 77 m_port(sc_core::sc_gen_unique_name("tlm_base_target_socket_port")) 78 {} 79 80 explicit tlm_base_target_socket(const char *name) : 81 export_type(name), m_port(sc_core::sc_gen_unique_name( 82 (std::string(name) + "_port").c_str())) 83 {} 84 85 virtual const char *kind() const { return "tlm_base_target_socket"; } 86 87 // 88 // Bind target socket to initiator socket 89 // - Binds the port of the initiator socket to the export of the target 90 // socket 91 // - Binds the port of the target socket to the export of the initiator 92 // socket 93 // 94 virtual void 95 bind(base_initiator_socket_type &s) 96 { 97 // initiator.port -> target.export 98 (s.get_base_port())(get_base_interface()); 99 // target.port -> initiator.export 100 get_base_port()(s.get_base_interface()); 101 } 102 103 void operator () (base_initiator_socket_type &s) { bind(s); } 104 105 // 106 // Bind target socket to target socket (hierarchical bind) 107 // - Binds both the export and the port 108 // 109 virtual void 110 bind(base_type &s) 111 { 112 // export 113 (get_base_export())(s.get_base_export()); 114 // port 115 (s.get_base_port())(get_base_port()); 116 } 117 118 void operator () (base_type &s) { bind(s); } 119 120 // 121 // Bind interface to socket 122 // - Binds the interface to the export 123 // 124 virtual void 125 bind(fw_interface_type &ifs) 126 { 127 export_type *exp = &get_base_export(); 128 if (this == exp) { 129 export_type::bind(ifs); 130 } else { 131 exp->bind( ifs ); 132 } 133 } 134 135 void operator () (fw_interface_type &s) { bind(s); } 136 137 // 138 // Forward to 'size()' of port class. 139 // 140 int size() const { return m_port.size(); } 141 142 // 143 // Forward to 'operator->()' of port class. 144 // 145 bw_interface_type *operator->() { return m_port.operator->(); } 146 147 // 148 // Forward to 'operator[]()' of port class. 149 // 150 bw_interface_type *operator[](int i) { return m_port.operator[](i); } 151 152 // Implementation of tlm_base_socket_if functions. 153 virtual sc_core::sc_port_base &get_port_base() { return m_port; } 154 virtual sc_core::sc_port_base const & 155 get_port_base() const 156 { 157 return m_port; 158 } 159 virtual sc_core::sc_export_base &get_export_base() { return *this; } 160 virtual sc_core::sc_export_base const & 161 get_export_base() const 162 { 163 return *this; 164 } 165 virtual unsigned int get_bus_width() const { return BUSWIDTH; } 166 virtual tlm_socket_category 167 get_socket_category() const 168 { 169 return TLM_TARGET_SOCKET; 170 } 171 172 // Implementation of tlm_base_target_socket_b functions 173 virtual sc_core::sc_port_b<BW_IF> &get_base_port() { return m_port; } 174 virtual sc_core::sc_port_b<BW_IF> const & 175 get_base_port() const 176 { 177 return m_port; 178 } 179 180 virtual FW_IF &get_base_interface() { return *this; } 181 virtual FW_IF const &get_base_interface() const { return *this; } 182 183 virtual sc_core::sc_export<FW_IF> &get_base_export() { return *this; } 184 virtual sc_core::sc_export<FW_IF> const & 185 get_base_export() const 186 { 187 return *this; 188 } 189 190 protected: 191 port_type m_port; 192}; 193 194template <unsigned int BUSWIDTH=32, typename TYPES=tlm_base_protocol_types, 195 int N=1, sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 196class tlm_target_socket : 197 public tlm_base_target_socket< 198 BUSWIDTH, tlm_fw_transport_if<TYPES>, 199 tlm_bw_transport_if<TYPES>, N, POL> 200{ 201 public: 202 tlm_target_socket() : 203 tlm_base_target_socket< 204 BUSWIDTH, tlm_fw_transport_if<TYPES>, 205 tlm_bw_transport_if<TYPES>, N, POL>() 206 {} 207 208 explicit tlm_target_socket(const char *name) : 209 tlm_base_target_socket< 210 BUSWIDTH, tlm_fw_transport_if<TYPES>, 211 tlm_bw_transport_if<TYPES>, N, POL>(name) 212 {} 213 214 virtual const char* kind() const { return "tlm_target_socket"; } 215 216 virtual std::type_index 217 get_protocol_types() const 218 { 219 return typeid(TYPES); 220 } 221}; 222 223} // namespace tlm 224 225#endif /* __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_TARGET_SOCKET_HH__ */ 226