Skip to content

Commit 2fcc770

Browse files
committed
fixes credit to flit dependency in CXS tx & rx
1 parent 4429911 commit 2fcc770

File tree

1 file changed

+37
-40
lines changed

1 file changed

+37
-40
lines changed

src/interfaces/cxs/cxs_tlm.h

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <cci_configuration>
2121
#include <cstdint>
22-
#include <scc/fifo_w_cb.h>
22+
#include <scc/cci_param_restricted.h>
2323
#include <scc/peq.h>
2424
#include <scc/report.h>
2525
#include <scc/sc_variable.h>
@@ -141,7 +141,7 @@ struct cxs_transmitter : public sc_core::sc_module,
141141

142142
cci::cci_param<sc_core::sc_time> clock_period{"clock_period", sc_core::SC_ZERO_TIME, "clock period of the CXS transmitter"};
143143

144-
cci::cci_param<unsigned> burst_len{"burst_len", 1, "minimum amount of credits to start transmitting flits"};
144+
scc::cci_param_restricted<unsigned> burst_len{"burst_len", 1, scc::min_restriction(1u), "minimum amount of credits to start transmitting flits, shall be larger than 0"};
145145

146146
cxs_transmitter(sc_core::sc_module_name const& nm)
147147
: sc_core::sc_module(nm) {
@@ -151,8 +151,8 @@ struct cxs_transmitter : public sc_core::sc_module,
151151
SC_HAS_PROCESS(cxs_transmitter);
152152
SC_METHOD(clock);
153153
sensitive << clk_i.pos();
154-
SC_METHOD(reset);
155-
sensitive << rst_i;
154+
SC_METHOD(handle_received_credits);
155+
sensitive<<received_credits.event();
156156
dont_initialize();
157157
}
158158

@@ -188,8 +188,8 @@ struct cxs_transmitter : public sc_core::sc_module,
188188
tlm::tlm_sync_enum nb_transport_bw(flit_tx_type& trans, flit_phase_type& phase, sc_core::sc_time& t) override {
189189
SCCTRACEALL(SCMOD) << "Received non-blocking transaction in bw path with phase " << phase.get_name();
190190
if(phase == tlm::nw::REQUEST && trans.get_command() == cxs::CXS_CMD::CREDIT) {
191-
received_credits += trans.get_data()[0];
192-
SCCTRACE(SCMOD) << "Received " << static_cast<unsigned>(trans.get_data()[0]) << " credit(s), " << received_credits.get()
191+
received_credits.notify(trans.get_data()[0], sc_core::SC_ZERO_TIME);
192+
SCCTRACE(SCMOD) << "Received " << static_cast<unsigned>(trans.get_data()[0]) << " credit(s), " << available_credits.get()
193193
<< " credit(s) in total";
194194
if(clock_period.get_value() > sc_core::SC_ZERO_TIME)
195195
t += clock_period - 1_ps;
@@ -199,10 +199,22 @@ struct cxs_transmitter : public sc_core::sc_module,
199199
throw std::runtime_error("illegal request in backward path");
200200
}
201201

202+
void handle_received_credits(){
203+
while(received_credits.has_next()) {
204+
auto crd = received_credits.get();
205+
available_credits += crd;
206+
}
207+
}
208+
202209
void clock() {
203-
if((!pending_pkt && !pkt_peq.has_next()) || // there are no packets to send
204-
(received_credits < burst_len.get_value() && !burst_credits) ||
205-
rst_i.read()) // we do not have enough credits to send them as burst
210+
if(rst_i.read()) {
211+
available_credits = 0;
212+
pkt_peq.clear();
213+
pending_pkt = nullptr;
214+
return;
215+
}
216+
if((!pending_pkt && !pkt_peq.has_next()) || // there are no packets to send
217+
(!burst_credits && (available_credits < burst_len.get_value()))) // we do not have enough credits to burst-send flits
206218
return;
207219
auto* ptr = cxs_flit_mm::get().allocate();
208220
auto ext = ptr->get_extension<orig_pkt_extension>();
@@ -243,25 +255,18 @@ struct cxs_transmitter : public sc_core::sc_module,
243255
isck->nb_transport_fw(*ptr, phase, t);
244256
if(!burst_credits) {
245257
burst_credits = burst_len.get_value();
246-
received_credits -= burst_credits;
258+
available_credits -= burst_credits;
247259
}
248260
burst_credits--;
249-
SCCTRACE(SCMOD) << "Transmitted one flit, " << received_credits.get() << " credit(s) in total";
250-
}
251-
252-
void reset() {
253-
if(rst_i.read()) {
254-
received_credits = 0;
255-
pkt_peq.clear();
256-
pending_pkt = nullptr;
257-
}
261+
SCCTRACE(SCMOD) << "Transmitted one flit, " << available_credits.get() << " credit(s) in total";
258262
}
259263

260264
scc::peq<cxs_pkt_shared_ptr> pkt_peq;
261265
cxs_pkt_shared_ptr pending_pkt;
262266
unsigned transfered_pkt_bytes{0};
263267

264-
scc::sc_variable<unsigned> received_credits{"received_credits", 0};
268+
scc::peq<unsigned> received_credits;
269+
scc::sc_variable<unsigned> available_credits{"available_credits", 0};
265270
unsigned burst_credits{0};
266271
};
267272

@@ -288,7 +293,7 @@ struct cxs_receiver : public sc_core::sc_module,
288293

289294
cci::cci_param<sc_core::sc_time> clock_period{"clock_period", sc_core::SC_ZERO_TIME, "clock period of the CXS receiver"};
290295

291-
cci::cci_param<unsigned> max_credit{"max_credits", 1, "CXS_MAX_CREDIT property"};
296+
scc::cci_param_restricted<unsigned> max_credit{"max_credits", 1, scc::min_restriction(1u), "CXS_MAX_CREDIT property, shall be larger than 0"};
292297

293298
cxs_receiver(sc_core::sc_module_name const& nm)
294299
: sc_core::sc_module(nm) {
@@ -299,11 +304,8 @@ struct cxs_receiver : public sc_core::sc_module,
299304
SC_METHOD(clock);
300305
sensitive << clk_i.pos();
301306
dont_initialize();
302-
SC_METHOD(reset);
303-
sensitive << rst_i;
304-
dont_initialize();
305-
SC_METHOD(send_credit);
306-
sensitive << credit_returned.data_written_event();
307+
SC_METHOD(handle_received_credits);
308+
sensitive<<returned_credits.event();
307309
dont_initialize();
308310
}
309311

@@ -323,7 +325,7 @@ struct cxs_receiver : public sc_core::sc_module,
323325

324326
tlm::tlm_sync_enum nb_transport_fw(flit_tx_type& trans, flit_phase_type& phase, sc_core::sc_time& t) override {
325327
SCCTRACEALL(SCMOD) << "Received non-blocking transaction in fw path with phase " << phase.get_name();
326-
credit_returned.push_back(1);
328+
returned_credits.notify(1, sc_core::SC_ZERO_TIME);
327329
if(trans.end) {
328330
auto ext = trans.get_extension<cxs::orig_pkt_extension>();
329331
for(auto& orig_ptr : ext->orig_ext) {
@@ -349,22 +351,17 @@ struct cxs_receiver : public sc_core::sc_module,
349351
throw std::runtime_error("illegal request in backward path");
350352
}
351353

352-
void reset() {
353-
if(rst_i.read()) {
354-
credit_returned.push_back(max_credit.get_value());
354+
void handle_received_credits() {
355+
while(returned_credits.has_next()) {
356+
auto crd = returned_credits.get();
357+
available_credits += crd;
355358
}
356359
}
357360

358-
void send_credit() {
359-
auto amount = credit_returned.front();
360-
credit_returned.pop_front();
361-
available_credits += amount;
362-
}
363-
364361
void clock() {
365-
if(rst_i.read())
366-
return;
367-
if(available_credits > 0) {
362+
if(rst_i.read()) {
363+
available_credits = max_credit.get_value();
364+
} else if(available_credits > 0) {
368365
auto* ptr = cxs_flit_mm::get().allocate();
369366
ptr->set_command(cxs::CXS_CMD::CREDIT);
370367
ptr->set_data({1});
@@ -376,7 +373,7 @@ struct cxs_receiver : public sc_core::sc_module,
376373
}
377374
}
378375
scc::sc_variable<unsigned> available_credits{"available_credits", 0};
379-
scc::fifo_w_cb<unsigned char> credit_returned;
376+
scc::peq<unsigned> returned_credits;
380377
};
381378

382379
template <unsigned PHITWIDTH = 64>

0 commit comments

Comments
 (0)