Packet Header Formatter
A packet header mixes fields that change with every packet and fields that never do. The fixed ones, such as sync words and reserved bits, still have to be driven to exact constants.
The solution module constructs a 32-bit packet header combinationally. The header format is assembled from dynamic input ports and fixed constants. The upper byte is a synchronization word that changes based on the operating mode. The middle sections contain the device identifier and payload length, separated by reserved zero-padded bits. The lower byte contains a hardcoded protocol version and a terminating reserved sequence.
| Signal | Direction | Width | Description |
|---|---|---|---|
mode |
input | 1 | Operating mode flag. |
device_id |
input | 5 | Unique identifier for the transmitting device. |
payload_len |
input | 8 | Length of the data payload in bytes. |
header_word |
output | 32 | Formatted 32-bit header. |
The 32-bit header_word is constructed using the following exact bit mapping:
header_word[31:24]: Synchronization byte. Tied to8'hAAwhenmodeis 1; tied to8'h55whenmodeis 0.header_word[23:19]: Assigned directly to thedevice_idinput.header_word[18:16]: Reserved field. Tied to the constant3'b000.header_word[15:8]: Assigned directly to thepayload_leninput.header_word[7:4]: Protocol version field. Tied to the constant4'b0100(Version 4).header_word[3:0]: Terminator field. Tied to the constant4'b1111.
Constraints
- The
header_wordoutput must be driven purely combinationally; there is no clock or reset in this circuit. - All reserved and fixed fields must match the exact bit widths and binary values specified.
- The
modeinput only affects the upper 8 bits; all other constants remain fixed regardless of the operating mode.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of Combinational RTL
Problem 15 of 15 in the Combinational RTL track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks