forked from amrkhalid-star902/AMBA-BUS-PROTOCOL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31bdad9
commit 68f18af
Showing
3 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
`timescale 1ns / 1ps | ||
|
||
|
||
module Find_first( | ||
|
||
Indices, | ||
logic_arr, | ||
index_out, | ||
valid_out | ||
|
||
); | ||
|
||
parameter N = 4; | ||
parameter DATAW = 2; | ||
parameter REVERSE = 0; | ||
localparam LOGN = $clog2(N); | ||
|
||
input [N*DATAW-1 : 0] Indices; | ||
input [N-1 : 0] logic_arr; | ||
output [DATAW-1 : 0] index_out; | ||
output valid_out; | ||
|
||
localparam TL = (1 << LOGN) - 1; | ||
localparam TN = (1 << (LOGN+1)) - 1; | ||
|
||
wire [TN-1 : 0] logic_value; | ||
wire [DATAW-1 : 0]index_value[TN-1 : 0]; | ||
|
||
|
||
/*for(genvar i = 0 ; i < TL ; i = i + 1) | ||
begin | ||
assign logic_value[i] = 0; | ||
assign index_value[i] = {DATAW{1'b0}}; | ||
end | ||
*/ | ||
|
||
for(genvar i = 0 ; i < N ; i = i + 1) | ||
begin | ||
|
||
assign logic_value[TL + i] = REVERSE ? logic_arr[N-1-i] : logic_arr[i]; | ||
assign index_value[TL + i] = REVERSE ? Indices[((N-i)*DATAW-1) : (N-i-1)*DATAW] : Indices[((i+1)*DATAW-1) : (i)*DATAW]; | ||
|
||
end | ||
|
||
for(genvar i = TL + N ; i < TN ; i = i + 1) | ||
begin | ||
|
||
assign logic_value[i] = 0; | ||
assign index_value[i] = {DATAW{1'b0}}; | ||
|
||
end | ||
|
||
|
||
for(genvar j = 0 ; j < LOGN ; j = j + 1)begin | ||
for(genvar i = 0 ; i < (2**j) ; i = i + 1)begin | ||
|
||
assign logic_value[2**j-1+i] = logic_value[2**(j+1)-1+2*i] | logic_value[2**(j+1)-1+2*i+1]; | ||
assign index_value[2**j-1+i] = logic_value[2**(j+1)-1+2*i] ? index_value[2**(j+1)-1+2*i] : index_value[2**(j+1)-1+2*i+1]; | ||
|
||
end | ||
end | ||
|
||
|
||
assign valid_out = logic_value[0]; | ||
assign index_out = index_value[0]; | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
`timescale 1ns / 1ps | ||
|
||
|
||
module Fixed_Arbiter( | ||
|
||
requests, | ||
grant_idx, | ||
grant_onehot, | ||
grant_valid | ||
|
||
); | ||
|
||
parameter N = 4; | ||
parameter MODE = 0; | ||
parameter REVERSE = 0; | ||
|
||
|
||
localparam LOGN = $clog2(N); | ||
|
||
input [N-1 : 0] requests; | ||
output [LOGN-1 : 0] grant_idx; | ||
output [N-1 : 0] grant_onehot; | ||
output grant_valid; | ||
|
||
wire [LOGN-1 : 0] index; | ||
reg [N-1 : 0] onehot; | ||
|
||
Lazy_counter lzc( | ||
|
||
.In_logic(requests), | ||
.Idx(index), | ||
.valid(grant_valid) | ||
|
||
); | ||
|
||
defparam lzc.N = N; | ||
defparam lzc.MODE = MODE; | ||
defparam lzc.REVERSE = REVERSE; | ||
|
||
assign grant_idx = index; | ||
assign grant_onehot = onehot; | ||
|
||
always@(index) | ||
begin | ||
|
||
onehot = {N{1'b0}}; | ||
onehot[index] = 1'b1; | ||
|
||
end | ||
|
||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
`timescale 1ns / 1ps | ||
|
||
|
||
|
||
module Lazy_counter( | ||
|
||
In_logic, | ||
Idx, | ||
valid | ||
|
||
); | ||
|
||
parameter N = 4; | ||
parameter MODE = 0; | ||
parameter REVERSE = 0; | ||
|
||
localparam LOGN = $clog2(N); | ||
|
||
input [N-1 : 0] In_logic; | ||
output [LOGN-1 : 0] Idx; | ||
output valid; | ||
|
||
wire [N*LOGN-1 : 0] indices; | ||
|
||
for (genvar i = 0; i < N; i = i + 1) | ||
begin | ||
|
||
assign indices[((i+1)*LOGN-1) : (i)*LOGN] = MODE ? N-1-i : i; | ||
|
||
end | ||
|
||
Find_first find_first( | ||
|
||
.Indices(indices), | ||
.logic_arr(In_logic), | ||
.index_out(Idx), | ||
.valid_out(valid) | ||
|
||
); | ||
|
||
defparam find_first.N = N; | ||
defparam find_first.DATAW = LOGN; | ||
defparam find_first.REVERSE = REVERSE; | ||
|
||
endmodule |