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
23#include "tlm_core/tlm_1/tlm_req_rsp/tlm_1_interfaces/tlm_master_slave_ifs.h"
24
25namespace tlm {
26
27template< typename REQ , typename RSP >
28class tlm_transport_to_master :
29  public sc_core::sc_module ,
30  public virtual tlm_transport_if< REQ , RSP >
31{
32public:
33  sc_core::sc_export< tlm_transport_if< REQ , RSP > > target_export;
34  sc_core::sc_port< tlm_master_if< REQ , RSP > > master_port;
35
36  tlm_transport_to_master( sc_core::sc_module_name nm ) :
37    sc_core::sc_module( nm ) {
38
39    target_export( *this );
40
41  }
42
43  tlm_transport_to_master() :
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
62private:
63  sc_core::sc_mutex mutex;
64  RSP rsp;
65
66};
67
68template< typename REQ , typename RSP >
69class tlm_slave_to_transport : public sc_core::sc_module
70{
71public:
72
73  SC_HAS_PROCESS( tlm_slave_to_transport );
74
75  sc_core::sc_port< tlm_slave_if< REQ , RSP > > slave_port;
76  sc_core::sc_port< tlm_transport_if< REQ , RSP > > initiator_port;
77
78  tlm_slave_to_transport( sc_core::sc_module_name nm ) : sc_core::sc_module( nm )
79  {}
80
81  tlm_slave_to_transport() :
82    sc_core::sc_module( sc_core::sc_module_name( sc_core::sc_gen_unique_name("slave_to_transport") ) )
83  {}
84
85private:
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
106