TLM-2.0: include/tlm/tlm_h/tlm_sockets/tlm_initiator_socket.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# include/tlm/tlm_h/tlm_sockets/tlm_initiator_socket.h

Go to the documentation of this file.

    00001 /*****************************************************************************
    00002
    00003   The following code is derived, directly or indirectly, from the SystemC
    00004   source code Copyright (c) 1996-2008 by all Contributors.
    00005   All Rights reserved.
    00006
    00007   The contents of this file are subject to the restrictions and limitations
    00008   set forth in the SystemC Open Source License Version 3.0 (the "License");
    00009   You may not use this file except in compliance with such restrictions and
    00010   limitations. You may obtain instructions on how to receive a copy of the
    00011   License at http://www.systemc.org/. Software distributed by Contributors
    00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
    00013   ANY KIND, either express or implied. See the License for the specific
    00014   language governing rights and limitations under the License.
    00015
    00016  *****************************************************************************/
    00017
    00018 #ifndef __TLM_INITIATOR_SOCKET_H__
    00019 #define __TLM_INITIATOR_SOCKET_H__
    00020
    00021 //#include <systemc>
    00022 #include "tlm_h/tlm_2_interfaces/tlm_fw_bw_ifs.h"
    00023
    00024 namespace tlm {
    00025
    00026
    00027 template <unsigned int BUSWIDTH = 32,
    00028           typename FW_IF = tlm_fw_transport_if<>,
    00029           typename BW_IF = tlm_bw_transport_if<> >
    00030 class tlm_base_initiator_socket_b
    00031 {
    00032 public:
    00033   virtual ~tlm_base_initiator_socket_b() {}
    00034
    00035   virtual sc_core::sc_port_b<FW_IF> & get_base_port() = 0;
    00036   virtual                    BW_IF  & get_base_interface() = 0;
    00037   virtual sc_core::sc_export<BW_IF> & get_base_export() = 0;
    00038 };
    00039
    00040
    00041 template <unsigned int BUSWIDTH,
    00042           typename FW_IF,
    00043           typename BW_IF> class tlm_base_target_socket_b;
    00044
    00045 template <unsigned int BUSWIDTH,
    00046           typename FW_IF,
    00047           typename BW_IF,
    00048           int N
    00049 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
    00050           ,sc_core::sc_port_policy POL
    00051 #endif
    00052           > class tlm_base_target_socket;
    00053
    00054 template <unsigned int BUSWIDTH = 32,
    00055           typename FW_IF = tlm_fw_transport_if<>,
    00056           typename BW_IF = tlm_bw_transport_if<>,
    00057           int N = 1
    00058 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
    00059           ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND
    00060 #endif
    00061           >
    00062 class tlm_base_initiator_socket : public tlm_base_initiator_socket_b<BUSWIDTH, FW_IF, BW_IF>,
    00063                                   public sc_core::sc_port<FW_IF, N
    00064 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
    00065                                                         , POL
    00066 #endif
    00067                                                     >
    00068
    00069 {
    00070 public:
    00071   typedef FW_IF                                 fw_interface_type;
    00072   typedef BW_IF                                 bw_interface_type;
    00073   typedef sc_core::sc_port<fw_interface_type, N
    00074 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
    00075                                             , POL
    00076 #endif
    00077                                             >   port_type;
    00078
    00079   typedef sc_core::sc_export<bw_interface_type> export_type;
    00080
    00081   typedef tlm_base_target_socket_b<BUSWIDTH,
    00082                                    fw_interface_type,
    00083                                    bw_interface_type> base_target_socket_type;
    00084   typedef tlm_base_initiator_socket_b<BUSWIDTH,
    00085                                       fw_interface_type,
    00086                                       bw_interface_type> base_type;
    00087
    00088   template <unsigned int, typename, typename, int
    00089 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
    00090            ,sc_core::sc_port_policy
    00091 #endif
    00092            >
    00093   friend class tlm_base_target_socket;
    00094
    00095 public:
    00096   tlm_base_initiator_socket()
    00097   : port_type(sc_core::sc_gen_unique_name("tlm_base_initiator_socket"))
    00098   , m_export(sc_core::sc_gen_unique_name("tlm_base_initiator_socket_export"))
    00099   {
    00100   }
    00101
    00102   explicit tlm_base_initiator_socket(const char* name)
    00103   : port_type(name)
    00104   , m_export(sc_core::sc_gen_unique_name((std::string(name) + "_export").c_str()))
    00105   {
    00106   }
    00107
    00108   virtual const char* kind() const
    00109   {
    00110     return "tlm_base_initiator_socket";
    00111   }
    00112
    00113   unsigned int get_bus_width() const
    00114   {
    00115     return BUSWIDTH;
    00116   }
    00117
    00118   //
    00119   // Bind initiator socket to target socket
    00120   // - Binds the port of the initiator socket to the export of the target
    00121   //   socket
    00122   // - Binds the port of the target socket to the export of the initiator
    00123   //   socket
    00124   //
    00125   void bind(base_target_socket_type& s)
    00126   {
    00127     // initiator.port -> target.export
    00128     (get_base_port())(s.get_base_interface());
    00129     // target.port -> initiator.export
    00130     (s.get_base_port())(get_base_interface());
    00131   }
    00132
    00133   void operator() (base_target_socket_type& s)
    00134   {
    00135     bind(s);
    00136   }
    00137
    00138   //
    00139   // Bind initiator socket to initiator socket (hierarchical bind)
    00140   // - Binds both the export and the port
    00141   //
    00142   void bind(base_type& s)
    00143   {
    00144     // port
    00145     (get_base_port())(s.get_base_port());
    00146     // export
    00147     (s.get_base_export())(get_base_export());
    00148   }
    00149
    00150   void operator() (base_type& s)
    00151   {
    00152     bind(s);
    00153   }
    00154
    00155   //
    00156   // Bind interface to socket
    00157   // - Binds the interface to the export of this socket
    00158   //
    00159   void bind(bw_interface_type& ifs)
    00160   {
    00161     (get_base_export())(ifs);
    00162   }
    00163
    00164   void operator() (bw_interface_type& s)
    00165   {
    00166     bind(s);
    00167   }
    00168
    00169   // Implementation of pure virtual functions of base class
    00170   virtual sc_core::sc_port_b<FW_IF> &   get_base_port()      { return *this;   }
    00171   virtual                    BW_IF  &   get_base_interface() { return m_export; }
    00172   virtual sc_core::sc_export<BW_IF> &   get_base_export()    { return m_export; }
    00173
    00174 protected:
    00175   export_type m_export;
    00176 };
    00177
    00178 //
    00179 // Convenience socket classes
    00180 //
    00181
    00182 template <unsigned int BUSWIDTH = 32,
    00183           typename TYPES = tlm_base_protocol_types,
    00184           int N = 1
    00185 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
    00186           ,sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND
    00187 #endif
    00188           >
    00189 class tlm_initiator_socket :
    00190   public tlm_base_initiator_socket <BUSWIDTH,
    00191                                tlm_fw_transport_if<TYPES>,
    00192                                tlm_bw_transport_if<TYPES>,
    00193                                N
    00194 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
    00195                                ,POL
    00196 #endif
    00197                               >
    00198 {
    00199 public:
    00200   tlm_initiator_socket() :
    00201     tlm_base_initiator_socket<BUSWIDTH,
    00202                          tlm_fw_transport_if<TYPES>,
    00203                          tlm_bw_transport_if<TYPES>,
    00204                          N
    00205 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
    00206                          ,POL
    00207 #endif
    00208                          >()
    00209   {
    00210   }
    00211
    00212   explicit tlm_initiator_socket(const char* name) :
    00213     tlm_base_initiator_socket<BUSWIDTH,
    00214                          tlm_fw_transport_if<TYPES>,
    00215                          tlm_bw_transport_if<TYPES>,
    00216                          N
    00217 #if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
    00218                          ,POL
    00219 #endif
    00220                          >(name)
    00221   {
    00222   }
    00223
    00224   virtual const char* kind() const
    00225   {
    00226     return "tlm_initiator_socket";
    00227   }
    00228 };
    00229
    00230 } // namespace tlm
    00231
    00232 #endif