tlm_initiator_socket.h revision 12027:1eb7dc7aa10b
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20#ifndef __TLM_INITIATOR_SOCKET_H__ 21#define __TLM_INITIATOR_SOCKET_H__ 22 23//#include <systemc> 24#include "tlm_core/tlm_2/tlm_2_interfaces/tlm_fw_bw_ifs.h" 25 26namespace tlm { 27 28 29template <unsigned int BUSWIDTH = 32, 30 typename FW_IF = tlm_fw_transport_if<>, 31 typename BW_IF = tlm_bw_transport_if<> > 32class tlm_base_initiator_socket_b 33{ 34public: 35 virtual ~tlm_base_initiator_socket_b() {} 36 37 virtual sc_core::sc_port_b<FW_IF> & get_base_port() = 0; 38 virtual sc_core::sc_port_b<FW_IF> const & get_base_port() const = 0; 39 virtual BW_IF & get_base_interface() = 0; 40 virtual BW_IF const & get_base_interface() const = 0; 41 virtual sc_core::sc_export<BW_IF> & get_base_export() = 0; 42 virtual sc_core::sc_export<BW_IF> const & get_base_export() const = 0; 43}; 44 45 46template <unsigned int BUSWIDTH, 47 typename FW_IF, 48 typename BW_IF> class tlm_base_target_socket_b; 49 50template <unsigned int BUSWIDTH, 51 typename FW_IF, 52 typename BW_IF, 53 int N 54#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 55 ,sc_core::sc_port_policy POL 56#endif 57 > class tlm_base_target_socket; 58 59template <unsigned int BUSWIDTH = 32, 60 typename FW_IF = tlm_fw_transport_if<>, 61 typename BW_IF = tlm_bw_transport_if<>, 62 int N = 1 63#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 64 ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND 65#endif 66 > 67class tlm_base_initiator_socket : public tlm_base_initiator_socket_b<BUSWIDTH, FW_IF, BW_IF>, 68 public sc_core::sc_port<FW_IF, N 69#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 70 , POL 71#endif 72 > 73 74{ 75public: 76 typedef FW_IF fw_interface_type; 77 typedef BW_IF bw_interface_type; 78 typedef sc_core::sc_port<fw_interface_type, N 79#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 80 , POL 81#endif 82 > port_type; 83 84 typedef sc_core::sc_export<bw_interface_type> export_type; 85 86 typedef tlm_base_target_socket_b<BUSWIDTH, 87 fw_interface_type, 88 bw_interface_type> base_target_socket_type; 89 typedef tlm_base_initiator_socket_b<BUSWIDTH, 90 fw_interface_type, 91 bw_interface_type> base_type; 92 93 template <unsigned int, typename, typename, int 94#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 95 ,sc_core::sc_port_policy 96#endif 97 > 98 friend class tlm_base_target_socket; 99 100public: 101 tlm_base_initiator_socket() 102 : port_type(sc_core::sc_gen_unique_name("tlm_base_initiator_socket")) 103 , m_export(sc_core::sc_gen_unique_name("tlm_base_initiator_socket_export")) 104 { 105 } 106 107 explicit tlm_base_initiator_socket(const char* name) 108 : port_type(name) 109 , m_export(sc_core::sc_gen_unique_name((std::string(name) + "_export").c_str())) 110 { 111 } 112 113 virtual const char* kind() const 114 { 115 return "tlm_base_initiator_socket"; 116 } 117 118 unsigned int get_bus_width() const 119 { 120 return BUSWIDTH; 121 } 122 123 // 124 // Bind initiator socket to target socket 125 // - Binds the port of the initiator socket to the export of the target 126 // socket 127 // - Binds the port of the target socket to the export of the initiator 128 // socket 129 // 130 virtual void bind(base_target_socket_type& s) 131 { 132 // initiator.port -> target.export 133 (get_base_port())(s.get_base_interface()); 134 // target.port -> initiator.export 135 (s.get_base_port())(get_base_interface()); 136 } 137 138 void operator() (base_target_socket_type& s) 139 { 140 bind(s); 141 } 142 143 // 144 // Bind initiator socket to initiator socket (hierarchical bind) 145 // - Binds both the export and the port 146 // 147 virtual void bind(base_type& s) 148 { 149 // port 150 (get_base_port())(s.get_base_port()); 151 // export 152 (s.get_base_export())(get_base_export()); 153 } 154 155 void operator() (base_type& s) 156 { 157 bind(s); 158 } 159 160 // 161 // Bind interface to socket 162 // - Binds the interface to the export of this socket 163 // 164 virtual void bind(bw_interface_type& ifs) 165 { 166 (get_base_export())(ifs); 167 } 168 169 void operator() (bw_interface_type& s) 170 { 171 bind(s); 172 } 173 174 // Implementation of pure virtual functions of base class 175 virtual sc_core::sc_port_b<FW_IF> & get_base_port() 176 { return *this; } 177 virtual sc_core::sc_port_b<FW_IF> const & get_base_port() const 178 { return *this; } 179 180 virtual BW_IF & get_base_interface() 181 { return m_export; } 182 virtual BW_IF const & get_base_interface() const 183#if !( defined(IEEE_1666_SYSTEMC) && IEEE_1666_SYSTEMC >= 201101L ) 184 { return const_cast<export_type &>(m_export); } 185#else 186 { return m_export; } 187#endif 188 189 virtual sc_core::sc_export<BW_IF> & get_base_export() 190 { return m_export; } 191 virtual sc_core::sc_export<BW_IF> const & get_base_export() const 192 { return m_export; } 193 194protected: 195 export_type m_export; 196}; 197 198// 199// Convenience socket classes 200// 201 202template <unsigned int BUSWIDTH = 32, 203 typename TYPES = tlm_base_protocol_types, 204 int N = 1 205#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 206 ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND 207#endif 208 > 209class tlm_initiator_socket : 210 public tlm_base_initiator_socket <BUSWIDTH, 211 tlm_fw_transport_if<TYPES>, 212 tlm_bw_transport_if<TYPES>, 213 N 214#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 215 ,POL 216#endif 217 > 218{ 219public: 220 tlm_initiator_socket() : 221 tlm_base_initiator_socket<BUSWIDTH, 222 tlm_fw_transport_if<TYPES>, 223 tlm_bw_transport_if<TYPES>, 224 N 225#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 226 ,POL 227#endif 228 >() 229 { 230 } 231 232 explicit tlm_initiator_socket(const char* name) : 233 tlm_base_initiator_socket<BUSWIDTH, 234 tlm_fw_transport_if<TYPES>, 235 tlm_bw_transport_if<TYPES>, 236 N 237#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714) 238 ,POL 239#endif 240 >(name) 241 { 242 } 243 244 virtual const char* kind() const 245 { 246 return "tlm_initiator_socket"; 247 } 248}; 249 250} // namespace tlm 251 252#endif 253