Attention

This documentation is a work in progress. Expect to see errors and unfinished things.

rr_arb Source File

 1/* rr_arb
 2   Generic round-robin arbiter based on request-grant handshake.
 3   Can be used as is or can be taken as an example of how the rr_next() function
 4   can be incorporated into other designs.
 5*/
 6
 7module rr_arb #(
 8   parameter NREQ = 2
 9) (
10   input             clk,
11   input  [NREQ-1:0] req_bus,
12   output [NREQ-1:0] grant_bus
13);
14   localparam NREQ_LOG2 = $clog2(NREQ);
15
16   function [NREQ-1:0] rr_next;
17      input [NREQ-1:0] reqs;
18      input [NREQ-1:0] base;
19      reg [NREQ*2-1:0] double_req;
20      reg [NREQ*2-1:0] double_grant;
21   begin
22      double_req = {reqs, reqs};
23      double_grant = ~(double_req - base) & double_req;
24      rr_next = double_grant[NREQ*2-1:NREQ] | double_grant[NREQ-1:0];
25   end endfunction
26
27   reg [NREQ-1:0] base=1; // one-hot encoded
28   always @(posedge clk) begin
29      if (|(grant_bus & req_bus)) base <= base << 1 | base[NREQ-1];
30   end
31
32   assign grant_bus = rr_next(req_bus, base);
33
34endmodule