scc  2022.4.0
SystemC components library
base.h
1 /*
2  * Copyright 2020 - 2022 Arteris IP
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.axi_util.cpp
15  */
16 
17 #pragma once
18 
19 #include "types.h"
20 #include <axi/axi_tlm.h>
21 #include <deque>
22 #include <scc/fifo_w_cb.h>
23 #include <scc/peq.h>
24 #include <scc/report.h>
25 #include <tlm/scc/tlm_gp_shared.h>
26 #include <unordered_map>
27 
28 namespace axi {
29 namespace fsm {
31 struct fsm_handle;
32 
33 inline std::ostream& operator<<(std::ostream& os,
34  const std::tuple<axi::fsm::fsm_handle*, axi::fsm::protocol_time_point_e>&) {
35  return os;
36 }
37 
38 using axi::operator<<;
39 
43 struct base {
45  using payload_type = axi::axi_protocol_types::tlm_payload_type;
46  using phase_type = axi::axi_protocol_types::tlm_phase_type;
52  base(size_t transfer_width, bool coherent = false,
53  axi::fsm::protocol_time_point_e wr_start = axi::fsm::RequestPhaseBeg);
57  virtual ~base() {}
66  tlm::tlm_sync_enum nb_fw(payload_type& trans, phase_type const& phase, sc_core::sc_time& t);
75  tlm::tlm_sync_enum nb_bw(payload_type& trans, phase_type const& phase, sc_core::sc_time& t);
82  axi::fsm::fsm_handle* find_or_create(payload_type* gp = nullptr, bool ace = false);
97  void process_fsm_event();
102  void process_fsm_clk_queue();
107  inline void schedule(axi::fsm::protocol_time_point_e e, tlm::scc::tlm_gp_shared_ptr& gp, unsigned cycles) {
108  schedule(e, gp.get(), cycles);
109  }
110  void schedule(axi::fsm::protocol_time_point_e e, payload_type* gp, unsigned cycles) {
111  SCCTRACE(instance_name) << "pushing sync event " << evt2str(e) << " for transaction " << *gp
112  << " (sync:" << cycles << ")";
113  fsm_clk_queue.push_back(std::make_tuple(e, gp, cycles));
114  }
119  inline void schedule(axi::fsm::protocol_time_point_e e, tlm::scc::tlm_gp_shared_ptr& gp, sc_core::sc_time delay,
120  bool syncronize = false) {
121  schedule(e, gp.get(), delay, syncronize);
122  }
123  void schedule(axi::fsm::protocol_time_point_e e, payload_type* gp, sc_core::sc_time delay,
124  bool syncronize = false) {
125  SCCTRACE(instance_name) << "pushing event " << evt2str(e) << " for transaction " << *gp << " (delay " << delay
126  << ")";
127  fsm_event_queue.notify(std::make_tuple(e, gp, syncronize), delay);
128  }
134  inline void react(axi::fsm::protocol_time_point_e event, tlm::scc::tlm_gp_shared_ptr& trans) {
135  react(event, trans.get());
136  }
137 
138  inline void react(axi::fsm::protocol_time_point_e event, payload_type* trans) {
139  SCCTRACE(instance_name) << "reacting on event " << evt2str(static_cast<unsigned>(event)) << " for trans "
140  << *trans;
141  auto fsm_hndl = active_fsm[trans];
142  if(!fsm_hndl) {
143  SCCFATAL(instance_name) << "No valid FSM found for trans " << std::hex << trans;
144  throw std::runtime_error("No valid FSM found for trans");
145  }
146  react(event, fsm_hndl);
147  }
148 
149  void react(axi::fsm::protocol_time_point_e, axi::fsm::fsm_handle*);
150 
152 
154 
155  sc_core::sc_process_handle fsm_clk_queue_hndl;
156 
157  size_t transfer_width_in_bytes;
158 
159  const axi::fsm::protocol_time_point_e wr_start;
160 
161  const bool coherent;
162 
163  std::unordered_map<payload_type*, axi::fsm::fsm_handle*> active_fsm;
164 
165  std::deque<axi::fsm::fsm_handle*> idle_fsm;
166 
167  std::vector<std::unique_ptr<axi::fsm::fsm_handle>> allocated_fsm;
168 
169  std::string instance_name;
170 
171  sc_core::sc_event finish_evt;
172 };
173 } // namespace fsm
174 } // namespace axi
fifo with callbacks
Definition: fifo_w_cb.h:38
tlm::tlm_generic_payload * get() const noexcept
Return the stored pointer.
Definition: tlm_gp_shared.h:91
TLM2.0 components modeling AHB.
Definition: axi_initiator.h:30
base class of all AXITLM based adapters and interfaces.
Definition: base.h:43
void react(axi::fsm::protocol_time_point_e event, tlm::scc::tlm_gp_shared_ptr &trans)
triggers the FSM with event and given transaction
Definition: base.h:134
tlm::tlm_sync_enum nb_fw(payload_type &trans, phase_type const &phase, sc_core::sc_time &t)
triggers the FSM based on TLM phases in the forward path. Should be called from np_transport_fw of th...
Definition: base.cpp:190
void schedule(axi::fsm::protocol_time_point_e e, tlm::scc::tlm_gp_shared_ptr &gp, sc_core::sc_time delay, bool syncronize=false)
processes the fsm_sched_queue and propagates events to fsm_clk_queue. Should be registered as falling...
Definition: base.h:119
virtual void setup_callbacks(axi::fsm::fsm_handle *)=0
this function is called to add the callbacks to the fsm handle during creation. Needs to be implement...
base(size_t transfer_width, bool coherent=false, axi::fsm::protocol_time_point_e wr_start=axi::fsm::RequestPhaseBeg)
the constructor
Definition: base.cpp:43
void schedule(axi::fsm::protocol_time_point_e e, tlm::scc::tlm_gp_shared_ptr &gp, unsigned cycles)
processes the fsm_sched_queue and propagates events to fsm_clk_queue. Should be registered as falling...
Definition: base.h:107
void process_fsm_clk_queue()
processes the fsm_clk_queue and triggers the FSM accordingly. Should be registered as rising-edge clo...
Definition: base.cpp:107
tlm::tlm_sync_enum nb_bw(payload_type &trans, phase_type const &phase, sc_core::sc_time &t)
triggers the FSM based on TLM phases in the backward path. Should be called from np_transport_bw of t...
Definition: base.cpp:235
axi::fsm::fsm_handle * find_or_create(payload_type *gp=nullptr, bool ace=false)
retrieve the FSM handle based on the transaction passed. If non exist one will be created
Definition: base.cpp:65
virtual ~base()
the destructor
Definition: base.h:57
void process_fsm_event()
processes the fsm_event_queue and triggers FSM aligned
Definition: base.cpp:97
axi::axi_protocol_types::tlm_payload_type payload_type
aliases used in the class
Definition: base.h:45
virtual axi::fsm::fsm_handle * create_fsm_handle()=0
function to create a fsm_handle. Needs to be implemented by the derived class
priority event queue
Definition: peq.h:41
void notify(const TYPE &entry, const sc_core::sc_time &t)
non-blocking push.
Definition: peq.h:77