Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / verilog / mem / fbdimm / library / fifo / 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 fbd_fifo (rdata,wfull,rempty,wdata,winc,wclk,wrst_n,rinc,rclk,rrst_n,count);
36parameter DSIZE = 72;
37parameter ASIZE = 6;
38
39output [DSIZE-1:0] rdata;
40output wfull;
41output rempty;
42input [DSIZE-1:0] wdata;
43input winc,wclk,wrst_n;
44input rinc,rclk,rrst_n;
45output [ASIZE-1:0] count;
46reg [ASIZE-1:0] count_reg;
47
48wire [ASIZE-1:0] waddr,raddr;
49wire [ASIZE:0] wptr,rptr,wrptr2,rwptr2;
50
51wire [ASIZE-1:0] count = count_reg;
52
53
54
55sync_r2w #(ASIZE) sync_r2w ( .wrptr2(wrptr2),
56 .rptr(rptr),
57 .wclk(wclk),
58 .wrst_n(wrst_n));
59
60sync_w2r #(ASIZE) sync_w2r( .rwptr2(rwptr2),
61 .wptr(wptr),
62 .rclk(rclk),
63 .rrst_n(rrst_n));
64
65fifomem #(DSIZE,ASIZE) fifomem ( .rdata(rdata),
66 .wdata(wdata),
67 .waddr(waddr),
68 .raddr(raddr),
69 .wclken(winc),
70 .wclk(wclk));
71
72rptr_empty #(ASIZE) rptr_empty ( .rempty(rempty),
73 .raddr(raddr),
74 .rptr(rptr),
75 .rwptr2(rwptr2),
76 .rinc(rinc),
77 .rclk(rclk),
78 .rrst_n(rrst_n));
79
80wptr_full #(ASIZE) wptr_full ( .wfull(wfull),
81 .waddr(waddr),
82 .wptr(wptr),
83 .wrptr2(wrptr2),
84 .winc(winc),
85 .wclk(wclk),
86 .wrst_n(wrst_n));
87
88
89endmodule
90
91
92module beh_fifo (rdata,wfull,rempty,wdata,winc,wclk,wrst_n,rinc,rclk,rrst_n,inv);
93parameter DSIZE = 72;
94parameter ASIZE = 6;
95
96output [DSIZE-1:0] rdata;
97output wfull;
98output rempty;
99input [DSIZE-1:0] wdata;
100input winc,wclk,wrst_n;
101input rinc,rclk,rrst_n;
102input inv;
103wire [ASIZE-1:0] waddr,raddr;
104reg [ASIZE:0] wptr,wrptr1,wrptr2,wrptr3;
105reg [ASIZE:0] rptr,rwptr1,rwptr2,rwptr3;
106
107parameter MEMDEPTH = 1<<ASIZE;
108
109`ifdef AXIS
110wire [DSIZE-1:0] axis_rdata ;
111wire [DSIZE-1:0] axis_wdata = wdata;
112wire axis_winc = winc;
113wire axis_rinc = rinc;
114wire axis_rclk = rclk;
115wire axis_wclk = wclk;
116wire [ASIZE-1:0] axis_rptr = (rinc && !rempty) ? rptr[ASIZE-1:0]+1 : rptr[ASIZE-1:0];
117wire [ASIZE-1:0] axis_wptr = wptr[ASIZE-1:0];
118
119
120`ifdef PALLADIUM
121
122reg [(DSIZE - 1):0] ex_mem [0:MEMDEPTH-1];
123reg [(DSIZE - 1):0] axis_rdata_reg;
124
125assign axis_rdata=axis_rdata_reg;
126always @ (posedge axis_rclk)
127 axis_rdata_reg <= ex_mem[axis_rptr];
128
129always @ (posedge axis_wclk)
130begin
131 if (axis_winc)
132 ex_mem[axis_wptr] <= axis_wdata;
133
134end
135
136`else
137axis_smem #(ASIZE,DSIZE,2,0) ex_mem ( {axis_rdata,{DSIZE{1'bz}}}, // output port
138 {{DSIZE{1'bz}},axis_wdata}, // input port
139 {axis_rptr,axis_wptr}, //address port
140 {1'b0,axis_winc}, // write enable
141 {1'b1,1'b1}, // chip enable
142 {axis_rclk,axis_wclk}, // clock
143 {{DSIZE{1'bz}},{DSIZE{1'bz}}} // write masks
144 );
145
146`endif // PALLADIUM
147
148assign rdata = axis_rdata;
149`else
150 reg [DSIZE-1:0] ex_mem [0:MEMDEPTH-1];
151`endif
152
153
154`ifdef AXIS
155initial begin
156{rwptr3,rwptr2,rwptr1} = 0;
157 rptr = 0;
158 {wrptr3,wrptr2,wrptr1} =0;
159 wptr = 0;
160end
161
162 always@(posedge wclk)
163begin
164 if ( !wrst_n || inv) wptr <= 0;
165 else if (winc && ~wfull) begin
166 wptr <= wptr+1;
167 end
168end
169
170always@(posedge wclk) // or negedge wrst_n)
171 if (!wrst_n ) {wrptr3,wrptr2,wrptr1} <=0;
172 else if ( inv ) {wrptr3,wrptr2,wrptr1} <=0;
173 else {wrptr3,wrptr2,wrptr1} <= {wrptr2,wrptr1,rptr} ;
174
175always@(posedge rclk ) //or negedge rrst_n)
176 if (!rrst_n ) rptr <=0;
177 else if ( inv) rptr <=0;
178 else if ( rinc && !rempty ) rptr <= rptr+1;
179
180always@(posedge rclk ) //or negedge rrst_n)
181 if (!rrst_n ) {rwptr3,rwptr2,rwptr1} <=0;
182 else if ( inv ) {rwptr3,rwptr2,rwptr1} <=0;
183 else {rwptr3,rwptr2,rwptr1} <= {rwptr2,rwptr1,wptr} ;
184
185`else
186// VCS control logic
187
188initial begin
189{rwptr3,rwptr2,rwptr1} = 0;
190 rptr = 0;
191 {wrptr3,wrptr2,wrptr1} =0;
192 wptr = 0;
193end
194
195
196assign rdata=ex_mem[rptr[ASIZE-1:0]];
197
198always@(posedge wclk)
199begin
200 if ( !wrst_n || inv) wptr <= 0;
201 else if (winc && ~wfull) begin
202 ex_mem[wptr[ASIZE-1:0]] <= wdata;
203 wptr <= wptr+1;
204 end
205end
206
207always@(posedge wclk)
208 if (!wrst_n || inv ) {wrptr3,wrptr2,wrptr1} <=0;
209 else {wrptr3,wrptr2,wrptr1} <= {wrptr2,wrptr1,rptr} ;
210
211always@(posedge rclk)
212 if (!rrst_n || inv) rptr <=0;
213 else if ( rinc && !rempty ) rptr <= rptr+1;
214
215always@(posedge rclk)
216 if (!rrst_n || inv ) {rwptr3,rwptr2,rwptr1} <=0;
217 else {rwptr3,rwptr2,rwptr1} <= {rwptr2,rwptr1,wptr} ;
218
219`endif
220
221assign rempty = (rptr[ASIZE:0] == rwptr3[ASIZE:0]) ? 1'b1 : 1'b0;
222assign wfull = (( wptr[ASIZE-1:0] == wrptr3[ASIZE-1:0]) & ( wptr[ASIZE] != wrptr3[ASIZE]));
223endmodule
224