113521Sgabeblack@google.com/*****************************************************************************
213521Sgabeblack@google.com
313521Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
413521Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
513521Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
613521Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
713521Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
813521Sgabeblack@google.com  License.  You may obtain a copy of the License at
913521Sgabeblack@google.com
1013521Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1113521Sgabeblack@google.com
1213521Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1313521Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1413521Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1513521Sgabeblack@google.com  implied.  See the License for the specific language governing
1613521Sgabeblack@google.com  permissions and limitations under the License.
1713521Sgabeblack@google.com
1813521Sgabeblack@google.com *****************************************************************************/
1913521Sgabeblack@google.com
2013521Sgabeblack@google.com#ifndef __SYSTEMC_EXT_TLM_CORE_1_REQ_RSP_ADAPTERS_HH__
2113521Sgabeblack@google.com#define __SYSTEMC_EXT_TLM_CORE_1_REQ_RSP_ADAPTERS_HH__
2213521Sgabeblack@google.com
2313586Sgabeblack@google.com#include "../interfaces/master_slave_ifs.hh"
2413521Sgabeblack@google.com
2513521Sgabeblack@google.comnamespace tlm
2613521Sgabeblack@google.com{
2713521Sgabeblack@google.com
2813521Sgabeblack@google.comtemplate <typename REQ, typename RSP>
2913521Sgabeblack@google.comclass tlm_transport_to_master : public sc_core::sc_module,
3013521Sgabeblack@google.com    public virtual tlm_transport_if<REQ, RSP>
3113521Sgabeblack@google.com{
3213521Sgabeblack@google.com  public:
3313521Sgabeblack@google.com    sc_core::sc_export<tlm_transport_if<REQ, RSP>> target_export;
3413521Sgabeblack@google.com    sc_core::sc_port<tlm_master_if<REQ, RSP>> master_port;
3513521Sgabeblack@google.com
3613521Sgabeblack@google.com    tlm_transport_to_master(sc_core::sc_module_name nm) :
3713521Sgabeblack@google.com        sc_core::sc_module(nm)
3813521Sgabeblack@google.com    {
3913521Sgabeblack@google.com        target_export( *this );
4013521Sgabeblack@google.com    }
4113521Sgabeblack@google.com
4213521Sgabeblack@google.com    tlm_transport_to_master() :
4313521Sgabeblack@google.com        sc_core::sc_module(sc_core::sc_module_name(
4413521Sgabeblack@google.com                    sc_core::sc_gen_unique_name("transport_to_master")))
4513521Sgabeblack@google.com    {
4613521Sgabeblack@google.com        target_export( *this );
4713521Sgabeblack@google.com    }
4813521Sgabeblack@google.com
4913521Sgabeblack@google.com    RSP
5013521Sgabeblack@google.com    transport(const REQ &req)
5113521Sgabeblack@google.com    {
5213521Sgabeblack@google.com        mutex.lock();
5313521Sgabeblack@google.com        master_port->put(req);
5413521Sgabeblack@google.com        rsp = master_port->get();
5513521Sgabeblack@google.com
5613521Sgabeblack@google.com        mutex.unlock();
5713521Sgabeblack@google.com        return rsp;
5813521Sgabeblack@google.com    }
5913521Sgabeblack@google.com
6013521Sgabeblack@google.com  private:
6113521Sgabeblack@google.com    sc_core::sc_mutex mutex;
6213521Sgabeblack@google.com    RSP rsp;
6313521Sgabeblack@google.com};
6413521Sgabeblack@google.com
6513521Sgabeblack@google.comtemplate <typename REQ, typename RSP>
6613521Sgabeblack@google.comclass tlm_slave_to_transport : public sc_core::sc_module
6713521Sgabeblack@google.com{
6813521Sgabeblack@google.com  public:
6913521Sgabeblack@google.com    SC_HAS_PROCESS(tlm_slave_to_transport);
7013521Sgabeblack@google.com
7113521Sgabeblack@google.com    sc_core::sc_port<tlm_slave_if<REQ, RSP>> slave_port;
7213521Sgabeblack@google.com    sc_core::sc_port<tlm_transport_if<REQ, RSP>> initiator_port;
7313521Sgabeblack@google.com
7413521Sgabeblack@google.com    tlm_slave_to_transport(sc_core::sc_module_name nm) :
7513521Sgabeblack@google.com        sc_core::sc_module(nm)
7613521Sgabeblack@google.com    {}
7713521Sgabeblack@google.com
7813521Sgabeblack@google.com    tlm_slave_to_transport() :
7913521Sgabeblack@google.com        sc_core::sc_module(sc_core::sc_module_name(
8013521Sgabeblack@google.com                    sc_core::sc_gen_unique_name("slave_to_transport")))
8113521Sgabeblack@google.com    {}
8213521Sgabeblack@google.com
8313521Sgabeblack@google.com  private:
8413521Sgabeblack@google.com    void
8513521Sgabeblack@google.com    run()
8613521Sgabeblack@google.com    {
8713521Sgabeblack@google.com        REQ req;
8813521Sgabeblack@google.com        RSP rsp;
8913521Sgabeblack@google.com
9013521Sgabeblack@google.com        while (true) {
9113521Sgabeblack@google.com            slave_port->get(req);
9213521Sgabeblack@google.com            rsp = initiator_port->transport(req);
9313521Sgabeblack@google.com            slave_port->put(rsp);
9413521Sgabeblack@google.com        }
9513521Sgabeblack@google.com    }
9613521Sgabeblack@google.com};
9713521Sgabeblack@google.com
9813521Sgabeblack@google.com} // namespace tlm
9913521Sgabeblack@google.com
10013521Sgabeblack@google.com#endif /* __SYSTEMC_EXT_TLM_CORE_1_REQ_RSP_ADAPTERS_HH__ */
101