scc 2025.09
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
31namespace ahb {
33namespace pe {
37class ahb_target_b : public sc_core::sc_module, public tlm::tlm_fw_transport_if<tlm::tlm_base_protocol_types> {
38public:
39#if SYSTEMC_VERSION < 20250221
40 SC_HAS_PROCESS(ahb_target_b);
41#endif
42 using payload_type = tlm::tlm_base_protocol_types::tlm_payload_type;
43 using phase_type = tlm::tlm_base_protocol_types::tlm_phase_type;
44
45 sc_core::sc_in<bool> clk_i{"clk_i"};
50 sc_core::sc_attribute<unsigned> wr_data_accept_delay{"wr_data_accept_delay", 0};
54 sc_core::sc_attribute<unsigned> rd_addr_accept_delay{"rd_addr_accept_delay", 0};
58 sc_core::sc_attribute<unsigned> rd_data_beat_delay{"rd_data_beat_delay", 0};
63 sc_core::sc_attribute<unsigned> rd_resp_delay{"rd_resp_delay", 0};
68 sc_core::sc_attribute<unsigned> wr_resp_delay{"wr_resp_delay", 0};
69
70 void b_transport(payload_type& trans, sc_core::sc_time& t) override;
71
72 tlm::tlm_sync_enum nb_transport_fw(payload_type& trans, phase_type& phase, sc_core::sc_time& t) override;
73
74 bool get_direct_mem_ptr(payload_type& trans, tlm::tlm_dmi& dmi_data) override;
75
76 unsigned int transport_dbg(payload_type& trans) override;
86
87 void set_operation_cb(std::function<unsigned(payload_type& trans)> cb) { operation_cb = cb; }
93 void operation_resp(payload_type& trans, bool sync = false);
94
95protected:
103 explicit ahb_target_b(const sc_core::sc_module_name& nm,
104 sc_core::sc_port_b<tlm::tlm_bw_transport_if<tlm::tlm_base_protocol_types>>& port, size_t transfer_width);
105
106 ahb_target_b() = delete;
107
108 ahb_target_b(ahb_target_b const&) = delete;
109
110 ahb_target_b(ahb_target_b&&) = delete;
111
112 ahb_target_b& operator=(ahb_target_b const&) = delete;
113
114 ahb_target_b& operator=(ahb_target_b&&) = delete;
115
116 void send_resp_thread();
117
118 sc_core::sc_port_b<tlm::tlm_bw_transport_if<tlm::tlm_base_protocol_types>>& socket_bw;
119 sc_core::sc_semaphore sn_sem{1};
120 sc_core::sc_mutex wr, rd, sn;
121 bool fast_resp{false};
122 bool fast_req{false};
123 std::function<unsigned(payload_type& trans)> operation_cb;
124 scc::ordered_semaphore rd_resp{1}, wr_resp{1};
125 sc_core::sc_clock* clk_if{nullptr};
126 void end_of_elaboration() override;
127};
128
132template <unsigned int BUSWIDTH = 32, typename TYPES = tlm::tlm_base_protocol_types, int N = 1,
133 sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND>
134class ahb3_target : public ahb_target_b {
135public:
136 using base = ahb_target_b;
137 using payload_type = base::payload_type;
138 using phase_type = base::phase_type;
143 ahb3_target(tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>& socket)
144 : // @suppress("Class members should be properly initialized")
145 ahb3_target(sc_core::sc_gen_unique_name("simple_target"), socket) {}
146
147 ahb3_target(const sc_core::sc_module_name& nm, tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>& socket)
148 : ahb_target_b(nm, socket.get_base_port(), BUSWIDTH)
149 , socket(socket) {
150 socket(*this);
151 }
152
153 ahb3_target() = delete;
154
155 ahb3_target(ahb3_target const&) = delete;
156
157 ahb3_target(ahb3_target&&) = delete;
158
159 ahb3_target& operator=(ahb3_target const&) = delete;
160
161 ahb3_target& operator=(ahb3_target&&) = delete;
162
163private:
164 tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>& socket;
165};
166
167} // namespace pe
168} // namespace ahb
169
170#endif // _BUS_AHB_PE_TARGET_H_
ahb3_target(tlm::tlm_target_socket< BUSWIDTH, TYPES, N, POL > &socket)
the constructor
Definition ahb_target.h:143
void operation_resp(payload_type &trans, bool sync=false)
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:50
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:63
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:87
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:58
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:54
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:68
The ordered_semaphore primitive channel class.
protocol engine implementations
TLM2.0 components modeling AHB.
Definition ahb_tlm.cpp:19