initiator_socket.hh revision 13521
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_INITIATOR_SOCKET_HH__
2113521Sgabeblack@google.com#define __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__
2213521Sgabeblack@google.com
2313521Sgabeblack@google.com#include "tlm_core/2/interfaces/fw_bw_ifs.hh"
2413521Sgabeblack@google.com#include "tlm_core/2/sockets/base_socket_if.hh"
2513521Sgabeblack@google.com
2613521Sgabeblack@google.comnamespace tlm
2713521Sgabeblack@google.com{
2813521Sgabeblack@google.com
2913521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32,
3013521Sgabeblack@google.com          typename FW_IF=tlm_fw_transport_if<>,
3113521Sgabeblack@google.com          typename BW_IF=tlm_bw_transport_if<>>
3213521Sgabeblack@google.comclass tlm_base_initiator_socket_b
3313521Sgabeblack@google.com{
3413521Sgabeblack@google.com  public:
3513521Sgabeblack@google.com    virtual ~tlm_base_initiator_socket_b() {}
3613521Sgabeblack@google.com
3713521Sgabeblack@google.com    virtual sc_core::sc_port_b<FW_IF> &get_base_port() = 0;
3813521Sgabeblack@google.com    virtual sc_core::sc_port_b<FW_IF> const &get_base_port() const = 0;
3913521Sgabeblack@google.com    virtual BW_IF &get_base_interface() = 0;
4013521Sgabeblack@google.com    virtual BW_IF const &get_base_interface() const = 0;
4113521Sgabeblack@google.com    virtual sc_core::sc_export<BW_IF> &get_base_export() = 0;
4213521Sgabeblack@google.com    virtual sc_core::sc_export<BW_IF> const &get_base_export() const = 0;
4313521Sgabeblack@google.com};
4413521Sgabeblack@google.com
4513521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF>
4613521Sgabeblack@google.comclass tlm_base_target_socket_b;
4713521Sgabeblack@google.com
4813521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
4913521Sgabeblack@google.com          sc_core::sc_port_policy POL>
5013521Sgabeblack@google.comclass tlm_base_target_socket;
5113521Sgabeblack@google.com
5213521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>,
5313521Sgabeblack@google.com          typename BW_IF=tlm_bw_transport_if<>, int N=1,
5413521Sgabeblack@google.com          sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
5513521Sgabeblack@google.comclass tlm_base_initiator_socket :
5613521Sgabeblack@google.com    public tlm_base_socket_if,
5713521Sgabeblack@google.com    public tlm_base_initiator_socket_b<BUSWIDTH, FW_IF, BW_IF>,
5813521Sgabeblack@google.com    public sc_core::sc_port<FW_IF, N, POL>
5913521Sgabeblack@google.com{
6013521Sgabeblack@google.com  public:
6113521Sgabeblack@google.com    typedef FW_IF fw_interface_type;
6213521Sgabeblack@google.com    typedef BW_IF bw_interface_type;
6313521Sgabeblack@google.com    typedef sc_core::sc_port<fw_interface_type, N, POL> port_type;
6413521Sgabeblack@google.com
6513521Sgabeblack@google.com    typedef sc_core::sc_export<bw_interface_type> export_type;
6613521Sgabeblack@google.com
6713521Sgabeblack@google.com    typedef tlm_base_target_socket_b<
6813521Sgabeblack@google.com        BUSWIDTH, fw_interface_type, bw_interface_type>
6913521Sgabeblack@google.com        base_target_socket_type;
7013521Sgabeblack@google.com    typedef tlm_base_initiator_socket_b<
7113521Sgabeblack@google.com        BUSWIDTH, fw_interface_type, bw_interface_type> base_type;
7213521Sgabeblack@google.com
7313521Sgabeblack@google.com    template <unsigned int, typename, typename, int, sc_core::sc_port_policy>
7413521Sgabeblack@google.com    friend class tlm_base_target_socket;
7513521Sgabeblack@google.com
7613521Sgabeblack@google.com  public:
7713521Sgabeblack@google.com    tlm_base_initiator_socket() :
7813521Sgabeblack@google.com        port_type(sc_core::sc_gen_unique_name("tlm_base_initiator_socket")),
7913521Sgabeblack@google.com        m_export(sc_core::sc_gen_unique_name(
8013521Sgabeblack@google.com                    "tlm_base_initiator_socket_export"))
8113521Sgabeblack@google.com    {}
8213521Sgabeblack@google.com
8313521Sgabeblack@google.com    explicit tlm_base_initiator_socket(const char *name) : port_type(name),
8413521Sgabeblack@google.com        m_export(sc_core::sc_gen_unique_name(
8513521Sgabeblack@google.com                    (std::string(name) + "_export").c_str()))
8613521Sgabeblack@google.com    {}
8713521Sgabeblack@google.com
8813521Sgabeblack@google.com    virtual const char* kind() const { return "tlm_base_initiator_socket"; }
8913521Sgabeblack@google.com
9013521Sgabeblack@google.com    //
9113521Sgabeblack@google.com    // Bind initiator socket to target socket
9213521Sgabeblack@google.com    // - Binds the port of the initiator socket to the export of the target
9313521Sgabeblack@google.com    //   socket
9413521Sgabeblack@google.com    // - Binds the port of the target socket to the export of the initiator
9513521Sgabeblack@google.com    //   socket
9613521Sgabeblack@google.com    //
9713521Sgabeblack@google.com    virtual void
9813521Sgabeblack@google.com    bind(base_target_socket_type &s)
9913521Sgabeblack@google.com    {
10013521Sgabeblack@google.com        // initiator.port -> target.export
10113521Sgabeblack@google.com        (get_base_port())(s.get_base_interface());
10213521Sgabeblack@google.com        // target.port -> initiator.export
10313521Sgabeblack@google.com        (s.get_base_port())(get_base_interface());
10413521Sgabeblack@google.com    }
10513521Sgabeblack@google.com
10613521Sgabeblack@google.com    void operator () (base_target_socket_type &s) { bind(s); }
10713521Sgabeblack@google.com
10813521Sgabeblack@google.com    //
10913521Sgabeblack@google.com    // Bind initiator socket to initiator socket (hierarchical bind)
11013521Sgabeblack@google.com    // - Binds both the export and the port
11113521Sgabeblack@google.com    //
11213521Sgabeblack@google.com    virtual void
11313521Sgabeblack@google.com    bind(base_type &s)
11413521Sgabeblack@google.com    {
11513521Sgabeblack@google.com        // port
11613521Sgabeblack@google.com        (get_base_port())(s.get_base_port());
11713521Sgabeblack@google.com        // export
11813521Sgabeblack@google.com        (s.get_base_export())(get_base_export());
11913521Sgabeblack@google.com    }
12013521Sgabeblack@google.com
12113521Sgabeblack@google.com    void operator() (base_type &s) { bind(s); }
12213521Sgabeblack@google.com
12313521Sgabeblack@google.com    //
12413521Sgabeblack@google.com    // Bind interface to socket
12513521Sgabeblack@google.com    // - Binds the interface to the export of this socket
12613521Sgabeblack@google.com    //
12713521Sgabeblack@google.com    virtual void bind(bw_interface_type &ifs) { (get_base_export())(ifs); }
12813521Sgabeblack@google.com    void operator() (bw_interface_type &s) { bind(s); }
12913521Sgabeblack@google.com
13013521Sgabeblack@google.com    // Implementation of tlm_base_socket_if functions
13113521Sgabeblack@google.com    virtual sc_core::sc_port_base &get_port_base() { return *this; }
13213521Sgabeblack@google.com    virtual sc_core::sc_port_base const &
13313521Sgabeblack@google.com    get_port_base() const
13413521Sgabeblack@google.com    {
13513521Sgabeblack@google.com        return *this;
13613521Sgabeblack@google.com    }
13713521Sgabeblack@google.com    virtual sc_core::sc_export_base &get_export_base() { return m_export; }
13813521Sgabeblack@google.com    virtual sc_core::sc_export_base const &
13913521Sgabeblack@google.com    get_export_base() const
14013521Sgabeblack@google.com    {
14113521Sgabeblack@google.com        return m_export;
14213521Sgabeblack@google.com    }
14313521Sgabeblack@google.com    virtual unsigned int get_bus_width() const { return BUSWIDTH; }
14413521Sgabeblack@google.com    virtual tlm_socket_category
14513521Sgabeblack@google.com    get_socket_category() const
14613521Sgabeblack@google.com    {
14713521Sgabeblack@google.com        return TLM_INITIATOR_SOCKET;
14813521Sgabeblack@google.com    }
14913521Sgabeblack@google.com
15013521Sgabeblack@google.com    // Implementation of tlm_base_target_socket_b functions
15113521Sgabeblack@google.com    virtual sc_core::sc_port_b<FW_IF> &get_base_port() { return *this; }
15213521Sgabeblack@google.com    virtual sc_core::sc_port_b<FW_IF> const &
15313521Sgabeblack@google.com    get_base_port() const
15413521Sgabeblack@google.com    {
15513521Sgabeblack@google.com        return *this;
15613521Sgabeblack@google.com    }
15713521Sgabeblack@google.com
15813521Sgabeblack@google.com    virtual BW_IF &get_base_interface() { return m_export; }
15913521Sgabeblack@google.com    virtual BW_IF const &get_base_interface() const { return m_export; }
16013521Sgabeblack@google.com
16113521Sgabeblack@google.com    virtual sc_core::sc_export<BW_IF> &get_base_export() { return m_export; }
16213521Sgabeblack@google.com    virtual sc_core::sc_export<BW_IF> const &
16313521Sgabeblack@google.com    get_base_export() const
16413521Sgabeblack@google.com    {
16513521Sgabeblack@google.com        return m_export;
16613521Sgabeblack@google.com    }
16713521Sgabeblack@google.com
16813521Sgabeblack@google.com  protected:
16913521Sgabeblack@google.com    export_type m_export;
17013521Sgabeblack@google.com};
17113521Sgabeblack@google.com
17213521Sgabeblack@google.com//
17313521Sgabeblack@google.com// Convenience socket classes
17413521Sgabeblack@google.com//
17513521Sgabeblack@google.com
17613521Sgabeblack@google.comtemplate <unsigned int BUSWIDTH=32, typename TYPES=tlm_base_protocol_types,
17713521Sgabeblack@google.com          int N=1, sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
17813521Sgabeblack@google.comclass tlm_initiator_socket : public tlm_base_initiator_socket<
17913521Sgabeblack@google.com                             BUSWIDTH, tlm_fw_transport_if<TYPES>,
18013521Sgabeblack@google.com                             tlm_bw_transport_if<TYPES>, N, POL>
18113521Sgabeblack@google.com{
18213521Sgabeblack@google.com  public:
18313521Sgabeblack@google.com    tlm_initiator_socket() : tlm_base_initiator_socket<
18413521Sgabeblack@google.com                             BUSWIDTH, tlm_fw_transport_if<TYPES>,
18513521Sgabeblack@google.com                             tlm_bw_transport_if<TYPES>, N, POL>()
18613521Sgabeblack@google.com    {}
18713521Sgabeblack@google.com
18813521Sgabeblack@google.com    explicit tlm_initiator_socket(const char *name) :
18913521Sgabeblack@google.com        tlm_base_initiator_socket<BUSWIDTH, tlm_fw_transport_if<TYPES>,
19013521Sgabeblack@google.com                                  tlm_bw_transport_if<TYPES>, N, POL>(name)
19113521Sgabeblack@google.com    {}
19213521Sgabeblack@google.com
19313521Sgabeblack@google.com    virtual const char *kind() const { return "tlm_initiator_socket"; }
19413521Sgabeblack@google.com
19513521Sgabeblack@google.com    virtual sc_core::sc_type_index
19613521Sgabeblack@google.com    get_protocol_types() const
19713521Sgabeblack@google.com    {
19813521Sgabeblack@google.com        return typeid(TYPES);
19913521Sgabeblack@google.com    }
20013521Sgabeblack@google.com};
20113521Sgabeblack@google.com
20213521Sgabeblack@google.com} // namespace tlm
20313521Sgabeblack@google.com
20413521Sgabeblack@google.com#endif /* __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__ */
205