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 113

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

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

powered by: WebSVN 2.1.0

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