Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / design / sys / iop / dmu / rtl / dmu_dsn_mondo_fifo.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: dmu_dsn_mondo_fifo.v
4// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6//
7// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; version 2 of the License.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// For the avoidance of doubt, and except that if any non-GPL license
23// choice is available it will apply instead, Sun elects to use only
24// the General Public License version 2 (GPLv2) at this time for any
25// software where a choice of GPL license versions is made
26// available with the language indicating that GPLv2 or any later version
27// may be used, or where a choice of which version of the GPL is applied is
28// otherwise unspecified.
29//
30// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31// CA 95054 USA or visit www.sun.com if you need additional information or
32// have any questions.
33//
34// ========== Copyright Header End ============================================
35module dmu_dsn_mondo_fifo (
36 clk,
37 rst_l,
38
39 data_in,
40 write,
41
42 data_out,
43 read,
44
45// fifo_full,
46// fifo_almost_full,
47 fifo_empty
48
49 );
50
51
52//############################################################################
53// PARAMETERS
54//############################################################################
55parameter FIFO_WIDTH = 8;
56parameter FIFO_DEPTH = 3'd4;
57parameter FIFO_PTR_WDTH = 2;
58parameter FIFO_DEPTH_MINUS_ONE = 2'd3;
59
60
61//############################################################################
62// PORT DECLARATIONS
63//############################################################################
64
65 input clk; // The input clock
66 input rst_l; // The fifo rst_l
67
68 input [FIFO_WIDTH - 1:0] data_in; // The input data
69 input write; // The syncronous write strobe
70
71 output [FIFO_WIDTH - 1:0] data_out; // The output data
72 input read; // The syncronous read strobe
73
74// output fifo_full; // The fifo full flag
75// output fifo_almost_full; // The fifo almost full flag (full -1)
76 output fifo_empty; // The fifo empty flag
77
78
79//############################################################################
80// SIGNAL DECLARATIONS
81//############################################################################
82
83 //**************************************************
84 // Registers that Are Flops
85 //**************************************************
86 reg [FIFO_WIDTH - 1:0] fifo_ram[0:FIFO_DEPTH -1'b1]; // The fifo storge arrary
87 reg [FIFO_PTR_WDTH - 1:0] wr_ptr, rd_ptr; // Read and write pointers
88 reg [FIFO_PTR_WDTH:0] fifo_count; // Number of entries in fifo
89 reg over_flow_err, under_flow_err; // Under flow and over flow errors
90
91
92 //**************************************************
93 // Registers that Are NOT Flops
94 //**************************************************
95 reg [FIFO_PTR_WDTH:0] n_fifo_count; // Next Number of entries in fifo
96 reg n_over_flow_err, n_under_flow_err; // Next Under flow and over flow errors
97
98 //**************************************************
99 // Wires
100 //**************************************************
101 wire [FIFO_PTR_WDTH - 1:0] n_wr_ptr, n_rd_ptr; // Next Read and write pointers
102// wire fifo_full, fifo_empty; // Full and empty signals
103 wire fifo_empty; // Full and empty signals
104
105 wire [FIFO_WIDTH - 1:0] data_out;
106
107//############################################################################
108// ZERO IN CHECKERS
109//############################################################################
110
111// A fifo checker for this fifo
112
113//0in fifo -enq write -deq read -depth FIFO_DEPTH -enq_data data_in -deq_data data_out
114
115// ***********************************************
116// If this is a write access, put the data on the
117// input bus into the location pointed to by the
118// fifo write pointer
119//************************************************
120always @ (posedge clk)
121 if (~rst_l)
122 begin : scb_reg_reset
123 integer i;
124 for (i=0; i<4; i=i+1)
125 begin
126 fifo_ram[i] <= 8'b0 ;
127 end
128 end
129 else begin
130 if (write) begin
131 fifo_ram[wr_ptr] <= data_in;
132 end
133end
134
135//***********************************************
136// If this is a read get the data that is in
137// the location pointed to by the read pointer
138// and put it onto the output bus
139//************************************************
140
141assign data_out = fifo_ram[rd_ptr];
142
143
144//************************************************
145// Increment the write pointer on every write and
146// the read pointer on every read
147//************************************************/
148always @ (posedge clk)
149 if (!rst_l)
150 begin
151 wr_ptr <= 2'b00;
152 rd_ptr <= 2'b00;
153 end
154 else
155 begin
156 wr_ptr <= n_wr_ptr;
157 rd_ptr <= n_rd_ptr;
158 end
159
160assign n_wr_ptr = write ? ((wr_ptr == FIFO_DEPTH_MINUS_ONE) ? 2'b00 : (wr_ptr + 2'b01)) : wr_ptr;
161assign n_rd_ptr = read ? ((rd_ptr == FIFO_DEPTH_MINUS_ONE) ? 2'b00 : (rd_ptr + 2'b01)) : rd_ptr;
162
163
164
165//*********************************************
166// The fifo counter increment on every write and
167// decrement on every read
168//**********************************************/
169
170always @ (posedge clk)
171 if (!rst_l)
172 begin
173 fifo_count <= 3'b000;
174 over_flow_err <= 1'b0;
175 under_flow_err <= 1'b0;
176 end
177 else
178 begin
179 fifo_count <= n_fifo_count;
180 over_flow_err <= n_over_flow_err;
181 under_flow_err <= n_under_flow_err;
182 end
183
184
185assign fifo_empty = (fifo_count == 3'b000);
186
187//assign fifo_full = (fifo_count == FIFO_DEPTH);
188
189//assign fifo_almost_full = (fifo_count == FIFO_DEPTH - 1) |
190// (fifo_count == FIFO_DEPTH);
191
192
193always @ (write or read or over_flow_err or under_flow_err or fifo_count)
194 begin
195 n_fifo_count = 3'b000;
196 n_over_flow_err = 1'b0;
197 n_under_flow_err = 1'b0;
198 case ({write, read})
199 2'b00:
200 begin
201 n_fifo_count = fifo_count; // No transaction
202 n_over_flow_err = over_flow_err;
203 n_under_flow_err = under_flow_err;
204 end
205
206 2'b01:
207 begin
208 n_fifo_count = (fifo_count == 3'b000) ? 3'b000 : fifo_count - 3'b001;
209 n_over_flow_err = 1'b0;
210 n_under_flow_err = (fifo_count == 3'b000) ? 1'b1 : 1'b0; // Under flow case should not happen
211 end
212
213 2'b10:
214 begin
215 n_fifo_count = (fifo_count == FIFO_DEPTH) ? FIFO_DEPTH : fifo_count + 3'b001;
216 n_over_flow_err = (fifo_count == FIFO_DEPTH) ? 1'b1 : 1'b0; // Over flow case shuld not happen
217 n_under_flow_err = 1'b0;
218 end
219
220 2'b11:
221 begin
222 n_fifo_count = fifo_count; // both transaction
223 n_over_flow_err = 1'b0; // Over flow case shuld not happen
224 n_under_flow_err = 1'b0;
225 end
226 default: begin
227 n_fifo_count = 3'b000; //0in < fire -message " got x's in dsn_mondo_fifo"
228 n_over_flow_err = 1'b0;
229 n_under_flow_err = 1'b0;
230 end
231
232 endcase
233 end
234
235endmodule