scc 2025.09
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
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
24using namespace axi;
25
26axi_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#if SYSTEMC_VERSION < 20250221
31 SC_HAS_PROCESS(axi_initiator_base);
32#endif
33 // Register callback for incoming b_transport interface method call
34 tsck.register_b_transport(this, &axi_initiator_base::b_transport);
35 setup_cb = [this](tlm::tlm_generic_payload& p) {
36 auto len = p.get_data_length();
37 auto* ext = p.get_extension<axi::axi4_extension>();
38 ext->set_size(scc::ilog2(std::min<size_t>(len, buswidth / 8)));
39 sc_assert(len < (buswidth / 8) || len % (buswidth / 8) == 0);
40 ext->set_length((len * 8 - 1) / buswidth);
41 ext->set_burst(axi::burst_e::INCR);
42 ext->set_id(id);
43 };
44}
45
46void axi_initiator_base::b_transport(tlm::tlm_generic_payload& trans, sc_core::sc_time& delay) {
47 tlm::scc::tlm_gp_shared_ptr payload = create_axi_trans(trans);
48 pe.transport(*payload, false);
49 trans.update_original_from(*payload);
50}
51
52tlm::tlm_generic_payload* axi_initiator_base::create_axi_trans(tlm::tlm_generic_payload& p) {
53 tlm::tlm_generic_payload* trans = nullptr;
54 if(p.has_mm()) {
55 trans = &p;
56 auto* ext = new axi::axi4_extension;
57 trans->set_auto_extension(ext);
58 } else {
60 trans->deep_copy_from(p);
61 tlm::scc::tlm_gp_mm::add_data_ptr(trans->get_data_length(), trans);
62 std::copy(p.get_data_ptr(), p.get_data_ptr() + p.get_data_length(), trans->get_data_ptr());
63 }
64 tlm::scc::setId(*trans, id++);
65 setup_cb(*trans);
66 return trans;
67}
axi_initiator class provides an input_socket for incoming TLM transactions. It attaches AXI extension...
tlm::tlm_generic_payload * create_axi_trans(tlm::tlm_generic_payload &p)
payload_type * allocate()
get a plain tlm_payload_type without extensions
Definition tlm_mm.h:218
protocol engine implementations
TLM2.0 components modeling AHB.
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:338