scc  2022.4.0
SystemC components library
ahb_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_AHB_PE_INITIATOR_H_
18 #define _BUS_AHB_PE_INITIATOR_H_
19 
20 #include <ahb/ahb_tlm.h>
21 #include <scc/ordered_semaphore.h>
22 #include <scc/peq.h>
23 #include <systemc>
24 #include <tlm_utils/peq_with_get.h>
25 #include <tuple>
26 #include <unordered_map>
27 
29 namespace ahb {
31 namespace pe {
32 
33 class ahb_initiator_b : public sc_core::sc_module, public tlm::tlm_bw_transport_if<tlm::tlm_base_protocol_types> {
34 public:
35  SC_HAS_PROCESS(ahb_initiator_b);
36 
37  using payload_type = tlm::tlm_generic_payload;
38  using phase_type = tlm::tlm_phase;
39 
40  sc_core::sc_in<bool> clk_i{"clk_i"};
41 
42  tlm::tlm_sync_enum nb_transport_bw(payload_type& trans, phase_type& phase, sc_core::sc_time& t) override;
43 
44  void invalidate_direct_mem_ptr(sc_dt::uint64 start_range, sc_dt::uint64 end_range) override;
45 
46  size_t get_transferwith_in_bytes() const { return transfer_width_in_bytes; }
56  void transport(payload_type& trans, bool blocking);
57 
58  ahb_initiator_b(sc_core::sc_module_name nm, sc_core::sc_port_b<tlm::tlm_fw_transport_if<tlm::tlm_base_protocol_types>>& port,
59  size_t transfer_width, bool coherent);
60 
61  virtual ~ahb_initiator_b();
62 
63  ahb_initiator_b() = delete;
64 
65  ahb_initiator_b(ahb_initiator_b const&) = delete;
66 
67  ahb_initiator_b(ahb_initiator_b&&) = delete;
68 
69  ahb_initiator_b& operator=(ahb_initiator_b const&) = delete;
70 
71  ahb_initiator_b& operator=(ahb_initiator_b&&) = delete;
72 
73  void snoop_resp(payload_type& trans, bool sync = false) {}
74 
76  sc_core::sc_attribute<unsigned> artv{"artv", 0};
78  sc_core::sc_attribute<unsigned> awtv{"awtv", 0};
80  sc_core::sc_attribute<unsigned> wbv{"wbv", 0};
82  sc_core::sc_attribute<unsigned> rbr{"rbr", 0};
84  sc_core::sc_attribute<unsigned> br{"br", 0};
85 
86 protected:
87  unsigned calculate_beats(payload_type& p) {
88  sc_assert(p.get_data_length() > 0);
89  return p.get_data_length() < transfer_width_in_bytes ? 1 : p.get_data_length() / transfer_width_in_bytes;
90  }
91 
92  const size_t transfer_width_in_bytes;
93 
94  const bool coherent;
95 
96  sc_core::sc_port_b<tlm::tlm_fw_transport_if<tlm::tlm_base_protocol_types>>& socket_fw;
97 
98  struct tx_state {
99  payload_type* active_tx{nullptr};
101  // scc::ordered_semaphore mtx{1};
102  };
103  std::unordered_map<payload_type*, tx_state*> tx_state_by_id;
104 
105  scc::ordered_semaphore_t<1> addr_chnl;
106 
107  scc::ordered_semaphore_t<1> data_chnl;
108 
109  sc_core::sc_event any_tx_finished;
110 
111  sc_core::sc_time clk_period{10, sc_core::SC_NS};
112 
113 private:
114  sc_core::sc_clock* clk_if{nullptr};
115  void end_of_elaboration() override { clk_if = dynamic_cast<sc_core::sc_clock*>(clk_i.get_interface()); }
116 
117  tlm::tlm_phase send(payload_type& trans, ahb_initiator_b::tx_state* txs, tlm::tlm_phase phase);
118 
119  unsigned m_clock_counter{0};
120  unsigned m_prev_clk_cnt{0};
121 };
122 
126 template <unsigned int BUSWIDTH = 32, typename TYPES = tlm::tlm_base_protocol_types, int N = 1,
127  sc_core::sc_port_policy POL = sc_core::SC_ONE_OR_MORE_BOUND>
129 public:
130  using base = ahb_initiator_b;
131 
132  using payload_type = base::payload_type;
133  using phase_type = base::phase_type;
140  ahb3_initiator(const sc_core::sc_module_name& nm, tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N, POL>& socket)
141  : ahb_initiator_b(nm, socket.get_base_port(), BUSWIDTH, false)
142  , socket(socket) {
143  socket(*this);
144  }
145 
146  ahb3_initiator() = delete;
147 
148  ahb3_initiator(ahb3_initiator const&) = delete;
149 
150  ahb3_initiator(ahb3_initiator&&) = delete;
151 
152  ahb3_initiator& operator=(ahb3_initiator const&) = delete;
153 
154  ahb3_initiator& operator=(ahb3_initiator&&) = delete;
155 
156 private:
157  tlm::tlm_initiator_socket<BUSWIDTH, TYPES, N, POL>& socket;
158 };
159 
160 } /* namespace pe */
161 } /* namespace ahb */
162 
163 #endif /* _BUS_AHB_PE_INITIATOR_H_ */
ahb3_initiator(const sc_core::sc_module_name &nm, tlm::tlm_initiator_socket< BUSWIDTH, TYPES, N, POL > &socket)
the constructor
sc_core::sc_attribute< unsigned > wbv
Write data handshake to next beat valid.
Definition: ahb_initiator.h:80
sc_core::sc_attribute< unsigned > artv
Read address valid to next read address valid.
Definition: ahb_initiator.h:76
sc_core::sc_attribute< unsigned > br
Write response valid to ready.
Definition: ahb_initiator.h:84
sc_core::sc_attribute< unsigned > awtv
Write address valid to next write address valid.
Definition: ahb_initiator.h:78
void transport(payload_type &trans, bool blocking)
The forward transport function. It behaves blocking and is re-entrant.
sc_core::sc_attribute< unsigned > rbr
Read data valid to same beat ready.
Definition: ahb_initiator.h:82
TLM2.0 components modeling AHB.
Definition: ahb_tlm.cpp:19
priority event queue
Definition: peq.h:41