TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
tlm_adapters.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 #ifndef __TLM_ADAPTERS_H__
19 #define __TLM_ADAPTERS_H__
20 
22 
23 namespace tlm {
24 
25 template< typename REQ , typename RSP >
27  public sc_core::sc_module ,
28  public virtual tlm_transport_if< REQ , RSP >
29 {
30 public:
33 
35  sc_core::sc_module( nm ) {
36 
37  target_export( *this );
38 
39  }
40 
42  sc_core::sc_module( sc_core::sc_module_name( sc_core::sc_gen_unique_name( "transport_to_master" ) ) ){
43 
44  target_export( *this );
45 
46  }
47 
48  RSP transport( const REQ &req ) {
49 
50  mutex.lock();
51 
52  master_port->put( req );
53  rsp = master_port->get();
54 
55  mutex.unlock();
56  return rsp;
57 
58  }
59 
60 private:
61  sc_core::sc_mutex mutex;
62  RSP rsp;
63 
64 };
65 
66 template< typename REQ , typename RSP >
68 {
69 public:
70 
72 
75 
77  {}
78 
80  sc_core::sc_module( sc_core::sc_module_name( sc_core::sc_gen_unique_name("slave_to_transport") ) )
81  {}
82 
83 private:
84  void run() {
85 
86  REQ req;
87  RSP rsp;
88 
89  while( true ) {
90 
91  slave_port->get( req );
92  rsp = initiator_port->transport( req );
93  slave_port->put( rsp );
94 
95  }
96 
97  }
98 
99 };
100 
101 } // namespace tlm
102 
103 #endif
tlm_slave_to_transport(sc_core::sc_module_name nm)
Definition: tlm_adapters.h:76
tlm_transport_to_master(sc_core::sc_module_name nm)
Definition: tlm_adapters.h:34
sc_core::sc_port< tlm_transport_if< REQ, RSP > > initiator_port
Definition: tlm_adapters.h:74
virtual int lock()
sc_core::sc_port< tlm_master_if< REQ, RSP > > master_port
Definition: tlm_adapters.h:32
RSP transport(const REQ &req)
Definition: tlm_adapters.h:48
const char * sc_gen_unique_name(const char *, bool preserve_first)
SC_HAS_PROCESS(tlm_slave_to_transport)
sc_core::sc_export< tlm_transport_if< REQ, RSP > > target_export
Definition: tlm_adapters.h:31
sc_core::sc_port< tlm_slave_if< REQ, RSP > > slave_port
Definition: tlm_adapters.h:73
virtual int unlock()
friend friend class sc_module
friend friend class sc_module_name