Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add port to show index of granted signal #2

Merged
merged 1 commit into from Dec 8, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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