scc  2022.4.0
SystemC components library
ace_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/ordered_semaphore.h>
28 #include <scc/sc_attribute_randomized.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 
35 namespace axi {
37 namespace pe {
41 class ace_target_pe : public sc_core::sc_module,
42  protected axi::fsm::base,
43  public axi::axi_bw_transport_if<axi::axi_protocol_types>,
44  public axi::ace_fw_transport_if<axi::axi_protocol_types> {
45  struct bw_intor_impl;
46 public:
47 
48  using payload_type = axi::axi_protocol_types::tlm_payload_type;
49  using phase_type = axi::axi_protocol_types::tlm_phase_type;
50 
51  sc_core::sc_in<bool> clk_i{"clk_i"};
52 
53  // hongyu?? here first hardcoded
54  axi::axi_initiator_socket<64> isckt_axi{"isckt_axi"};
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 
60 
61  scc::sc_attribute_randomized<int> rd_resp_delay{"rd_resp_delay", 0};
67 
68  void b_transport(payload_type& trans, sc_core::sc_time& t) override;
69 
70  tlm::tlm_sync_enum nb_transport_fw(payload_type& trans, phase_type& phase, sc_core::sc_time& t) override;
71 
72  bool get_direct_mem_ptr(payload_type& trans, tlm::tlm_dmi& dmi_data) override;
73 
74  unsigned int transport_dbg(payload_type& trans) override;
85  void set_operation_cb(std::function<unsigned(payload_type& trans)> cb) { operation_cb = cb; }
92  void operation_resp(payload_type& trans, unsigned clk_delay = 0);
98  bool is_active() { return !active_fsm.empty(); }
104  const sc_core::sc_event& tx_finish_event() { return finish_evt; }
105 
106  /* overwrite function, defined in axi_bw_transport_if */
107  tlm::tlm_sync_enum nb_transport_bw(payload_type& trans, phase_type& phase, sc_core::sc_time& t) override {
108  SCCTRACE(SCMOD) << " in nb_transport_bw () " ;
109  return socket_bw->nb_transport_bw(trans, phase, t);
110  }
111 
112  void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) override {}
113 
114 
115  ~ace_target_pe();
116 
122  explicit ace_target_pe(const sc_core::sc_module_name& nm, size_t transfer_width);
123 
124  void set_bw_interface(axi::axi_bw_transport_if<axi_protocol_types>* ifs) {socket_bw=ifs;}
125 
126  void snoop(payload_type& trans);
127 
128 protected:
129  ace_target_pe() = delete;
130 
131  ace_target_pe(ace_target_pe const&) = delete;
132 
133  ace_target_pe(ace_target_pe&&) = delete;
134 
135  ace_target_pe& operator=(ace_target_pe const&) = delete;
136 
137  ace_target_pe& operator=(ace_target_pe&&) = delete;
138 
139  void end_of_elaboration() override;
140 
141  void start_of_simulation() override;
142 
143  void fsm_clk_method() { process_fsm_clk_queue(); }
147  fsm::fsm_handle* create_fsm_handle() override;
151  void setup_callbacks(fsm::fsm_handle*) override;
152 
153  unsigned operations_callback(payload_type& trans);
154 
156  std::function<unsigned(payload_type& trans)> operation_cb;
157  sc_core::sc_fifo<payload_type*> rd_resp_fifo{1}, wr_resp_fifo{1};
158 
159  sc_core::sc_fifo<std::tuple<fsm::fsm_handle*, axi::fsm::protocol_time_point_e>> wr_resp_beat_fifo{128},
160  rd_resp_beat_fifo{128};
161  scc::ordered_semaphore rd_resp{1}, wr_resp_ch{1}, rd_resp_ch{1};
162 
163  sc_core::sc_clock* clk_if{nullptr};
164  std::unique_ptr<bw_intor_impl> bw_intor;
165  std::array<unsigned, 3> outstanding_cnt{{0, 0, 0}}; // count for limiting
166 
167  void nb_fw(payload_type& trans, const phase_type& phase) {
168  auto delay = sc_core::SC_ZERO_TIME;
169  base::nb_fw(trans, phase, delay);
170  }
171  tlm_utils::peq_with_cb_and_phase<ace_target_pe> fw_peq{this, &ace_target_pe::nb_fw};
172  std::unordered_set<unsigned> active_rdresp_id;
173 
174 };
175 
176 } // namespace pe
177 } // namespace axi
void operation_resp(payload_type &trans, unsigned clk_delay=0)
fsm::fsm_handle * create_fsm_handle() 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...
Definition: ace_target_pe.h:66
void set_operation_cb(std::function< unsigned(payload_type &trans)> cb)
Set the operation callback function.
Definition: ace_target_pe.h:85
ace_target_pe(const sc_core::sc_module_name &nm, size_t transfer_width)
void setup_callbacks(fsm::fsm_handle *) override
const sc_core::sc_event & tx_finish_event()
The ordered_semaphore primitive channel class.
TLM2.0 components modeling AHB.
Definition: axi_initiator.h:30
tlm::tlm_bw_transport_if< TYPES > axi_bw_transport_if
alias declaration for the backward interface:
Definition: axi_tlm.h:918
tlm::tlm_fw_transport_if< TYPES > ace_fw_transport_if
alias declaration for the ACE forward interface
Definition: axi_tlm.h:920
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