Write the master of a Clause 22 MDIO bus. Send frames bit by bit, let go of the line in time, and catch the PHY's answer.
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 chip manages its PHY over two wires. MDC is the clock it drives; MDIO is a shared data line with a pull-up. Write the master.
mdio_start begins one frame. Then the bench calls mdio_drive and mdio_sample once per MDC cycle until busy falls.
A read must let go of MDIO for the PHY. Report the 16 data bits, and whether a PHY answered at all.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
test_number | 8 | input of each check |
Full specification
bit [15:0] rdata; bit ta_ok; bit busy;
function automatic void mdio_start(input bit read, input [4:0] phyad, input [4:0] regad, input [15:0] wdata, input bit no_pre);
function automatic [1:0] mdio_drive(); // {oe, out} for this MDC cycle
function automatic void mdio_sample(input bit line); // MDIO at this cycle's rising edge
| Field | Bits | Write | Read |
|---|---|---|---|
| PRE | 32 | 32 ones (none when no_pre is 1) | the same |
| ST | 2 | 01 | 01 |
| OP | 2 | 01 | 10 |
| PHYAD, REGAD | 5 + 5 | most significant bit first | the same |
| TA | 2 | the master drives 1, then 0 | the master lets go of both bits; a PHY drives 0 in the second |
| DATA | 16 | the master drives wdata, bit 15 first | the PHY drives the register, bit 15 first |
| After the frame | busy = 0 and the master lets go | the same |
Let go means oe = 0. When nobody drives MDIO, the pull-up makes it 1. ta_ok is 1 only if MDIO was 0 in the second turnaround bit of a read.
Examples
Example 1
Read Register 2- Input
PHY 1, register 2
- Output
mdio_bits_from_st = 0x608a1a2b, cycles_master_drove = 46, write_frame_st_to_ta = 0x0, ones_before_st = 32, busy_after = no, ta_ok = yes, rdata = 0x1a2b
After 32 ones the line shows ST, OP, both addresses, the turnaround and the PHY's 16 data bits.
Example 2
Write, Then Read Back- Input
write 8001h, read register 4
- Output
mdio_bits_from_st = 0x60928001, cycles_master_drove = 46, write_frame_st_to_ta = 0x5092, ones_before_st = 32, busy_after = no, ta_ok = yes, rdata = 0x8001
A write drives every bit itself. The read that follows shows whether the PHY stored the value.
Example 3
No PHY at That Address- Input
read PHY 7
- Output
mdio_bits_from_st = 0x638bffff, cycles_master_drove = 46, write_frame_st_to_ta = 0x0, ones_before_st = 32, busy_after = no, ta_ok = no, rdata = 0xffff
Nobody answers, so the line stays high through the turnaround and the data.
Constraints and Contract
- Keep the names and arguments; you may add variables.
- One frame takes exactly 64 MDC cycles, or 32 with no_pre.
- Two drivers at once make MDIO unknown, and the test fails.
- Off limits: the names
phy,rng,tb,root, names that begin withref_and the modules of the bench.
Hints
Hint 1
Count the cycles of a read: in which cycle does the first turnaround bit fall?
Hint 2
What does the line show in the second turnaround bit if no PHY has that address?
Hint 3
Without the preamble, where does ST sit in the 64-bit frame you built?
What the grader checks: The fixture checks 13 literal transactions against an independent JavaScript model of the frame and the bench PHY. It also checks 600 random transactions cycle by cycle against a private reference master. It does not model MDC timing (400 ns period, 10 ns setup and hold) or Clause 45 frames.
15 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