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

Subversion Repositories orsoc_graphics_accelerator

[/] [orsoc_graphics_accelerator/] [tags/] [version1.0/] [rtl/] [verilog/] [gfx/] [basic_fifo.v] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 maiden
/*
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
    clock,
27
    reset,
28
 
29
    data_in,
30
    enq,
31
    full,
32
 
33
    data_out,
34
    valid_out,
35
    deq
36
);
37
 
38
parameter fifo_width = 42;
39
parameter fifo_bit_depth = 6;
40
 
41
input clock, reset;
42
 
43
input [fifo_width-1:0] data_in;
44
input enq;
45
output full;
46
reg full;
47
 
48
output [fifo_width-1:0] data_out;
49
reg [fifo_width-1:0] data_out;
50
output valid_out;
51
reg valid_out;
52
input deq;
53
 
54
 
55
 
56
reg [fifo_width-1:0] fifo_data [0:2**(fifo_bit_depth)-1];
57
reg [fifo_bit_depth:0] fifo_head, fifo_tail;
58
reg [fifo_bit_depth:0] next_tail;
59
 
60
 
61
// accept input
62
wire next_full = fifo_head[fifo_bit_depth-1:0] == next_tail[fifo_bit_depth-1:0] &&
63
    fifo_head[fifo_bit_depth] != next_tail[fifo_bit_depth];
64
wire is_full = fifo_head[fifo_bit_depth-1:0] == fifo_tail[fifo_bit_depth-1:0] &&
65
    fifo_head[fifo_bit_depth] != fifo_tail[fifo_bit_depth];
66
always @(posedge clock or posedge reset)
67
  if (reset)
68
  begin
69
    fifo_tail <= 1'b0;
70
    next_tail <= 1'b1;
71
    full <= 1'b0;
72
  end
73
  else if (/*!full && */ enq)
74
  begin
75
     // We can only enqueue when not full
76
     fifo_data[fifo_tail[fifo_bit_depth-1:0]] <= data_in;
77
     next_tail <= next_tail + 1'b1;
78
     fifo_tail <= next_tail;
79
 
80
     // We have to compute if it's full on next cycle
81
     full <= next_full;
82
   end
83
   else
84
     full <= is_full;
85
 
86
// provide output
87
wire is_empty = fifo_head == fifo_tail;
88
always @(posedge clock or posedge reset)
89
  if (reset) begin
90
    valid_out <= 1'b0;
91
    fifo_head <= 1'b0;
92
  end
93
  else
94
  begin
95
    if (!is_empty)
96
    begin
97
      if (!valid_out || deq)
98
        fifo_head <= fifo_head + 1'b1;
99
 
100
      valid_out <= 1'b1;
101
    end
102
    else if (deq)
103
      valid_out <= 1'b0;
104
  end
105
 
106
always @(posedge clock)
107
    // If no valid out or we're dequeueing, we want to grab
108
    // the next data.  If we're empty, we don't get valid_out,
109
    // so we don't care if it's garbage.
110
  if (!valid_out || deq)
111
    data_out <= fifo_data[fifo_head[fifo_bit_depth-1:0]];
112
 
113
endmodule

powered by: WebSVN 2.1.0

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