-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIFO_Simple.v
136 lines (123 loc) · 2.5 KB
/
FIFO_Simple.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 11:26:12 07/06/2021
// Design Name:
// Module Name: FIFO_Simple
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module FIFO_Simple(clk,reset,din,read,write,dout,empty,full);
input clk;
input reset;
input [15:0]din;
input read;
input write;
output [15:0]dout;
output empty;
output full;
parameter DEPTH=3, MAX_COUNT=3'b111;
reg [15:0]dout;
reg empty;
reg full;
reg [(DEPTH-1):0]tail;
reg [(DEPTH-1):0]head;
reg [(DEPTH-1):0]count;
reg [15:0]fifo_mem[0:MAX_COUNT];
reg sr_read_write_empty;
always @(posedge clk)
begin
if(reset==1)
sr_read_write_empty <= 0;
else if(read==1 && empty==1 && write==1)
sr_read_write_empty <= 1;
else
sr_read_write_empty <= 0;
end
always @(posedge clk)
begin
if(reset==1)
count <= 3'b000;
else
begin
case({read,write})
2'b00:
count <= count;
2'b01:
if(count!=MAX_COUNT)
count <= count+1;
2'b10:
if(count!=3'b000)
count <= count-1;
2'b11:
if(sr_read_write_empty==1)
count <= count+1;
else
count <= count;
default:
count <= count;
endcase
end
end
always @(count)
begin
if(count==3'b000)
empty <= 1;
else
empty <= 0;
end
always @(count)
begin
if(count==MAX_COUNT)
full <= 1;
else
full <= 0;
end
always @(posedge clk)
begin
if(reset==1)
head <= 3'b000;
else
begin
if(write==1 && full==0)
head <= head+1;
end
end
always @(posedge clk)
begin
if(reset==1)
tail <= 3'b000;
else
begin
if(read==1 && empty==0)
tail <= tail+1;
end
end
always @(posedge clk)
begin
if(write==1 && full==0)
fifo_mem[head] <= din;
else
fifo_mem[head] <= fifo_mem[head];
end
always @(posedge clk)
begin
if(reset==1)
dout <= 16'h0000;
else if(read==1 && empty==0)
dout <= fifo_mem[tail];
else
dout <= dout;
end
endmodule