17#ifndef SC_INCLUDE_DYNAMIC_PROCESSES
18#define SC_INCLUDE_DYNAMIC_PROCESSES
22#include "protocol_fsm.h"
23#include <scc/report.h>
24#include <scc/utilities.h>
26#include <tlm/scc/tlm_id.h>
27#include <tlm/scc/tlm_mm.h>
29using namespace sc_core;
34fsm_handle::fsm_handle()
39fsm_handle::~fsm_handle() {
44base::base(
size_t transfer_width,
bool coherent, protocol_time_point_e wr_start)
45: transfer_width_in_bytes(transfer_width / 8)
48 assert(wr_start == RequestPhaseBeg || wr_start == WValidE);
51 sc_core::sc_spawn_options opts;
52 opts.dont_initialize();
54 opts.set_sensitivity(&fsm_event_queue.event());
55 sc_core::sc_spawn(sc_bind(&
base::process_fsm_event,
this), sc_core::sc_gen_unique_name(
"fsm_event_method"), &opts);
56 fsm_clk_queue.set_avail_cb([
this]() {
57 if(fsm_clk_queue_hndl.valid())
58 fsm_clk_queue_hndl.enable();
60 fsm_clk_queue.set_empty_cb([
this]() {
61 if(fsm_clk_queue_hndl.valid())
62 fsm_clk_queue_hndl.disable();
67 auto it = active_fsm.find(gp);
68 if(!gp || it == active_fsm.end()) {
70 SCCTRACE(instance_name) <<
"creating fsm for trans " << *gp;
72 SCCTRACE(instance_name) <<
"creating fsm for new transaction";
74 if(idle_fsm.empty()) {
77 idle_fsm.push_back(fsm_hndl);
78 allocated_fsm.emplace_back(fsm_hndl);
80 auto fsm_hndl = idle_fsm.front();
89 active_fsm.insert(std::make_pair(fsm_hndl->trans.get(), fsm_hndl));
90 fsm_hndl->start = sc_time_stamp();
93 it->second->start = sc_time_stamp();
99 while(
auto e = fsm_event_queue.get_next()) {
100 auto entry = e.get();
101 if(std::get<2>(entry))
102 schedule(std::get<0>(entry), std::get<1>(entry), 0);
104 react(std::get<0>(entry), std::get<1>(entry));
109 if(!fsm_clk_queue_hndl.valid())
110 fsm_clk_queue_hndl = sc_process_handle(sc_get_current_process_handle());
111 if(fsm_clk_queue.avail())
112 while(fsm_clk_queue.avail()) {
113 auto entry = fsm_clk_queue.front();
114 if(std::get<2>(entry) == 0) {
115 SCCTRACE(instance_name) <<
"processing event " << evt2str(std::get<0>(entry)) <<
" of trans " << *std::get<1>(entry);
116 react(std::get<0>(entry), std::get<1>(entry));
118 std::get<2>(entry) -= 1;
119 fsm_clk_queue.push_back(entry);
121 fsm_clk_queue.pop_front();
125 fsm_clk_queue_hndl.disable();
129 SCCTRACE(instance_name) <<
"in react() base has coherent =" << coherent <<
" with event " << evt2str(event);
130 fsm_hndl->state = event;
133 fsm_hndl->
fsm->process_event(
WReq());
136 case RequestPhaseBeg:
164 SCCTRACE(instance_name) <<
"in EndResp of base() with coherent =" << coherent;
165 if(!coherent || fsm_hndl->
is_snoop) {
166 SCCTRACE(instance_name) <<
"freeing fsm for trans " << *fsm_hndl->
trans;
168 active_fsm.erase(fsm_hndl->
trans.
get());
169 fsm_hndl->
trans =
nullptr;
170 idle_fsm.push_back(fsm_hndl);
173 fsm_hndl->
fsm->process_event(EndRespNoAck());
177 SCCTRACE(instance_name) <<
"freeing fsm for trans " << *fsm_hndl->
trans;
178 fsm_hndl->
fsm->process_event(AckRecv());
179 active_fsm.erase(fsm_hndl->
trans.
get());
180 fsm_hndl->
trans =
nullptr;
181 idle_fsm.push_back(fsm_hndl);
185 SCCFATAL(instance_name) <<
"No valid protocol time point";
190 SCCTRACE(instance_name) <<
"base::nb_fw " << phase <<
" with delay = " << t <<
" of trans " << trans;
191 if(phase == BEGIN_PARTIAL_REQ || phase == BEGIN_REQ) {
193 if(!trans.is_read()) {
194 protocol_time_point_e evt = axi::fsm::RequestPhaseBeg;
195 if(fsm_hndl->
beat_count == 0 && wr_start != RequestPhaseBeg)
198 evt = phase == BEGIN_PARTIAL_REQ ? BegPartReqE : BegReqE;
199 if(t == SC_ZERO_TIME) {
205 if(t == SC_ZERO_TIME) {
206 react(BegReqE, &trans);
210 }
else if(phase == END_PARTIAL_RESP || phase == END_RESP) {
211 if(t == SC_ZERO_TIME) {
212 react(phase == END_RESP ? EndRespE : EndPartRespE, &trans);
214 schedule(phase == END_RESP ? EndRespE : EndPartRespE, &trans, t);
215 }
else if(phase == END_REQ) {
216 if(t == SC_ZERO_TIME) {
217 react(EndReqE, &trans);
220 }
else if(phase == BEGIN_PARTIAL_RESP || phase == BEGIN_RESP) {
221 if(t == SC_ZERO_TIME) {
222 react(phase == BEGIN_RESP ? BegRespE : BegPartRespE, &trans);
224 schedule(phase == BEGIN_RESP ? BegRespE : BegPartRespE, &trans, t);
225 }
else if(phase == axi::ACK) {
226 if(t == SC_ZERO_TIME) {
235 SCCTRACE(instance_name) <<
"base::nb_bw " << phase <<
" of trans " << trans;
236 if(phase == END_PARTIAL_REQ || phase == END_REQ) {
237 if(t == SC_ZERO_TIME) {
238 react(phase == END_REQ ? EndReqE : EndPartReqE, &trans);
240 schedule(phase == END_REQ ? EndReqE : EndPartReqE, &trans, t);
241 }
else if(phase == BEGIN_PARTIAL_RESP || phase == BEGIN_RESP) {
242 if(t == SC_ZERO_TIME) {
243 react(phase == BEGIN_RESP ? BegRespE : BegPartRespE, &trans);
245 schedule(phase == BEGIN_RESP ? BegRespE : BegPartRespE, &trans, t);
246 }
else if(phase == BEGIN_REQ) {
249 if(t == SC_ZERO_TIME) {
250 react(BegReqE, &trans);
253 }
else if(phase == END_PARTIAL_RESP || phase == END_RESP) {
254 if(t == SC_ZERO_TIME) {
255 react(phase == END_RESP ? EndRespE : EndPartRespE, &trans);
257 schedule(phase == END_RESP ? EndRespE : EndPartRespE, &trans, t);
payload_type * allocate()
get a plain tlm_payload_type without extensions
T * get() const noexcept
Return the stored pointer.
TLM2.0 components modeling AHB.
bool is_burst(const axi::axi_protocol_types::tlm_payload_type &trans)
void react(axi::fsm::protocol_time_point_e event, tlm::scc::tlm_gp_shared_ptr &trans)
triggers the FSM with event and given transaction
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...
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
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...
void process_fsm_clk_queue()
processes the fsm_clk_queue and triggers the FSM accordingly. Should be registered as rising-edge clo...
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...
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
void process_fsm_event()
processes the fsm_event_queue and triggers FSM aligned
axi::axi_protocol_types::tlm_payload_type payload_type
aliases used in the class
tlm::scc::tlm_gp_shared_ptr trans
pointer to the associated AXITLM payload
size_t beat_count
beat count of this transaction
AxiProtocolFsm *const fsm
pointer to the FSM
bool is_snoop
indicator if this is a snoop access
static tlm_mm & get()
accessor function of the singleton