scc  2022.4.0
SystemC components library
apb_initiator.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_APB_PE_APB_INITIATOR_H_
18 #define _BUS_APB_PE_APB_INITIATOR_H_
19 
20 #include <scc/ordered_semaphore.h>
21 #include <scc/peq.h>
22 #include <tlm>
23 
25 namespace apb {
27 namespace pe {
28 
29 class apb_initiator_b : public sc_core::sc_module, public tlm::tlm_bw_transport_if<tlm::tlm_base_protocol_types> {
30 public:
31  SC_HAS_PROCESS(apb_initiator_b);
32 
33  using payload_type = tlm::tlm_generic_payload;
34  using phase_type = tlm::tlm_phase;
35 
36  sc_core::sc_in<bool> clk_i{"clk_i"};
37 
38  tlm::tlm_sync_enum nb_transport_bw(payload_type& trans, phase_type& phase, sc_core::sc_time& t) override;
39 
40  void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) override;
41 
42  size_t get_transferwith_in_bytes() const { return transfer_width_in_bytes; }
52  void transport(payload_type& trans, bool blocking);
53 
54  apb_initiator_b(sc_core::sc_module_name nm, sc_core::sc_port_b<tlm::tlm_fw_transport_if<tlm::tlm_base_protocol_types>>& port,
55  size_t transfer_width, bool coherent);
56 
57  virtual ~apb_initiator_b();
58 
59  apb_initiator_b() = delete;
60 
61  apb_initiator_b(apb_initiator_b const&) = delete;
62 
63  apb_initiator_b(apb_initiator_b&&) = delete;
64 
65  apb_initiator_b& operator=(apb_initiator_b const&) = delete;
66 
67  apb_initiator_b& operator=(apb_initiator_b&&) = delete;
68 
69 protected:
70  const size_t transfer_width_in_bytes;
71 
72  sc_core::sc_port_b<tlm::tlm_fw_transport_if<tlm::tlm_base_protocol_types>>& socket_fw;
73 
75 
77 
78  sc_core::sc_event any_tx_finished;
79 
80  sc_core::sc_time clk_period{10, sc_core::SC_NS};
81 
82 private:
83  sc_core::sc_clock* clk_if{nullptr};
84  void end_of_elaboration() override { clk_if = dynamic_cast<sc_core::sc_clock*>(clk_i.get_interface()); }
85 
86  unsigned m_clock_counter{0};
87  unsigned m_prev_clk_cnt{0};
88 };
89 
93 template <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>
96 public:
97  using base = apb_initiator_b;
98 
99  using payload_type = base::payload_type;
100  using phase_type = base::phase_type;
107  apb_initiator(const sc_core::sc_module_name& nm, tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N, POL>& socket)
108  : apb_initiator_b(nm, socket.get_base_port(), BUSWIDTH, false)
109  , socket(socket) {
110  socket(*this);
111  }
112 
113  apb_initiator() = delete;
114 
115  apb_initiator(apb_initiator const&) = delete;
116 
117  apb_initiator(apb_initiator&&) = delete;
118 
119  apb_initiator& operator=(apb_initiator const&) = delete;
120 
121  apb_initiator& operator=(apb_initiator&&) = delete;
122 
123 private:
124  tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N, POL>& socket;
125 };
126 
127 } /* namespace pe */
128 } /* namespace apb */
129 
130 #endif /* _BUS_APB_PE_APB_INITIATOR_H_ */
void transport(payload_type &trans, bool blocking)
The forward transport function. It behaves blocking and is re-entrant.
apb_initiator(const sc_core::sc_module_name &nm, tlm::tlm_initiator_socket< BUSWIDTH, TYPES, N, POL > &socket)
the constructor
TLM2.0 components modeling APB.
Definition: apb_initiator.h:25
priority event queue
Definition: peq.h:41