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

Subversion Repositories s1_core

[/] [s1_core/] [trunk/] [hdl/] [rtl/] [s1_top/] [simple_fifo.v] - Blame information for rev 114

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 113 albert.wat
/*
2 114 albert.wat
 * Simple FIFO
3 113 albert.wat
 *
4 114 albert.wat
 * (C) Copyleft 2007 Fabrizio Fazzino
5 113 albert.wat
 *
6
 * LICENSE:
7
 * This is a Free Hardware Design; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * version 2 as published by the Free Software Foundation.
10
 * The above named program is distributed in the hope that it will
11
 * be useful, but WITHOUT ANY WARRANTY; without even the implied
12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 * See the GNU General Public License for more details.
14
 *
15
 * DESCRIPTION:
16
 * Simple FIFO with full and empty status flags (which require an
17
 * extra bit added to the pointers).
18
 */
19
 
20
`timescale 1ns/100ps
21
 
22
module simple_fifo #(
23
  parameter name = "simple_fifo",
24
  parameter fifo_depth = 8,
25
  parameter data_width = 64
26
) (
27
  // System inputs
28
  input                                   sys_clock_i,
29
  input                                   sys_reset_i,
30
 
31
  // FIFO inputs
32
  input                                   read,
33
  input                                   write,
34
  input [(data_width-1):0]                data_in,
35
 
36
  // FIFO outputs
37
  output                                  empty,
38
  output                                  full,
39
  output reg [(data_width-1):0]           data_out
40
);
41
  localparam pointer_width = $clog2(fifo_depth);
42
 
43
  // Read/Write Pointers
44
  logic [(pointer_width-1):0] rd_ptr;
45
  logic [(pointer_width-1):0] wr_ptr;
46
 
47
  // Memory Array
48
  logic [(data_width-1):0] mem[fifo_depth];
49
 
50
`ifdef SIMPLY_RISC_DEBUG
51
  // For debugging
52
  logic printed_once = 0;
53
`endif
54
 
55
  // One-process style for reset/read/write
56
  always @(posedge sys_clock_i) begin
57
 
58
    // Reset
59
    if (sys_reset_i) begin
60
`ifdef SIMPLY_RISC_DEBUG
61
      if (!printed_once) begin
62
        $display("FIFO %s Asynchronous Clear", name);
63
        printed_once = 1;
64
      end
65
`endif
66
      rd_ptr = {pointer_width{1'b0}};
67
      wr_ptr = {pointer_width{1'b0}};
68
 
69
    end else begin
70
 
71
      // Read
72
      if (read) begin
73
`ifdef SIMPLY_RISC_DEBUG
74
        if (empty) $fatal(1, "*** ERROR *** Attempt to read FIFO %s whilst empty", name);
75
        $display("FIFO %s Read Request: rd_ptr=%0d, data=0x%032X", name, rd_ptr, mem[rd_ptr]);
76
`endif
77
        rd_ptr <= rd_ptr + 1;
78
      end
79
 
80
      // Write
81
      if (write) begin
82
`ifdef SIMPLY_RISC_DEBUG
83
        if (full) $fatal(1, "*** ERROR *** Attempt to write FIFO %s whilst full", name);
84
        $display("FIFO %s Write Request: wr_ptr=%0d, data=0x%032X", name, wr_ptr, data_in);
85
`endif
86
        mem[wr_ptr] <= data_in;
87
        wr_ptr <= wr_ptr + 1;
88
      end
89
    end
90
  end // always @ (posedge clock)
91
 
92
  // Always output the next element
93
  assign data_out = mem[rd_ptr];
94
 
95
  // FIFO status flags
96
  assign empty = (rd_ptr == wr_ptr);
97
  assign full = ((rd_ptr[pointer_width-2:0] == wr_ptr[pointer_width-2:0]) && (rd_ptr[pointer_width-1] != wr_ptr[pointer_width-1]));
98
 
99
endmodule
100
 

powered by: WebSVN 2.1.0

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