@@ -44,6 +44,16 @@ struct cxs_flit_payload : public tlm::nw::tlm_network_payload<CXS_CMD> {
4444 uint8_t end{0 };
4545 uint8_t end_error{0 };
4646 bool last{false };
47+
48+ cxs_flit_payload& operator =(const cxs_flit_payload& x) {
49+ tlm::nw::tlm_network_payload<CXS_CMD>::operator =(x);
50+ start_ptr = x.start_ptr ;
51+ end_ptr = x.end_ptr ;
52+ end = x.end ;
53+ end_error = x.end_error ;
54+ last = x.last ;
55+ return (*this );
56+ }
4757};
4858
4959struct cxs_flit_types {
@@ -64,6 +74,9 @@ struct cxs_packet_types {
6474 using tlm_phase_type = ::tlm::tlm_phase;
6575};
6676
77+ bool register_extensions ();
78+ extern bool registered;
79+
6780} // namespace cxs
6881
6982namespace tlm {
@@ -132,6 +145,7 @@ struct cxs_transmitter : public sc_core::sc_module,
132145
133146 cxs_transmitter (sc_core::sc_module_name const & nm)
134147 : sc_core::sc_module(nm) {
148+ register_extensions ();
135149 tsck (*this );
136150 isck (*this );
137151 SC_HAS_PROCESS (cxs_transmitter);
@@ -158,9 +172,11 @@ struct cxs_transmitter : public sc_core::sc_module,
158172 }
159173
160174 tlm::tlm_sync_enum nb_transport_fw (pkt_tx_type& trans, pkt_phase_type& phase, sc_core::sc_time& t) override {
161- SCCTRACE (SCMOD) << " Forwarding CXS packet with size " << trans.get_data ().size () << " bytes" ;
175+ SCCTRACEALL (SCMOD) << " Forwarding CXS packet with size " << trans.get_data ().size () << " bytes" ;
162176 if (phase == tlm::nw::REQUEST) {
163177 pkt_peq.notify (cxs_pkt_shared_ptr (&trans), t);
178+ if (clock_period.get_value () != sc_core::SC_ZERO_TIME)
179+ t += clock_period.get_value () - 1_ps;
164180 phase = tlm::nw::CONFIRM;
165181 return tlm::TLM_UPDATED;
166182 }
@@ -170,11 +186,13 @@ struct cxs_transmitter : public sc_core::sc_module,
170186 unsigned int transport_dbg (pkt_tx_type& trans) override { return 0 ; }
171187
172188 tlm::tlm_sync_enum nb_transport_bw (flit_tx_type& trans, flit_phase_type& phase, sc_core::sc_time& t) override {
173- SCCTRACE (SCMOD) << " Received non-blocking transaction in bw path with phase " << phase.get_name ();
174- if (phase == tlm::nw::REQUEST) {
189+ SCCTRACEALL (SCMOD) << " Received non-blocking transaction in bw path with phase " << phase.get_name ();
190+ if (phase == tlm::nw::REQUEST && trans. get_command () == cxs::CXS_CMD::CREDIT ) {
175191 received_credits += trans.get_data ()[0 ];
176- SCCDEBUG (SCMOD) << " Received " << static_cast <unsigned >(trans.get_data ()[0 ]) << " credit(s), " << received_credits.get ()
192+ SCCTRACE (SCMOD) << " Received " << static_cast <unsigned >(trans.get_data ()[0 ]) << " credit(s), " << received_credits.get ()
177193 << " credit(s) in total" ;
194+ if (clock_period.get_value () > sc_core::SC_ZERO_TIME)
195+ t += clock_period - 1_ps;
178196 phase = tlm::nw::CONFIRM;
179197 return tlm::TLM_UPDATED;
180198 }
@@ -228,6 +246,7 @@ struct cxs_transmitter : public sc_core::sc_module,
228246 received_credits -= burst_credits;
229247 }
230248 burst_credits--;
249+ SCCTRACE (SCMOD) << " Transmitted one flit, " << received_credits.get () << " credit(s) in total" ;
231250 }
232251
233252 void reset () {
@@ -273,6 +292,7 @@ struct cxs_receiver : public sc_core::sc_module,
273292
274293 cxs_receiver (sc_core::sc_module_name const & nm)
275294 : sc_core::sc_module(nm) {
295+ register_extensions ();
276296 tsck (*this );
277297 isck (*this );
278298 SC_HAS_PROCESS (cxs_receiver);
@@ -302,28 +322,28 @@ struct cxs_receiver : public sc_core::sc_module,
302322 }
303323
304324 tlm::tlm_sync_enum nb_transport_fw (flit_tx_type& trans, flit_phase_type& phase, sc_core::sc_time& t) override {
305- SCCTRACE (SCMOD) << " Received non-blocking transaction in fw path with phase " << phase.get_name ();
325+ SCCTRACEALL (SCMOD) << " Received non-blocking transaction in fw path with phase " << phase.get_name ();
306326 credit_returned.push_back (1 );
307327 if (trans.end ) {
308328 auto ext = trans.get_extension <cxs::orig_pkt_extension>();
309329 for (auto & orig_ptr : ext->orig_ext ) {
310330 auto ph = tlm::nw::REQUEST;
311331 auto d = sc_core::SC_ZERO_TIME;
312- SCCTRACE (SCMOD) << " Forwarding CXS pkt with size " << orig_ptr->get_data ().size () << " bytes" ;
332+ SCCDEBUG (SCMOD) << " Forwarding CXS pkt with size " << orig_ptr->get_data ().size () << " bytes" ;
313333 auto status = isck->nb_transport_fw (*orig_ptr, ph, t);
314334 sc_assert (status == tlm::TLM_UPDATED);
315335 }
316336 }
317- phase = tlm::nw::RESPONSE;
318337 if (clock_period.get_value () != sc_core::SC_ZERO_TIME)
319338 t += clock_period.get_value () - 1_ps;
339+ phase = tlm::nw::RESPONSE;
320340 return tlm::TLM_UPDATED;
321341 }
322342
323343 unsigned int transport_dbg (flit_tx_type& trans) override { return 0 ; }
324344
325345 tlm::tlm_sync_enum nb_transport_bw (pkt_tx_type& trans, flit_phase_type& phase, sc_core::sc_time& t) override {
326- SCCTRACE (SCMOD) << " Received non-blocking transaction in bw path with phase " << phase.get_name ();
346+ SCCTRACEALL (SCMOD) << " Received non-blocking transaction in bw path with phase " << phase.get_name ();
327347 if (phase == tlm::nw::CONFIRM)
328348 return tlm::TLM_ACCEPTED;
329349 throw std::runtime_error (" illegal request in backward path" );
@@ -367,8 +387,12 @@ struct cxs_channel : public sc_core::sc_module,
367387 using transaction_type = cxs_flit_types::tlm_payload_type;
368388 using phase_type = cxs_flit_types::tlm_phase_type;
369389
390+ sc_core::sc_in<bool > tx_clk_i{" tx_clk_i" };
391+
370392 cxs_flit_target_socket<PHITWIDTH> tsck{" tsck" };
371393
394+ sc_core::sc_in<bool > rx_clk_i{" rx_clk_i" };
395+
372396 cxs_flit_initiator_socket<PHITWIDTH> isck{" isck" };
373397
374398 cci::cci_param<sc_core::sc_time> channel_delay{" channel_delay" , sc_core::SC_ZERO_TIME, " delay of the CXS channel" };
@@ -394,7 +418,7 @@ struct cxs_channel : public sc_core::sc_module,
394418 }
395419
396420 tlm::tlm_sync_enum nb_transport_fw (transaction_type& trans, phase_type& phase, sc_core::sc_time& t) override {
397- SCCTRACE (SCMOD) << " Received non-blocking transaction in fw path with phase " << phase.get_name ();
421+ SCCTRACEALL (SCMOD) << " Received non-blocking transaction in fw path with phase " << phase.get_name ();
398422 if (phase == tlm::nw::REQUEST) {
399423 if (trans.get_data ().size () > PHITWIDTH / 8 ) {
400424 SCCERR (SCMOD) << " A CXS flit can be maximal " << PHITWIDTH / 8 << " bytes long, current data length is "
@@ -413,9 +437,9 @@ struct cxs_channel : public sc_core::sc_module,
413437 }
414438
415439 tlm::tlm_sync_enum nb_transport_bw (transaction_type& trans, phase_type& phase, sc_core::sc_time& t) override {
416- SCCTRACE (SCMOD) << " Received non-blocking transaction in bw path with phase " << phase.get_name ();
440+ SCCTRACEALL (SCMOD) << " Received non-blocking transaction in bw path with phase " << phase.get_name ();
417441 if (phase == tlm::nw::REQUEST) { // this is a credit
418- SCCDEBUG (SCMOD) << " Forwarding " << static_cast <unsigned >(trans.get_data ()[0 ]) << " credit(s)" ;
442+ SCCTRACE (SCMOD) << " Forwarding " << static_cast <unsigned >(trans.get_data ()[0 ]) << " credit(s)" ;
419443 bw_peq.notify (cxs_flit_shared_ptr (&trans), channel_delay.get_value ());
420444 if (tx_clock_period.get_value () > sc_core::SC_ZERO_TIME)
421445 t += tx_clock_period - 1_ps;
@@ -431,6 +455,15 @@ struct cxs_channel : public sc_core::sc_module,
431455 unsigned int transport_dbg (transaction_type& trans) override { return isck->transport_dbg (trans); }
432456
433457private:
458+ void start_of_simulation () override {
459+ if (tx_clock_period.get_value () == sc_core::SC_ZERO_TIME)
460+ if (auto clk_if = dynamic_cast <sc_core::sc_clock*>(tx_clk_i.get_interface ()))
461+ tx_clock_period.set_value (clk_if->period ());
462+ if (rx_clock_period.get_value () == sc_core::SC_ZERO_TIME)
463+ if (auto clk_if = dynamic_cast <sc_core::sc_clock*>(rx_clk_i.get_interface ()))
464+ rx_clock_period.set_value (clk_if->period ());
465+ }
466+
434467 void fw () {
435468 while (fw_peq.has_next ()) {
436469 auto ptr = fw_peq.get ();
@@ -467,5 +500,6 @@ struct cxs_channel : public sc_core::sc_module,
467500 scc::peq<cxs_flit_shared_ptr> bw_peq;
468501 sc_core::sc_event fw_resp, bw_resp;
469502};
503+
470504} // namespace cxs
471505#endif // _CXS_CXS_TLM_H_
0 commit comments