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

Generated on Thu Jun 5 17:43:04 2008 for TLM 2 by  doxygen 1.5.3