TLM-2.0: include/tlm/tlm_utils/simple_initiator_socket.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# include/tlm/tlm_utils/simple_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 __SIMPLE_INITIATOR_SOCKET_H__
    00019 #define __SIMPLE_INITIATOR_SOCKET_H__
    00020
    00021 #include "tlm.h"
    00022 #include <sstream>
    00023
    00024 namespace tlm_utils {
    00025
    00026 template <typename MODULE,
    00027           unsigned int BUSWIDTH = 32,
    00028           typename TYPES = tlm::tlm_base_protocol_types>
    00029 class simple_initiator_socket :
    00030   public tlm::tlm_initiator_socket<BUSWIDTH, TYPES>
    00031 {
    00032 public:
    00033   typedef typename TYPES::tlm_payload_type              transaction_type;
    00034   typedef typename TYPES::tlm_phase_type                phase_type;
    00035   typedef tlm::tlm_sync_enum                            sync_enum_type;
    00036   typedef tlm::tlm_fw_transport_if<TYPES>               fw_interface_type;
    00037   typedef tlm::tlm_bw_transport_if<TYPES>               bw_interface_type;
    00038   typedef tlm::tlm_initiator_socket<BUSWIDTH, TYPES>    base_type;
    00039
    00040 public:
    00041   simple_initiator_socket() :
    00042     base_type(sc_core::sc_gen_unique_name("simple_initiator_socket")),
    00043     m_process(this->name())
    00044   {
    00045     this->m_export.bind(m_process);
    00046   }
    00047
    00048   explicit simple_initiator_socket(const char* n) :
    00049     base_type(n),
    00050     m_process(this->name())
    00051   {
    00052     this->m_export.bind(m_process);
    00053   }
    00054
    00055   void register_nb_transport_bw(MODULE* mod,
    00056                                 sync_enum_type (MODULE::*cb)(transaction_type&,
    00057                                                              phase_type&,
    00058                                                              sc_core::sc_time&))
    00059   {
    00060     m_process.set_transport_ptr(mod, cb);
    00061   }
    00062
    00063   void register_invalidate_direct_mem_ptr(MODULE* mod,
    00064                                           void (MODULE::*cb)(sc_dt::uint64, sc_dt::uint64))
    00065   {
    00066     m_process.set_invalidate_direct_mem_ptr(mod, cb);
    00067   }
    00068
    00069 private:
    00070   class process : public tlm::tlm_bw_transport_if<TYPES>
    00071   {
    00072   public:
    00073     typedef sync_enum_type (MODULE::*TransportPtr)(transaction_type&,
    00074                                                    phase_type&,
    00075                                                    sc_core::sc_time&);
    00076     typedef void (MODULE::*InvalidateDirectMemPtr)(sc_dt::uint64,
    00077                                                    sc_dt::uint64);
    00078
    00079     process(const std::string& name) :
    00080       m_name(name),
    00081       m_mod(0),
    00082       m_transport_ptr(0),
    00083       m_invalidate_direct_mem_ptr(0)
    00084     {
    00085     }
    00086
    00087     void set_transport_ptr(MODULE* mod, TransportPtr p)
    00088     {
    00089       if (m_transport_ptr) {
    00090         std::stringstream s;
    00091         s << m_name << ": non-blocking callback allready registered";
    00092         SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket",s.str().c_str());
    00093       } else {
    00094         assert(!m_mod || m_mod == mod);
    00095         m_mod = mod;
    00096         m_transport_ptr = p;
    00097       }
    00098     }
    00099
    00100     void set_invalidate_direct_mem_ptr(MODULE* mod, InvalidateDirectMemPtr p)
    00101     {
    00102       if (m_invalidate_direct_mem_ptr) {
    00103         std::stringstream s;
    00104         s << m_name << ": invalidate DMI callback allready registered";
    00105         SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket",s.str().c_str());
    00106       } else {
    00107         assert(!m_mod || m_mod == mod);
    00108         m_mod = mod;
    00109         m_invalidate_direct_mem_ptr = p;
    00110       }
    00111     }
    00112
    00113     sync_enum_type nb_transport_bw(transaction_type& trans, phase_type& phase, sc_core::sc_time& t)
    00114     {
    00115       if (m_transport_ptr) {
    00116         // forward call
    00117         assert(m_mod);
    00118         return (m_mod->*m_transport_ptr)(trans, phase, t);
    00119
    00120       } else {
    00121         std::stringstream s;
    00122         s << m_name << ": no transport callback registered";
    00123         SC_REPORT_ERROR("/OSCI_TLM-2/simple_socket",s.str().c_str());
    00124       }
    00125       return tlm::TLM_ACCEPTED;
    00126     }
    00127
    00128     void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
    00129                                    sc_dt::uint64 end_range)
    00130     {
    00131       if (m_invalidate_direct_mem_ptr) {
    00132         // forward call
    00133         assert(m_mod);
    00134         (m_mod->*m_invalidate_direct_mem_ptr)(start_range, end_range);
    00135       }
    00136     }
    00137
    00138   private:
    00139     const std::string m_name;
    00140     MODULE* m_mod;
    00141     TransportPtr m_transport_ptr;
    00142     InvalidateDirectMemPtr m_invalidate_direct_mem_ptr;
    00143   };
    00144
    00145 private:
    00146   process m_process;
    00147 };
    00148
    00149 // Tagged version
    00150
    00151 template <typename MODULE,
    00152           unsigned int BUSWIDTH = 32,
    00153           typename TYPES = tlm::tlm_base_protocol_types>
    00154 class simple_initiator_socket_tagged :
    00155   public tlm::tlm_initiator_socket<BUSWIDTH, TYPES>
    00156 {
    00157 public:
    00158   typedef typename TYPES::tlm_payload_type              transaction_type;
    00159   typedef typename TYPES::tlm_phase_type                phase_type;
    00160   typedef tlm::tlm_sync_enum                            sync_enum_type;
    00161   typedef tlm::tlm_fw_transport_if<TYPES>               fw_interface_type;
    00162   typedef tlm::tlm_bw_transport_if<TYPES>               bw_interface_type;
    00163   typedef tlm::tlm_initiator_socket<BUSWIDTH, TYPES>    base_type;
    00164
    00165 public:
    00166   simple_initiator_socket_tagged() :
    00167     base_type(sc_core::sc_gen_unique_name("simple_initiator_socket_tagged")),
    00168     m_process(this->name())
    00169   {
    00170     this->m_export.bind(m_process);
    00171   }
    00172
    00173   explicit simple_initiator_socket_tagged(const char* n) :
    00174     base_type(n),
    00175     m_process(this->name())
    00176   {
    00177     this->m_export.bind(m_process);
    00178   }
    00179
    00180   void register_nb_transport_bw(MODULE* mod,
    00181                                 sync_enum_type (MODULE::*cb)(int,
    00182                                                              transaction_type&,
    00183                                                              phase_type&,
    00184                                                              sc_core::sc_time&),
    00185                                 int id)
    00186   {
    00187     m_process.set_transport_ptr(mod, cb);
    00188     m_process.set_transport_user_id(id);
    00189   }
    00190
    00191   void register_invalidate_direct_mem_ptr(MODULE* mod,
    00192                                           void (MODULE::*cb)(int, sc_dt::uint64, sc_dt::uint64),
    00193                                            int id)
    00194   {
    00195     m_process.set_invalidate_direct_mem_ptr(mod, cb);
    00196     m_process.set_invalidate_dmi_user_id(id);
    00197   }
    00198
    00199 private:
    00200   class process : public tlm::tlm_bw_transport_if<TYPES>
    00201   {
    00202   public:
    00203     typedef sync_enum_type (MODULE::*TransportPtr)(int,
    00204                                                    transaction_type&,
    00205                                                    phase_type&,
    00206                                                    sc_core::sc_time&);
    00207     typedef void (MODULE::*InvalidateDirectMemPtr)(int,
    00208                                                    sc_dt::uint64,
    00209                                                    sc_dt::uint64);
    00210
    00211     process(const std::string& name) :
    00212       m_name(name),
    00213       m_mod(0),
    00214       m_transport_ptr(0),
    00215       m_invalidate_direct_mem_ptr(0),
    00216       m_transport_user_id(0),
    00217       m_invalidate_direct_mem_user_id(0)
    00218     {
    00219     }
    00220
    00221     void set_transport_user_id(int id) { m_transport_user_id = id; }
    00222     void set_invalidate_dmi_user_id(int id) { m_invalidate_direct_mem_user_id = id; }
    00223
    00224     void set_transport_ptr(MODULE* mod, TransportPtr p)
    00225     {
    00226       if (m_transport_ptr) {
    00227         std::stringstream s;
    00228         s << m_name << ": non-blocking callback allready registered";
    00229         SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket",s.str().c_str());
    00230       } else {
    00231         assert(!m_mod || m_mod == mod);
    00232         m_mod = mod;
    00233         m_transport_ptr = p;
    00234       }
    00235     }
    00236
    00237     void set_invalidate_direct_mem_ptr(MODULE* mod, InvalidateDirectMemPtr p)
    00238     {
    00239       if (m_invalidate_direct_mem_ptr) {
    00240         std::stringstream s;
    00241         s << m_name << ": invalidate DMI callback allready registered";
    00242         SC_REPORT_WARNING("/OSCI_TLM-2/simple_socket",s.str().c_str());
    00243       } else {
    00244         assert(!m_mod || m_mod == mod);
    00245         m_mod = mod;
    00246         m_invalidate_direct_mem_ptr = p;
    00247       }
    00248     }
    00249
    00250     sync_enum_type nb_transport_bw(transaction_type& trans, phase_type& phase, sc_core::sc_time& t)
    00251     {
    00252       if (m_transport_ptr) {
    00253         // forward call
    00254         assert(m_mod);
    00255         return (m_mod->*m_transport_ptr)(m_transport_user_id, trans, phase, t);
    00256
    00257       } else {
    00258         std::stringstream s;
    00259         s << m_name << ": no transport callback registered";
    00260         SC_REPORT_ERROR("/OSCI_TLM-2/simple_socket",s.str().c_str());
    00261       }
    00262       return tlm::TLM_ACCEPTED;
    00263     }
    00264
    00265     void invalidate_direct_mem_ptr(sc_dt::uint64 start_range,
    00266                                    sc_dt::uint64 end_range)
    00267     {
    00268       if (m_invalidate_direct_mem_ptr) {
    00269         // forward call
    00270         assert(m_mod);
    00271         (m_mod->*m_invalidate_direct_mem_ptr)(m_invalidate_direct_mem_user_id, start_range, end_range);
    00272       }
    00273     }
    00274
    00275   private:
    00276     const std::string m_name;
    00277     MODULE* m_mod;
    00278     TransportPtr m_transport_ptr;
    00279     InvalidateDirectMemPtr m_invalidate_direct_mem_ptr;
    00280     int m_transport_user_id;
    00281     int m_invalidate_direct_mem_user_id;
    00282   };
    00283
    00284 private:
    00285   process m_process;
    00286 };
    00287
    00288 }
    00289
    00290 #endif