Medium · Finite State Machines · Interfaces & Handshakes
Implement a 4-requester round-robin arbiter. Several clients want one shared resource (a bus, a memory port, an output link). Each cycle the arbiter grants it to at most one requester. A fixed-priority arbiter would let requester 0 starve everyone else; a round-robin arbiter rotates the priority so that every requester is served fairly.
module rr_arbiter (
input logic clk,
input logic rst, // synchronous, active-high
input logic [3:0] req, // req[i] = 1: requester i wants the resource this cycle
output logic [3:0] grant // one-hot (or all zeros): grant[i] = 1 gives it to requester i
);
The arbiter keeps one piece of state: a 2-bit pointer last, the index of the requester that was granted most recently.
last+1, last+2, last+3, last (indices modulo 4). The first one with req[i] = 1 is granted. So the requester granted most recently has the lowest priority, and the one right after it has the highest.
grant depends only on the current req and the currentlast, and must reflect a change of req within the same cycle (no clock edge in between).
grant is one-hot when req != 0, and grant = 4'b0000 whenreq = 4'b0000. A requester is never granted unless its req bit is 1.
clk (with rst = 0): if a grant was given inthat cycle (grant != 0), last becomes the index of the granted requester. If no grant was given (req = 0), last does not change.
rst = 1, last becomes 3, so right after reset the orderis 0, 1, 2, 3 (requester 0 has the highest priority).
req bit high is grantedwithin at most 4 consecutive cycles, regardless of what the others do.
Note that a grant lasts one cycle: a requester that keeps req high after being granted competes again in the next cycle, now with the lowest priority.
| cycle | req (bits 3..0) | last | search order | grant |
|---|---|---|---|---|
| 1 | 1111 | 3 | 0,1,2,3 | 0001 |
| 2 | 1111 | 0 | 1,2,3,0 | 0010 |
| 3 | 1111 | 1 | 2,3,0,1 | 0100 |
| 4 | 1111 | 2 | 3,0,1,2 | 1000 |
| 5 | 0101 | 3 | 0,1,2,3 | 0001 |
| 6 | 0101 | 0 | 1,2,3,0 | 0100 |
| 7 | 0000 | 2 | – | 0000 (last stays 2) |
| 8 | 0011 | 2 | 3,0,1,2 | 0001 |
Sign up free to solve Round-Robin Arbiter in your browser.