Put the fields of a MAC frame in order, pad short data to the minimum, and place the check sequence last.
Hardware context: An Ethernet MAC and physical coding sublayer: frame builder and checker, reconciliation sublayer and block encoder. Build, check and pace Ethernet frames, and code them for the physical layer as IEEE 802.3 specifies.
A MAC transmitter gets two addresses, a Length/Type value and up to 64 octets of data. It must return the frame, ready to send.
Write build_frame. The frame holds both addresses, the Length/Type field and the data. A pad follows if the frame would be too short. The check sequence comes last.
The check sequence is computed for you. Call eth_fcs(f, n) with your frame so far and its octet count. Your job is the order, the pad and the sizes.
Short frames are the usual bug. A receiver drops a frame under 64 octets without reporting any error.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
test_number | 8 | input of each check |
Full specification
function automatic [671:0] build_frame(input [47:0] da, input [47:0] sa, input [15:0] lt, input [511:0] data, input int len);
// returns {octet_count[15:0], frame[655:0]}; octet k of the frame is frame[8*k +: 8]
function automatic [31:0] eth_fcs(input [655:0] f, input int n); // given
// the check sequence of octets 0 to n-1 of f; send result[7:0] first
| Field | Octets | Rule |
|---|---|---|
| Destination address | 6 | da[47:40] is the first octet, da[7:0] the last |
| Source address | 6 | The same order, from sa |
| Length/Type | 2 | lt[15:8] first, then lt[7:0] |
| Data | len | Octet i is data[8*i +: 8]. Ignore the octets from len up |
| Pad | as needed | Zero octets, so that the whole frame is at least 64 octets |
| Check sequence | 4 | The four octets from eth_fcs, low octet first, over everything before it |
len is 0 to 64. The frame is therefore 64 to 82 octets long. Octets of the result above the frame must be zero.
Examples
Example 1
Ten Data Octets- Input
ten data octets and a type
- Output
frame_octets = 64, fcs_fold = 0x2b90, pad_is_zero = yes, first_octet = 0xa, length_type_octets = 0x800
Fourteen header octets and ten data octets make 24. The pad brings that to 60, and the check sequence to 64.
Example 2
Forty-Six Data Octets- Input
46 data octets
- Output
frame_octets = 64, fcs_fold = 0x48e6, pad_is_zero = yes, first_octet = 0xa, length_type_octets = 0x800
The frame reaches 60 octets without any pad. With the check sequence it is exactly 64.
Example 3
No Data- Input
len = 0
- Output
frame_octets = 64, fcs_fold = 0x662e, pad_is_zero = yes, first_octet = 0xff, length_type_octets = 0x0
The whole data field is pad: 46 zero octets after the Length/Type field.
Constraints and Contract
- Keep the function name, the arguments and the 672-bit result.
lenis between 0 and 64. Data octets at and abovelenhold junk and must not reach the frame.- You may add helper functions. Do not rewrite
eth_fcs. - Off limits: the names
lib,fc,rng,tb,rootand the modules of the bench.
Hints
Hint 1
Keep one counter for the next free octet, and write every field through it.
Hint 2
How many octets of the 64 are not data? Subtract them to get the smallest data-plus-pad size.
Hint 3
The check sequence must cover the pad. Decide which of the two you append first.
What the grader checks: The fixture checks five fixed frames against an independent model and 160 random frames against the bench library, octet by octet. It does not test data longer than 64 octets or the check-sequence arithmetic itself.
8 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 1 steps and the final capstone