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

Subversion Repositories mips32r1

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

powered by: WebSVN 2.1.0

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