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