Cut packets into flits with head and tail marks. Send each flit only with a link credit, from the first two credits to the last one returned.
Hardware context: The network-layer packetizer of an on-chip network link with credit flow control. Implement a packetizer that emits header and data flits with head and tail marks and spends one credit per flit.
Lesson P1.13 sent requests and responses as flits on a link with credits. Something has to turn a packet into those flits. That block is the network layer's packetizer, and the link layer's credits decide when each flit may go.
Write module flit_tx. It takes a packet with a destination, a tag and up to three data bytes. It sends a header flit, then one flit per byte. The first flit carries head and the last carries tail; a header-only packet carries both.
Every flit spends a credit. You start with two, the size of the receiver's buffer, and get one back each time the receiver frees a flit. The fixture plays that receiver, sometimes slowly, and checks every flit.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
packets | 4 | input of each check |
Full specification
module flit_tx (
input logic clk,
input logic rst_n,
// packets in: a header and up to three data bytes
input logic pkt_valid,
output logic pkt_ready,
input logic [1:0] pkt_dest,
input logic [5:0] pkt_tag,
input logic [1:0] pkt_len, // data bytes: 0 to 3
input logic [23:0] pkt_data, // byte 0 in bits 7:0
// flits out, paid for with credits
output logic flit_valid, // a flit crosses at this edge
output logic [11:0] flit, // {head, tail, payload[9:0]}
input logic crd // the receiver returns one credit at this edge
);
// your packetizer
endmodule
| Flit | Bits {head, tail, payload[9:0]} |
|---|---|
| Header | {1, tail, dest[1:0], len[1:0], tag[5:0]}; tail = 1 only when len = 0. |
| Data byte k (1 to len) | {0, tail, 2'b00, byte k - 1}; tail = 1 on byte len. |
| Rule | Meaning |
|---|---|
| Packets | A packet moves at a rising edge where pkt_valid and pkt_ready are both 1. Packets keep their order. |
| Credits | Start with 2 after reset. A flit spends one; with none left, no flit goes. |
| Returned credits | crd = 1 at an edge returns one credit. It can pay for a flit from the next edge on, not at this one. |
The result is {packets_ok[7:0], flits[7:0], bad_flits[7:0], credit_errors[7:0], 16 zero bits, checksum[31:0]}. The checksum rotates and folds in every flit in arrival order. Each case runs 90 edges.
Examples
Example 1
One Packet, Three Bytes- Input
Packets (dest, tag, data bytes): 2/5/332211; receiver frees a flit by 16'hffff
- Output
packets_ok = 1, flits = 4, bad_flits = 0, credit_errors = 0, checksum = 0x521b
Four flits: the header with dest 2, len 3 and tag 5, then 11, 22 and 33. Only 33 carries tail.
Example 2
A Header-Only Packet- Input
Packets (dest, tag, data bytes): 1/9/-; receiver frees a flit by 16'hffff
- Output
packets_ok = 1, flits = 1, bad_flits = 0, credit_errors = 0, checksum = 0xd09
One flit carries both head and tail: {1, 1, dest 1, len 0, tag 9}.
Example 3
Every Packet Length- Input
Packets (dest, tag, data bytes): 0/1/-, 1/2/aa, 2/3/ccbb, 3/4/ffeedd; receiver frees a flit by 16'hffff
- Output
packets_ok = 4, flits = 10, bad_flits = 0, credit_errors = 0, checksum = 0x11b617
Four packets of 0 to 3 data bytes make ten flits. The first packet's only flit carries both head and tail.
Constraints and Contract
- Keep the module name and the ports. flit_valid and flit must come from flops: the fixture samples them just before each edge.
- Do not reach outside your ports.
Hints
Hint 1
Latch the whole packet when you take it, and hold pkt_ready low until its last flit has gone.
Hint 2
A flit counter k: 0 is the header, 1 to len the data bytes. tail is k == len.
Hint 3
Update the credit count once per edge: plus one for crd, minus one for a flit sent. Decide whether to send from the count before this edge's crd.
What the grader checks: Your packetizer sends nine sets of packets into a receiver that frees flits by a pattern. Every flit is checked against the packets and the credit count. Passing shows framing and credits are right on these packets.
9 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 1 steps and the final capstone