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

Subversion Repositories s1_core

[/] [s1_core/] [trunk/] [hdl/] [rtl/] [s1_top/] [pcx_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 PCX 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
 * Replica of the 'pcx_fifo' module used by Dmitry for his advanced
18
 * bridge, the original one was from an Altera SCFIFO Megafunction.
19
 */
20
 
21
`timescale 1ns/100ps
22
 
23
`define PCX_FIFO_DATA_WIDTH 130
24
 
25
module pcx_fifo(
26
  // System
27
  input aclr,   // Async Clear (resets the FIFO to empty)
28
  input clock,  // Clock
29
 
30
  // FIFO
31
  input rdreq,                               // Read Request (when not empty)
32
  input wrreq,                               // Write Request (when not full)
33
  input [(`PCX_FIFO_DATA_WIDTH-1):0] data,   // Data Input
34
  output empty,                              // FIFO is empty
35
  output full,                               // FIFO is full
36
  output reg [(`PCX_FIFO_DATA_WIDTH-1):0] q  // Data Output (oldest data when Read Request)
37
);
38
 
39
  // Local Params TODO CHECKME
40
  localparam fifo_depth = 32;    // TODO Dmitry says this should be enough, put an assertion to detect overflow
41
  localparam pointer_width = 6;  // 5 bits to address 32 elements + 1 to detect wrapping
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 [(`PCX_FIFO_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 clock) begin
57
    // Reset
58
    if (aclr) begin
59
`ifdef SIMPLY_RISC_DEBUG
60
      if (!printed_once) begin
61
        $display("PCX FIFO Asynchronous Clear");
62
        printed_once = 1;
63
      end
64
`endif
65
      rd_ptr = {pointer_width{1'b0}};
66
      wr_ptr = {pointer_width{1'b0}};
67
    end else begin
68
      // Read
69
      if (rdreq) begin
70
`ifdef SIMPLY_RISC_DEBUG
71
        if (empty) $fatal(1, "*** ERROR *** Attempt to read PCX FIFO whilst empty");
72
        $display("PCX FIFO Read Request: rd_ptr=%0d, data=0x%032X", rd_ptr, mem[rd_ptr]);
73
`endif
74
        q <= mem[rd_ptr];
75
        rd_ptr <= rd_ptr + 1;
76
      end
77
      // Write
78
      if (wrreq) begin
79
`ifdef SIMPLY_RISC_DEBUG
80
        if (full) $fatal(1, "*** ERROR *** Attempt to write PCX FIFO whilst full");
81
        $display("PCX FIFO Write Request: wr_ptr=%0d, data=0x%032X", wr_ptr, data);
82
`endif
83
        mem[wr_ptr] <= data;
84
        wr_ptr <= wr_ptr + 1;
85
      end
86
    end
87
  end // always @ (posedge clock)
88
 
89
  // FIFO status flags
90
  assign empty = (rd_ptr == wr_ptr);
91
  assign full = ((rd_ptr[pointer_width-2:0] == wr_ptr[pointer_width-2:0]) && (rd_ptr[pointer_width-1] != wr_ptr[pointer_width-1]));
92
 
93
endmodule // pcx_fifo
94
 

powered by: WebSVN 2.1.0

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