scc  2022.4.0
SystemC components library
axi_initiator.cpp
1 /*******************************************************************************
2  * Copyright 2021 MINRES Technologies GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************/
16 
17 #include "axi_initiator.h"
18 #include <scc/report.h>
19 #include <tlm/scc/tlm_gp_shared.h>
20 #include <tlm/scc/tlm_id.h>
21 #include <tlm/scc/tlm_mm.h>
22 
23 using namespace axi;
24 
25 axi_initiator_base::axi_initiator_base(const sc_core::sc_module_name& nm, axi::pe::simple_initiator_b& pe, uint32_t width)
26 : sc_module(nm)
27 , pe(pe)
28 , buswidth(width) {
29  SC_HAS_PROCESS(axi_initiator_base);
30  // Register callback for incoming b_transport interface method call
31  b_tsck.register_b_transport(this, &axi_initiator_base::b_transport);
32  setup_cb = [this](tlm::tlm_generic_payload& p) {
33  auto len = p.get_data_length();
34  auto* ext = p.get_extension<axi::axi4_extension>();
35  ext->set_size(scc::ilog2(std::min<size_t>(len, buswidth / 8)));
36  sc_assert(len < (buswidth / 8) || len % (buswidth / 8) == 0);
37  ext->set_length((len * 8 - 1) / buswidth);
38  ext->set_burst(axi::burst_e::INCR);
39  ext->set_id(id);
40  };
41 }
42 
43 void axi_initiator_base::b_transport(tlm::tlm_generic_payload& trans, sc_core::sc_time& delay) {
45  pe.transport(*payload, false);
46  trans.update_original_from(*payload);
47 }
48 
49 tlm::tlm_generic_payload* axi_initiator_base::create_axi_trans(tlm::tlm_generic_payload& p) {
50  tlm::tlm_generic_payload* trans = nullptr;
51  if(p.has_mm()) {
52  trans = &p;
53  auto* ext = new axi::axi4_extension;
54  trans->set_auto_extension(ext);
55  } else {
57  trans->deep_copy_from(p);
58  tlm::scc::tlm_gp_mm::add_data_ptr(trans->get_data_length(), trans);
59  std::copy(p.get_data_ptr(), p.get_data_ptr() + p.get_data_length(), trans->get_data_ptr());
60  }
61  tlm::scc::setId(*trans, id++);
62  setup_cb(*trans);
63  return trans;
64 }
axi_initiator class provides an input_socket for incoming TLM transactions. It attaches AXI extension...
Definition: axi_initiator.h:35
tlm::tlm_generic_payload * create_axi_trans(tlm::tlm_generic_payload &p)
void transport(payload_type &trans, bool blocking) override
The forward transport function. It behaves blocking and is re-entrant.
payload_type * allocate()
get a plain tlm_payload_type without extensions
Definition: tlm_mm.h:228
static tlm_mm & get()
accessor function of the singleton
Definition: tlm_mm.h:222
TLM2.0 components modeling AHB.
Definition: axi_initiator.h:30
void set_size(uint8_t)
get the AxSIZE value of the transaction, the length is 2^size. It needs to be less than 10 (512 bit w...
Definition: axi_tlm.h:1384