Build a four-requester weighted round-robin arbiter whose weights are turn lengths, released early whenever the winner stops asking.
Hardware context: Three requesters sharing one target through an arbiter. Implement a weighted round-robin arbiter with programmable turn lengths that release early.
Lesson P1.9 ran a three-requester arbiter with fixed weights. This one has four requesters, and the weights are inputs, so software can retune the bandwidth split.
Write module wrr_arbiter. It grants one requester per cycle, in the same cycle as the request. The winner keeps the grant while it asks and has turns left. When its turn ends, or it stops asking, the search starts at the next requester round the ring.
The fixture runs twenty cycles per case with a request pattern and four weights. It compares your grant in every cycle with a model.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
pattern | 5 | input of each check |
Full specification
module wrr_arbiter (
input logic clk,
input logic rst_n,
input logic [3:0] req, // bit k: requester k asks in this cycle
input logic [1:0] w0, w1, w2, w3, // weights, 1 to 3: the longest turn of each requester
output logic [3:0] grant // one-hot in the same cycle as req, 0 when nobody asks
);
// your arbiter
endmodule
| In each cycle | Rule |
|---|---|
| The last winner still asks and has had fewer grants in a row than its weight | It wins again. |
| Otherwise | Search from the requester after the last winner: last + 1, last + 2, ..., last + 4, modulo 4. The first one asking wins. Its new turn counts 1. |
| Nobody asks | grant = 0, and nothing changes. |
| After reset | The first search starts at requester 0, and no turn is running. |
The result is the grant of each of the 20 cycles, four bits each, cycle 0 in bits 3 to 0.
Examples
Example 1
Equal Weights- Input
weights 1, 1, 1, 1; req by cycle (bit k = requester k): 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111
- Output
grants = 0x84218421842184218421
With every weight 1 and everyone asking, the grant goes 0, 1, 2, 3 and around again: plain round robin.
Example 2
Weights 3, 1, 2, 1, All Asking- Input
weights 3, 1, 2, 1; req by cycle (bit k = requester k): 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111
- Output
grants = 0x44211184421118442111
Requester 0 wins three cycles in a row, then 1 once, 2 twice and 3 once. The round of seven grants repeats.
Example 3
A Turn Released Early- Input
weights 3, 1, 1, 1; req by cycle (bit k = requester k): 1111 1111 1110 1111 1111 1111 1110 1111 1111 1110 1111 1111 1111 1110 1111 1111 1110 1111 1111 1111
- Output
grants = 0x18428421842842184211
Requester 0 drops out in the third cycle, one grant short of its weight. The turn passes on at once; nobody waits for it.
Constraints and Contract
- Keep the module name and the ports. grant must be one-hot or 0, computed from req and your state.
- The fixture changes req between edges and reads grant 1 ns later. Weights do not change inside a case.
Hints
Hint 1
Two registers: the index of the last winner and the grants in a row it has had.
Hint 2
The search loop runs k from 1 to 4. With k = 4 it reaches the last winner itself, which starts a new turn if it is the only one asking.
Hint 3
Count grants, not cycles. A cycle with no grant leaves both registers alone.
What the grader checks: Your arbiter runs eleven 20-cycle cases with fixed and seeded requests and weights. Every grant is compared with an independent model.
11 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 3 steps and the final capstone