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_ADAPTERS_H__ 00019 #define __TLM_ADAPTERS_H__ 00020 00021 #include "tlm_h/tlm_req_rsp/tlm_1_interfaces/tlm_master_slave_ifs.h" 00022 00023 namespace tlm { 00024 00025 template< typename REQ , typename RSP > 00026 class tlm_transport_to_master : 00027 public sc_core::sc_module , 00028 public virtual tlm_transport_if< REQ , RSP > 00029 { 00030 public: 00031 sc_core::sc_export< tlm_transport_if< REQ , RSP > > target_export; 00032 sc_core::sc_port< tlm_master_if< REQ , RSP > > master_port; 00033 00034 tlm_transport_to_master( sc_core::sc_module_name nm ) : 00035 sc_core::sc_module( nm ) { 00036 00037 target_export( *this ); 00038 00039 } 00040 00041 tlm_transport_to_master() : 00042 sc_core::sc_module( sc_core::sc_module_name( sc_core::sc_gen_unique_name( "transport_to_master" ) ) ){ 00043 00044 target_export( *this ); 00045 00046 } 00047 00048 RSP transport( const REQ &req ) { 00049 00050 mutex.lock(); 00051 00052 master_port->put( req ); 00053 rsp = master_port->get(); 00054 00055 mutex.unlock(); 00056 return rsp; 00057 00058 } 00059 00060 private: 00061 sc_core::sc_mutex mutex; 00062 RSP rsp; 00063 00064 }; 00065 00066 template< typename REQ , typename RSP > 00067 class tlm_slave_to_transport : public sc_core::sc_module 00068 { 00069 public: 00070 00071 SC_HAS_PROCESS( tlm_slave_to_transport ); 00072 00073 sc_core::sc_port< tlm_slave_if< REQ , RSP > > slave_port; 00074 sc_core::sc_port< tlm_transport_if< REQ , RSP > > initiator_port; 00075 00076 tlm_slave_to_transport( sc_core::sc_module_name nm ) : sc_core::sc_module( nm ) 00077 {} 00078 00079 tlm_slave_to_transport() : 00080 sc_core::sc_module( sc_core::sc_module_name( sc_core::sc_gen_unique_name("slave_to_transport") ) ) 00081 {} 00082 00083 private: 00084 void run() { 00085 00086 REQ req; 00087 RSP rsp; 00088 00089 while( true ) { 00090 00091 slave_port->get( req ); 00092 rsp = initiator_port->transport( req ); 00093 slave_port->put( rsp ); 00094 00095 } 00096 00097 } 00098 00099 }; 00100 00101 } // namespace tlm 00102 00103 #endif