Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / common / verilog / misc / fifo.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: 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 fifo ();
36
37parameter ENTRY_BITS = 5;
38parameter DEPTH = 9;
39parameter PTR_BITS = 4;
40
41reg [(ENTRY_BITS-1):0] fifo [0:(DEPTH-1)];
42reg [(PTR_BITS-1):0] push_ptr;
43reg [(PTR_BITS-1):0] pop_ptr;
44
45integer i;
46
47`ifdef DEBUG_FIFO
48 wire [(ENTRY_BITS-1):0] fifo0 = fifo[0];
49 wire [(ENTRY_BITS-1):0] fifo1 = fifo[1];
50 wire [(ENTRY_BITS-1):0] fifo2 = fifo[2];
51 wire [(ENTRY_BITS-1):0] fifo3 = fifo[3];
52 wire [(ENTRY_BITS-1):0] fifo4 = fifo[4];
53 wire [(ENTRY_BITS-1):0] fifo5 = fifo[5];
54 wire [(ENTRY_BITS-1):0] fifo6 = fifo[6];
55 wire [(ENTRY_BITS-1):0] fifo7 = fifo[7];
56`endif
57
58//----------------------------------------------------------
59initial begin // {
60`ifdef PALLADIUM
61`else
62 #1;
63`endif
64 push_ptr = 3'b0;
65 pop_ptr = 3'b0;
66 for (i=0; i<=(DEPTH-1); i=i+1) begin
67 fifo[i] = 0;
68 end
69end // }
70
71//----------------------------------------------------------
72task push_fifo;
73input [(ENTRY_BITS-1):0] entry;
74
75 begin
76 fifo[push_ptr] <= entry;
77 if (push_ptr == (DEPTH-1)) begin // {
78 push_ptr <= 3'b0;
79 // Check for Overflow
80 if (pop_ptr == 3'b0) begin // {
81 `PR_ERROR ("fifo", `ERROR, "FIFO Overflow.");
82 end // }
83 end // }
84 else begin // {
85 push_ptr <= push_ptr + 1;
86 // Check for Overflow
87 if (pop_ptr == push_ptr+1) begin // {
88 `PR_ERROR ("fifo", `ERROR, "FIFO Overflow.");
89 end // }
90 end // }
91
92 end
93endtask
94
95//----------------------------------------------------------
96task pop_fifo;
97output [(ENTRY_BITS-1):0] entry;
98
99 begin
100 // Check for Underflow
101 if (pop_ptr == push_ptr) begin
102 `PR_ERROR ("fifo", `ERROR, "FIFO Underflow.");
103 end
104
105 entry = fifo[pop_ptr];
106 fifo[pop_ptr] <= 0; // clear entry that was popped
107 if (pop_ptr == (DEPTH-1)) begin // {
108 pop_ptr <= 3'b0;
109 end // }
110 else begin // {
111 pop_ptr <= pop_ptr + 1;
112 end // }
113 end
114endtask
115
116endmodule
117
118//----------------------------------------------------------
119//----------------------------------------------------------