scc 2026.07
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
28namespace axi {
29namespace fsm {
31struct fsm_handle;
32
33inline std::ostream& operator<<(std::ostream& os, const std::tuple<axi::fsm::fsm_handle*, axi::fsm::protocol_time_point_e>&) { return os; }
34
35using axi::operator<<;
36
40struct base {
42 using payload_type = axi::axi_protocol_types::tlm_payload_type;
43 using phase_type = axi::axi_protocol_types::tlm_phase_type;
49 base(size_t transfer_width, bool coherent = false, axi::fsm::protocol_time_point_e wr_start = axi::fsm::RequestPhaseBeg);
53 virtual ~base() {}
62 tlm::tlm_sync_enum nb_fw(payload_type& trans, phase_type const& phase, sc_core::sc_time& t);
71 tlm::tlm_sync_enum nb_bw(payload_type& trans, phase_type const& phase, sc_core::sc_time& t);
78 axi::fsm::fsm_handle* find_or_create(payload_type* gp = nullptr, bool ace = false);
93 void process_fsm_event();
103 inline void schedule(axi::fsm::protocol_time_point_e e, tlm::scc::tlm_gp_shared_ptr& gp, unsigned cycles) {
104 schedule(e, gp.get(), cycles);
105 }
106 void schedule(axi::fsm::protocol_time_point_e e, payload_type* gp, unsigned cycles) {
107 SCCTRACE(instance_name) << "pushing sync event " << evt2str(e) << " for transaction " << *gp << " (sync:" << cycles << ")";
108 fsm_clk_queue.push_back(std::make_tuple(e, gp, cycles));
109 }
114 inline void schedule(axi::fsm::protocol_time_point_e e, tlm::scc::tlm_gp_shared_ptr& gp, sc_core::sc_time delay,
115 bool syncronize = false) {
116 schedule(e, gp.get(), delay, syncronize);
117 }
118 void schedule(axi::fsm::protocol_time_point_e e, payload_type* gp, sc_core::sc_time delay, bool syncronize = false) {
119 SCCTRACE(instance_name) << "pushing event " << evt2str(e) << " for transaction " << *gp << " (delay " << delay << ")";
120 fsm_event_queue.notify(std::make_tuple(e, gp, syncronize), delay);
121 }
127 inline void react(axi::fsm::protocol_time_point_e event, tlm::scc::tlm_gp_shared_ptr& trans) { react(event, trans.get()); }
128
129 inline void react(axi::fsm::protocol_time_point_e event, payload_type* trans) {
130 SCCTRACE(instance_name) << "processing event " << evt2str(static_cast<unsigned>(event)) << " for trans " << *trans;
131 auto fsm_hndl = active_fsm[trans];
132 if(!fsm_hndl) {
133 SCCFATAL(instance_name) << "No valid FSM found for trans " << std::hex << trans;
134 throw std::runtime_error("No valid FSM found for trans");
135 }
136 react(event, fsm_hndl);
137 }
138
139 void react(axi::fsm::protocol_time_point_e, axi::fsm::fsm_handle*);
140
142
144
145 sc_core::sc_process_handle fsm_clk_queue_hndl;
146
147 size_t transfer_width_in_bytes;
148
149 const axi::fsm::protocol_time_point_e wr_start;
150
151 const bool coherent;
152
153 std::unordered_map<payload_type*, axi::fsm::fsm_handle*> active_fsm;
154
155 std::deque<axi::fsm::fsm_handle*> idle_fsm;
156
157 std::vector<std::unique_ptr<axi::fsm::fsm_handle>> allocated_fsm;
158
159 std::string instance_name;
160
161 sc_core::sc_event finish_evt;
162};
163} // namespace fsm
164} // namespace axi
fifo with callbacks
Definition fifo_w_cb.h:38
T * get() const noexcept
Return the stored pointer.
TLM2.0 components modeling AHB.
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:127
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:189
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:114
virtual axi::fsm::fsm_handle * create_fsm_handle()=0
function to create a fsm_handle. Needs to be implemented by the derived class
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:44
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:103
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:108
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:234
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:66
virtual ~base()
the destructor
Definition base.h:53
void process_fsm_event()
processes the fsm_event_queue and triggers FSM aligned
Definition base.cpp:98
axi::axi_protocol_types::tlm_payload_type payload_type
aliases used in the class
Definition base.h:42
priority event queue
Definition peq.h:42
void notify(TYPE const &entry, const sc_core::sc_time &t)
non-blocking push.
Definition peq.h:78