21 #ifndef NVHLS_SERDES_H
22 #define NVHLS_SERDES_H
26 #include <nvhls_int.h>
27 #include <nvhls_types.h>
28 #include <nvhls_packet.h>
29 #include <nvhls_connections.h>
30 #include <hls_globals.h>
70 template <
typename packet_t,
typename flit_t, RouterType Rtype = StoreForward>
76 Connections::In<packet_t> in_packet;
77 Connections::Out<flit_t> out_flit;
78 static const int header_data_width = flit_t::data_width - packet_t::dest_width;
79 static const int num_flits = (((packet_t::data_width-header_data_width) % flit_t::data_width) == 0) ? ((packet_t::data_width-header_data_width) / flit_t::data_width) : ((packet_t::data_width-header_data_width) / flit_t::data_width+1) ;
88 in_packet(
"in_packet"),
89 out_flit(
"out_flit") {
91 sensitive << clk.pos();
96 template <
typename packet_t,
typename flit_t, RouterType Rtype>
105 NVUINTW(packet_t::data_width) data;
107 if (in_packet.PopNB(packet_reg)) {
109 flit_reg.dest = packet_reg.dest;
110 flit_reg.packet_id = packet_reg.packet_id;
111 data = packet_reg.data;
112 for (
int i = 0; i < num_flits; i++) {
113 if (num_flits == 1) {
114 flit_reg.flit_id.set(FlitId2bit::SNGL);
116 flit_reg.flit_id.set(FlitId2bit::HEAD);
117 }
else if (i == num_flits - 1) {
118 flit_reg.flit_id.set(FlitId2bit::TAIL);
120 flit_reg.flit_id.set(FlitId2bit::BODY);
123 nvhls::get_slc<flit_t::data_width>(data, i * flit_t::data_width);
124 out_flit.Push(flit_reg);
162 template <
int PacketDataWidth,
int DestWidthPerHop,
int MaxHops,
163 int PacketIdWidth,
int FlitDataWidth,
class FlitId>
165 Packet<PacketDataWidth, DestWidthPerHop, MaxHops, PacketIdWidth>,
166 Flit<FlitDataWidth, 0, 0, PacketIdWidth, FlitId, WormHole>, WormHole>
176 static const int header_data_width = flit_t::data_width - packet_t::dest_width;
178 static const int num_flits = (((packet_t::data_width-header_data_width) % flit_t::data_width) == 0) ? ((packet_t::data_width-header_data_width) / flit_t::data_width) : ((packet_t::data_width-header_data_width) / flit_t::data_width+1) ;
180 Connections::In<packet_t> in_packet;
181 Connections::Out<flit_t> out_flit;
187 NVUINTW(log_num_flits) num = 0;
193 packet_reg = in_packet.Pop();
194 flit_reg.packet_id = packet_reg.packet_id;
195 flit_reg.data = packet_reg.dest;
196 NVUINTW(header_data_width) header_data = nvhls::get_slc<header_data_width>(packet_reg.data, 0);
197 flit_reg.data =
nvhls::set_slc(flit_reg.data, header_data, packet_t::dest_width);
198 flit_reg.flit_id.set(
202 flit_reg.packet_id = packet_reg.packet_id;
203 if (num == num_flits) {
204 flit_reg.flit_id.set(FlitId2bit::TAIL);
205 int num_minus_one = num - 1;
207 packet_reg.data, packet_t::data_width - 1, num_minus_one * flit_t::data_width + header_data_width);
210 flit_reg.flit_id.set(FlitId2bit::BODY);
211 int num_minus_one = num - 1;
212 flit_reg.data = nvhls::get_slc<flit_t::data_width>(
213 packet_reg.data, num_minus_one * flit_t::data_width + header_data_width);
217 out_flit.Push(flit_reg);
227 in_packet(
"in_packet"),
228 out_flit(
"out_flit") {
230 sensitive << clk.pos();
246 template <
int PacketDataWidth,
int DestWidthPerHop,
int MaxHops,
247 int FlitDataWidth,
class FlitId>
249 Flit<FlitDataWidth, 0, 0, 0, FlitId, WormHole>, WormHole>
259 static const int num_flits = ((packet_t::data_width % flit_t::data_width) == 0) ? (packet_t::data_width / flit_t::data_width) : (packet_t::data_width / flit_t::data_width+1) ;
260 Connections::In<packet_t> in_packet;
261 Connections::Out<flit_t> out_flit;
272 if (in_packet.PopNB(packet_reg)) {
273 flit_reg.data = packet_reg.dest;
274 flit_reg.flit_id.set(
276 out_flit.Push(flit_reg);
277 #pragma hls_unroll yes
278 for (
int i = 0; i < num_flits; i++) {
281 if (i == num_flits - 1) {
282 flit_reg.flit_id.set(FlitId2bit::TAIL);
284 flit_reg.flit_id.set(FlitId2bit::BODY);
286 flit_reg.data = nvhls::get_slc<flit_t::data_width>(
287 packet_reg.data, i * flit_t::data_width);
288 out_flit.Push(flit_reg);
300 in_packet(
"in_packet"),
301 out_flit(
"out_flit") {
303 sensitive << clk.pos();
347 template <
typename packet_t,
typename flit_t,
int buffersize,
348 RouterType Rtype = StoreForward>
354 Connections::Out<packet_t> out_packet;
355 Connections::In<flit_t> in_flit;
359 packet_t buffer[buffersize];
361 typedef NVUINTW(logbufsize) BuffIdx;
366 static const int num_flits = packet_t::data_width / flit_t::data_width;
367 static const int log_num_flits =
369 NVUINTW(log_num_flits)
370 num_flits_received[buffersize];
379 out_packet(
"out_packet"),
382 sensitive << clk.pos();
387 template <
typename packet_t,
typename flit_t,
int buffersize, RouterType Rtype>
392 #pragma hls_unroll yes
393 for (
int i = 0; i < buffersize; i++) {
394 if (!fifo.isFull()) {
404 if (in_flit.PopNB(flit_reg)) {
407 if (flit_reg.flit_id.isHeader()) {
409 packet_pos = fifo.pop();
410 buffer[packet_pos].packet_id = flit_reg.packet_id;
411 buffer[packet_pos].dest = flit_reg.dest;
412 buffer[packet_pos].data =
414 num_flits_received[packet_pos] = 1;
418 #pragma hls_unroll yes
419 for (
int i = 0; i < buffersize; i++) {
420 BuffIdx head = fifo.get_head();
421 BuffIdx tail = fifo.get_tail();
423 if((((tail < head) && ((i >= tail) && (i < head))) ||
424 ((head < tail) && ((i >= tail) || (i < head))) || fifo.isFull()) && (!fifo.isEmpty())) {
425 if (buffer[i].packet_id == flit_reg.packet_id) {
428 num_flits_received[i] * flit_t::data_width);
429 num_flits_received[i]++;
437 if (flit_reg.flit_id.isTail()) {
438 out_packet.Push(buffer[packet_pos]);
441 fifo.push(packet_pos);
484 template <
int PacketDataWidth,
int DestWidthPerHop,
int MaxHops,
485 int PacketIdWidth,
int FlitDataWidth,
class FlitId,
int buffersize>
487 Packet<PacketDataWidth, DestWidthPerHop, MaxHops, PacketIdWidth>,
488 Flit<FlitDataWidth, 0, 0, PacketIdWidth, FlitId, WormHole>, buffersize,
489 WormHole> :
public sc_module {
498 Connections::Out<packet_t> out_packet;
499 Connections::In<flit_t> in_flit;
504 typedef NVUINTW(logbufsize) BuffIdx;
509 static const int num_flits = packet_t::data_width / flit_t::data_width;
511 NVUINTW(log_num_flits)
512 num_flits_received[buffersize];
518 #pragma hls_unroll yes
519 for (
int i = 0; i < buffersize; i++) {
520 if (!fifo.isFull()) {
531 if (in_flit.PopNB(flit_reg)) {
534 if (flit_reg.flit_id.isHeader()) {
536 packet_pos = fifo.pop();
537 buffer[packet_pos].packet_id = flit_reg.packet_id;
538 buffer[packet_pos].dest = flit_reg.data;
539 num_flits_received[packet_pos] = 0;
543 #pragma hls_unroll yes
544 for (
int i = 0; i < buffersize; i++) {
546 BuffIdx head = fifo.get_head();
547 BuffIdx tail = fifo.get_tail();
548 if((((tail < head) && ((i >= tail) && (i < head))) ||
549 ((head < tail) && ((i >= tail) || (i < head))) || fifo.isFull()) && (!fifo.isEmpty())) {
550 if (buffer[i].packet_id == flit_reg.packet_id) {
553 num_flits_received[i] * flit_t::data_width);
554 num_flits_received[i]++;
561 if (flit_reg.flit_id.isTail()) {
562 out_packet.Push(buffer[packet_pos]);
565 fifo.push(packet_pos);
577 out_packet(
"out_packet"),
580 sensitive << clk.pos();
617 template <
int PacketDataWidth,
int DestWidthPerHop,
int MaxHops,
618 int PacketIdWidth,
int FlitDataWidth,
class FlitId>
620 Packet<PacketDataWidth, DestWidthPerHop, MaxHops, PacketIdWidth>,
621 Flit<FlitDataWidth, 0, 0, PacketIdWidth, FlitId, WormHole>, 0,
622 WormHole> :
public sc_module {
630 Connections::Out<packet_t> out_packet;
631 Connections::In<flit_t> in_flit;
635 static const int header_data_width = flit_t::data_width - packet_t::dest_width;
637 static const int num_flits = (((packet_t::data_width-header_data_width) % flit_t::data_width) == 0) ? ((packet_t::data_width-header_data_width) / flit_t::data_width) : ((packet_t::data_width-header_data_width) / flit_t::data_width+1) ;
639 NVUINTW(log_num_flits) num_flits_received;
647 out_packet(
"out_packet"),
650 sensitive << clk.pos();
655 template <
int PacketDataWidth,
int DestWidthPerHop,
int MaxHops,
656 int PacketIdWidth,
int FlitDataWidth,
class FlitId>
660 WormHole>::Process() {
663 num_flits_received = 0;
669 if (in_flit.PopNB(flit_reg)) {
671 if (flit_reg.flit_id.isHeader()) {
672 buffer.dest =
static_cast<NVUINTW(packet_t::dest_width)
> (flit_reg.data);
673 buffer.data = nvhls::get_slc<header_data_width>(flit_reg.data, packet_t::dest_width);
674 num_flits_received = 0;
676 buffer.data |= (
static_cast<NVUINTW(PacketDataWidth)
>(flit_reg.data) << num_flits_received * flit_t::data_width + header_data_width);
677 num_flits_received++;
680 if (flit_reg.flit_id.isTail()) {
681 out_packet.Push(buffer);
682 num_flits_received = 0;
Parameterized implementation of a network packet.
Deserializer for store-forward router.
serializer for store-forward router
#define NVHLS_ASSERT_MSG(X, MSG)
NVUINTW(Wrapped< T >::width) TypeToNVUINT(T in)
Convert Type to NVUINT.
type1 set_slc(type1 X, type2 Y, const unsigned int i)
Function that replaces slice of bits.
nvhls_t< W >::nvuint_t get_slc(type X, const unsigned int i)
Function that returns slice of bits.
#define NVHLS_NEG_RESET_SIGNAL_IS(port)
ENABLE_SYNC_RESET define: Select synchronous or asynchronous reset.
Compute index width of a constant.