scc 2025.09
SystemC components library
axi_target_pe.h
1/*
2 * Copyright 2020-2022 Arteris IP
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.axi_util.cpp
15 */
16
17#pragma once
18
19#ifndef SC_INCLUDE_DYNAMIC_PROCESSES
20#define SC_INCLUDE_DYNAMIC_PROCESSES
21#endif
22
23#include <array>
24#include <axi/fsm/base.h>
25#include <functional>
26#include <memory>
27#include <scc/mt19937_rng.h>
28#include <scc/ordered_semaphore.h>
29#include <scc/sc_variable.h>
30#include <tlm/scc/pe/intor_if.h>
31#include <tlm_utils/peq_with_cb_and_phase.h>
32#include <unordered_set>
33
35namespace axi {
37namespace pe {
38
39inline unsigned get_cci_randomized_value(cci::cci_param<int> const& p) {
40 if(p.get_value() < 0)
41 return scc::MT19937::uniform(0, -p.get_value());
42 return p.get_value();
43}
47class axi_target_pe : public sc_core::sc_module, protected axi::fsm::base, public axi::axi_fw_transport_if<axi::axi_protocol_types> {
48 struct bw_intor_impl;
49
50public:
51 using payload_type = axi::axi_protocol_types::tlm_payload_type;
52 using phase_type = axi::axi_protocol_types::tlm_phase_type;
53
54 sc_core::sc_in<bool> clk_i{"clk_i"};
55
56 sc_core::sc_port<tlm::scc::pe::intor_fw_nb, 1, sc_core::SC_ZERO_OR_MORE_BOUND> fw_o{"fw_o"};
57
58 sc_core::sc_export<tlm::scc::pe::intor_bw_nb> bw_i{"bw_i"};
59
64 cci::cci_param<unsigned> max_outstanding_tx{"max_outstanding_tx", 0};
68 cci::cci_param<bool> rd_data_interleaving{"rd_data_interleaving", true};
73 cci::cci_param<int> wr_data_accept_delay{"wr_data_accept_delay", 0};
77 cci::cci_param<int> rd_addr_accept_delay{"rd_addr_accept_delay", 0};
81 cci::cci_param<int> rd_data_beat_delay{"rd_data_beat_delay", 0};
86 cci::cci_param<int> rd_resp_delay{"rd_resp_delay", 0};
91 cci::cci_param<int> wr_resp_delay{"wr_resp_delay", 0};
92
93 void b_transport(payload_type& trans, sc_core::sc_time& t) override;
94
95 tlm::tlm_sync_enum nb_transport_fw(payload_type& trans, phase_type& phase, sc_core::sc_time& t) override;
96
97 bool get_direct_mem_ptr(payload_type& trans, tlm::tlm_dmi& dmi_data) override;
98
99 unsigned int transport_dbg(payload_type& trans) override;
109
110 void set_operation_cb(std::function<unsigned(payload_type& trans)> cb) { operation_cb = cb; }
117 void operation_resp(payload_type& trans, unsigned clk_delay = 0);
123 bool is_active() { return !active_fsm.empty(); }
129 const sc_core::sc_event& tx_finish_event() { return finish_evt; }
130
132
139 explicit axi_target_pe(const sc_core::sc_module_name& nm, size_t transfer_width, flavor_e flavor = flavor_e::AXI);
140
141 void set_bw_interface(axi::axi_bw_transport_if<axi_protocol_types>* ifs) { socket_bw = ifs; }
142
143 inline unsigned getAllOutStandingTx() const { return outstanding_rd_tx + outstanding_wr_tx + outstanding_ign_tx; }
144
145protected:
146 axi_target_pe() = delete;
147
148 axi_target_pe(axi_target_pe const&) = delete;
149
150 axi_target_pe(axi_target_pe&&) = delete;
151
152 axi_target_pe& operator=(axi_target_pe const&) = delete;
153
154 axi_target_pe& operator=(axi_target_pe&&) = delete;
155
156 void end_of_elaboration() override;
157
158 void start_of_simulation() override;
159
160 void fsm_clk_method() { process_fsm_clk_queue(); }
164 fsm::fsm_handle* create_fsm_handle() override;
168 void setup_callbacks(fsm::fsm_handle*) override;
169
170 unsigned operations_callback(payload_type& trans);
171
173 std::function<unsigned(payload_type& trans)> operation_cb;
174 scc::fifo_w_cb<std::tuple<payload_type*, unsigned>> rd_req2resp_fifo{"rd_req2resp_fifo"};
175 scc::fifo_w_cb<std::tuple<payload_type*, unsigned>> wr_req2resp_fifo{"wr_req2resp_fifo"};
176 void process_req2resp_fifos();
177 sc_core::sc_fifo<payload_type*> rd_resp_fifo{1}, wr_resp_fifo{1};
178 void start_rd_resp_thread();
179 void start_wr_resp_thread();
180 sc_core::sc_fifo<std::tuple<fsm::fsm_handle*, axi::fsm::protocol_time_point_e>> wr_resp_beat_fifo{128}, rd_resp_beat_fifo{128};
181 scc::ordered_semaphore rd_resp{1}, wr_resp_ch{1}, rd_resp_ch{1};
182 void send_wr_resp_beat_thread();
183 void send_rd_resp_beat_thread();
184
185 sc_core::sc_clock* clk_if{nullptr};
186 std::unique_ptr<bw_intor_impl> bw_intor;
187 std::array<unsigned, 3> outstanding_cnt{{0, 0, 0}}; // count for limiting
188 scc::sc_variable<unsigned> outstanding_rd_tx{"OutstandingRd", 0};
189 scc::sc_variable<unsigned> outstanding_wr_tx{"OutstandingWr", 0};
190 scc::sc_variable<unsigned> outstanding_ign_tx{"OutstandingIgn", 0};
191 inline scc::sc_variable<unsigned>& getOutStandingTx(tlm::tlm_command cmd) {
192 switch(cmd) {
193 case tlm::TLM_READ_COMMAND:
194 return outstanding_rd_tx;
195 case tlm::TLM_WRITE_COMMAND:
196 return outstanding_wr_tx;
197 default:
198 return outstanding_ign_tx;
199 }
200 }
201 inline scc::sc_variable<unsigned> const& getOutStandingTx(tlm::tlm_command cmd) const {
202 switch(cmd) {
203 case tlm::TLM_READ_COMMAND:
204 return outstanding_rd_tx;
205 case tlm::TLM_WRITE_COMMAND:
206 return outstanding_wr_tx;
207 default:
208 return outstanding_ign_tx;
209 }
210 }
211 std::array<tlm::tlm_generic_payload*, 3> stalled_tx{nullptr, nullptr, nullptr};
212 std::array<axi::fsm::protocol_time_point_e, 3> stalled_tp{{axi::fsm::CB_CNT, axi::fsm::CB_CNT, axi::fsm::CB_CNT}};
213 void nb_fw(payload_type& trans, const phase_type& phase) {
214 auto delay = sc_core::SC_ZERO_TIME;
215 base::nb_fw(trans, phase, delay);
216 }
217 tlm_utils::peq_with_cb_and_phase<axi_target_pe> fw_peq{this, &axi_target_pe::nb_fw};
218 std::unordered_set<unsigned> active_rdresp_id;
219};
220
221} // namespace pe
222} // namespace axi
cci::cci_param< int > rd_addr_accept_delay
the latency between between BEGIN_REQ and END_REQ (ARVALID to ARREADY) -> APR
cci::cci_param< int > wr_data_accept_delay
the latency between between BEGIN(_PARTIAL)_REQ and END(_PARTIAL)_REQ (AWVALID to AWREADY and WVALID ...
const sc_core::sc_event & tx_finish_event()
cci::cci_param< bool > rd_data_interleaving
enable data interleaving on read responses if rd_data_beat_delay is greater than 0
fsm::fsm_handle * create_fsm_handle() override
void set_operation_cb(std::function< unsigned(payload_type &trans)> cb)
Set the operation callback function.
axi_target_pe(const sc_core::sc_module_name &nm, size_t transfer_width, flavor_e flavor=flavor_e::AXI)
void operation_resp(payload_type &trans, unsigned clk_delay=0)
cci::cci_param< int > rd_data_beat_delay
the latency between between END(_PARTIAL)_RESP and BEGIN(_PARTIAL)_RESP (RREADY to RVALID) -> RBV
void setup_callbacks(fsm::fsm_handle *) override
cci::cci_param< int > rd_resp_delay
the latency between request and response phase. Will be overwritten by the return of the callback fun...
cci::cci_param< unsigned > max_outstanding_tx
the number of supported outstanding transactions. If this limit is reached the target starts to do ba...
cci::cci_param< int > wr_resp_delay
the latency between request and response phase. Will be overwritten by the return of the callback fun...
static uint64_t uniform()
Definition mt19937_rng.h:60
protocol engine implementations
TLM2.0 components modeling AHB.
tlm::tlm_bw_transport_if< TYPES > axi_bw_transport_if
alias declaration for the backward interface:
Definition axi_tlm.h:956
tlm::tlm_fw_transport_if< TYPES > axi_fw_transport_if
alias declaration for the forward interface
Definition axi_tlm.h:954
base class of all AXITLM based adapters and interfaces.
Definition base.h:43
void process_fsm_clk_queue()
processes the fsm_clk_queue and triggers the FSM accordingly. Should be registered as rising-edge clo...
Definition base.cpp:107
axi::axi_protocol_types::tlm_payload_type payload_type
aliases used in the class
Definition base.h:45