scc 2025.09
SystemC components library
apb_target.h
1/*******************************************************************************
2 * Copyright 2019-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_APB_PE_APB_TARGET_H_
18#define _BUS_APB_PE_APB_TARGET_H_
19
20#include <functional>
21#include <scc/ordered_semaphore.h>
22#include <tlm>
23
25namespace apb {
27namespace pe {
31class apb_target_b : public sc_core::sc_module, public tlm::tlm_fw_transport_if<tlm::tlm_base_protocol_types> {
32public:
33#if SYSTEMC_VERSION < 20250221
34 SC_HAS_PROCESS(apb_target_b);
35#endif
36 using payload_type = tlm::tlm_base_protocol_types::tlm_payload_type;
37 using phase_type = tlm::tlm_base_protocol_types::tlm_phase_type;
38
39 sc_core::sc_in<bool> clk_i{"clk_i"};
40
41 void b_transport(payload_type& trans, sc_core::sc_time& t) override;
42
43 tlm::tlm_sync_enum nb_transport_fw(payload_type& trans, phase_type& phase, sc_core::sc_time& t) override;
44
45 bool get_direct_mem_ptr(payload_type& trans, tlm::tlm_dmi& dmi_data) override;
46
47 unsigned int transport_dbg(payload_type& trans) override;
57
58 void set_operation_cb(std::function<unsigned(payload_type& trans)> cb) { operation_cb = cb; }
59
60protected:
68 explicit apb_target_b(const sc_core::sc_module_name& nm,
69 sc_core::sc_port_b<tlm::tlm_bw_transport_if<tlm::tlm_base_protocol_types>>& port, size_t transfer_width);
70
71 apb_target_b() = delete;
72
73 apb_target_b(apb_target_b const&) = delete;
74
75 apb_target_b(apb_target_b&&) = delete;
76
77 apb_target_b& operator=(apb_target_b const&) = delete;
78
79 apb_target_b& operator=(apb_target_b&&) = delete;
80
81 tlm::tlm_generic_payload* active_tx{nullptr};
82 void response();
83 sc_core::sc_port_b<tlm::tlm_bw_transport_if<tlm::tlm_base_protocol_types>>& socket_bw;
84 std::function<unsigned(payload_type& trans)> operation_cb;
85 sc_core::sc_clock* clk_if{nullptr};
86 void end_of_elaboration() override;
87 sc_core::sc_process_handle mhndl;
88};
89
93template <unsigned int BUSWIDTH = 32, typename TYPES = tlm::tlm_base_protocol_types, int N = 1,
94 sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND>
95class apb_target : public apb_target_b {
96public:
97 using base = apb_target_b;
98 using payload_type = base::payload_type;
99 using phase_type = base::phase_type;
104 apb_target(tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>& socket)
105 : // @suppress("Class members should be properly initialized")
106 apb_target(sc_core::sc_gen_unique_name("simple_target"), socket) {}
107
108 apb_target(const sc_core::sc_module_name& nm, tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>& socket)
109 : apb_target_b(nm, socket.get_base_port(), BUSWIDTH)
110 , socket(socket) {
111 socket(*this);
112 }
113
114 apb_target() = delete;
115
116 apb_target(apb_target const&) = delete;
117
118 apb_target(apb_target&&) = delete;
119
120 apb_target& operator=(apb_target const&) = delete;
121
122 apb_target& operator=(apb_target&&) = delete;
123
124private:
125 tlm::tlm_target_socket<BUSWIDTH, TYPES, N, POL>& socket;
126};
127
128} // namespace pe
129} // namespace apb
130
131#endif /*_BUS_APB_PE_APB_TARGET_H_*/
apb_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 apb_target.h:58
apb_target(tlm::tlm_target_socket< BUSWIDTH, TYPES, N, POL > &socket)
the constructor
Definition apb_target.h:104
protocol engine implementations
TLM2.0 components modeling APB.
Definition apb_tlm.cpp:21