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

Subversion Repositories versatile_library

[/] [versatile_library/] [trunk/] [rtl/] [verilog/] [memories.v] - Blame information for rev 31

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Versatile library, memories                                 ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  memories                                                    ////
7
////                                                              ////
8
////                                                              ////
9
////  To Do:                                                      ////
10
////   - add more memory types                                    ////
11
////                                                              ////
12
////  Author(s):                                                  ////
13
////      - Michael Unneback, unneback@opencores.org              ////
14
////        ORSoC AB                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
 
43
/// ROM
44
 
45 7 unneback
module vl_rom_init ( adr, q, clk);
46
   parameter data_width = 32;
47
   parameter addr_width = 8;
48
   input [(addr_width-1):0]       adr;
49
   output reg [(data_width-1):0] q;
50
   input                         clk;
51
   reg [data_width-1:0] rom [(1<<addr_width)-1:0];
52
   parameter memory_file = "vl_rom.vmem";
53
   initial
54
     begin
55
        $readmemh(memory_file, rom);
56
     end
57
 
58
   always @ (posedge clk)
59
     q <= rom[adr];
60 5 unneback
 
61 7 unneback
endmodule
62
 
63 14 unneback
/*
64 7 unneback
module vl_rom ( adr, q, clk);
65
 
66 5 unneback
parameter data_width = 32;
67
parameter addr_width = 4;
68
 
69
parameter [0:1>>addr_width-1] data [data_width-1:0] = {
70
    {32'h18000000},
71
    {32'hA8200000},
72
    {32'hA8200000},
73
    {32'hA8200000},
74
    {32'h44003000},
75
    {32'h15000000},
76
    {32'h15000000},
77
    {32'h15000000},
78
    {32'h15000000},
79
    {32'h15000000},
80
    {32'h15000000},
81
    {32'h15000000},
82
    {32'h15000000},
83
    {32'h15000000},
84
    {32'h15000000},
85
    {32'h15000000}};
86
 
87 7 unneback
input [addr_width-1:0] adr;
88 5 unneback
output reg [data_width-1:0] q;
89
input clk;
90
 
91
always @ (posedge clk)
92 7 unneback
    q <= data[adr];
93 5 unneback
 
94
endmodule
95 14 unneback
*/
96 5 unneback
// Single port RAM
97
 
98
module vl_ram ( d, adr, we, q, clk);
99
   parameter data_width = 32;
100
   parameter addr_width = 8;
101
   input [(data_width-1):0]      d;
102
   input [(addr_width-1):0]       adr;
103
   input                         we;
104 7 unneback
   output reg [(data_width-1):0] q;
105 5 unneback
   input                         clk;
106
   reg [data_width-1:0] ram [(1<<addr_width)-1:0];
107 7 unneback
   parameter init = 0;
108
   parameter memory_file = "vl_ram.vmem";
109
   generate if (init) begin : init_mem
110
   initial
111
     begin
112
        $readmemh(memory_file, ram);
113
     end
114
   end
115
   endgenerate
116
 
117 5 unneback
   always @ (posedge clk)
118
   begin
119
   if (we)
120
     ram[adr] <= d;
121
   q <= ram[adr];
122
   end
123
 
124
endmodule
125
 
126 7 unneback
module vl_ram_be ( d, adr, be, we, q, clk);
127
   parameter data_width = 32;
128
   parameter addr_width = 8;
129
   input [(data_width-1):0]      d;
130
   input [(addr_width-1):0]       adr;
131
   input [(addr_width/4)-1:0]    be;
132
   input                         we;
133
   output reg [(data_width-1):0] q;
134
   input                         clk;
135
 
136
   reg [data_width-1:0] ram [(1<<addr_width)-1:0];
137
 
138
   parameter init = 0;
139
   parameter memory_file = "vl_ram.vmem";
140
   generate if (init) begin : init_mem
141
   initial
142
     begin
143
        $readmemh(memory_file, ram);
144
     end
145
   end
146
   endgenerate
147
 
148
   genvar i;
149
   generate for (i=0;i<addr_width/4;i=i+1) begin : be_ram
150
      always @ (posedge clk)
151
      if (we & be[i])
152
        ram[adr][(i+1)*8-1:i*8] <= d[(i+1)*8-1:i*8];
153
   end
154
   endgenerate
155
 
156
   always @ (posedge clk)
157
      q <= ram[adr];
158
 
159
endmodule
160
 
161
 
162 5 unneback
// Dual port RAM
163
 
164
// ACTEL FPGA should not use logic to handle rw collision
165
`ifdef ACTEL
166
        `define SYN /*synthesis syn_ramstyle = "no_rw_check"*/
167
`else
168
        `define SYN
169
`endif
170
 
171 7 unneback
module vl_dpram_1r1w ( d_a, adr_a, we_a, clk_a, q_b, adr_b, clk_b );
172 5 unneback
   parameter data_width = 32;
173
   parameter addr_width = 8;
174
   input [(data_width-1):0]      d_a;
175
   input [(addr_width-1):0]       adr_a;
176
   input [(addr_width-1):0]       adr_b;
177
   input                         we_a;
178
   output [(data_width-1):0]      q_b;
179
   input                         clk_a, clk_b;
180
   reg [(addr_width-1):0]         adr_b_reg;
181
   reg [data_width-1:0] ram [(1<<addr_width)-1:0] `SYN;
182 7 unneback
 
183
   parameter init = 0;
184
   parameter memory_file = "vl_ram.vmem";
185
   generate if (init) begin : init_mem
186
   initial
187
     begin
188
        $readmemh(memory_file, ram);
189
     end
190
   end
191
   endgenerate
192
 
193 5 unneback
   always @ (posedge clk_a)
194
   if (we_a)
195
     ram[adr_a] <= d_a;
196
   always @ (posedge clk_b)
197
   adr_b_reg <= adr_b;
198
   assign q_b = ram[adr_b_reg];
199
endmodule
200
 
201 7 unneback
module vl_dpram_2r1w ( d_a, q_a, adr_a, we_a, clk_a, q_b, adr_b, clk_b );
202 5 unneback
   parameter data_width = 32;
203
   parameter addr_width = 8;
204
   input [(data_width-1):0]      d_a;
205
   input [(addr_width-1):0]       adr_a;
206
   input [(addr_width-1):0]       adr_b;
207
   input                         we_a;
208
   output [(data_width-1):0]      q_b;
209
   output reg [(data_width-1):0] q_a;
210
   input                         clk_a, clk_b;
211
   reg [(data_width-1):0]         q_b;
212
   reg [data_width-1:0] ram [(1<<addr_width)-1:0] `SYN;
213 7 unneback
 
214
   parameter init = 0;
215
   parameter memory_file = "vl_ram.vmem";
216
   generate if (init) begin : init_mem
217
   initial
218
     begin
219
        $readmemh(memory_file, ram);
220
     end
221
   end
222
   endgenerate
223
 
224 5 unneback
   always @ (posedge clk_a)
225
     begin
226
        q_a <= ram[adr_a];
227
        if (we_a)
228
             ram[adr_a] <= d_a;
229
     end
230
   always @ (posedge clk_b)
231
          q_b <= ram[adr_b];
232
endmodule
233
 
234 7 unneback
module vl_dpram_2r2w ( d_a, q_a, adr_a, we_a, clk_a, d_b, q_b, adr_b, we_b, clk_b );
235 5 unneback
   parameter data_width = 32;
236
   parameter addr_width = 8;
237
   input [(data_width-1):0]      d_a;
238
   input [(addr_width-1):0]       adr_a;
239
   input [(addr_width-1):0]       adr_b;
240
   input                         we_a;
241
   output [(data_width-1):0]      q_b;
242
   input [(data_width-1):0]       d_b;
243
   output reg [(data_width-1):0] q_a;
244
   input                         we_b;
245
   input                         clk_a, clk_b;
246
   reg [(data_width-1):0]         q_b;
247
   reg [data_width-1:0] ram [(1<<addr_width)-1:0] `SYN;
248 7 unneback
 
249
   parameter init = 0;
250
   parameter memory_file = "vl_ram.vmem";
251
   generate if (init) begin : init_mem
252
   initial
253
     begin
254
        $readmemh(memory_file, ram);
255
     end
256
   end
257
   endgenerate
258
 
259 5 unneback
   always @ (posedge clk_a)
260
     begin
261
        q_a <= ram[adr_a];
262
        if (we_a)
263
             ram[adr_a] <= d_a;
264
     end
265
   always @ (posedge clk_b)
266
     begin
267
        q_b <= ram[adr_b];
268
        if (we_b)
269
          ram[adr_b] <= d_b;
270
     end
271
endmodule
272
 
273
// Content addresable memory, CAM
274
 
275
// FIFO
276 25 unneback
module vl_fifo_1r1w_fill_level_sync (
277
    d, wr, fifo_full,
278
    q, rd, fifo_empty,
279
    fill_level,
280
    clk, rst
281
    );
282
 
283
parameter data_width = 18;
284
parameter addr_width = 4;
285 5 unneback
 
286 25 unneback
// write side
287
input  [data_width-1:0] d;
288
input                   wr;
289
output                  fifo_full;
290
// read side
291
output [data_width-1:0] q;
292
input                   rd;
293
output                  fifo_empty;
294
// common
295
output [addr_width:0]   fill_level;
296
input rst, clk;
297
 
298
wire [addr_width:1] wadr, radr;
299
 
300
vl_cnt_bin_ce
301
    # ( .length(addr_width))
302
    fifo_wr_adr( .cke(wr), .q(wadr), .rst(rst), .clk(clk));
303
 
304
vl_cnt_bin_ce
305
    # (.length(addr_width))
306
    fifo_rd_adr( .cke(rd), .q(radr), .rst(rst), .clk(clk));
307
 
308
vl_dpram_1r1w
309
    # (.data_width(data_width), .addr_width(addr_width))
310
    dpram ( .d_a(d), .adr_a(wadr), .we_a(wr), .clk_a(clk), .q_b(q), .adr_b(radr), .clk_b(clk));
311
 
312 31 unneback
vl_cnt_bin_ce_rew_q_zq_l1
313 27 unneback
    # (.length(addr_width+1), .level1_value(1<<addr_width))
314 25 unneback
    fill_level_cnt( .cke(rd ^ wr), .rew(rd), .q(fill_level), .zq(fifo_empty), .level1(fifo_full), .rst(rst), .clk(clk));
315
 
316
endmodule
317
 
318 27 unneback
// Intended use is two small FIFOs (RX and TX typically) in one FPGA RAM resource
319
// RAM is supposed to be larger than the two FIFOs
320
// LFSR counters used adr pointers
321
module vl_fifo_2r2w_sync_simplex (
322
    // a side
323
    a_d, a_wr, a_fifo_full,
324
    a_q, a_rd, a_fifo_empty,
325
    a_fill_level,
326
    // b side
327
    b_d, b_wr, b_fifo_full,
328
    b_q, b_rd, b_fifo_empty,
329
    b_fill_level,
330
    // common
331
    clk, rst
332
    );
333
parameter data_width = 8;
334
parameter addr_width = 5;
335
parameter fifo_full_level = (1<<addr_width)-1;
336
 
337
// a side
338
input  [data_width-1:0] a_d;
339
input                   a_wr;
340
output                  a_fifo_full;
341
output [data_width-1:0] a_q;
342
input                   a_rd;
343
output                  a_fifo_empty;
344
output [addr_width-1:0] a_fill_level;
345
 
346
// b side
347
input  [data_width-1:0] b_d;
348
input                   b_wr;
349
output                  b_fifo_full;
350
output [data_width-1:0] b_q;
351
input                   b_rd;
352
output                  b_fifo_empty;
353
output [addr_width-1:0] b_fill_level;
354
 
355
input                   clk;
356
input                   rst;
357
 
358
// adr_gen
359
wire [addr_width:1] a_wadr, a_radr;
360
wire [addr_width:1] b_wadr, b_radr;
361
// dpram
362
wire [addr_width:0] a_dpram_adr, b_dpram_adr;
363
 
364
vl_cnt_lfsr_ce
365
    # ( .length(addr_width))
366
    fifo_a_wr_adr( .cke(a_wr), .q(a_wadr), .rst(rst), .clk(clk));
367
 
368
vl_cnt_lfsr_ce
369
    # (.length(addr_width))
370
    fifo_a_rd_adr( .cke(a_rd), .q(a_radr), .rst(rst), .clk(clk));
371
 
372
vl_cnt_lfsr_ce
373
    # ( .length(addr_width))
374
    fifo_b_wr_adr( .cke(b_wr), .q(b_wadr), .rst(rst), .clk(clk));
375
 
376
vl_cnt_lfsr_ce
377
    # (.length(addr_width))
378
    fifo_b_rd_adr( .cke(b_rd), .q(b_radr), .rst(rst), .clk(clk));
379
 
380
// mux read or write adr to DPRAM
381
assign a_dpram_adr = (a_wr) ? {1'b0,a_wadr} : {1'b1,a_radr};
382
assign b_dpram_adr = (b_wr) ? {1'b1,b_wadr} : {1'b0,b_radr};
383
 
384
vl_dpram_2r2w
385
    # (.data_width(data_width), .addr_width(addr_width+1))
386
    dpram ( .d_a(a_d), .q_a(a_q), .adr_a(a_dpram_adr), .we_a(a_wr), .clk_a(a_clk),
387
            .d_b(b_d), .q_b(b_q), .adr_b(b_dpram_adr), .we_b(b_wr), .clk_b(b_clk));
388
 
389
vl_cnt_bin_ce_rew_zq_l1
390 28 unneback
    # (.length(addr_width), .level1_value(fifo_full_level))
391 27 unneback
    a_fill_level_cnt( .cke(a_rd ^ a_wr), .rew(a_rd), .q(a_fill_level), .zq(a_fifo_empty), .level1(a_fifo_full), .rst(rst), .clk(clk));
392
 
393
vl_cnt_bin_ce_rew_zq_l1
394 28 unneback
    # (.length(addr_width), .level1_value(fifo_full_level))
395 27 unneback
    b_fill_level_cnt( .cke(b_rd ^ b_wr), .rew(b_rd), .q(b_fill_level), .zq(b_fifo_empty), .level1(b_fifo_full), .rst(rst), .clk(clk));
396
 
397
endmodule
398
 
399 5 unneback
module vl_fifo_cmp_async ( wptr, rptr, fifo_empty, fifo_full, wclk, rclk, rst );
400
 
401 11 unneback
   parameter addr_width = 4;
402
   parameter N = addr_width-1;
403 5 unneback
 
404
   parameter Q1 = 2'b00;
405
   parameter Q2 = 2'b01;
406
   parameter Q3 = 2'b11;
407
   parameter Q4 = 2'b10;
408
 
409
   parameter going_empty = 1'b0;
410
   parameter going_full  = 1'b1;
411
 
412
   input [N:0]  wptr, rptr;
413 14 unneback
   output       fifo_empty;
414 5 unneback
   output       fifo_full;
415
   input        wclk, rclk, rst;
416
 
417
`ifndef GENERATE_DIRECTION_AS_LATCH
418
   wire direction;
419
`endif
420
`ifdef GENERATE_DIRECTION_AS_LATCH
421
   reg direction;
422
`endif
423
   reg  direction_set, direction_clr;
424
 
425
   wire async_empty, async_full;
426
   wire fifo_full2;
427 14 unneback
   wire fifo_empty2;
428 5 unneback
 
429
   // direction_set
430
   always @ (wptr[N:N-1] or rptr[N:N-1])
431
     case ({wptr[N:N-1],rptr[N:N-1]})
432
       {Q1,Q2} : direction_set <= 1'b1;
433
       {Q2,Q3} : direction_set <= 1'b1;
434
       {Q3,Q4} : direction_set <= 1'b1;
435
       {Q4,Q1} : direction_set <= 1'b1;
436
       default : direction_set <= 1'b0;
437
     endcase
438
 
439
   // direction_clear
440
   always @ (wptr[N:N-1] or rptr[N:N-1] or rst)
441
     if (rst)
442
       direction_clr <= 1'b1;
443
     else
444
       case ({wptr[N:N-1],rptr[N:N-1]})
445
         {Q2,Q1} : direction_clr <= 1'b1;
446
         {Q3,Q2} : direction_clr <= 1'b1;
447
         {Q4,Q3} : direction_clr <= 1'b1;
448
         {Q1,Q4} : direction_clr <= 1'b1;
449
         default : direction_clr <= 1'b0;
450
       endcase
451
 
452
`ifndef GENERATE_DIRECTION_AS_LATCH
453 18 unneback
    vl_dff_sr dff_sr_dir( .aclr(direction_clr), .aset(direction_set), .clock(1'b1), .data(1'b1), .q(direction));
454 5 unneback
`endif
455
 
456
`ifdef GENERATE_DIRECTION_AS_LATCH
457
   always @ (posedge direction_set or posedge direction_clr)
458
     if (direction_clr)
459
       direction <= going_empty;
460
     else
461
       direction <= going_full;
462
`endif
463
 
464
   assign async_empty = (wptr == rptr) && (direction==going_empty);
465
   assign async_full  = (wptr == rptr) && (direction==going_full);
466
 
467 18 unneback
    vl_dff_sr dff_sr_empty0( .aclr(rst), .aset(async_full), .clock(wclk), .data(async_full), .q(fifo_full2));
468
    vl_dff_sr dff_sr_empty1( .aclr(rst), .aset(async_full), .clock(wclk), .data(fifo_full2), .q(fifo_full));
469 5 unneback
 
470
/*
471
   always @ (posedge wclk or posedge rst or posedge async_full)
472
     if (rst)
473
       {fifo_full, fifo_full2} <= 2'b00;
474
     else if (async_full)
475
       {fifo_full, fifo_full2} <= 2'b11;
476
     else
477
       {fifo_full, fifo_full2} <= {fifo_full2, async_full};
478
*/
479 14 unneback
/*   always @ (posedge rclk or posedge async_empty)
480 5 unneback
     if (async_empty)
481
       {fifo_empty, fifo_empty2} <= 2'b11;
482
     else
483 14 unneback
       {fifo_empty,fifo_empty2} <= {fifo_empty2,async_empty}; */
484 18 unneback
    vl_dff # ( .reset_value(1'b1)) dff0 ( .d(async_empty), .q(fifo_empty2), .clk(rclk), .rst(async_empty));
485
    vl_dff # ( .reset_value(1'b1)) dff1 ( .d(fifo_empty2), .q(fifo_empty),  .clk(rclk), .rst(async_empty));
486 5 unneback
 
487 25 unneback
endmodule // async_compb
488 5 unneback
 
489
module vl_fifo_1r1w_async (
490
    d, wr, fifo_full, wr_clk, wr_rst,
491
    q, rd, fifo_empty, rd_clk, rd_rst
492
    );
493
 
494
parameter data_width = 18;
495
parameter addr_width = 4;
496
 
497
// write side
498
input  [data_width-1:0] d;
499
input                   wr;
500
output                  fifo_full;
501
input                   wr_clk;
502
input                   wr_rst;
503
// read side
504
output [data_width-1:0] q;
505
input                   rd;
506
output                  fifo_empty;
507
input                   rd_clk;
508
input                   rd_rst;
509
 
510
wire [addr_width:1] wadr, wadr_bin, radr, radr_bin;
511 23 unneback
 
512 18 unneback
vl_cnt_gray_ce_bin
513 5 unneback
    # ( .length(addr_width))
514
    fifo_wr_adr( .cke(wr), .q(wadr), .q_bin(wadr_bin), .rst(wr_rst), .clk(wr_clk));
515
 
516 18 unneback
vl_cnt_gray_ce_bin
517 5 unneback
    # (.length(addr_width))
518 23 unneback
    fifo_rd_adr( .cke(rd), .q(radr), .q_bin(radr_bin), .rst(rd_rst), .clk(rd_clk));
519 5 unneback
 
520 7 unneback
vl_dpram_1r1w
521 5 unneback
    # (.data_width(data_width), .addr_width(addr_width))
522
    dpram ( .d_a(d), .adr_a(wadr_bin), .we_a(wr), .clk_a(wr_clk), .q_b(q), .adr_b(radr_bin), .clk_b(rd_clk));
523
 
524
vl_fifo_cmp_async
525
    # (.addr_width(addr_width))
526
    cmp ( .wptr(wadr), .rptr(radr), .fifo_empty(fifo_empty), .fifo_full(fifo_full), .wclk(wr_clk), .rclk(rd_clk), .rst(wr_rst) );
527
 
528
endmodule
529
 
530 7 unneback
module vl_fifo_2r2w_async (
531 5 unneback
    // a side
532
    a_d, a_wr, a_fifo_full,
533
    a_q, a_rd, a_fifo_empty,
534
    a_clk, a_rst,
535
    // b side
536
    b_d, b_wr, b_fifo_full,
537
    b_q, b_rd, b_fifo_empty,
538
    b_clk, b_rst
539
    );
540
 
541
parameter data_width = 18;
542
parameter addr_width = 4;
543
 
544
// a side
545
input  [data_width-1:0] a_d;
546
input                   a_wr;
547
output                  a_fifo_full;
548
output [data_width-1:0] a_q;
549
input                   a_rd;
550
output                  a_fifo_empty;
551
input                   a_clk;
552
input                   a_rst;
553
 
554
// b side
555
input  [data_width-1:0] b_d;
556
input                   b_wr;
557
output                  b_fifo_full;
558
output [data_width-1:0] b_q;
559
input                   b_rd;
560
output                  b_fifo_empty;
561
input                   b_clk;
562
input                   b_rst;
563
 
564
vl_fifo_1r1w_async # (.data_width(data_width), .addr_width(addr_width))
565
vl_fifo_1r1w_async_a (
566
    .d(a_d), .wr(a_wr), .fifo_full(a_fifo_full), .wr_clk(a_clk), .wr_rst(a_rst),
567
    .q(b_q), .rd(b_rd), .fifo_empty(b_fifo_empty), .rd_clk(b_clk), .rd_rst(b_rst)
568
    );
569
 
570
vl_fifo_1r1w_async # (.data_width(data_width), .addr_width(addr_width))
571
vl_fifo_1r1w_async_b (
572
    .d(b_d), .wr(b_wr), .fifo_full(b_fifo_full), .wr_clk(b_clk), .wr_rst(b_rst),
573
    .q(a_q), .rd(a_rd), .fifo_empty(a_fifo_empty), .rd_clk(a_clk), .rd_rst(a_rst)
574
    );
575
 
576
endmodule
577
 
578 7 unneback
module vl_fifo_2r2w_async_simplex (
579 5 unneback
    // a side
580
    a_d, a_wr, a_fifo_full,
581
    a_q, a_rd, a_fifo_empty,
582
    a_clk, a_rst,
583
    // b side
584
    b_d, b_wr, b_fifo_full,
585
    b_q, b_rd, b_fifo_empty,
586
    b_clk, b_rst
587
    );
588
 
589
parameter data_width = 18;
590
parameter addr_width = 4;
591
 
592
// a side
593
input  [data_width-1:0] a_d;
594
input                   a_wr;
595
output                  a_fifo_full;
596
output [data_width-1:0] a_q;
597
input                   a_rd;
598
output                  a_fifo_empty;
599
input                   a_clk;
600
input                   a_rst;
601
 
602
// b side
603
input  [data_width-1:0] b_d;
604
input                   b_wr;
605
output                  b_fifo_full;
606
output [data_width-1:0] b_q;
607
input                   b_rd;
608
output                  b_fifo_empty;
609
input                   b_clk;
610
input                   b_rst;
611
 
612
// adr_gen
613
wire [addr_width:1] a_wadr, a_wadr_bin, a_radr, a_radr_bin;
614
wire [addr_width:1] b_wadr, b_wadr_bin, b_radr, b_radr_bin;
615
// dpram
616
wire [addr_width:0] a_dpram_adr, b_dpram_adr;
617
 
618 18 unneback
vl_cnt_gray_ce_bin
619 5 unneback
    # ( .length(addr_width))
620
    fifo_a_wr_adr( .cke(a_wr), .q(a_wadr), .q_bin(a_wadr_bin), .rst(a_rst), .clk(a_clk));
621
 
622 18 unneback
vl_cnt_gray_ce_bin
623 5 unneback
    # (.length(addr_width))
624
    fifo_a_rd_adr( .cke(a_rd), .q(a_radr), .q_bin(a_radr_bin), .rst(a_rst), .clk(a_clk));
625
 
626 18 unneback
vl_cnt_gray_ce_bin
627 5 unneback
    # ( .length(addr_width))
628
    fifo_b_wr_adr( .cke(b_wr), .q(b_wadr), .q_bin(b_wadr_bin), .rst(b_rst), .clk(b_clk));
629
 
630 18 unneback
vl_cnt_gray_ce_bin
631 5 unneback
    # (.length(addr_width))
632
    fifo_b_rd_adr( .cke(b_rd), .q(b_radr), .q_bin(b_radr_bin), .rst(b_rst), .clk(b_clk));
633
 
634
// mux read or write adr to DPRAM
635
assign a_dpram_adr = (a_wr) ? {1'b0,a_wadr_bin} : {1'b1,a_radr_bin};
636
assign b_dpram_adr = (b_wr) ? {1'b1,b_wadr_bin} : {1'b0,b_radr_bin};
637
 
638 11 unneback
vl_dpram_2r2w
639 5 unneback
    # (.data_width(data_width), .addr_width(addr_width+1))
640
    dpram ( .d_a(a_d), .q_a(a_q), .adr_a(a_dpram_adr), .we_a(a_wr), .clk_a(a_clk),
641
            .d_b(b_d), .q_b(b_q), .adr_b(b_dpram_adr), .we_b(b_wr), .clk_b(b_clk));
642
 
643 11 unneback
vl_fifo_cmp_async
644 5 unneback
    # (.addr_width(addr_width))
645
    cmp1 ( .wptr(a_wadr), .rptr(b_radr), .fifo_empty(b_fifo_empty), .fifo_full(a_fifo_full), .wclk(a_clk), .rclk(b_clk), .rst(a_rst) );
646
 
647 11 unneback
vl_fifo_cmp_async
648 5 unneback
    # (.addr_width(addr_width))
649
    cmp2 ( .wptr(b_wadr), .rptr(a_radr), .fifo_empty(a_fifo_empty), .fifo_full(b_fifo_full), .wclk(b_clk), .rclk(a_clk), .rst(b_rst) );
650
 
651
endmodule

powered by: WebSVN 2.1.0

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