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

Subversion Repositories orsoc_graphics_accelerator

[/] [orsoc_graphics_accelerator/] [trunk/] [rtl/] [verilog/] [gfx/] [basic_fifo.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 Orka
/*
2
 Basic fifo
3
 Copyright 2005, Timothy Miller
4
 
5
 Updated 2012 by Per Lenander & Anton Fosselius (ORSoC)
6
      - basic fifo is no longer of a fixed depth
7
 
8
 This file is part of orgfx.
9
 
10
 orgfx is free software: you can redistribute it and/or modify
11
 it under the terms of the GNU Lesser General Public License as published by
12
 the Free Software Foundation, either version 3 of the License, or
13
 (at your option) any later version.
14
 
15
 orgfx is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU Lesser General Public License for more details.
19
 
20
 You should have received a copy of the GNU Lesser General Public License
21
 along with orgfx.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
 
25
module basic_fifo(
26
  clk_i,
27
  rst_i,
28
 
29
  data_i,
30
  enq_i,
31
  full_o,
32
  count_o,
33
 
34
  data_o,
35
  valid_o,
36
  deq_i
37
);
38
 
39
parameter fifo_width     = 32;
40
parameter fifo_bit_depth = 6;
41
 
42
input clk_i, rst_i;
43
 
44
input        [fifo_width-1:0] data_i;
45
input                         enq_i;
46
output                        full_o;
47
output reg [fifo_bit_depth:0] count_o;
48
 
49
output reg [fifo_width-1:0] data_o;
50
output reg                  valid_o;
51
input                       deq_i;
52
 
53
 
54
 
55
reg   [fifo_width-1:0] fifo_data [2**(fifo_bit_depth)-1:0];
56
reg [fifo_bit_depth:0] fifo_head, fifo_tail;
57
reg [fifo_bit_depth:0] next_tail;
58
 
59
 
60
// accept input
61
wire next_full = fifo_head[fifo_bit_depth-1:0] == next_tail[fifo_bit_depth-1:0] &&
62
                 fifo_head[fifo_bit_depth]     != next_tail[fifo_bit_depth];
63
always @(posedge clk_i or posedge rst_i)
64
  if (rst_i)
65
  begin
66
    fifo_tail <= 1'b0;
67
    next_tail <= 1'b1;
68
  end
69
  else if (!next_full && enq_i)
70
  begin
71
     // We can only enqueue when not full
72
     fifo_data[fifo_tail[fifo_bit_depth-1:0]] <= data_i;
73
     next_tail <= next_tail + 1'b1;
74
     fifo_tail <= next_tail;
75
   end
76
 
77
assign full_o = next_full;
78
 
79
always @(posedge clk_i or posedge rst_i)
80
  if(rst_i)
81
    count_o <= 1'b0;
82
  else if(enq_i & ~deq_i & ~next_full)
83
    count_o <= count_o + 1'b1;
84
  else if(~enq_i & deq_i & valid_o)
85
    count_o <= count_o - 1'b1;
86
 
87
// provide output
88
wire is_empty = (fifo_head == fifo_tail);
89
always @(posedge clk_i or posedge rst_i)
90
  if (rst_i) begin
91
    valid_o <= 1'b0;
92
    fifo_head <= 1'b0;
93
  end
94
  else
95
  begin
96
    if (!is_empty)
97
    begin
98
      if (!valid_o || deq_i)
99
        fifo_head <= fifo_head + 1'b1;
100
 
101
      valid_o <= 1'b1;
102
    end
103
    else if (deq_i)
104
      valid_o <= 1'b0;
105
  end
106
 
107
always @(posedge clk_i)
108
    // If no valid out or we're dequeueing, we want to grab
109
    // the next data.  If we're empty, we don't get valid_o,
110
    // so we don't care if it's garbage.
111
  if (!valid_o || deq_i)
112
    data_o <= fifo_data[fifo_head[fifo_bit_depth-1:0]];
113
 
114
endmodule

powered by: WebSVN 2.1.0

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