-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIFO_Status.v
More file actions
35 lines (30 loc) · 795 Bytes
/
Copy pathFIFO_Status.v
File metadata and controls
35 lines (30 loc) · 795 Bytes
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
module FIFO_Status #(
parameter n = 3, // n address bits
parameter SIZE = 8 // size of fifo
) (
input clk, rst, write, read,
input [n-1:0] write_addr, read_addr,
output reg fifo_full, fifo_empty, fifo_overflow, fifo_underflow
);
reg [n-1:0] counter;
assign fifo_overflow = fifo_full & write;
assign fifo_underflow = fifo_empty & read;
always @(posedge clk or negedge rst) begin
if (~rst) begin
counter <= 0;
end
else if (~fifo_full && write) begin
counter <= counter + 1;
end
else if (~fifo_empty && read) begin
counter <= counter - 1;
end
else begin
counter <= counter;
end
end
always @(counter) begin
fifo_empty = (counter == 0);
fifo_full = (counter == SIZE);
end
endmodule