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

Subversion Repositories opengfx430

[/] [opengfx430/] [trunk/] [core/] [rtl/] [verilog/] [ogfx_reg_fifo.v] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2015 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
//
25
// *File Name: ogfx_backend_lut_fifo.v
26
//
27
// *Module Description:
28
//                      Simple FIFO module
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34
// $Rev$
35
// $LastChangedBy$
36
// $LastChangedDate$
37
//----------------------------------------------------------------------------
38
`ifdef OGFX_NO_INCLUDE
39
`else
40
`include "openGFX430_defines.v"
41
`endif
42
 
43
module  ogfx_reg_fifo (
44
 
45
// OUTPUTs
46
    fifo_cnt_o,                         // Fifo counter
47
    fifo_data_o,                        // Read data output
48
    fifo_done_evt_o,                    // Fifo has been emptied
49
    fifo_empty_o,                       // Fifo is currentely empty
50
    fifo_full_o,                        // Fifo is currentely full
51
    fifo_ovfl_evt_o,                    // Fifo overflow event
52
 
53
// INPUTs
54
    mclk,                               // Main system clock
55
    puc_rst,                            // Main system reset
56
 
57
    fifo_data_i,                        // Read data input
58
    fifo_enable_i,                      // Enable fifo (flushed when disabled)
59
    fifo_pop_i,                         // Pop data from the fifo
60
    fifo_push_i                         // Push new data to the fifo
61
);
62
 
63
// OUTPUTs
64
//=========
65
output         [3:0] fifo_cnt_o;        // Fifo counter
66
output        [15:0] fifo_data_o;       // Read data output
67
output               fifo_done_evt_o;   // Fifo has been emptied
68
output               fifo_empty_o;      // Fifo is currentely empty
69
output               fifo_full_o;       // Fifo is currentely full
70
output               fifo_ovfl_evt_o;   // Fifo overflow event
71
 
72
// INPUTs
73
//=========
74
input                mclk;              // Main system clock
75
input                puc_rst;           // Main system reset
76
 
77
input         [15:0] fifo_data_i;       // Read data input
78
input                fifo_enable_i;     // Enable fifo (flushed when disabled)
79
input                fifo_pop_i;        // Pop data from the fifo
80
input                fifo_push_i;       // Push new data to the fifo
81
 
82
 
83
//=============================================================================
84
// 1)  WIRE, REGISTERS AND PARAMETER DECLARATION
85
//=============================================================================
86
 
87
// Some parameter(s)
88
parameter    FIFO_EMPTY        =  4'h0,
89
             FIFO_FULL         =  4'hf;
90
 
91
// Others
92
reg    [3:0] fifo_cnt_o;
93
wire   [3:0] fifo_cnt_nxt;
94
 
95
 
96
//============================================================================
97
// 5) FIFO COUNTER
98
//============================================================================
99
 
100
// Control signals
101
wire      fifo_full_o     =  (fifo_cnt_o == FIFO_FULL);
102
wire      fifo_empty_o    =  (fifo_cnt_o == FIFO_EMPTY);
103
wire      fifo_push_int   =  fifo_push_i & !fifo_full_o;
104
wire      fifo_pop_int    =  fifo_pop_i  & !fifo_empty_o;
105
 
106
// Events
107
assign    fifo_done_evt_o = ~fifo_empty_o & (fifo_cnt_nxt == FIFO_EMPTY);
108
assign    fifo_ovfl_evt_o =  fifo_push_i  &  fifo_full_o;
109
 
110
 
111
// Fifo counter
112
assign fifo_cnt_nxt = ~fifo_enable_i                 ?  FIFO_EMPTY        : // Initialize
113
                      (fifo_push_int & fifo_pop_int) ?  fifo_cnt_o        : // Keep value (pop & push at the same time)
114
                       fifo_push_int                 ?  fifo_cnt_o + 3'h1 : // Push
115
                       fifo_pop_int                  ?  fifo_cnt_o - 3'h1 : // Pop
116
                                                        fifo_cnt_o;         // Hold
117
 
118
always @(posedge mclk or posedge puc_rst)
119
  if (puc_rst) fifo_cnt_o <= FIFO_EMPTY;
120
  else         fifo_cnt_o <= fifo_cnt_nxt;
121
 
122
 
123
//============================================================================
124
// 6) FIFO MEMORY & RD/WR POINTERS
125
//============================================================================
126
 
127
// Write pointer
128
reg [3:0] wr_ptr;
129
always @(posedge mclk or posedge puc_rst)
130
  if (puc_rst)                    wr_ptr  <=  4'h0;
131
  else if (~fifo_enable_i)        wr_ptr  <=  4'h0;
132
  else if (fifo_push_int)
133
    begin
134
       if (wr_ptr==(FIFO_FULL-1)) wr_ptr  <=  4'h0;
135
       else                       wr_ptr  <=  wr_ptr + 4'h1;
136
    end
137
 
138
// Memory
139
reg [15:0] fifo_mem [0:15];
140
always @(posedge mclk or posedge puc_rst)
141
  if (puc_rst)
142
    begin
143
       fifo_mem[0]      <=  16'h0000;
144
       fifo_mem[1]      <=  16'h0000;
145
       fifo_mem[2]      <=  16'h0000;
146
       fifo_mem[3]      <=  16'h0000;
147
       fifo_mem[4]      <=  16'h0000;
148
       fifo_mem[5]      <=  16'h0000;
149
       fifo_mem[6]      <=  16'h0000;
150
       fifo_mem[7]      <=  16'h0000;
151
       fifo_mem[8]      <=  16'h0000;
152
       fifo_mem[9]      <=  16'h0000;
153
       fifo_mem[10]     <=  16'h0000;
154
       fifo_mem[11]     <=  16'h0000;
155
       fifo_mem[12]     <=  16'h0000;
156
       fifo_mem[13]     <=  16'h0000;
157
       fifo_mem[14]     <=  16'h0000;
158
       fifo_mem[15]     <=  16'h0000;
159
    end
160
  else if (fifo_push_int)
161
    begin
162
       fifo_mem[wr_ptr] <=  fifo_data_i;
163
    end
164
 
165
// Read pointer
166
reg [3:0] rd_ptr;
167
always @(posedge mclk or posedge puc_rst)
168
  if (puc_rst)                    rd_ptr  <=  4'h0;
169
  else if (~fifo_enable_i)        rd_ptr  <=  4'h0;
170
  else if (fifo_pop_int)
171
    begin
172
       if (rd_ptr==(FIFO_FULL-1)) rd_ptr  <=  4'h0;
173
       else                       rd_ptr  <=  rd_ptr + 4'h1;
174
    end
175
 
176
assign fifo_data_o = fifo_mem[rd_ptr];
177
 
178
 
179
endmodule // ogfx_reg_fifo
180
 
181
`ifdef OGFX_NO_INCLUDE
182
`else
183
`include "openGFX430_undefines.v"
184
`endif

powered by: WebSVN 2.1.0

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