forked from sudhamshu091/32-Verilog-Mini-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fifo.v
110 lines (56 loc) · 1.27 KB
/
fifo.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
module FIFObuffer( Clk,
dataIn,
RD,
WR,
EN,
dataOut,
Rst,
EMPTY,
FULL
);
input Clk,
RD,
WR,
EN,
Rst;
output EMPTY,
FULL;
input [31:0] dataIn;
output reg [31:0] dataOut; // internal registers
reg [2:0] Count = 0;
reg [31:0] FIFO [0:7];
reg [2:0] readCounter = 0,
writeCounter = 0;
assign EMPTY = (Count==0)? 1'b1:1'b0;
assign FULL = (Count==8)? 1'b1:1'b0;
always @ (posedge Clk)
begin
if (EN==0);
else begin
if (Rst) begin
readCounter = 0;
writeCounter = 0;
end
else if (RD ==1'b1 && Count!=0) begin
dataOut = FIFO[readCounter];
readCounter = readCounter+1;
end
else if (WR==1'b1 && Count<8) begin
FIFO[writeCounter] = dataIn;
writeCounter = writeCounter+1;
end
else;
end
if (writeCounter==8)
writeCounter=0;
else if (readCounter==8)
readCounter=0;
else;
if (readCounter > writeCounter) begin
Count=readCounter-writeCounter;
end
else if (writeCounter > readCounter)
Count=writeCounter-readCounter;
else;
end
endmodule