| parameter SEL_WIDTH = (NUM_PORTS > 1 ? $clog2(NUM_PORTS) : 1); |
| input [NUM_PORTS - 1:0] request; |
| output reg [NUM_PORTS - 1:0] grant; |
| output reg [SEL_WIDTH - 1:0] select; |
| localparam WRAP_LENGTH = 2 * NUM_PORTS; |
| function [SEL_WIDTH - 1:0] ff1; |
| input [NUM_PORTS - 1:0] in; |
| for (i = 0; i < NUM_PORTS; i = i + 1) |
| wire [NUM_PORTS - 1:0] order; |
| reg [NUM_PORTS - 1:0] token; |
| wire [NUM_PORTS - 1:0] token_lookahead [NUM_PORTS - 1:0]; |
| wire [WRAP_LENGTH - 1:0] token_wrap; |
| assign token_wrap = {token, token}; |
| assign next = ~|(token & request); |
| always @(posedge clk) grant <= token & request; |
| always @(posedge clk) select <= ff1(token & request); |
| always @(posedge clk) active <= |(token & request); |
| for (yy = 0; yy < NUM_PORTS; yy = yy + 1) |
| token <= token_lookahead[yy]; |
| for (xx = 0; xx < NUM_PORTS; xx = xx + 1) begin : ORDER_ |
| assign token_lookahead[xx] = token_wrap[xx+:NUM_PORTS]; |
| assign order[xx] = |(token_lookahead[xx] & request); |