Watch the 64-bit bus between a receive MAC and its client. Report each frame: its size, its FCS, the MAC's verdict and any tkeep fault.
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 receive MAC hands frames to its client on the 64-bit stream bus of P11.7. The FCS is passed on as the last four octets.
Write rx_cycle. It is called once per clock with the bus signals. In the clock of a frame's last beat it returns a summary of that frame; in every other clock it returns 0.
The FCS helpers are given. Call fcs_start() at the start of a frame, fcs_octet(b) for each octet in order, and fcs_good() at the end.
A checker like this sits in every MAC testbench. It must not be fooled by idle clocks, junk on unused signals, or a short last beat.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
test_number | 8 | input of each check |
Full specification
function automatic [19:0] rx_cycle(input bit valid, input [63:0] data, input [7:0] keep, input bit last, input bit user);
// returns {done, keep_error, mac_bad, fcs_ok, octets[15:0]}
function automatic void fcs_start();
function automatic void fcs_octet(input [7:0] b);
function automatic bit fcs_good(); // 1 if the octets so far end in a good FCS
| Bus rule | Value |
|---|---|
| A beat | a clock with valid = 1. In other clocks every other input is junk |
| Byte order | byte x is data[8*x +: 8]; byte 0 comes first |
| tkeep | byte x belongs to the frame when keep[x] is 1 |
| Frame | starts with the first beat after a last beat (or after time 0) and ends with the beat where last = 1 |
user | read on the last beat only: 1 means the MAC calls the frame bad. Junk on other beats |
| Field | In the clock of the last beat |
|---|---|
| done | 1 |
| keep_error | 1 if a beat before the last had keep other than FFh. Also 1 if the last keep is not 01h, 03h, 07h, 0Fh, 1Fh, 3Fh, 7Fh or FFh |
| mac_bad | user of the last beat |
| fcs_ok | fcs_good() after every kept octet of the frame, FCS included |
| octets | the number of kept octets in the frame |
Count and check every kept octet, even in a beat that breaks a tkeep rule.
Examples
Example 1
A Good 64-octet Frame- Input
eight full beats
- Output
octets = 64, fcs_ok = yes, mac_bad = no, keep_error = no, done = yes
All 64 octets are kept and the FCS checks out.
Example 2
A Damaged Frame- Input
one flipped bit, user = 1
- Output
octets = 64, fcs_ok = no, mac_bad = yes, keep_error = no, done = yes
The FCS no longer checks out, and the MAC says so on the last beat.
Example 3
A 65-octet Frame- Input
nine beats, the last with tkeep 01h
- Output
octets = 65, fcs_ok = yes, mac_bad = no, keep_error = no, done = yes
A short last beat is legal. Only its kept octet counts.
Constraints and Contract
- Keep the function name, the arguments and the 20-bit result.
- Keep state in module-level variables. The first call comes at time 0 with no frame open.
- Use the given FCS helpers; do not redefine them.
- Off limits: the names
rng,tb,root, names that begin withfx_and the modules of the bench.
Hints
Hint 1
Which inputs mean anything in a clock where valid is 0?
Hint 2
A frame has no start flag. What tells you that the next beat begins a new frame?
Hint 3
For the last beat, write the eight legal tkeep values in binary. What do they have in common?
What the grader checks: The fixture checks five literal frames against an independent model: zlib.crc32 and the residue 2144DF1Ch. It checks 360 random frames clock by clock against a second JavaScript model. It does not test frames longer than 210 octets or a bus wider than 64 bits.
10 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