Skip to content

Commit

Permalink
Add port to show index of granted signal
Browse files Browse the repository at this point in the history
The sel port displays the index of the currently granted signal.
This is useful for directly driving multiplexers

Signed-off-by: Olof Kindgren <olof.kindgren@gmail.com>
  • Loading branch information
olofk committed Oct 20, 2014
1 parent 4d7be0f commit f847af1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/arbiter.v
Expand Up @@ -31,9 +31,22 @@ module arbiter
input rst,
input [NUM_PORTS-1:0] request,
output reg [NUM_PORTS-1:0] grant,
output reg [$clog2(NUM_PORTS)-1:0] sel,
output reg active
);

// Find First 1 - Start from MSB and count downwards, returns 0 when no bit set
function [$clog2(NUM_PORTS)-1:0] ff1;
input [NUM_PORTS-1:0] in;
integer i;
begin
ff1 = 0;
for (i = NUM_PORTS-1; i >= 0; i=i-1) begin
if (in[i])
ff1 = i;
end
end
endfunction

/**
* Local parameters
Expand Down Expand Up @@ -72,6 +85,8 @@ module arbiter
always @(posedge clk)
grant <= token & request;

always @(posedge clk)
sel <= ff1(token & request);

always @(posedge clk)
active <= |(token & request);
Expand Down

0 comments on commit f847af1

Please sign in to comment.