-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweighted_round_arbiter.v
62 lines (50 loc) · 1.32 KB
/
weighted_round_arbiter.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
`include "defines.vh"
module weight_round_arb
(
input clk,
input reset_n,
input [`N-1:0] req,
input [`N-1:0] WEIGHT,
output [`N-1:0] grant
);
reg [`N-1:0] round_priority;
reg [`N-1:0] count [`N-1:0];// two dimension
wire [`N-1:0] round_cell_en;
wire round_en;
genvar i;
generate
for(i=0;i<`N;i++) begin: counter
always @(posedge clk or negedge reset_n) begin
if(!reset_n)
count[i] <= {`N{1'b0}};
else if(|grant) begin
if(grant[i])
count[i] <= count[i] + 1'b1;
else
count[i] <= {`N{1'b0}};
end
end
end
assign round_cell_en[i] = (count[i] ==WEIGHT[i]) | ((count[i]!=0) & (~req[i]));
endgenerate
assign round_en = (| round_cell_en[`N-1:0] ) & (| req);
always @(posedge clk or negedge reset_n)
begin
if(!reset_n)
round_priority <= {`N{1'b0}};
else if(round_en)
round_priority <= {grant[`N-2:0],grant[`N-1]};
end
wire [`N*2-1:0] double_req = {req,req};
wire [`N*2-1:0] req_sub_round_priority = double_req - round_priority;
wire [`N*2-1:0] double_grant = double_req & (~req_sub_round_priority);
assign grant = double_grant[`N-1:0] | double_grant[`N*2-1:`N];
endmodule
sel_prio
case (sel)
0: 1
1: base
2: priority
3: round_priority
double_grant = double_req &~ (double_req - sel_prio) ;
cnt_en = |gnt & sel==3