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