Changed behavior of the simulation generic models
[or1200.git] / rtl / verilog / or1200_spram_32x24.v
blob34a01f439c7498322f751f5ff1bba8eb70463d9b
1 //////////////////////////////////////////////////////////////////////
2 //// ////
3 //// Generic Single-Port Synchronous RAM ////
4 //// ////
5 //// This file is part of memory library available from ////
6 //// http://www.opencores.org/cvsweb.shtml/generic_memories/ ////
7 //// ////
8 //// Description ////
9 //// This block is a wrapper with common single-port ////
10 //// synchronous memory interface for different ////
11 //// types of ASIC and FPGA RAMs. Beside universal memory ////
12 //// interface it also provides behavioral model of generic ////
13 //// single-port synchronous RAM. ////
14 //// It should be used in all OPENCORES designs that want to be ////
15 //// portable accross different target technologies and ////
16 //// independent of target memory. ////
17 //// ////
18 //// Supported ASIC RAMs are: ////
19 //// - Artisan Single-Port Sync RAM ////
20 //// - Avant! Two-Port Sync RAM (*) ////
21 //// - Virage Single-Port Sync RAM ////
22 //// - Virtual Silicon Single-Port Sync RAM ////
23 //// ////
24 //// Supported FPGA RAMs are: ////
25 //// - Xilinx Virtex RAMB4_S16 ////
26 //// - Altera LPM ////
27 //// ////
28 //// To Do: ////
29 //// - xilinx rams need external tri-state logic ////
30 //// - fix avant! two-port ram ////
31 //// - add additional RAMs ////
32 //// ////
33 //// Author(s): ////
34 //// - Damjan Lampret, lampret@opencores.org ////
35 //// ////
36 //////////////////////////////////////////////////////////////////////
37 //// ////
38 //// Copyright (C) 2000 Authors and OPENCORES.ORG ////
39 //// ////
40 //// This source file may be used and distributed without ////
41 //// restriction provided that this copyright statement is not ////
42 //// removed from the file and that any derivative work contains ////
43 //// the original copyright notice and the associated disclaimer. ////
44 //// ////
45 //// This source file is free software; you can redistribute it ////
46 //// and/or modify it under the terms of the GNU Lesser General ////
47 //// Public License as published by the Free Software Foundation; ////
48 //// either version 2.1 of the License, or (at your option) any ////
49 //// later version. ////
50 //// ////
51 //// This source is distributed in the hope that it will be ////
52 //// useful, but WITHOUT ANY WARRANTY; without even the implied ////
53 //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
54 //// PURPOSE. See the GNU Lesser General Public License for more ////
55 //// details. ////
56 //// ////
57 //// You should have received a copy of the GNU Lesser General ////
58 //// Public License along with this source; if not, download it ////
59 //// from http://www.opencores.org/lgpl.shtml ////
60 //// ////
61 //////////////////////////////////////////////////////////////////////
63 // CVS Revision History
65 // $Log$
66 // Revision 1.2 2004/06/08 18:15:32 lampret
67 // Changed behavior of the simulation generic models
69 // Revision 1.1 2004/04/08 11:00:46 simont
70 // Add support for 512B instruction cache.
75 // synopsys translate_off
76 `include "timescale.v"
77 // synopsys translate_on
78 `include "or1200_defines.v"
80 module or1200_spram_32x24(
81 `ifdef OR1200_BIST
82 // RAM BIST
83 mbist_si_i, mbist_so_o, mbist_ctrl_i,
84 `endif
85 // Generic synchronous single-port RAM interface
86 clk, rst, ce, we, oe, addr, di, doq
90 // Default address and data buses width
92 parameter aw = 5;
93 parameter dw = 24;
95 `ifdef OR1200_BIST
97 // RAM BIST
99 input mbist_si_i;
100 input [`OR1200_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;
101 output mbist_so_o;
102 `endif
105 // Generic synchronous single-port RAM interface
107 input clk; // Clock
108 input rst; // Reset
109 input ce; // Chip enable input
110 input we; // Write enable input
111 input oe; // Output enable input
112 input [aw-1:0] addr; // address bus inputs
113 input [dw-1:0] di; // input data bus
114 output [dw-1:0] doq; // output data bus
117 // Internal wires and registers
119 wire [31:24] unconnected;
121 `ifdef OR1200_ARTISAN_SSP
122 `else
123 `ifdef OR1200_VIRTUALSILICON_SSP
124 `else
125 `ifdef OR1200_BIST
126 `endif
127 `endif
128 `endif
130 `ifdef OR1200_ARTISAN_SSP
133 // Instantiation of ASIC memory:
135 // Artisan Synchronous Single-Port RAM (ra1sh)
137 `ifdef UNUSED
138 `else
139 `ifdef OR1200_BIST
140 `else
141 `endif
142 `endif
143 `ifdef OR1200_BIST
144 // RAM BIST
145 `endif
147 `else
149 `ifdef OR1200_AVANT_ATP
152 // Instantiation of ASIC memory:
154 // Avant! Asynchronous Two-Port RAM
157 `else
159 `ifdef OR1200_VIRAGE_SSP
162 // Instantiation of ASIC memory:
164 // Virage Synchronous 1-port R/W RAM
167 `else
169 `ifdef OR1200_VIRTUALSILICON_SSP
172 // Instantiation of ASIC memory:
174 // Virtual Silicon Single-Port Synchronous SRAM
176 `ifdef UNUSED
177 `else
178 `ifdef OR1200_BIST
179 `else
180 `endif
181 `endif
182 `ifdef OR1200_BIST
183 // RAM BIST
184 `endif
186 `else
188 `ifdef OR1200_XILINX_RAMB4
191 // Instantiation of FPGA memory:
193 // Virtex/Spartan2
197 // Block 0
199 RAMB4_S16 ramb4_s16_0(
200 .CLK(clk),
201 .RST(rst),
202 .ADDR({3'h0, addr}),
203 .DI(di[15:0]),
204 .EN(ce),
205 .WE(we),
206 .DO(doq[15:0])
210 // Block 1
212 RAMB4_S16 ramb4_s16_1(
213 .CLK(clk),
214 .RST(rst),
215 .ADDR({3'h0, addr}),
216 .DI({8'h00, di[23:16]}),
217 .EN(ce),
218 .WE(we),
219 .DO({unconnected, doq[23:16]})
222 `else
224 `ifdef OR1200_ALTERA_LPM
227 // Instantiation of FPGA memory:
229 // Altera LPM
231 // Added By Jamil Khatib
235 `else
238 // Generic single-port synchronous RAM model
242 // Generic RAM's registers and wires
244 reg [dw-1:0] mem [(1<<aw)-1:0]; // RAM content
245 reg [aw-1:0] addr_reg; // RAM address register
248 // Data output drivers
250 assign doq = (oe) ? mem[addr_reg] : {dw{1'b0}};
253 // RAM address register
255 always @(posedge clk or posedge rst)
256 if (rst)
257 addr_reg <= #1 {aw{1'b0}};
258 else if (ce)
259 addr_reg <= #1 addr;
262 // RAM write
264 always @(posedge clk)
265 if (ce && we)
266 mem[addr] <= #1 di;
268 `endif // !OR1200_ALTERA_LPM
269 `endif // !OR1200_XILINX_RAMB4_S16
270 `endif // !OR1200_VIRTUALSILICON_SSP
271 `endif // !OR1200_VIRAGE_SSP
272 `endif // !OR1200_AVANT_ATP
273 `endif // !OR1200_ARTISAN_SSP
275 endmodule