scc  2022.4.0
SystemC components library
ahb_target.h
1 /*******************************************************************************
2  * Copyright 2020-2022 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 #ifndef _BUS_AHB_PE_TARGET_H_
18 #define _BUS_AHB_PE_TARGET_H_
19 
20 #ifndef SC_INCLUDE_DYNAMIC_PROCESSES
21 #define SC_INCLUDE_DYNAMIC_PROCESSES
22 #endif
23 
24 #include <ahb/ahb_tlm.h>
25 #include <array>
26 #include <functional>
27 #include <scc/ordered_semaphore.h>
28 #include <unordered_set>
29 
31 namespace ahb {
33 namespace pe {
37 class ahb_target_b : public sc_core::sc_module, public tlm::tlm_fw_transport_if<tlm::tlm_base_protocol_types> {
38 public:
39  SC_HAS_PROCESS(ahb_target_b);
40 
41  using payload_type = tlm::tlm_base_protocol_types::tlm_payload_type;
42  using phase_type = tlm::tlm_base_protocol_types::tlm_phase_type;
43 
44  sc_core::sc_in<bool> clk_i{"clk_i"};
49  sc_core::sc_attribute<unsigned> wr_data_accept_delay{"wr_data_accept_delay", 0};
53  sc_core::sc_attribute<unsigned> rd_addr_accept_delay{"rd_addr_accept_delay", 0};
57  sc_core::sc_attribute<unsigned> rd_data_beat_delay{"rd_data_beat_delay", 0};
62  sc_core::sc_attribute<unsigned> rd_resp_delay{"rd_resp_delay", 0};
67  sc_core::sc_attribute<unsigned> wr_resp_delay{"wr_resp_delay", 0};
68 
69  void b_transport(payload_type& trans, sc_core::sc_time& t) override;
70 
71  tlm::tlm_sync_enum nb_transport_fw(payload_type& trans, phase_type& phase, sc_core::sc_time& t) override;
72 
73  bool get_direct_mem_ptr(payload_type& trans, tlm::tlm_dmi& dmi_data) override;
74 
75  unsigned int transport_dbg(payload_type& trans) override;
86  void set_operation_cb(std::function<unsigned(payload_type& trans)> cb) { operation_cb = cb; }
92  void operation_resp(payload_type& trans, bool sync = false);
93 
94 protected:
102  explicit ahb_target_b(const sc_core::sc_module_name& nm,
103  sc_core::sc_port_b<tlm::tlm_bw_transport_if<tlm::tlm_base_protocol_types>>& port, size_t transfer_width);
104 
105  ahb_target_b() = delete;
106 
107  ahb_target_b(ahb_target_b const&) = delete;
108 
109  ahb_target_b(ahb_target_b&&) = delete;
110 
111  ahb_target_b& operator=(ahb_target_b const&) = delete;
112 
113  ahb_target_b& operator=(ahb_target_b&&) = delete;
114 
115  void send_resp_thread();
116 
117  sc_core::sc_port_b<tlm::tlm_bw_transport_if<tlm::tlm_base_protocol_types>>& socket_bw;
118  sc_core::sc_semaphore sn_sem{1};
119  sc_core::sc_mutex wr, rd, sn;
120  bool fast_resp{false};
121  bool fast_req{false};
122  std::function<unsigned(payload_type& trans)> operation_cb;
123  scc::ordered_semaphore rd_resp{1}, wr_resp{1};
124  sc_core::sc_clock* clk_if{nullptr};
125  void end_of_elaboration() override;
126 };
127 
131 template <unsigned int BUSWIDTH = 32, typename TYPES = tlm::tlm_base_protocol_types, int N = 1,
132  sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND>
133 class ahb3_target : public ahb_target_b {
134 public:
135  using base = ahb_target_b;
136  using payload_type = base::payload_type;
137  using phase_type = base::phase_type;
142  ahb3_target(tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>& socket)
143  : // @suppress("Class members should be properly initialized")
144  ahb3_target(sc_core::sc_gen_unique_name("simple_target"), socket) {}
145 
146  ahb3_target(const sc_core::sc_module_name& nm, tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>& socket)
147  : ahb_target_b(nm, socket.get_base_port(), BUSWIDTH)
148  , socket(socket) {
149  socket(*this);
150  }
151 
152  ahb3_target() = delete;
153 
154  ahb3_target(ahb3_target const&) = delete;
155 
156  ahb3_target(ahb3_target&&) = delete;
157 
158  ahb3_target& operator=(ahb3_target const&) = delete;
159 
160  ahb3_target& operator=(ahb3_target&&) = delete;
161 
162 private:
163  tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>& socket;
164 };
165 
166 } // namespace pe
167 } // namespace ahb
168 
169 #endif // _BUS_AHB_PE_TARGET_H_
ahb3_target(tlm::tlm_target_socket< BUSWIDTH, TYPES, N, POL > &socket)
the constructor
Definition: ahb_target.h:142
void operation_resp(payload_type &trans, bool sync=false)
Definition: ahb_target.cpp:68
sc_core::sc_attribute< unsigned > wr_data_accept_delay
the latency between between BEGIN(_PARTIAL)_REQ and END(_PARTIAL)_REQ (AWVALID to AWREADY and WVALID ...
Definition: ahb_target.h:49
sc_core::sc_attribute< unsigned > rd_resp_delay
the latency between request and response phase. Will be overwritten by the return of the callback fun...
Definition: ahb_target.h:62
ahb_target_b(const sc_core::sc_module_name &nm, sc_core::sc_port_b< tlm::tlm_bw_transport_if< tlm::tlm_base_protocol_types >> &port, size_t transfer_width)
void set_operation_cb(std::function< unsigned(payload_type &trans)> cb)
Set the operation callback function.
Definition: ahb_target.h:86
sc_core::sc_attribute< unsigned > rd_data_beat_delay
the latency between between END(_PARTIAL)_RESP and BEGIN(_PARTIAL)_RESP (RREADY to RVALID)
Definition: ahb_target.h:57
sc_core::sc_attribute< unsigned > rd_addr_accept_delay
the latency between between BEGIN_REQ and END_REQ (ARVALID to ARREADY)
Definition: ahb_target.h:53
sc_core::sc_attribute< unsigned > wr_resp_delay
the latency between request and response phase. Will be overwritten by the return of the callback fun...
Definition: ahb_target.h:67
The ordered_semaphore primitive channel class.
TLM2.0 components modeling AHB.
Definition: ahb_tlm.cpp:19