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 114

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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