-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path24_sync_fifo_review.v
82 lines (70 loc) · 1.23 KB
/
24_sync_fifo_review.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
//The review of sync fifo
//author:WangFW
//date:2020-6-5
module sync_fifo_review(clk,rst_n,din,wr,rd,full,empty,dout);
input clk;
input rst_n;
input wr;
input rd;
input [7:0] din;
output reg full;
output reg empty;
output reg [7:0] dout;
reg [7:0] mem [15:0];
reg [3:0] wp;
reg [3:0] rp;
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
wp<=4'd0;
else
if(wr&&(~full))
wp<=wp+1'b1;
end
always @(posedge clk)
begin
if(wr&&(~full))
mem[wp]<=din;
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
rp<=4'd0;
else
if(rd&&(~empty))
rp<=rp+1'b1;
end
always @(posedge clk)
begin
if(rd&&(~empty))
dout<=mem[rp];
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
full<=1'b0;
else
begin
if(((~rd&&wr)&&(wp==rp-1'b1))||((wp==4'hf)&&(rp==4'h0)))
full<=1'b1;
else if(full&&rd)
full<=1'b0;
else
full<=1'b0;
end
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
empty<=1'b0;
else
begin
if(((~wr&&rd)&&(rp==wr-1'b1))||((rp==4'hf)&&(wp==4'h0)))
empty<=1'b1;
else if(empty&&wr)
empty<=1'b0;
else
empty<=1'b0;
end
end
endmodule