OpenCores
URL https://opencores.org/ocsvn/firewire/firewire/trunk

Subversion Repositories firewire

[/] [firewire/] [trunk/] [bench/] [verilog/] [fifo_beh.v] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 johnsonw10
/******************************************************************************
2
  $Id: fifo_beh.v,v 1.1 2002-03-10 17:18:37 johnsonw10 Exp $
3
 
4
  Author(s): Johnsonw10@opencors.org
5
 
6
  Revision History:
7
  $Log: not supported by cvs2svn $
8
 
9
******************************************************************************/
10
`timescale 1 ns / 100 ps
11
module fifo_beh (
12
                 clk,
13
                 reset_n,
14
                 wr,
15
                 din,
16
 
17
                 rd,
18
                 dout,
19
 
20
                 empty,
21
                 full
22
);
23
 
24
parameter DATA_WIDTH   = 32;
25
parameter FIFO_SIZE    = 64;
26
 
27
input reset_n;
28
input clk;
29
 
30
input wr;
31
input [0:DATA_WIDTH-1] din;
32
 
33
input rd;
34
output [0:DATA_WIDTH-1] dout;
35
reg [0:DATA_WIDTH-1] dout;
36
output empty;
37
output full;
38
 
39
reg [0:DATA_WIDTH-1] mem[0:FIFO_SIZE-1];
40
integer rd_ptr, wr_ptr, dcnt;
41
 
42
wire empty_o, full_o;
43
wire rd_i = rd & (!empty_o);
44
wire wr_i = wr & (!full_o);
45
 
46
always @ (negedge reset_n or posedge clk) begin
47
    if (!reset_n) begin
48
        rd_ptr <= 0;
49
        wr_ptr <= 0;
50
        dcnt <= 0;
51
    end
52
    else begin
53
        if (rd_i) begin
54
            dout <= mem[rd_ptr];
55
            rd_ptr <= rd_ptr + 1;
56
        end
57
 
58
        if (wr_i) begin
59
            mem[wr_ptr] <= din;
60
            wr_ptr <= wr_ptr + 1;
61
        end
62
 
63
        if (rd_i && wr_i)
64
            dcnt <= dcnt;
65
        else if (rd_i)
66
            dcnt <= dcnt - 1;
67
        else if (wr_i)
68
            dcnt <= dcnt + 1;
69
    end
70
end
71
 
72
assign empty_o = (dcnt == 0);
73
assign full_o  = (dcnt == FIFO_SIZE);
74
 
75
assign empty = empty_o;
76
assign full  = full_o;
77
 
78
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.