TLM-2.0  2.0.4
Accellera TLM-2.0 proof-of-concept library
tlm_adapters.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 #ifndef __TLM_ADAPTERS_H__
21 #define __TLM_ADAPTERS_H__
22 
24 
25 namespace tlm {
26 
27 template< typename REQ , typename RSP >
29  public sc_core::sc_module ,
30  public virtual tlm_transport_if< REQ , RSP >
31 {
32 public:
35 
37  sc_core::sc_module( nm ) {
38 
39  target_export( *this );
40 
41  }
42 
44  sc_core::sc_module( sc_core::sc_module_name( sc_core::sc_gen_unique_name( "transport_to_master" ) ) ){
45 
46  target_export( *this );
47 
48  }
49 
50  RSP transport( const REQ &req ) {
51 
52  mutex.lock();
53 
54  master_port->put( req );
55  rsp = master_port->get();
56 
57  mutex.unlock();
58  return rsp;
59 
60  }
61 
62 private:
63  sc_core::sc_mutex mutex;
64  RSP rsp;
65 
66 };
67 
68 template< typename REQ , typename RSP >
70 {
71 public:
72 
74 
77 
79  {}
80 
82  sc_core::sc_module( sc_core::sc_module_name( sc_core::sc_gen_unique_name("slave_to_transport") ) )
83  {}
84 
85 private:
86  void run() {
87 
88  REQ req;
89  RSP rsp;
90 
91  while( true ) {
92 
93  slave_port->get( req );
94  rsp = initiator_port->transport( req );
95  slave_port->put( rsp );
96 
97  }
98 
99  }
100 
101 };
102 
103 } // namespace tlm
104 
105 #endif
RSP transport(const REQ &req)
Definition: tlm_adapters.h:50
tlm_transport_to_master(sc_core::sc_module_name nm)
Definition: tlm_adapters.h:36
sc_core::sc_export< tlm_transport_if< REQ, RSP > > target_export
Definition: tlm_adapters.h:33
virtual int unlock()
virtual int lock()
tlm_slave_to_transport(sc_core::sc_module_name nm)
Definition: tlm_adapters.h:78
sc_core::sc_port< tlm_transport_if< REQ, RSP > > initiator_port
Definition: tlm_adapters.h:76
friend friend class sc_module_name
sc_core::sc_port< tlm_slave_if< REQ, RSP > > slave_port
Definition: tlm_adapters.h:75
sc_core::sc_port< tlm_master_if< REQ, RSP > > master_port
Definition: tlm_adapters.h:34
SC_API const char * sc_gen_unique_name(const char *, bool preserve_first)
#define SC_HAS_PROCESS(user_module_name)