Practice

Uplink Slot Arbiter

Four water-quality analyzers at a treatment plant share one telemetry uplink, with one message slot per clock cycle. The old arbiter used fixed priority, intake first. During the spring floods, the intake analyzer went into alarm and requested nonstop for 6 hours. The outfall analyzer, the one measuring the water leaving the plant, never got a single slot. Those are exactly the readings the regulator fines the plant over. The incident report has your block's name on the fix line.

Your task: build a rotating-priority round-robin arbiter, so that no analyzer, however noisy, can starve the others. The rotation rule is the classic one, and the bench holds you to it exactly. Remember the last analyzer granted. When requests arrive, scan upward from the analyzer just after the last winner, wrapping around; the first requester found wins. If analyzer 1 won last and 0, 1, 3 are asking, 3 wins. Next slot the scan starts after 3, so 0 wins.

Interface

PortDirectionTypeDescription
clkin1 bitClock, one uplink slot per cycle
rstin1 bitSynchronous reset (active high)
reqin4-bit vectorRequest lines, one per analyzer (bit 0 = intake)
grantout4-bit vectorOne-hot grant, or all zeros (registered)

Behavior

  • req is sampled at each rising edge; the resulting grant is presented during the following cycle
  • When at least one request bit is set, the winner is the first requester found scanning upward from (last winner + 1) mod 4, wrapping around
  • grant is one-hot for that winner: exactly that analyzer's bit is high
  • The winner becomes the new "last winner", so it has lowest priority in the next arbitration
  • When req is all zeros, grant is all zeros and the last-winner memory does not move
  • grant is never anything other than one-hot or all zeros, and never points at an analyzer whose request bit was 0 at the sampling edge
  • With all four requesting continuously, the grant sequence rotates 0, 1, 2, 3, 0, 1, 2, 3; a lone continuous requester is granted every cycle
  • rst = 1 at a clock edge clears grant and resets the rotation so that analyzer 0 has first priority again

What the bench checks

  • The testbench checks grant on every cycle against a rotating-priority reference model
  • With all four requests high, grants must rotate through every requester and wrap cleanly
  • Idle cycles must not move priority, while a lone requester may receive back-to-back grants
  • Directed mixtures cover noisy pairs, a brief new requester, request dropout, and scanning across missing requesters
  • Reset during traffic must clear the grant and restore requester 0 as first priority
  • Forty pseudo-random request patterns then exercise the same rotation rule

Constraints

TIMING

everything is synchronous to clk and grant is registered.

SCOPE

this models the slot arbiter alone. The analyzers, their request logic, and the telemetry uplink itself are out of scope.

How you implement the scan is your business. What is not negotiable is the rotation rule, exact to the cycle, under every request pattern the bench can invent.

Do not add ports.

Loading editor...

Click Run to execute your code. Output will appear here.