Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
amrkhalid-star902 committed Aug 20, 2023
1 parent 31bdad9 commit 68f18af
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
69 changes: 69 additions & 0 deletions AHB/Arbiter/Find_first.v
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
52 changes: 52 additions & 0 deletions AHB/Arbiter/Fixed_Arbiter.v
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
45 changes: 45 additions & 0 deletions AHB/Arbiter/Lazy_counter.v
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

0 comments on commit 68f18af

Please sign in to comment.