OpenCores
URL https://opencores.org/ocsvn/sd_card_controller/sd_card_controller/trunk

Subversion Repositories sd_card_controller

[/] [sd_card_controller/] [trunk/] [rtl/] [verilog/] [generic_dpram.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 rozpruwacz
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Generic Dual-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 dual-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
////  dual-port synchronous RAM.                                  ////
14
////  It also contains a fully synthesizeable model for FPGAs.    ////
15
////  It should be used in all OPENCORES designs that want to be  ////
16
////  portable accross different target technologies and          ////
17
////  independent of target memory.                               ////
18
////                                                              ////
19
////  Supported ASIC RAMs are:                                    ////
20
////  - Artisan Dual-Port Sync RAM                                ////
21
////  - Avant! Two-Port Sync RAM (*)                              ////
22
////  - Virage 2-port Sync RAM                                    ////
23
////                                                              ////
24
////  Supported FPGA RAMs are:                                    ////
25
////  - Generic FPGA (VENDOR_FPGA)                                ////
26
////    Tested RAMs: Altera, Xilinx                               ////
27
////    Synthesis tools: LeonardoSpectrum, Synplicity             ////
28
////  - Xilinx (VENDOR_XILINX)                                    ////
29
////  - Altera (VENDOR_ALTERA)                                    ////
30
////                                                              ////
31
////  To Do:                                                      ////
32
////   - fix Avant!                                               ////
33
////   - add additional RAMs (VS etc)                             ////
34
////                                                              ////
35
////  Author(s):                                                  ////
36
////      - Richard Herveille, richard@asics.ws                   ////
37
////      - Damjan Lampret, lampret@opencores.org                 ////
38
////                                                              ////
39
//////////////////////////////////////////////////////////////////////
40
////                                                              ////
41
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
42
////                                                              ////
43
//// This source file may be used and distributed without         ////
44
//// restriction provided that this copyright statement is not    ////
45
//// removed from the file and that any derivative work contains  ////
46
//// the original copyright notice and the associated disclaimer. ////
47
////                                                              ////
48
//// This source file is free software; you can redistribute it   ////
49
//// and/or modify it under the terms of the GNU Lesser General   ////
50
//// Public License as published by the Free Software Foundation; ////
51
//// either version 2.1 of the License, or (at your option) any   ////
52
//// later version.                                               ////
53
////                                                              ////
54
//// This source is distributed in the hope that it will be       ////
55
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
56
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
57
//// PURPOSE.  See the GNU Lesser General Public License for more ////
58
//// details.                                                     ////
59
////                                                              ////
60
//// You should have received a copy of the GNU Lesser General    ////
61
//// Public License along with this source; if not, download it   ////
62
//// from http://www.opencores.org/lgpl.shtml                     ////
63
////                                                              ////
64
//////////////////////////////////////////////////////////////////////
65
//
66
// CVS Revision History
67
//
68
// $Log: not supported by cvs2svn $
69
// Revision 1.3  2001/11/09 00:34:18  samg
70
// minor changes: unified with all common rams
71
//
72
// Revision 1.2  2001/11/08 19:11:31  samg
73
// added valid checks to behvioral model
74
//
75
// Revision 1.1.1.1  2001/09/14 09:57:10  rherveille
76
// Major cleanup.
77
// Files are now compliant to Altera & Xilinx memories.
78
// Memories are now compatible, i.e. drop-in replacements.
79
// Added synthesizeable generic FPGA description.
80
// Created "generic_memories" cvs entry.
81
//
82
// Revision 1.1.1.2  2001/08/21 13:09:27  damjan
83
// *** empty log message ***
84
//
85
// Revision 1.1  2001/08/20 18:23:20  damjan
86
// Initial revision
87
//
88
// Revision 1.1  2001/08/09 13:39:33  lampret
89
// Major clean-up.
90
//
91
// Revision 1.2  2001/07/30 05:38:02  lampret
92
// Adding empty directories required by HDL coding guidelines
93
//
94
//
95
 
96
//`include "timescale.v"
97
 
98
`define VENDOR_FPGA
99
//`define VENDOR_XILINX
100
//`define VENDOR_ALTERA
101
 
102
module generic_dpram(
103
        // Generic synchronous dual-port RAM interface
104
        rclk, rrst, rce, oe, raddr, do,
105
        wclk, wrst, wce, we, waddr, di
106
);
107
 
108
        //
109
        // Default address and data buses width
110
        //
111
        parameter aw = 5;  // number of bits in address-bus
112
        parameter dw = 16; // number of bits in data-bus
113
 
114
        //
115
        // Generic synchronous double-port RAM interface
116
        //
117
        // read port
118
        input           rclk;  // read clock, rising edge trigger
119
        input           rrst;  // read port reset, active high
120
        input           rce;   // read port chip enable, active high
121
        input           oe;        // output enable, active high
122
        input  [aw-1:0] raddr; // read address
123
        output [dw-1:0] do;    // data output
124
 
125
        // write port
126
        input          wclk;  // write clock, rising edge trigger
127
        input          wrst;  // write port reset, active high
128
        input          wce;   // write port chip enable, active high
129
        input          we;    // write enable, active high
130
        input [aw-1:0] waddr; // write address
131
        input [dw-1:0] di;    // data input
132
 
133
        //
134
        // Module body
135
        //
136
 
137
`ifdef VENDOR_FPGA
138
        //
139
        // Instantiation synthesizeable FPGA memory
140
        //
141
        // This code has been tested using LeonardoSpectrum and Synplicity.
142
        // The code correctly instantiates Altera EABs and Xilinx BlockRAMs.
143
        //
144
        reg [dw-1:0] mem [(1<<aw) -1:0]; // instantiate memory
145
        reg [aw-1:0] ra;                 // register read address
146
 
147
        // read operation
148
        always @(posedge rclk)
149
          if (rce)
150
            ra <= raddr;
151
 
152
        assign do = mem[ra];
153
 
154
        // write operation
155
        always@(posedge wclk)
156
                if (we && wce)
157
                        mem[waddr] <= di;
158
 
159
`else
160
 
161
`ifdef VENDOR_XILINX
162
        //
163
        // Instantiation of FPGA memory:
164
        //
165
        // Virtex/Spartan2 BlockRAMs
166
        //
167
        xilinx_ram_dp xilinx_ram(
168
                // read port
169
                .CLKA(rclk),
170
                .RSTA(rrst),
171
                .ENA(rce),
172
                .ADDRA(raddr),
173
                .DIA( {dw{1'b0}} ),
174
                .WEA(1'b0),
175
                .DOA(do),
176
 
177
                // write port
178
                .CLKB(wclk),
179
                .RSTB(wrst),
180
                .ENB(wce),
181
                .ADDRB(waddr),
182
                .DIB(di),
183
                .WEB(we),
184
                .DOB()
185
        );
186
 
187
        defparam
188
                xilinx_ram.dwidth = dw,
189
                xilinx_ram.awidth = aw;
190
 
191
`else
192
 
193
`ifdef VENDOR_ALTERA
194
        //
195
        // Instantiation of FPGA memory:
196
        //
197
        // Altera FLEX/APEX EABs
198
        //
199
        altera_ram_dp altera_ram(
200
                // read port
201
                .rdclock(rclk),
202
                .rdclocken(rce),
203
                .rdaddress(raddr),
204
                .q(do),
205
 
206
                // write port
207
                .wrclock(wclk),
208
                .wrclocken(wce),
209
                .wren(we),
210
                .wraddress(waddr),
211
                .data(di)
212
        );
213
 
214
        defparam
215
                altera_ram.dwidth = dw,
216
                altera_ram.awidth = aw;
217
 
218
`else
219
 
220
`ifdef VENDOR_ARTISAN
221
 
222
        //
223
        // Instantiation of ASIC memory:
224
        //
225
        // Artisan Synchronous Double-Port RAM (ra2sh)
226
        //
227
        art_hsdp #(dw, 1<<aw, aw) artisan_sdp(
228
                // read port
229
                .qa(do),
230
                .clka(rclk),
231
                .cena(~rce),
232
                .wena(1'b1),
233
                .aa(raddr),
234
                .da( {dw{1'b0}} ),
235
                .oena(~oe),
236
 
237
                // write port
238
                .qb(),
239
                .clkb(wclk),
240
                .cenb(~wce),
241
                .wenb(~we),
242
                .ab(waddr),
243
                .db(di),
244
                .oenb(1'b1)
245
        );
246
 
247
`else
248
 
249
`ifdef VENDOR_AVANT
250
 
251
        //
252
        // Instantiation of ASIC memory:
253
        //
254
        // Avant! Asynchronous Two-Port RAM
255
        //
256
        avant_atp avant_atp(
257
                .web(~we),
258
                .reb(),
259
                .oeb(~oe),
260
                .rcsb(),
261
                .wcsb(),
262
                .ra(raddr),
263
                .wa(waddr),
264
                .di(di),
265
                .do(do)
266
        );
267
 
268
`else
269
 
270
`ifdef VENDOR_VIRAGE
271
 
272
        //
273
        // Instantiation of ASIC memory:
274
        //
275
        // Virage Synchronous 2-port R/W RAM
276
        //
277
        virage_stp virage_stp(
278
                // read port
279
                .CLKA(rclk),
280
                .MEA(rce_a),
281
                .ADRA(raddr),
282
                .DA( {dw{1'b0}} ),
283
                .WEA(1'b0),
284
                .OEA(oe),
285
                .QA(do),
286
 
287
                // write port
288
                .CLKB(wclk),
289
                .MEB(wce),
290
                .ADRB(waddr),
291
                .DB(di),
292
                .WEB(we),
293
                .OEB(1'b1),
294
                .QB()
295
        );
296
 
297
`else
298
 
299
        //
300
        // Generic dual-port synchronous RAM model
301
        //
302
 
303
        //
304
        // Generic RAM's registers and wires
305
        //
306
        reg     [dw-1:0] mem [(1<<aw)-1:0]; // RAM content
307
        reg     [dw-1:0] do_reg;            // RAM data output register
308
 
309
        //
310
        // Data output drivers
311
        //
312
        assign do = (oe & rce) ? do_reg : {dw{1'bz}};
313
 
314
        // read operation
315
        always @(posedge rclk)
316
                if (rce)
317
                        do_reg <= (we && (waddr==raddr)) ? {dw{1'b x}} : mem[raddr];
318
 
319
        // write operation
320
        always @(posedge wclk)
321
                if (wce && we)
322
                        mem[waddr] <= di;
323
 
324
 
325
        // Task prints range of memory
326
        // *** Remember that tasks are non reentrant, don't call this task in parallel for multiple instantiations.
327
        task print_ram;
328
        input [aw-1:0] start;
329
        input [aw-1:0] finish;
330
        integer rnum;
331
        begin
332
                for (rnum=start;rnum<=finish;rnum=rnum+1)
333
                        $display("Addr %h = %h",rnum,mem[rnum]);
334
        end
335
        endtask
336
 
337
`endif // !VENDOR_VIRAGE
338
`endif // !VENDOR_AVANT
339
`endif // !VENDOR_ARTISAN
340
`endif // !VENDOR_ALTERA
341
`endif // !VENDOR_XILINX
342
`endif // !VENDOR_FPGA
343
 
344
endmodule
345
 
346
//
347
// Black-box modules
348
//
349
 
350
`ifdef VENDOR_ALTERA
351
        module altera_ram_dp(
352
                data,
353
                wraddress,
354
                rdaddress,
355
                wren,
356
                wrclock,
357
                wrclocken,
358
                rdclock,
359
                rdclocken,
360
                q) /* synthesis black_box */;
361
 
362
                parameter awidth = 7;
363
                parameter dwidth = 8;
364
 
365
                input [dwidth -1:0] data;
366
                input [awidth -1:0] wraddress;
367
                input [awidth -1:0] rdaddress;
368
                input               wren;
369
                input               wrclock;
370
                input               wrclocken;
371
                input               rdclock;
372
                input               rdclocken;
373
                output [dwidth -1:0] q;
374
 
375
                // synopsis translate_off
376
                // exemplar translate_off
377
 
378
                syn_dpram_rowr #(
379
                        "UNUSED",
380
                        dwidth,
381
                        awidth,
382
                        1 << awidth
383
                )
384
                altera_dpram_model (
385
                        // read port
386
                        .RdClock(rdclock),
387
                        .RdClken(rdclocken),
388
                        .RdAddress(rdaddress),
389
                        .RdEn(1'b1),
390
                        .Q(q),
391
 
392
                        // write port
393
                        .WrClock(wrclock),
394
                        .WrClken(wrclocken),
395
                        .WrAddress(wraddress),
396
                        .WrEn(wren),
397
                        .Data(data)
398
                );
399
 
400
                // exemplar translate_on
401
                // synopsis translate_on
402
 
403
        endmodule
404
`endif // VENDOR_ALTERA
405
 
406
`ifdef VENDOR_XILINX
407
        module xilinx_ram_dp (
408
                ADDRA,
409
                CLKA,
410
                ADDRB,
411
                CLKB,
412
                DIA,
413
                WEA,
414
                DIB,
415
                WEB,
416
                ENA,
417
                ENB,
418
                RSTA,
419
                RSTB,
420
                DOA,
421
                DOB) /* synthesis black_box */ ;
422
 
423
        parameter awidth = 7;
424
        parameter dwidth = 8;
425
 
426
        // port_a
427
        input               CLKA;
428
        input               RSTA;
429
        input               ENA;
430
        input [awidth-1:0]  ADDRA;
431
        input [dwidth-1:0]  DIA;
432
        input               WEA;
433
        output [dwidth-1:0] DOA;
434
 
435
        // port_b
436
        input               CLKB;
437
        input               RSTB;
438
        input               ENB;
439
        input [awidth-1:0]  ADDRB;
440
        input [dwidth-1:0]  DIB;
441
        input               WEB;
442
        output [dwidth-1:0] DOB;
443
 
444
        // insert simulation model
445
 
446
 
447
        // synopsys translate_off
448
        // exemplar translate_off
449
 
450
        C_MEM_DP_BLOCK_V1_0 #(
451
                awidth,
452
                awidth,
453
                1,
454
                1,
455
                "0",
456
                1 << awidth,
457
                1 << awidth,
458
                1,
459
                1,
460
                1,
461
                1,
462
                1,
463
                1,
464
                1,
465
                1,
466
                1,
467
                1,
468
                1,
469
                1,
470
                1,
471
                "",
472
                16,
473
                0,
474
                0,
475
                1,
476
                1,
477
                1,
478
                1,
479
                dwidth,
480
                dwidth)
481
        xilinx_dpram_model (
482
                .ADDRA(ADDRA),
483
                .CLKA(CLKA),
484
                .ADDRB(ADDRB),
485
                .CLKB(CLKB),
486
                .DIA(DIA),
487
                .WEA(WEA),
488
                .DIB(DIB),
489
                .WEB(WEB),
490
                .ENA(ENA),
491
                .ENB(ENB),
492
                .RSTA(RSTA),
493
                .RSTB(RSTB),
494
                .DOA(DOA),
495
                .DOB(DOB));
496
 
497
                // exemplar translate_on
498
                // synopsys translate_on
499
 
500
        endmodule
501
`endif // VENDOR_XILINX

powered by: WebSVN 2.1.0

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