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 __SYSTEMC_EXT_TLM_CORE_1_REQ_RSP_ADAPTERS_HH__
21#define __SYSTEMC_EXT_TLM_CORE_1_REQ_RSP_ADAPTERS_HH__
22
23#include "../interfaces/master_slave_ifs.hh"
24
25namespace tlm
26{
27
28template <typename REQ, typename RSP>
29class tlm_transport_to_master : public sc_core::sc_module,
30    public virtual tlm_transport_if<REQ, RSP>
31{
32  public:
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    tlm_transport_to_master() :
43        sc_core::sc_module(sc_core::sc_module_name(
44                    sc_core::sc_gen_unique_name("transport_to_master")))
45    {
46        target_export( *this );
47    }
48
49    RSP
50    transport(const REQ &req)
51    {
52        mutex.lock();
53        master_port->put(req);
54        rsp = master_port->get();
55
56        mutex.unlock();
57        return rsp;
58    }
59
60  private:
61    sc_core::sc_mutex mutex;
62    RSP rsp;
63};
64
65template <typename REQ, typename RSP>
66class tlm_slave_to_transport : public sc_core::sc_module
67{
68  public:
69    SC_HAS_PROCESS(tlm_slave_to_transport);
70
71    sc_core::sc_port<tlm_slave_if<REQ, RSP>> slave_port;
72    sc_core::sc_port<tlm_transport_if<REQ, RSP>> initiator_port;
73
74    tlm_slave_to_transport(sc_core::sc_module_name nm) :
75        sc_core::sc_module(nm)
76    {}
77
78    tlm_slave_to_transport() :
79        sc_core::sc_module(sc_core::sc_module_name(
80                    sc_core::sc_gen_unique_name("slave_to_transport")))
81    {}
82
83  private:
84    void
85    run()
86    {
87        REQ req;
88        RSP rsp;
89
90        while (true) {
91            slave_port->get(req);
92            rsp = initiator_port->transport(req);
93            slave_port->put(rsp);
94        }
95    }
96};
97
98} // namespace tlm
99
100#endif /* __SYSTEMC_EXT_TLM_CORE_1_REQ_RSP_ADAPTERS_HH__ */
101