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

Subversion Repositories mips32r1

[/] [mips32r1/] [trunk/] [Hardware/] [XUPV5-LX110T_SoC/] [MIPS32-Pipelined-Hw/] [src/] [Common/] [FIFO_NoFull_Count.v] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ayersg
`timescale 1ns / 1ps
2
/*
3
 * File         : FIFO_NoFull_Count.v
4
 * Project      : University of Utah, XUM Project MIPS32 core
5
 * Creator(s)   : Grant Ayers (ayers@cs.utah.edu)
6
 *
7
 * Modification History:
8
 *   Rev   Date         Initials  Description of Change
9
 *   1.0   24-May-2010  GEA       Initial design.
10
 *
11
 * Standards/Formatting:
12
 *   Verilog 2001, 4 soft tab, wide column.
13
 *
14
 * Description:
15
 *   A synchronous FIFO of variable data width and depth. 'enQ' is ignored when
16
 *   the FIFO is full and 'deQ' is ignored when the FIFO is empty. If 'enQ' and
17
 *   'deQ' are asserted simultaneously, the FIFO is unchanged and the output data
18
 *   is the same as the input data.
19
 *
20
 *   This FIFO is "First word fall-through" meaning data can be read without
21
 *   asserting 'deQ' by merely supplying an address. However, when 'deQ' is
22
 *   asserted, the data is "removed" from the FIFO and one location is freed.
23
 *   If the FIFO is empty and 'enQ' and 'deQ' are not asserted simultaneously,
24
 *   the output data will be 0s.
25
 *
26
 * Variation:
27
 *   - There is no output to indicate the FIFO is full.
28
 *   - Output 'count' indicates how many elements are in the FIFO, from 0 to 256
29
 *     (for 8-bit ADDR_WIDTH).
30
 */
31
module FIFO_NoFull_Count(clock, reset, enQ, deQ, data_in, data_out, empty, count);
32
    parameter DATA_WIDTH = 8;
33
    parameter ADDR_WIDTH = 8;
34
    parameter RAM_DEPTH = 1 << ADDR_WIDTH;
35
    input clock;
36
    input reset;
37
    input enQ;
38
    input deQ;
39
    input [(DATA_WIDTH-1):0] data_in;
40
    output [(DATA_WIDTH-1):0] data_out;
41
    output empty;
42
    output reg [(ADDR_WIDTH):0] count;       // How many elements are in the FIFO (0->256)
43
 
44
    reg [(ADDR_WIDTH-1):0] enQ_ptr, deQ_ptr; // Addresses for reading from and writing to internal memory
45
 
46
    assign empty = (count == 0);
47
    wire full = (count == (1 << ADDR_WIDTH));
48
 
49
    wire [(DATA_WIDTH-1):0] w_data_out;
50
    assign data_out = (empty) ? ((enQ & deQ) ? data_in : 0) : w_data_out;
51
 
52
    wire w_enQ = (full) ? 0 : enQ;   // Mask 'enQ' when the FIFO is full
53
    wire w_deQ = (empty) ? 0 : deQ;  // Mask 'deQ' when the FIFO is empty
54
 
55
    always @(posedge clock) begin
56
        if (reset) begin
57
            enQ_ptr <= 0;
58
            deQ_ptr <= 0;
59
            count <= 0;
60
        end
61
        else begin
62
            enQ_ptr <= (w_enQ) ? enQ_ptr +1 : enQ_ptr;
63
            deQ_ptr <= (w_deQ) ? deQ_ptr +1 : deQ_ptr;
64
            count <= (w_enQ ~^ w_deQ) ? count : ((w_enQ) ? count +1 : count -1);
65
        end
66
    end
67
 
68
    SRAM #(
69
        .DATA_WIDTH (DATA_WIDTH),
70
        .ADDR_WIDTH (ADDR_WIDTH),
71
        .RAM_DEPTH  (RAM_DEPTH))
72
        ram(
73
        .clock   (clock),
74
        .wEn     (w_enQ),
75
        .rAddr   (deQ_ptr),
76
        .wAddr   (enQ_ptr),
77
        .dIn     (data_in),
78
        .dOut    (w_data_out)
79
    );
80
 
81
endmodule

powered by: WebSVN 2.1.0

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