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 6

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 6 olivier.gi
    fifo_cnt_o,                          // Fifo counter
47
    fifo_empty_cnt_o,                    // Fifo empty words counter
48
    fifo_data_o,                         // Read data output
49
    fifo_done_evt_o,                     // Fifo has been emptied
50
    fifo_empty_o,                        // Fifo is currentely empty
51
    fifo_full_o,                         // Fifo is currentely full
52
    fifo_ovfl_evt_o,                     // Fifo overflow event
53 3 olivier.gi
 
54
// INPUTs
55 6 olivier.gi
    mclk,                                // Main system clock
56
    puc_rst,                             // Main system reset
57 3 olivier.gi
 
58 6 olivier.gi
    fifo_data_i,                         // Read data input
59
    fifo_enable_i,                       // Enable fifo (flushed when disabled)
60
    fifo_pop_i,                          // Pop data from the fifo
61
    fifo_push_i                          // Push new data to the fifo
62 3 olivier.gi
);
63
 
64
// OUTPUTs
65
//=========
66 6 olivier.gi
output         [3:0] fifo_cnt_o;         // Fifo counter
67
output         [3:0] fifo_empty_cnt_o;   // Fifo empty word counter
68
output        [15:0] fifo_data_o;        // Read data output
69
output               fifo_done_evt_o;    // Fifo has been emptied
70
output               fifo_empty_o;       // Fifo is currentely empty
71
output               fifo_full_o;        // Fifo is currentely full
72
output               fifo_ovfl_evt_o;    // Fifo overflow event
73 3 olivier.gi
 
74
// INPUTs
75
//=========
76 6 olivier.gi
input                mclk;               // Main system clock
77
input                puc_rst;            // Main system reset
78 3 olivier.gi
 
79 6 olivier.gi
input         [15:0] fifo_data_i;        // Read data input
80
input                fifo_enable_i;      // Enable fifo (flushed when disabled)
81
input                fifo_pop_i;         // Pop data from the fifo
82
input                fifo_push_i;        // Push new data to the fifo
83 3 olivier.gi
 
84
 
85
//=============================================================================
86
// 1)  WIRE, REGISTERS AND PARAMETER DECLARATION
87
//=============================================================================
88
 
89
// Some parameter(s)
90
parameter    FIFO_EMPTY        =  4'h0,
91
             FIFO_FULL         =  4'hf;
92
 
93
// Others
94
reg    [3:0] fifo_cnt_o;
95
wire   [3:0] fifo_cnt_nxt;
96
 
97
 
98
//============================================================================
99
// 5) FIFO COUNTER
100
//============================================================================
101
 
102
// Control signals
103 6 olivier.gi
assign    fifo_full_o        =  (fifo_cnt_o == FIFO_FULL);
104
assign    fifo_empty_o       =  (fifo_cnt_o == FIFO_EMPTY);
105
assign    fifo_empty_cnt_o   =  (FIFO_FULL-fifo_cnt_o);
106
wire      fifo_push_int      =  fifo_push_i & !fifo_full_o;
107
wire      fifo_pop_int       =  fifo_pop_i  & !fifo_empty_o;
108 3 olivier.gi
 
109
// Events
110
assign    fifo_done_evt_o = ~fifo_empty_o & (fifo_cnt_nxt == FIFO_EMPTY);
111
assign    fifo_ovfl_evt_o =  fifo_push_i  &  fifo_full_o;
112
 
113
 
114
// Fifo counter
115
assign fifo_cnt_nxt = ~fifo_enable_i                 ?  FIFO_EMPTY        : // Initialize
116
                      (fifo_push_int & fifo_pop_int) ?  fifo_cnt_o        : // Keep value (pop & push at the same time)
117
                       fifo_push_int                 ?  fifo_cnt_o + 3'h1 : // Push
118
                       fifo_pop_int                  ?  fifo_cnt_o - 3'h1 : // Pop
119
                                                        fifo_cnt_o;         // Hold
120
 
121
always @(posedge mclk or posedge puc_rst)
122
  if (puc_rst) fifo_cnt_o <= FIFO_EMPTY;
123
  else         fifo_cnt_o <= fifo_cnt_nxt;
124
 
125
 
126
//============================================================================
127
// 6) FIFO MEMORY & RD/WR POINTERS
128
//============================================================================
129
 
130
// Write pointer
131
reg [3:0] wr_ptr;
132
always @(posedge mclk or posedge puc_rst)
133
  if (puc_rst)                    wr_ptr  <=  4'h0;
134
  else if (~fifo_enable_i)        wr_ptr  <=  4'h0;
135
  else if (fifo_push_int)
136
    begin
137
       if (wr_ptr==(FIFO_FULL-1)) wr_ptr  <=  4'h0;
138
       else                       wr_ptr  <=  wr_ptr + 4'h1;
139
    end
140
 
141
// Memory
142
reg [15:0] fifo_mem [0:15];
143
always @(posedge mclk or posedge puc_rst)
144
  if (puc_rst)
145
    begin
146
       fifo_mem[0]      <=  16'h0000;
147
       fifo_mem[1]      <=  16'h0000;
148
       fifo_mem[2]      <=  16'h0000;
149
       fifo_mem[3]      <=  16'h0000;
150
       fifo_mem[4]      <=  16'h0000;
151
       fifo_mem[5]      <=  16'h0000;
152
       fifo_mem[6]      <=  16'h0000;
153
       fifo_mem[7]      <=  16'h0000;
154
       fifo_mem[8]      <=  16'h0000;
155
       fifo_mem[9]      <=  16'h0000;
156
       fifo_mem[10]     <=  16'h0000;
157
       fifo_mem[11]     <=  16'h0000;
158
       fifo_mem[12]     <=  16'h0000;
159
       fifo_mem[13]     <=  16'h0000;
160
       fifo_mem[14]     <=  16'h0000;
161
       fifo_mem[15]     <=  16'h0000;
162
    end
163
  else if (fifo_push_int)
164
    begin
165
       fifo_mem[wr_ptr] <=  fifo_data_i;
166
    end
167
 
168
// Read pointer
169
reg [3:0] rd_ptr;
170
always @(posedge mclk or posedge puc_rst)
171
  if (puc_rst)                    rd_ptr  <=  4'h0;
172
  else if (~fifo_enable_i)        rd_ptr  <=  4'h0;
173
  else if (fifo_pop_int)
174
    begin
175
       if (rd_ptr==(FIFO_FULL-1)) rd_ptr  <=  4'h0;
176
       else                       rd_ptr  <=  rd_ptr + 4'h1;
177
    end
178
 
179
assign fifo_data_o = fifo_mem[rd_ptr];
180
 
181
 
182
endmodule // ogfx_reg_fifo
183
 
184
`ifdef OGFX_NO_INCLUDE
185
`else
186
`include "openGFX430_undefines.v"
187
`endif

powered by: WebSVN 2.1.0

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