initiator_socket.hh revision 13523
14120Sgblack@eecs.umich.edu/*****************************************************************************
24120Sgblack@eecs.umich.edu
34120Sgblack@eecs.umich.edu  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
44120Sgblack@eecs.umich.edu  more contributor license agreements.  See the NOTICE file distributed
54120Sgblack@eecs.umich.edu  with this work for additional information regarding copyright ownership.
64120Sgblack@eecs.umich.edu  Accellera licenses this file to you under the Apache License, Version 2.0
74120Sgblack@eecs.umich.edu  (the "License"); you may not use this file except in compliance with the
84120Sgblack@eecs.umich.edu  License.  You may obtain a copy of the License at
94120Sgblack@eecs.umich.edu
104120Sgblack@eecs.umich.edu    http://www.apache.org/licenses/LICENSE-2.0
114120Sgblack@eecs.umich.edu
124120Sgblack@eecs.umich.edu  Unless required by applicable law or agreed to in writing, software
134120Sgblack@eecs.umich.edu  distributed under the License is distributed on an "AS IS" BASIS,
144120Sgblack@eecs.umich.edu  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
154120Sgblack@eecs.umich.edu  implied.  See the License for the specific language governing
164120Sgblack@eecs.umich.edu  permissions and limitations under the License.
174120Sgblack@eecs.umich.edu
184120Sgblack@eecs.umich.edu *****************************************************************************/
194120Sgblack@eecs.umich.edu
204120Sgblack@eecs.umich.edu#ifndef __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__
214120Sgblack@eecs.umich.edu#define __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__
224120Sgblack@eecs.umich.edu
234120Sgblack@eecs.umich.edu#include <typeindex>
244120Sgblack@eecs.umich.edu
254120Sgblack@eecs.umich.edu#include "tlm_core/2/interfaces/fw_bw_ifs.hh"
264120Sgblack@eecs.umich.edu#include "tlm_core/2/sockets/base_socket_if.hh"
274120Sgblack@eecs.umich.edu
284120Sgblack@eecs.umich.edunamespace tlm
294120Sgblack@eecs.umich.edu{
304120Sgblack@eecs.umich.edu
314120Sgblack@eecs.umich.edutemplate <unsigned int BUSWIDTH=32,
324120Sgblack@eecs.umich.edu          typename FW_IF=tlm_fw_transport_if<>,
334120Sgblack@eecs.umich.edu          typename BW_IF=tlm_bw_transport_if<>>
344120Sgblack@eecs.umich.educlass tlm_base_initiator_socket_b
354120Sgblack@eecs.umich.edu{
364120Sgblack@eecs.umich.edu  public:
374120Sgblack@eecs.umich.edu    virtual ~tlm_base_initiator_socket_b() {}
384120Sgblack@eecs.umich.edu
394120Sgblack@eecs.umich.edu    virtual sc_core::sc_port_b<FW_IF> &get_base_port() = 0;
404120Sgblack@eecs.umich.edu    virtual sc_core::sc_port_b<FW_IF> const &get_base_port() const = 0;
414120Sgblack@eecs.umich.edu    virtual BW_IF &get_base_interface() = 0;
424120Sgblack@eecs.umich.edu    virtual BW_IF const &get_base_interface() const = 0;
434120Sgblack@eecs.umich.edu    virtual sc_core::sc_export<BW_IF> &get_base_export() = 0;
444120Sgblack@eecs.umich.edu    virtual sc_core::sc_export<BW_IF> const &get_base_export() const = 0;
454120Sgblack@eecs.umich.edu};
464120Sgblack@eecs.umich.edu
474120Sgblack@eecs.umich.edutemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF>
484120Sgblack@eecs.umich.educlass tlm_base_target_socket_b;
494120Sgblack@eecs.umich.edu
504120Sgblack@eecs.umich.edutemplate <unsigned int BUSWIDTH, typename FW_IF, typename BW_IF, int N,
514120Sgblack@eecs.umich.edu          sc_core::sc_port_policy POL>
524120Sgblack@eecs.umich.educlass tlm_base_target_socket;
534120Sgblack@eecs.umich.edu
544120Sgblack@eecs.umich.edutemplate <unsigned int BUSWIDTH=32, typename FW_IF=tlm_fw_transport_if<>,
554120Sgblack@eecs.umich.edu          typename BW_IF=tlm_bw_transport_if<>, int N=1,
564120Sgblack@eecs.umich.edu          sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
574120Sgblack@eecs.umich.educlass tlm_base_initiator_socket :
584120Sgblack@eecs.umich.edu    public tlm_base_socket_if,
594120Sgblack@eecs.umich.edu    public tlm_base_initiator_socket_b<BUSWIDTH, FW_IF, BW_IF>,
604120Sgblack@eecs.umich.edu    public sc_core::sc_port<FW_IF, N, POL>
614120Sgblack@eecs.umich.edu{
624120Sgblack@eecs.umich.edu  public:
634120Sgblack@eecs.umich.edu    typedef FW_IF fw_interface_type;
644120Sgblack@eecs.umich.edu    typedef BW_IF bw_interface_type;
654120Sgblack@eecs.umich.edu    typedef sc_core::sc_port<fw_interface_type, N, POL> port_type;
664120Sgblack@eecs.umich.edu
674120Sgblack@eecs.umich.edu    typedef sc_core::sc_export<bw_interface_type> export_type;
68
69    typedef tlm_base_target_socket_b<
70        BUSWIDTH, fw_interface_type, bw_interface_type>
71        base_target_socket_type;
72    typedef tlm_base_initiator_socket_b<
73        BUSWIDTH, fw_interface_type, bw_interface_type> base_type;
74
75    template <unsigned int, typename, typename, int, sc_core::sc_port_policy>
76    friend class tlm_base_target_socket;
77
78  public:
79    tlm_base_initiator_socket() :
80        port_type(sc_core::sc_gen_unique_name("tlm_base_initiator_socket")),
81        m_export(sc_core::sc_gen_unique_name(
82                    "tlm_base_initiator_socket_export"))
83    {}
84
85    explicit tlm_base_initiator_socket(const char *name) : port_type(name),
86        m_export(sc_core::sc_gen_unique_name(
87                    (std::string(name) + "_export").c_str()))
88    {}
89
90    virtual const char* kind() const { return "tlm_base_initiator_socket"; }
91
92    //
93    // Bind initiator socket to target socket
94    // - Binds the port of the initiator socket to the export of the target
95    //   socket
96    // - Binds the port of the target socket to the export of the initiator
97    //   socket
98    //
99    virtual void
100    bind(base_target_socket_type &s)
101    {
102        // initiator.port -> target.export
103        (get_base_port())(s.get_base_interface());
104        // target.port -> initiator.export
105        (s.get_base_port())(get_base_interface());
106    }
107
108    void operator () (base_target_socket_type &s) { bind(s); }
109
110    //
111    // Bind initiator socket to initiator socket (hierarchical bind)
112    // - Binds both the export and the port
113    //
114    virtual void
115    bind(base_type &s)
116    {
117        // port
118        (get_base_port())(s.get_base_port());
119        // export
120        (s.get_base_export())(get_base_export());
121    }
122
123    void operator() (base_type &s) { bind(s); }
124
125    //
126    // Bind interface to socket
127    // - Binds the interface to the export of this socket
128    //
129    virtual void bind(bw_interface_type &ifs) { (get_base_export())(ifs); }
130    void operator() (bw_interface_type &s) { bind(s); }
131
132    // Implementation of tlm_base_socket_if functions
133    virtual sc_core::sc_port_base &get_port_base() { return *this; }
134    virtual sc_core::sc_port_base const &
135    get_port_base() const
136    {
137        return *this;
138    }
139    virtual sc_core::sc_export_base &get_export_base() { return m_export; }
140    virtual sc_core::sc_export_base const &
141    get_export_base() const
142    {
143        return m_export;
144    }
145    virtual unsigned int get_bus_width() const { return BUSWIDTH; }
146    virtual tlm_socket_category
147    get_socket_category() const
148    {
149        return TLM_INITIATOR_SOCKET;
150    }
151
152    // Implementation of tlm_base_target_socket_b functions
153    virtual sc_core::sc_port_b<FW_IF> &get_base_port() { return *this; }
154    virtual sc_core::sc_port_b<FW_IF> const &
155    get_base_port() const
156    {
157        return *this;
158    }
159
160    virtual BW_IF &get_base_interface() { return m_export; }
161    virtual BW_IF const &get_base_interface() const { return m_export; }
162
163    virtual sc_core::sc_export<BW_IF> &get_base_export() { return m_export; }
164    virtual sc_core::sc_export<BW_IF> const &
165    get_base_export() const
166    {
167        return m_export;
168    }
169
170  protected:
171    export_type m_export;
172};
173
174//
175// Convenience socket classes
176//
177
178template <unsigned int BUSWIDTH=32, typename TYPES=tlm_base_protocol_types,
179          int N=1, sc_core::sc_port_policy POL=sc_core::SC_ONE_OR_MORE_BOUND>
180class tlm_initiator_socket : public tlm_base_initiator_socket<
181                             BUSWIDTH, tlm_fw_transport_if<TYPES>,
182                             tlm_bw_transport_if<TYPES>, N, POL>
183{
184  public:
185    tlm_initiator_socket() : tlm_base_initiator_socket<
186                             BUSWIDTH, tlm_fw_transport_if<TYPES>,
187                             tlm_bw_transport_if<TYPES>, N, POL>()
188    {}
189
190    explicit tlm_initiator_socket(const char *name) :
191        tlm_base_initiator_socket<BUSWIDTH, tlm_fw_transport_if<TYPES>,
192                                  tlm_bw_transport_if<TYPES>, N, POL>(name)
193    {}
194
195    virtual const char *kind() const { return "tlm_initiator_socket"; }
196
197    virtual std::type_index
198    get_protocol_types() const
199    {
200        return typeid(TYPES);
201    }
202};
203
204} // namespace tlm
205
206#endif /* __SYSTEMC_EXT_TLM_CORE_2_SOCKETS_INITIATOR_SOCKET_HH__ */
207