initiator_socket.hh revision 13521:74fa3ac44057
112866Sgabeblack@google.com/***************************************************************************** 212866Sgabeblack@google.com 312866Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412866Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512866Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612866Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712866Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812866Sgabeblack@google.com License. You may obtain a copy of the License at 912866Sgabeblack@google.com 1012866Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112866Sgabeblack@google.com 1212866Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312866Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412866Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512866Sgabeblack@google.com implied. See the License for the specific language governing 1612866Sgabeblack@google.com permissions and limitations under the License. 1712866Sgabeblack@google.com 1812866Sgabeblack@google.com *****************************************************************************/ 1912866Sgabeblack@google.com 2012866Sgabeblack@google.com#ifndef __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__ 2112866Sgabeblack@google.com#define __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__ 2212866Sgabeblack@google.com 2312866Sgabeblack@google.com#include "tlm_core/2/interfaces/fw_bw_ifs.hh" 2412866Sgabeblack@google.com#include "tlm_core/2/sockets/base_socket_if.hh" 2512866Sgabeblack@google.com 2612866Sgabeblack@google.comnamespace tlm 2712866Sgabeblack@google.com{ 2812866Sgabeblack@google.com 2912866Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, 3012866Sgabeblack@google.com typename FW_IF=tlm_fw_transport_if<>, 3112866Sgabeblack@google.com typename BW_IF=tlm_bw_transport_if<>> 3212866Sgabeblack@google.comclass tlm_base_initiator_socket_b 3312866Sgabeblack@google.com{ 3412866Sgabeblack@google.com public: 3512866Sgabeblack@google.com virtual ~tlm_base_initiator_socket_b() {} 3612866Sgabeblack@google.com 3712866Sgabeblack@google.com virtual sc_core::sc_port_b<FW_IF> &get_base_port() = 0; 3812866Sgabeblack@google.com virtual sc_core::sc_port_b<FW_IF> const &get_base_port() const = 0; 3912866Sgabeblack@google.com virtual BW_IF &get_base_interface() = 0; 4012866Sgabeblack@google.com virtual BW_IF const &get_base_interface() const = 0; 4112866Sgabeblack@google.com virtual sc_core::sc_export<BW_IF> &get_base_export() = 0; 4212866Sgabeblack@google.com virtual sc_core::sc_export<BW_IF> const &get_base_export() const = 0; 4312866Sgabeblack@google.com}; 4412866Sgabeblack@google.com 4512866Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF> 4612866Sgabeblack@google.comclass tlm_base_target_socket_b; 4713458Sgabeblack@google.com 4812866Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N, 4912866Sgabeblack@google.com sc_core::sc_port_policy POL> 5012866Sgabeblack@google.comclass tlm_base_target_socket; 5112866Sgabeblack@google.com 5212866Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>, 5312866Sgabeblack@google.com typename BW_IF=tlm_bw_transport_if<>, int N=1, 5412866Sgabeblack@google.com sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 5512866Sgabeblack@google.comclass tlm_base_initiator_socket : 5612866Sgabeblack@google.com public tlm_base_socket_if, 5712866Sgabeblack@google.com public tlm_base_initiator_socket_b<BUSWIDTH, FW_IF, BW_IF>, 5812866Sgabeblack@google.com public sc_core::sc_port<FW_IF, N, POL> 5912866Sgabeblack@google.com{ 6012866Sgabeblack@google.com public: 6112866Sgabeblack@google.com typedef FW_IF fw_interface_type; 6213458Sgabeblack@google.com typedef BW_IF bw_interface_type; 6313458Sgabeblack@google.com typedef sc_core::sc_port<fw_interface_type, N, POL> port_type; 6412866Sgabeblack@google.com 6512866Sgabeblack@google.com typedef sc_core::sc_export<bw_interface_type> export_type; 6612922Sgabeblack@google.com 6712869Sgabeblack@google.com typedef tlm_base_target_socket_b< 6812866Sgabeblack@google.com BUSWIDTH, fw_interface_type, bw_interface_type> 6912869Sgabeblack@google.com base_target_socket_type; 7013458Sgabeblack@google.com typedef tlm_base_initiator_socket_b< 7113458Sgabeblack@google.com BUSWIDTH, fw_interface_type, bw_interface_type> base_type; 7212866Sgabeblack@google.com 7312866Sgabeblack@google.com template <unsigned int, typename, typename, int, sc_core::sc_port_policy> 7412866Sgabeblack@google.com friend class tlm_base_target_socket; 7512866Sgabeblack@google.com 7612866Sgabeblack@google.com public: 7712866Sgabeblack@google.com tlm_base_initiator_socket() : 7812866Sgabeblack@google.com port_type(sc_core::sc_gen_unique_name("tlm_base_initiator_socket")), 7912866Sgabeblack@google.com m_export(sc_core::sc_gen_unique_name( 8012866Sgabeblack@google.com "tlm_base_initiator_socket_export")) 8112866Sgabeblack@google.com {} 8212922Sgabeblack@google.com 8312866Sgabeblack@google.com explicit tlm_base_initiator_socket(const char *name) : port_type(name), 8413098Sgabeblack@google.com m_export(sc_core::sc_gen_unique_name( 8513098Sgabeblack@google.com (std::string(name) + "_export").c_str())) 8613098Sgabeblack@google.com {} 8713098Sgabeblack@google.com 8812866Sgabeblack@google.com virtual const char* kind() const { return "tlm_base_initiator_socket"; } 8912866Sgabeblack@google.com 9012869Sgabeblack@google.com // 9113098Sgabeblack@google.com // Bind initiator socket to target socket 9212869Sgabeblack@google.com // - Binds the port of the initiator socket to the export of the target 9312869Sgabeblack@google.com // socket 9412869Sgabeblack@google.com // - Binds the port of the target socket to the export of the initiator 9512869Sgabeblack@google.com // socket 9613098Sgabeblack@google.com // 9713098Sgabeblack@google.com virtual void 9813098Sgabeblack@google.com bind(base_target_socket_type &s) 9913098Sgabeblack@google.com { 10013098Sgabeblack@google.com // initiator.port -> target.export 10113655Sgabeblack@google.com (get_base_port())(s.get_base_interface()); 10213655Sgabeblack@google.com // target.port -> initiator.export 10313458Sgabeblack@google.com (s.get_base_port())(get_base_interface()); 10413458Sgabeblack@google.com } 10513458Sgabeblack@google.com 10613458Sgabeblack@google.com void operator () (base_target_socket_type &s) { bind(s); } 10713458Sgabeblack@google.com 10812869Sgabeblack@google.com // 10912866Sgabeblack@google.com // Bind initiator socket to initiator socket (hierarchical bind) 11012866Sgabeblack@google.com // - Binds both the export and the port 11112866Sgabeblack@google.com // 11212866Sgabeblack@google.com virtual void 11312866Sgabeblack@google.com bind(base_type &s) 11412866Sgabeblack@google.com { 11512866Sgabeblack@google.com // port 11612866Sgabeblack@google.com (get_base_port())(s.get_base_port()); 11712866Sgabeblack@google.com // export 11812866Sgabeblack@google.com (s.get_base_export())(get_base_export()); 11912866Sgabeblack@google.com } 12012866Sgabeblack@google.com 12112866Sgabeblack@google.com void operator() (base_type &s) { bind(s); } 12212866Sgabeblack@google.com 12312866Sgabeblack@google.com // 12412866Sgabeblack@google.com // Bind interface to socket 12512866Sgabeblack@google.com // - Binds the interface to the export of this socket 12612866Sgabeblack@google.com // 12712866Sgabeblack@google.com virtual void bind(bw_interface_type &ifs) { (get_base_export())(ifs); } 12812866Sgabeblack@google.com void operator() (bw_interface_type &s) { bind(s); } 12912866Sgabeblack@google.com 13013458Sgabeblack@google.com // Implementation of tlm_base_socket_if functions 13113458Sgabeblack@google.com virtual sc_core::sc_port_base &get_port_base() { return *this; } 13213458Sgabeblack@google.com virtual sc_core::sc_port_base const & 13313458Sgabeblack@google.com get_port_base() const 13413458Sgabeblack@google.com { 13513458Sgabeblack@google.com return *this; 13613458Sgabeblack@google.com } 13713458Sgabeblack@google.com virtual sc_core::sc_export_base &get_export_base() { return m_export; } 13813458Sgabeblack@google.com virtual sc_core::sc_export_base const & 13912866Sgabeblack@google.com get_export_base() const 14012866Sgabeblack@google.com { 14112866Sgabeblack@google.com return m_export; 14212866Sgabeblack@google.com } 14312866Sgabeblack@google.com virtual unsigned int get_bus_width() const { return BUSWIDTH; } 14412866Sgabeblack@google.com virtual tlm_socket_category 14512866Sgabeblack@google.com get_socket_category() const 14612866Sgabeblack@google.com { 14712866Sgabeblack@google.com return TLM_INITIATOR_SOCKET; 14812866Sgabeblack@google.com } 14912866Sgabeblack@google.com 15012866Sgabeblack@google.com // Implementation of tlm_base_target_socket_b functions 15112866Sgabeblack@google.com virtual sc_core::sc_port_b<FW_IF> &get_base_port() { return *this; } 15212866Sgabeblack@google.com virtual sc_core::sc_port_b<FW_IF> const & 15312866Sgabeblack@google.com get_base_port() const 15412866Sgabeblack@google.com { 15512866Sgabeblack@google.com return *this; 15612866Sgabeblack@google.com } 15712866Sgabeblack@google.com 15812866Sgabeblack@google.com virtual BW_IF &get_base_interface() { return m_export; } 15912866Sgabeblack@google.com virtual BW_IF const &get_base_interface() const { return m_export; } 16012866Sgabeblack@google.com 16113458Sgabeblack@google.com virtual sc_core::sc_export<BW_IF> &get_base_export() { return m_export; } 16213458Sgabeblack@google.com virtual sc_core::sc_export<BW_IF> const & 16312866Sgabeblack@google.com get_base_export() const 16412866Sgabeblack@google.com { 16512866Sgabeblack@google.com return m_export; 16612866Sgabeblack@google.com } 16713458Sgabeblack@google.com 16813458Sgabeblack@google.com protected: 16913458Sgabeblack@google.com export_type m_export; 17012866Sgabeblack@google.com}; 17112866Sgabeblack@google.com 17212866Sgabeblack@google.com// 17312866Sgabeblack@google.com// Convenience socket classes 17413512Sgabeblack@google.com// 17512866Sgabeblack@google.com 17612866Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename TYPES=tlm_base_protocol_types, 17712866Sgabeblack@google.com int N=1, sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND> 17812866Sgabeblack@google.comclass tlm_initiator_socket : public tlm_base_initiator_socket< 17912866Sgabeblack@google.com BUSWIDTH, tlm_fw_transport_if<TYPES>, 18012866Sgabeblack@google.com tlm_bw_transport_if<TYPES>, N, POL> 18112866Sgabeblack@google.com{ 18212866Sgabeblack@google.com public: 18312866Sgabeblack@google.com tlm_initiator_socket() : tlm_base_initiator_socket< 18412866Sgabeblack@google.com BUSWIDTH, tlm_fw_transport_if<TYPES>, 18512866Sgabeblack@google.com tlm_bw_transport_if<TYPES>, N, POL>() 18612866Sgabeblack@google.com {} 18712866Sgabeblack@google.com 188 explicit tlm_initiator_socket(const char *name) : 189 tlm_base_initiator_socket<BUSWIDTH, tlm_fw_transport_if<TYPES>, 190 tlm_bw_transport_if<TYPES>, N, POL>(name) 191 {} 192 193 virtual const char *kind() const { return "tlm_initiator_socket"; } 194 195 virtual sc_core::sc_type_index 196 get_protocol_types() const 197 { 198 return typeid(TYPES); 199 } 200}; 201 202} // namespace tlm 203 204#endif /* __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__ */ 205