-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharbiter.v
95 lines (90 loc) · 1.29 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
module arbiter(input clk,input rst,input[2:0] req,input framein,output reg[2:0] gnt);
reg[2:0] buffer;
always @(posedge clk or rst or framein)
begin
if(rst==1'b1) begin gnt<=3'b111; end
else begin
//gnt<=3'b000;
buffer <= req;
end
end
always @(negedge clk or rst or framein)
begin
if(rst==1'b1) begin gnt<=3'b111; end
else if(framein==1'b1 && (gnt[0]==1'b0||gnt[1]==1'b0||gnt[2]==1'b0)) begin
gnt<=3'b111;
end
else if(framein==1'b1 && (gnt[0]==1'b1||gnt[1]==1'b1||gnt[2]==1'b1)) begin
gnt<=3'b111;
if (buffer[0]==1'b0)begin
gnt[0]<=1'b0;
end
else if (buffer[1]==1'b0)begin
gnt[1]<=1'b0;
end
else if (buffer[2]==1'b0)begin
gnt[2]<=1'b0;
end
else begin
gnt<=3'b111;
end
end
else begin end
end
endmodule
module tb();
reg clk,rst,framein;
reg [2:0]req;
wire [2:0]gnt;
always
begin
#5 clk=~clk;
end
initial
begin
$monitor($time,,"gnt:%b req:%b rst:%b framein:%d",gnt,req,rst,framein);
clk=1;
rst=1;
framein=1;
#10
rst=0;
req=3'b110;
#5
req=3'b100;
#10
framein=0;
#10
framein=1;
#20
req<=3'b101;
#5
framein=1;
#15
framein=0;
#5
framein=1;
/*
#5
framein=1;
#5
framein=1;
#10
req=3'b001;
#5
framein=1;
#5
req=3'b011;
#5
framein=1;
#5
rst=1;
#5
framein=1;
rst=0;
req=3'b010;
#5
req=3'b111;
*/
end
arbiter arb(clk,rst,req,framein,gnt);
endmodule