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

Subversion Repositories mips32r1

[/] [mips32r1/] [trunk/] [Hardware/] [XUPV5-LX110T_SoC/] [MIPS32-Pipelined-Hw/] [src/] [Common/] [FIFO.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.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   4-Apr-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
 *   - None. This is the basic FIFO module.
28
 */
29
module FIFO(clock, reset, clear, enQ, deQ, data_in, data_out, empty, full);
30
   parameter DATA_WIDTH = 8;
31
   parameter ADDR_WIDTH = 8;
32
   parameter RAM_DEPTH = 1 << ADDR_WIDTH;
33
   input clock;
34
   input reset;
35
   input enQ;
36
   input deQ;
37
   input [(DATA_WIDTH-1):0] data_in;
38
   output [(DATA_WIDTH-1):0] data_out;
39
   output empty;
40
   output full;
41
 
42
   reg [(ADDR_WIDTH-1):0] enQ_ptr, deQ_ptr;     // Addresses for reading from and writing to internal memory
43
   reg [(ADDR_WIDTH):0] count;                  // How many elements are in the FIFO (0->256)
44
   assign empty = (count == 0);
45
   assign full = (count == (1 << ADDR_WIDTH));
46
 
47
   wire [(DATA_WIDTH-1):0] w_data_out;
48
   assign data_out = (empty) ? ((enQ & deQ) ? data_in : 0) : w_data_out;
49
 
50
   wire w_enQ = (full) ? 0 : enQ;   // Mask 'enQ' when the FIFO is full
51
   wire w_deQ = (empty) ? 0 : deQ;  // Mask 'deQ' when the FIFO is empty
52
 
53
   always @(posedge clock) begin
54
      if (reset) begin
55
         enQ_ptr <= 0;
56
         deQ_ptr <= 0;
57
         count <= 0;
58
      end
59
      else begin
60
         enQ_ptr <= (w_enQ) ? enQ_ptr +1 : enQ_ptr;
61
         deQ_ptr <= (w_deQ) ? deQ_ptr +1 : deQ_ptr;
62
         count <= (w_enQ ~^ w_deQ) ? count : ((w_enQ) ? count +1 : count -1);
63
      end
64
   end
65
 
66
   SRAM #(
67
      .DATA_WIDTH (DATA_WIDTH),
68
      .ADDR_WIDTH (ADDR_WIDTH),
69
      .RAM_DEPTH  (RAM_DEPTH))
70
      RAM(
71
      .clock   (clock),
72
      .wEn     (w_enQ),
73
      .rAddr   (deQ_ptr),
74
      .wAddr   (enQ_ptr),
75
      .dIn     (data_in),
76
      .dOut    (w_data_out)
77
   );
78
 
79
endmodule

powered by: WebSVN 2.1.0

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