-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_arbiter.v
64 lines (60 loc) · 1.24 KB
/
client_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
module client_arbiter(
input clock,
input reset_n,
input priority_sel,
input client1_req,
input client2_req,
output o_grant1,
output o_grant2);
reg [1:0]curr_state,next_state;
reg client1_req_d,client2_req_d;
parameter IDLE=2'D0,CLIENT1=2'd1,CLIENT2=2'd2;
always@(client1_req_d,client2_req_d,curr_state,priority_sel)
begin
case(curr_state)
IDLE:if(priority_sel&&client1_req_d)
next_state=CLIENT1;
else if(client2_req_d)
next_state=CLIENT2;
else
next_state=IDLE;
CLIENT1:if(client2_req_d)
next_state=CLIENT2;
else
next_state=IDLE;
CLIENT2:if(client1_req_d)
next_state=CLIENT1;
else
next_state=IDLE;
default:next_state=IDLE;
endcase
end
always@(posedge clock or negedge reset_n)
begin
if(!reset_n)begin
curr_state<=2'd0;
end
else begin
curr_state<=next_state;
end
end
assign o_grant1=(curr_state==CLIENT1);
assign o_grant2=(curr_state==CLIENT2);
always@(posedge clock or negedge reset_n)
begin
if(!reset_n)begin
client1_req_d<=1'd0;
client2_req_d<=1'd0;
end
else begin
if(o_grant1)
client1_req_d<=1'd0;
else if(client1_req)
client1_req_d<=1'd1;
if(o_grant2)
client2_req_d<=1'd0;
else if(client2_req)
client2_req_d<=1'd1;
end
end
endmodule