P11.15.1 An MDIO Master

MediumImplementIcarus Verilog · serverReview the topic

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

SignalWidthRole
test_number8input of each check
Full specification
Signatures (keep them)
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
FieldBitsWriteRead
PRE3232 ones (none when no_pre is 1)the same
ST20101
OP20110
PHYAD, REGAD5 + 5most significant bit firstthe same
TA2the master drives 1, then 0the master lets go of both bits; a PHY drives 0 in the second
DATA16the master drives wdata, bit 15 firstthe PHY drives the register, bit 15 first
After the framebusy = 0 and the master lets gothe 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 with ref_ 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

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Read Register 2

Input
PHY 1, register 2
Expected 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.

Run samples executes all 3 public checks. Check all tests runs 15 checks on the server.

Icarus Verilog · server