20 #ifndef NVHLS_CONNECTIONS_NETWORK_H_
21 #define NVHLS_CONNECTIONS_NETWORK_H_
24 #include <nvhls_connections.h>
25 #include <nvhls_packet.h>
27 namespace Connections {
33 template <
typename Message,
unsigned int DestWidthPerHop,
unsigned int MaxHops,
34 unsigned int PacketIdWidth>
39 static const int kDebugLevel = 3;
40 typedef Wrapped<Message> WMessage;
41 static const unsigned int width = WMessage::width;
42 typedef sc_lv<WMessage::width> MsgBits;
53 : sc_module(sc_module_name(sc_gen_unique_name(
"in_network"))),
59 InNetwork(sc_module_name name) : sc_module(name), clk(
"clk"), rst(
"rst") {
65 #ifdef CONNECTIONS_SIM_ONLY
71 sensitive << enq._DATNAME_ << rst;
74 sensitive << enq._VLDNAME_;
77 sensitive << deq._RDYNAME_;
82 deq._DATNAME_.write(0);
83 }
else if (enq._VLDNAME_.read()) {
84 sc_lv<Wrapped<Packet_t>::width> pbits = enq._DATNAME_.read();
85 Marshaller<Wrapped<Packet_t>::width> pmarshaller(pbits);
87 packet.Marshall(pmarshaller);
88 MsgBits mbits(packet.data);
89 deq._DATNAME_.write(mbits);
93 void AssignVal() { deq._VLDNAME_.write(enq._VLDNAME_.read()); }
94 void AssignRdy() { enq._RDYNAME_.write(deq._RDYNAME_.read()); }
100 unsigned int pwidth = (Packet_t::width / 4);
102 if (enq._VLDNAME_.read() && enq._RDYNAME_.read()) {
103 CDCOUT(std::hex << std::setw(pwidth) << enq._DATNAME_.read(), kDebugLevel);
105 CDCOUT(std::setw(pwidth + 1) <<
" ", kDebugLevel);
107 CDCOUT(
" | ", kDebugLevel);
110 unsigned int mwidth = (Message().length() / 4);
111 if (deq._VLDNAME_.read() && deq._RDYNAME_.read()) {
112 CDCOUT(std::hex << std::setw(mwidth) << deq._DATNAME_.read(), kDebugLevel);
114 CDCOUT(std::setw(mwidth + 1) <<
" ", kDebugLevel);
116 CDCOUT(
" | ", kDebugLevel);
126 template <
typename Message,
unsigned int DestWidthPerHop,
unsigned int MaxHops,
127 unsigned int PacketIdWidth>
132 static const int kDebugLevel = 3;
133 typedef Wrapped<Message> WMessage;
134 static const unsigned int width = WMessage::width;
135 typedef sc_lv<WMessage::width> MsgBits;
144 In<sc_lv<DestWidthPerHop * MaxHops> > route;
145 In<sc_lv<PacketIdWidth> > id;
148 sc_signal<sc_lv<DestWidthPerHop * MaxHops> > route_state;
149 sc_signal<sc_lv<PacketIdWidth> > id_state;
152 : sc_module(sc_module_name(sc_gen_unique_name(
"out_network"))),
158 OutNetwork(sc_module_name name) : sc_module(name), clk(
"clk"), rst(
"rst") {
164 #ifdef CONNECTIONS_SIM_ONLY
167 route.disable_spawn();
171 SC_METHOD(AssignMsg);
172 sensitive << enq._DATNAME_ << id_state << route_state << rst;
174 SC_METHOD(AssignVal);
175 sensitive << enq._VLDNAME_;
177 SC_METHOD(AssignRdy);
178 sensitive << deq._RDYNAME_;
180 SC_METHOD(TieToHigh);
181 sensitive << clk.pos();
184 sensitive << clk.pos();
190 deq._DATNAME_.write(0);
191 }
else if (enq._VLDNAME_.read()) {
193 vector_to_type(id_state.read(),
false, &packet.packet_id);
194 vector_to_type(route_state.read(),
false, &packet.dest);
195 vector_to_type(enq._DATNAME_.read(),
false, &packet.data);
196 Marshaller<Wrapped<Packet_t>::width> pmarshaller;
197 packet.Marshall(pmarshaller);
198 deq._DATNAME_.write(pmarshaller.GetResult());
202 void AssignVal() { deq._VLDNAME_.write(enq._VLDNAME_.read()); }
203 void AssignRdy() { enq._RDYNAME_.write(deq._RDYNAME_.read()); }
206 route._RDYNAME_.write(1);
207 id._RDYNAME_.write(1);
212 route_state.write(0);
215 if (route._VLDNAME_.read()) {
216 route_state.write(route._DATNAME_.read());
219 if (
id._VLDNAME_.read()) {
220 id_state.write(
id._DATNAME_.read());
226 #ifndef __SYNTHESIS__
230 unsigned int mwidth = (Message().length() / 4);
232 if (enq._VLDNAME_.read() && enq._RDYNAME_.read()) {
233 CDCOUT(std::hex << std::setw(mwidth) << enq._DATNAME_.read(), kDebugLevel);
235 CDCOUT(std::setw(mwidth + 1) <<
" ", kDebugLevel);
237 CDCOUT(
" | ", kDebugLevel);
240 unsigned int pwidth = (Packet_t::width / 4);
241 if (deq._VLDNAME_.read() && deq._RDYNAME_.read()) {
242 CDCOUT(std::hex << std::setw(pwidth) << deq._DATNAME_.read(), kDebugLevel);
244 CDCOUT(std::setw(pwidth + 1) <<
" ", kDebugLevel);
246 CDCOUT(
" | ", kDebugLevel);
258 template <
typename Message,
unsigned int DestWidthPerHop,
unsigned int MaxHops,
259 unsigned int PacketIdWidth,
unsigned int CreditWidth>
264 static const int kDebugLevel = 3;
265 typedef Wrapped<Message> WMessage;
266 static const unsigned int width = WMessage::width;
267 typedef sc_lv<WMessage::width> MsgBits;
272 typedef sc_lv<CreditWidth> Credit_t;
279 Out<CreditPacket_t> credit;
280 In<Credit_t> init_credits;
281 In<sc_lv<DestWidthPerHop * MaxHops> > credit_route;
282 In<sc_lv<PacketIdWidth> > credit_id;
288 Combinational<Credit_t> credit_enq;
291 sc_signal<Credit_t> credits;
292 sc_signal<Credit_t> credits_next;
295 : sc_module(sc_module_name(sc_gen_unique_name(
"in_nw_credit"))),
298 credit_out(
"credit_out") {
303 : sc_module(name), clk(
"clk"), rst(
"rst"), credit_out(
"credit_out") {
309 #ifdef CONNECTIONS_SIM_ONLY
312 credit.disable_spawn();
313 init_credits.disable_spawn();
314 credit_route.disable_spawn();
315 credit_id.disable_spawn();
320 credit_out.route(credit_route);
321 credit_out.id(credit_id);
322 credit_out.enq(credit_enq);
323 credit_out.deq(credit);
325 SC_METHOD(AssignMsg);
326 sensitive << enq._DATNAME_ << rst;
328 SC_METHOD(AssignVal);
329 sensitive << enq._VLDNAME_;
331 SC_METHOD(AssignRdy);
332 sensitive << deq._RDYNAME_;
334 SC_METHOD(TieToHigh);
335 sensitive << clk.pos();
337 SC_METHOD(AssignNextCredits);
338 sensitive << deq._VLDNAME_ << deq._RDYNAME_ << credit_enq._VLDNAME_ << credit_enq._RDYNAME_
341 SC_METHOD(AssignCreditMsg);
342 sensitive << deq._VLDNAME_ << deq._RDYNAME_ << credit_enq._VLDNAME_ << credit_enq._RDYNAME_
345 SC_METHOD(AssignCreditVal);
346 sensitive << deq._VLDNAME_ << deq._RDYNAME_ << credits;
348 SC_THREAD(UpdateCredit);
349 sensitive << clk.pos();
355 deq._DATNAME_.write(0);
356 }
else if (enq._VLDNAME_.read()) {
357 sc_lv<Wrapped<Packet_t>::width> pbits = enq._DATNAME_.read();
358 Marshaller<Wrapped<Packet_t>::width> pmarshaller(pbits);
360 packet.Marshall(pmarshaller);
361 MsgBits mbits(packet.data);
362 deq._DATNAME_.write(mbits);
366 void AssignVal() { deq._VLDNAME_.write(enq._VLDNAME_.read()); }
367 void AssignRdy() { enq._RDYNAME_.write(deq._RDYNAME_.read()); }
369 void TieToHigh() { init_credits._RDYNAME_.write(1); }
371 void AssignNextCredits() {
372 bool do_deq = deq._VLDNAME_.read() && deq._RDYNAME_.read();
373 bool do_credit = credit_enq._VLDNAME_.read() && credit_enq._RDYNAME_.read();
374 if (do_credit && !do_deq && (credits.read() != 0)) {
375 credits_next.write(0);
376 }
else if (do_credit && do_deq) {
377 credits_next.write(0);
378 }
else if (!do_credit && do_deq) {
379 credits_next.write(credits.read().to_uint() + 1);
381 credits_next.write(credits.read());
385 void AssignCreditMsg() {
386 bool do_deq = deq._VLDNAME_.read() && deq._RDYNAME_.read();
387 bool do_credit = credit_enq._VLDNAME_.read() && credit_enq._RDYNAME_.read();
388 if (do_deq && do_credit && (credits.read() == 0)) {
389 credit_enq._DATNAME_.write(1);
390 }
else if (do_deq && do_credit && (credits.read() != 0)) {
391 credit_enq._DATNAME_.write(credits.read().to_uint() + 1);
392 }
else if (!do_deq && do_credit && (credits.read() != 0)) {
393 credit_enq._DATNAME_.write(credits.read());
395 credit_enq._DATNAME_.write(0);
399 void AssignCreditVal() {
400 bool do_deq = deq._VLDNAME_.read() && deq._RDYNAME_.read();
401 if (do_deq || (credits.read() != 0)) {
402 credit_enq._VLDNAME_.write(1);
404 credit_enq._VLDNAME_.write(0);
408 void UpdateCredit() {
412 if (init_credits._VLDNAME_.read()) {
413 credits.write(init_credits._DATNAME_.read());
415 credits.write(credits_next.read());
421 #ifndef __SYNTHESIS__
425 unsigned int pwidth = (Packet_t::width / 4);
427 if (enq._VLDNAME_.read() && enq._RDYNAME_.read()) {
428 CDCOUT(std::hex << std::setw(pwidth) << enq._DATNAME_.read(), kDebugLevel);
430 CDCOUT(std::setw(pwidth + 1) <<
" ", kDebugLevel);
432 CDCOUT(
" | ", kDebugLevel);
435 unsigned int mwidth = (Message().length() / 4);
436 if (deq._VLDNAME_.read() && deq._RDYNAME_.read()) {
437 CDCOUT(std::hex << std::setw(mwidth) << deq._DATNAME_.read(), kDebugLevel);
439 CDCOUT(std::setw(mwidth + 1) <<
" ", kDebugLevel);
441 CDCOUT(
" | ", kDebugLevel);
444 CDCOUT(std::hex <<
" ( " << credits.read() <<
" ) ", kDebugLevel);
447 unsigned int cwidth = (CreditPacket_t::width / 4);
448 if (credit._VLDNAME_.read() && credit._RDYNAME_.read()) {
449 CDCOUT(std::hex << std::setw(cwidth) << credit._DATNAME_.read(), kDebugLevel);
451 CDCOUT(std::setw(cwidth + 1) <<
" ", kDebugLevel);
453 CDCOUT(
" | ", kDebugLevel);
465 template <
typename Message,
unsigned int DestWidthPerHop,
unsigned int MaxHops,
466 unsigned int PacketIdWidth,
unsigned int CreditWidth>
471 static const int kDebugLevel = 3;
472 typedef Wrapped<Message> WMessage;
473 static const unsigned int width = WMessage::width;
474 typedef sc_lv<WMessage::width> MsgBits;
479 typedef sc_lv<CreditWidth> Credit_t;
486 In<CreditPacket_t> credit;
487 In<sc_lv<DestWidthPerHop * MaxHops> > route;
488 In<sc_lv<PacketIdWidth> > id;
494 Combinational<Credit_t> credit_deq;
497 sc_signal<sc_lv<DestWidthPerHop * MaxHops> > route_state;
498 sc_signal<sc_lv<PacketIdWidth> > id_state;
499 sc_signal<Credit_t> credits;
500 sc_signal<Credit_t> credits_next;
503 : sc_module(sc_module_name(sc_gen_unique_name(
"out_nw_credit"))),
506 credit_in(
"credit_in") {
511 : sc_module(name), clk(
"clk"), rst(
"rst"), credit_in(
"credit_in") {
517 #ifdef CONNECTIONS_SIM_ONLY
520 credit.disable_spawn();
521 route.disable_spawn();
527 credit_in.enq(credit);
528 credit_in.deq(credit_deq);
530 SC_METHOD(AssignMsg);
531 sensitive << enq._DATNAME_ << id_state << route_state << rst;
533 SC_METHOD(AssignVal);
534 sensitive << enq._VLDNAME_ << credits << credit_deq._VLDNAME_ << credit_deq._RDYNAME_;
536 SC_METHOD(AssignRdy);
537 sensitive << deq._RDYNAME_;
539 SC_METHOD(TieToHigh);
540 sensitive << clk.pos();
542 SC_METHOD(AssignNextCredits);
543 sensitive << deq._VLDNAME_ << deq._RDYNAME_ << credit_deq._VLDNAME_ << credit_deq._RDYNAME_
546 SC_METHOD(AssignCreditRdy);
547 sensitive << deq._VLDNAME_ << deq._RDYNAME_ << credits;
549 SC_THREAD(UpdateCredit);
550 sensitive << clk.pos();
554 sensitive << clk.pos();
560 deq._DATNAME_.write(0);
561 }
else if (enq._VLDNAME_.read()) {
563 vector_to_type(id_state.read(),
false, &packet.packet_id);
564 vector_to_type(route_state.read(),
false, &packet.dest);
565 vector_to_type(enq._DATNAME_.read(),
false, &packet.data);
566 Marshaller<Wrapped<Packet_t>::width> pmarshaller;
567 packet.Marshall(pmarshaller);
568 deq._DATNAME_.write(pmarshaller.GetResult());
573 bool do_credit = credit_deq._VLDNAME_.read() && credit_deq._RDYNAME_.read();
574 if (enq._VLDNAME_.read() && (credits.read() != 0)) {
575 deq._VLDNAME_.write(1);
576 }
else if (enq._VLDNAME_.read() && (credits.read() == 0) && do_credit) {
577 deq._VLDNAME_.write(1);
579 deq._VLDNAME_.write(0);
583 void AssignRdy() { enq._RDYNAME_.write(deq._RDYNAME_.read()); }
586 route._RDYNAME_.write(1);
587 id._RDYNAME_.write(1);
590 void AssignNextCredits() {
591 bool do_deq = deq._VLDNAME_.read() && deq._RDYNAME_.read();
592 bool do_credit = credit_deq._VLDNAME_.read() && credit_deq._RDYNAME_.read();
593 if (!do_credit && do_deq) {
594 credits_next.write(credits.read().to_uint() - 1);
595 }
else if (do_credit && !do_deq) {
596 credits_next.write(credits.read().to_uint() +
597 credit._DATNAME_.read().to_uint());
598 }
else if (do_credit && do_deq) {
599 credits_next.write(credits.read().to_uint() +
600 credit._DATNAME_.read().to_uint() - 1);
602 credits_next.write(credits.read());
606 void AssignCreditRdy() { credit_deq._RDYNAME_.write(1); }
608 void UpdateCredit() {
612 credits.write(credits_next.read());
619 route_state.write(0);
622 if (route._VLDNAME_.read()) {
623 route_state.write(route._DATNAME_.read());
626 if (
id._VLDNAME_.read()) {
627 id_state.write(
id._DATNAME_.read());
633 #ifndef __SYNTHESIS__
637 unsigned int mwidth = (Message().length() / 4);
639 if (enq._VLDNAME_.read() && enq._RDYNAME_.read()) {
640 CDCOUT(std::hex << std::setw(mwidth) << enq._DATNAME_.read(), kDebugLevel);
642 CDCOUT(std::setw(mwidth + 1) <<
" ", kDebugLevel);
644 CDCOUT(
" | ", kDebugLevel);
647 unsigned int pwidth = (Packet_t::width / 4);
648 if (deq._VLDNAME_.read() && deq._RDYNAME_.read()) {
649 CDCOUT(std::hex << std::setw(pwidth) << deq._DATNAME_.read(), kDebugLevel);
651 CDCOUT(std::setw(pwidth + 1) <<
" ", kDebugLevel);
653 CDCOUT(
" | ", kDebugLevel);
656 CDCOUT(std::hex <<
" ( " << credits.read() <<
" ) ", kDebugLevel);
659 unsigned int cwidth = (CreditPacket_t::width / 4);
660 if (credit._VLDNAME_.read() && credit._RDYNAME_.read()) {
661 CDCOUT(std::hex << std::setw(cwidth) << credit._DATNAME_.read(), kDebugLevel);
663 CDCOUT(std::setw(cwidth + 1) <<
" ", kDebugLevel);
665 CDCOUT(
" | ", kDebugLevel);
Parameterized implementation of a network packet.
#define NVHLS_NEG_RESET_SIGNAL_IS(port)
ENABLE_SYNC_RESET define: Select synchronous or asynchronous reset.