scc  2022.4.0
SystemC components library
ordered_target.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 #include <axi/pe/axi_target_pe.h>
20 #include <cci_configuration>
21 #include "target_info_if.h"
22 
24 namespace axi {
26 namespace pe {
27 class rate_limiting_buffer: public sc_core::sc_module, tlm::scc::pe::intor_fw_nb {
28 public:
29  sc_core::sc_in<bool> clk_i{"clk_i"};
30 
31  sc_core::sc_export<tlm::scc::pe::intor_fw_nb> fw_i{"fw_i"};
32 
33  sc_core::sc_port<tlm::scc::pe::intor_bw_nb, 1, sc_core::SC_ZERO_OR_MORE_BOUND> bw_o{"bw_o"};
34 
48  cci::cci_param<double> rd_bw_limit_byte_per_sec{"rd_bw_limit_byte_per_sec", -1.0};
52  cci::cci_param<double> wr_bw_limit_byte_per_sec{"wr_bw_limit_byte_per_sec", -1.0};
56  cci::cci_param<double> total_bw_limit_byte_per_sec{"total_bw_limit_byte_per_sec", -1.0};
57 
65  void transport(tlm::tlm_generic_payload& payload, bool lt_transport = false) override;
72  void snoop_resp(tlm::tlm_generic_payload& payload, bool sync = false) override {}
73 protected:
74  sc_core::sc_clock* clk_if{nullptr};
75  sc_core::sc_time time_per_byte_rd, time_per_byte_wr, time_per_byte_total;
78  scc::fifo_w_cb<std::tuple<tlm::tlm_generic_payload*, unsigned>> wr_req2resp_fifo{"wr_req2resp_fifo"};
81  scc::fifo_w_cb<tlm::tlm_generic_payload*> wr_resp_fifo{"wr_resp_fifo"};
82  scc::ordered_semaphore total_arb{1};
83  double total_residual_clocks{0.0};
84  void end_of_elaboration() override;
85  void start_of_simulation() override;
86 
87  void process_req2resp_fifos();
88  void start_rd_resp_thread();
89  void start_wr_resp_thread();
90 
91 };
96 template <unsigned int BUSWIDTH = 32, typename TYPES = axi::axi_protocol_types, int N = 1,
97  sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND>
98 class ordered_target : public sc_core::sc_module, public target_info_if {
99 public:
100  using base = axi_target_pe;
101  using payload_type = base::payload_type;
102  using phase_type = base::phase_type;
103  sc_core::sc_in<bool> clk_i{"clk_i"};
104 
106 
111  ordered_target(const sc_core::sc_module_name& nm)
112  : sc_core::sc_module(nm)
113  , pe("pe", BUSWIDTH)
114  , rate_limit_buffer("rate_limit_buffer", pe.rd_resp_delay, pe.wr_resp_delay){
115  sckt(pe);
116  pe.clk_i(clk_i);
117  rate_limit_buffer.clk_i(clk_i);
118  pe.fw_o(rate_limit_buffer.fw_i);
119  rate_limit_buffer.bw_o(pe.bw_i);
120  }
121 
122  ordered_target() = delete;
123 
124  ordered_target(ordered_target const&) = delete;
125 
126  ordered_target(ordered_target&&) = delete;
127 
128  ordered_target& operator=(ordered_target const&) = delete;
129 
130  ordered_target& operator=(ordered_target&&) = delete;
131 
132  size_t get_outstanding_tx_count() override { return pe.getAllOutStandingTx();}
133 
134 protected:
135  void end_of_elaboration(){
136  auto* ifs = sckt.get_base_port().get_interface(0);
137  sc_assert(ifs!=nullptr);
138  pe.set_bw_interface(ifs);
139  }
140 public:
141  axi_target_pe pe;
142  rate_limiting_buffer rate_limit_buffer;
143 };
144 } // namespace pe
145 } // namespace axi
ordered_target(const sc_core::sc_module_name &nm)
the constructor
scc::sc_attribute_randomized< int > & rd_resp_delay
the latency between request and response phase. Will be overwritten by the return of the callback fun...
scc::fifo_w_cb< std::tuple< tlm::tlm_generic_payload *, unsigned > > rd_req2resp_fifo
queues realizing the min latency
cci::cci_param< double > total_bw_limit_byte_per_sec
the bandwidth limit for read accesses
void snoop_resp(tlm::tlm_generic_payload &payload, bool sync=false) override
scc::sc_attribute_randomized< int > & wr_resp_delay
the latency between request and response phase. Will be overwritten by the return of the callback fun...
scc::fifo_w_cb< tlm::tlm_generic_payload * > rd_resp_fifo
queues to handle bandwidth limit
void transport(tlm::tlm_generic_payload &payload, bool lt_transport=false) override
cci::cci_param< double > rd_bw_limit_byte_per_sec
the bandwidth limit for read accesses
cci::cci_param< double > wr_bw_limit_byte_per_sec
the bandwidth limit for write accesses
fifo with callbacks
Definition: fifo_w_cb.h:38
The ordered_semaphore primitive channel class.
TLM2.0 components modeling AHB.
Definition: axi_initiator.h:30
The AXI protocol traits class. Since the protocoll defines additional non-ignorable phases a dedicate...
Definition: axi_tlm.h:890