scc  2024.06
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 "../../interfaces/axi/axi_initiator.h"
18 
19 #include <scc/report.h>
20 #include <tlm/scc/tlm_gp_shared.h>
21 #include <tlm/scc/tlm_id.h>
22 #include <tlm/scc/tlm_mm.h>
23 
24 using namespace axi;
25 
26 axi_initiator_base::axi_initiator_base(const sc_core::sc_module_name& nm, axi::pe::simple_initiator_b& pe, uint32_t width)
27 : sc_module(nm)
28 , pe(pe)
29 , buswidth(width) {
30  SC_HAS_PROCESS(axi_initiator_base);
31  // Register callback for incoming b_transport interface method call
32  tsck.register_b_transport(this, &axi_initiator_base::b_transport);
33  setup_cb = [this](tlm::tlm_generic_payload& p) {
34  auto len = p.get_data_length();
35  auto* ext = p.get_extension<axi::axi4_extension>();
36  ext->set_size(scc::ilog2(std::min<size_t>(len, buswidth / 8)));
37  sc_assert(len < (buswidth / 8) || len % (buswidth / 8) == 0);
38  ext->set_length((len * 8 - 1) / buswidth);
39  ext->set_burst(axi::burst_e::INCR);
40  ext->set_id(id);
41  };
42 }
43 
44 void axi_initiator_base::b_transport(tlm::tlm_generic_payload& trans, sc_core::sc_time& delay) {
46  pe.transport(*payload, false);
47  trans.update_original_from(*payload);
48 }
49 
50 tlm::tlm_generic_payload* axi_initiator_base::create_axi_trans(tlm::tlm_generic_payload& p) {
51  tlm::tlm_generic_payload* trans = nullptr;
52  if(p.has_mm()) {
53  trans = &p;
54  auto* ext = new axi::axi4_extension;
55  trans->set_auto_extension(ext);
56  } else {
58  trans->deep_copy_from(p);
59  tlm::scc::tlm_gp_mm::add_data_ptr(trans->get_data_length(), trans);
60  std::copy(p.get_data_ptr(), p.get_data_ptr() + p.get_data_length(), trans->get_data_ptr());
61  }
62  tlm::scc::setId(*trans, id++);
63  setup_cb(*trans);
64  return trans;
65 }
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:185
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:1456
static tlm_mm & get()
accessor function of the singleton
Definition: tlm_mm.h:293