Round-Robin Arbiter

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.

Specification

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.

last, and must reflect a change of req within the same cycle (no clock edge in between).

req = 4'b0000. A requester is never granted unless its req bit is 1.

that cycle (grant != 0), last becomes the index of the granted requester. If no grant was given (req = 0), last does not change.

is 0, 1, 2, 3 (requester 0 has the highest priority).

within 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.

Example

cyclereq (bits 3..0)lastsearch ordergrant
1111130,1,2,30001
2111101,2,3,00010
3111112,3,0,10100
4111123,0,1,21000
5010130,1,2,30001
6010101,2,3,00100
700002–0000 (last stays 2)
8001123,0,1,20001

Sign up free to solve Round-Robin Arbiter in your browser.

More Finite State Machines problems