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

Subversion Repositories or1k

[/] [or1k/] [branches/] [mp3_stable/] [mp3/] [lib/] [xilinx/] [coregen/] [XilinxCoreLib/] [async_fifo_v3_0.v] - Blame information for rev 317

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

Line No. Rev Author Line
1 266 lampret
// ************************************************************************
2
// $Id: async_fifo_v3_0.v,v 1.1.1.1 2001-11-04 19:00:03 lampret Exp $
3
// ************************************************************************
4
//  Copyright 2000 - Xilinx, Inc.
5
//  All rights reserved.
6
// ************************************************************************
7
//-- Filename: async_fifo_v3_0.v
8
//-- Author : Xilinx, Inc.
9
//-- Creation ; Sept. 7th, 1999
10
//-- Description: This file contains the verilog behavioral model for the asynchornous fifo core.
11
//**********************************************************************************************//
12
//**********************************************************************************************//
13
// Last Change  : 11/15/99 VK: Removing references to c_ports_differ and c_read_width etc.      //
14
//              : 12/01/99 CE: Added XCS Header (Id), cleaned up code (removed comments etc.)   //
15
//              : 12/01/99 CE: Removed timescale directive                                      //
16
//              : 12/07/99 CE: Fixes for CR 118497                                              //
17
//              : 12/15/99 CE: Fix for CR 118819, behavioral model of C_COUNTER_BINARY changed  //
18
//              : 12/16/99 CE: Added initial values to all four flag registers                  //
19
//              : 1/28/00  VK: Capitalised top level module name, ports names                   //
20
//              : 5/08/00  CE: V1 to V2 Conversion                                              //
21
//              : 5/18/00  CE: Delayed WR_EN & RD_EN inputs, for simulation functionality       //
22
//              : 6/12/00  CE: Added C_HAS_QDP0(SPO)_RST parameters (C_DIST_MEM_V3_0)           //
23
//              : 06/12/00 CE: V1 to V3 conversions                                             //
24
//              : 06/20/00 CE: Fix for CR124696 & CR124692 & CR124109                           //
25
//              : 08/11/00 KM: V2 to V3 conversions                                             //
26
//**********************************************************************************************//
27
/* ***************************************************************************
28
 * Last Modified 09/26/00 by jogden
29
 *              : Updated to new block memory and fixed CR.
30
 *
31
 *         jogden  10/4/00   Placed module declaration all on one line.
32
 *         robertle 10/13/00 Changed all V2 to V3
33
 *         robertle 10/16/00 Add 1 to C_LATENCY for C_ADDSUB_V3
34
 *         robertle 10/19/00 Fix Port size problem in memory block
35
 * **************************************************************************/
36
//`timescale 1 ns/10ps
37
 
38
`define true 1
39
`define false 0
40
 
41
`ifdef async_fifo_v3_0_def
42
`else
43
`define async_fifo_v3_0_def
44
 
45
 
46
 
47
`ifdef C_REG_FD_V3_0_DEF
48
`else
49
`include "XilinxCoreLib/C_REG_FD_V3_0.v"
50
`define C_REG_FD_V3_0_DEF
51
`endif
52
 
53
`ifdef C_GATE_BIT_V3_0_DEF
54
`else
55
`include "XilinxCoreLib/C_GATE_BIT_V3_0.v"
56
`define C_GATE_BIT_V3_0_DEF
57
`endif
58
 
59
`ifdef C_ADDSUB_V3_0_DEF
60
`else
61
`include "XilinxCoreLib/C_ADDSUB_V3_0.v"
62
`define C_ADDSUB_V3_0_DEF
63
`endif
64
 
65
 
66
`ifdef C_COMPARE_V3_0_DEF
67
`else
68
`include "XilinxCoreLib/C_COMPARE_V3_0.v"
69
`define C_COMPARE_V3_0_DEF
70
`endif
71
 
72
 
73
`ifdef C_MUX_BUS_V3_0_DEF
74
`else
75
`include "XilinxCoreLib/C_MUX_BUS_V3_0.v"
76
`define C_MUX_BUS_V3_0_DEF
77
`endif
78
 
79
 
80
`ifdef C_COUNTER_BINARY_V3_0_DEF
81
`else
82
`include "XilinxCoreLib/C_COUNTER_BINARY_V3_0.v"
83
`define C_COUNTER_BINARY_V3_0_DEF
84
`endif
85
 
86
`ifdef C_DIST_MEM_V3_0_DEF
87
`else
88
`include "XilinxCoreLib/C_DIST_MEM_V3_0.v"
89
`define C_DIST_MEM_V3_0_DEF
90
`endif
91
 
92
`ifdef C_BLKMEMDP_V3_0_DEF
93
`else
94
`include "XilinxCoreLib/blkmemdp_v3_0.v"
95
`define C_BLKMEMDP_V3_0_DEF
96
`endif
97
 
98
 
99
 
100
`define width 6
101
 
102
`define c_enable_rlocs   0
103
`define c_data_width             16
104
`define c_read_data_width        16
105
`define c_ports_differ  0
106
`define c_fifo_depth             63
107
`define c_has_almost_full        1
108
`define c_has_almost_empty       1
109
`define c_has_wr_count          1
110
`define c_has_rd_count          1
111
`define c_wr_count_width        6
112
`define c_rd_count_width        6
113
`define c_has_rd_ack              1
114
`define c_rd_ack_low              0
115
`define c_has_rd_err              1
116
`define c_rd_err_low              0
117
`define c_has_wr_ack              1
118
`define c_wr_ack_low              0
119
`define c_has_wr_err              1
120
`define c_wr_err_low              0
121
`define c_use_blockmem          1
122
 
123
 
124
 
125
 
126
 
127
 
128
                /* Memory Module */
129
module memory_v2 (d, wa, ra, we, wclk, re, rclk, q);
130
 
131
parameter use_blockmem          =1;     //= c_use_blockmem;
132
parameter c_enable_rlocs        =0;      //= 0;
133
parameter address_width         =6;     //= width;
134
parameter rd_addr_width         =6;     //= width;
135
parameter depth                 =64;    //= c_fifo_depth +1;
136
parameter rd_depth              =64;    //= c_fifo_depth +1;
137
parameter data_width            =16;    //= c_data_width;
138
parameter rd_data_width         =16;    //= c_data_width;
139
 
140
 
141
input [data_width-1 : 0] d;
142
input [address_width-1 : 0] wa;
143
input [rd_addr_width-1 : 0] ra;
144
input we;
145
input wclk;
146
input re;
147
input rclk;
148
output [rd_data_width-1 : 0] q;
149
 
150
 
151
wire port_enabled;
152
wire [data_width-1 : 0] sourceless;
153
wire [address_width-1 : 0] sourceless_addr;
154
wire [rd_data_width-1 : 0] sourceless_dib;
155
wire sourceless_net;
156
wire [data_width-1 : 0] spo_dummy;
157
wire [data_width-1 : 0] qspo_dummy;
158
wire [data_width-1 : 0] dpo_dummy;
159
wire [data_width-1 : 0] doa_dummy_a;
160
wire [data_width-1 : 0] doa_dummy_b;
161
wire [rd_data_width-1 : 0] dob_bmem_a;
162
wire [rd_data_width-1 : 0] dob_bmem_b;
163
wire [rd_data_width-1 : 0] q_dist_mem;
164
 
165
 
166
parameter zero = 8'b00110000;  //ascii 0
167
 
168
parameter default_data = {data_width{zero}};
169
parameter default_rd_data = {rd_data_width{zero}};
170
 
171
assign sourceless_net = 0;
172
assign port_enabled = 1;
173
assign sourceless_dib = {data_width-1{zero}};
174
assign sourceless_addr = {address_width{zero}};
175
 
176
 
177
/* ***************************************************************************
178
 * Modified 9/26/00 by jogden
179
 *   Changed the block memory to blkmemdp_v3_0
180
 * **************************************************************************/
181
   wire                    unconnected_port;
182
   wire [data_width-1 : 0] unconnected_douta;
183
   wire [rd_data_width-1 : 0] unconnected_dinb;
184
   wire                    unconnected_ena;
185
   wire                    unconnected_nda;
186
   wire                    unconnected_ndb;
187
   wire                    unconnected_sinita;
188
   wire                    unconnected_sinitb;
189
   wire                    unconnected_web;
190
 
191
   assign unconnected_dinb = {rd_data_width{zero}};
192
   assign unconnected_ena = 1'b1;
193
   assign unconnected_sinita = 1'b0;
194
   assign unconnected_sinitb = 1'b0;
195
   assign unconnected_web = 1'b0;
196
 
197
 
198
BLKMEMDP_V3_0 #(
199
                address_width,      //c_addra_width
200
                rd_addr_width,      //c_addrb_width
201
                default_data,       //c_default_data
202
                depth,              //c_depth_a
203
                rd_depth,           //c_depth_b
204
                0,                  //c_enable_rlocs
205
                1,                  //c_has_default_data
206
                1,                  //c_has_dina
207
                0,                  //c_has_dinb
208
                0,                  //c_has_douta
209
                1,                  //c_has_doutb
210
                0,                  //c_has_ena
211
                1,                  //c_has_enb
212
                0,                  //c_has_limit_data_pitch
213
                0,                  //c_has_nda
214
                0,                  //c_has_ndb
215
                0,                  //c_has_rdya
216
                0,                  //c_has_rdyb
217
                0,                  //c_has_rfda
218
                0,                  //c_has_rfdb
219
                0,                  //c_has_sinita
220
                0,                  //c_has_sinitb
221
                1,                  //c_has_wea
222
                0,                  //c_has_web
223
                18,                 //c_limit_data_pitch
224
                "null.mif" ,
225
                0,                  //c_pipe_stages_a
226
                0,                  //c_pipe_stages_b
227
                0,                  //c_reg_inputsa
228
                0,                  //c_reg_inputsb
229
                default_data,       //c_sinita_value
230
                default_data,       //c_sinitb_value
231
                data_width,         //c_width_a
232
                rd_data_width,      //c_width_b
233
                2,                  //c_write_modea
234
                2                   //c_write_modeb
235
               )
236
        bmem_a          (.ADDRA(wa),
237
                        .ADDRB(ra),
238
                        .CLKA(wclk),
239
                        .CLKB(rclk),
240
                        .DINA(d),
241
                        .DINB(sourceless_dib),
242
                        .DOUTA(unconnected_douta),
243
                        .DOUTB(dob_bmem_a),
244
                        .ENA(unconnected_ena),
245
                        .ENB(re),
246
                        .NDA(unconnected_nda),
247
                        .NDB(unconnected_ndb),
248
                        .RDYA(unconnected_port),
249
                        .RDYB(unconnected_port),
250
                        .RFDA(unconnected_port),
251
                        .RFDB(unconnected_port),
252
                        .SINITA(unconnected_sinita),
253
                        .SINITB(unconnected_sinitb),
254
                        .WEA(we),
255
                        .WEB(unconnected_web)
256
                        );
257
 
258
/*
259
blkmem1: IF (use_blockmem AND (address_width >= rd_addr_width)) GENERATE
260
*/
261
/*
262
   C_MEM_DP_BLOCK_V1_0  #(
263
                        address_width,
264
                        rd_addr_width,
265
                        1,
266
                        1,
267
                        default_data,
268
                        depth,
269
                        rd_depth,
270
                        1,
271
                        1,
272
                        0,
273
                        1,
274
                        1,
275
                        0,
276
                        1,
277
                        1,
278
                        1,
279
                        0,
280
                        0,
281
                        1,
282
                        1,
283
                        "null.mif",
284
                        2,
285
                        0,
286
                        0,
287
                        1,
288
                        1,
289
                        1,
290
                        1,
291
                        data_width,
292
                        rd_data_width
293
                        )
294
        bmem_a          (.ADDRA(wa),
295
                        .ADDRB(ra),
296
                        .DIA(d),
297
                        .DIB(sourceless_dib),
298
                        .CLKA(wclk),
299
                        .CLKB(rclk),
300
                        .WEA(we),
301
                        .WEB(sourceless_net),
302
                        .ENA(port_enabled),
303
                        .ENB(re),
304
                        .RSTA(sourceless_net),
305
                        .RSTB(sourceless_net),
306
                        .DOA(doa_dummy_a),
307
                        .DOB(dob_bmem_a)
308
                        );
309
 
310
*/
311
 
312
/*
313
blkmen2:IF (use_blockmem AND (address_width < rd_addr_width)) GENERATE
314
--Swap all the ports (because depth of A port must be >= depth of B port)?
315
--Only needed for the non-symmetric data port case
316
*/
317
 
318
/*
319
 
320
   C_MEM_DP_BLOCK_V1_0  #(
321
                        address_width,
322
                        rd_addr_width,
323
                        1,
324
                        1,
325
                        default_rd_data,
326
                        rd_depth,
327
                        depth,
328
                        1,
329
                        1,
330
                        0,
331
                        1,
332
                        1,
333
                        0,
334
                        1,
335
                        1,
336
                        1,
337
                        0,
338
                        0,
339
                        1,
340
                        1,
341
                        "null.mif",
342
                        2,
343
                        0,
344
                        0,
345
                        1,
346
                        1,
347
                        1,
348
                        1,
349
                        rd_data_width,
350
                        data_width
351
                        )
352
        bmem_b          (.ADDRA(ra),
353
                        .ADDRB(wa),
354
                        .DIA(sourceless_dib),
355
                        .DIB(d),
356
                        .CLKA(rclk),
357
                        .CLKB(wclk),
358
                        .WEA(sourceless_net),
359
                        .WEB(we),
360
                        .ENA(re),
361
                        .ENB(port_enabled),
362
                        .RSTA(sourceless_net),
363
                        .RSTB(sourceless_net),
364
                        .DOA(dob_bmem_b),
365
                        .DOB(doa_dummy_b)
366
                        );
367
*/
368
 
369
 
370
/* ***************************************************************************
371
 * END OF BLOCK MEMORY MODIFICATION (by jogden 9/26/00)
372
 * **************************************************************************/
373
 
374
 
375
 
376
 
377
   C_DIST_MEM_V3_0      #(address_width,
378
                        default_data,
379
                        2,      //c_default_data_radix
380
                        depth,
381
                        1,
382
                        0,
383
                        1,
384
                        1,      //c_has_d
385
                        0,
386
                        1,
387
                        0,       //c_has_i_ce
388
                        1,
389
                        1,
390
                        1,
391
                        0,       //c_has_qdpo_rst
392
                        1,      //c_has_qspo
393
                        1,
394
                        0,       //c_has_qspo_rst
395
                        0,       //c_has_rd_en
396
                        0,
397
                        0,
398
                        1,
399
                        "",     //c_mem_init_file
400
                        2,
401
                        2,
402
                        0,
403
                        1,
404
                        0,
405
                        0,
406
                        0,
407
                        0,
408
                        0,
409
                        data_width,
410
                        2
411
                        )
412
        dist_mem        (.A(wa),
413
                        .SPO(spo_dummy),
414
                        .QSPO(qspo_dummy),
415
                        .CLK(wclk),
416
                        .WE(we),
417
                        .RD_EN(sourceless_net),
418
                        .D(d),
419
                        .I_CE(sourceless_net),
420
                        .SPRA(sourceless_addr),
421
                        .DPRA(ra),
422
                        .DPO(dpo_dummy),
423
                        .QSPO_CE(sourceless_net),
424
                        .QDPO(q_dist_mem),
425
                        .QDPO_CLK(rclk),
426
                        .QDPO_CE(re)
427
                        );
428
 
429
 
430
 
431
assign q = use_blockmem ? (address_width >= rd_addr_width ? dob_bmem_a : dob_bmem_b) : q_dist_mem;
432
 
433
 
434
endmodule
435
               /* End Memory Module */
436
 
437
        /* Binary Counter Module. bcount_up_ainit.v */
438
 
439
 
440
module bcount_up_ainit_v2       (init, cen, clk, cnt);
441
 
442
 
443
parameter cnt_size      = 6;
444
parameter init_val      ="000000";
445
parameter c_enable_rlocs=1;
446
 
447
wire gnd = 1'b0;
448
wire vcc = 1'b1;
449
parameter no    =0;
450
parameter yes   =1;
451
wire unused_1 = 1'b0;
452
wire unused_2 = 1'b0;
453
wire unused_3 = 1'b0;
454
wire unused_4 = 1'b0;
455
wire [cnt_size-1 : 0] dummy_val;
456
 
457
 
458
input init;
459
input cen;
460
input clk;
461
output [cnt_size-1 : 0] cnt;
462
 
463
C_COUNTER_BINARY_V3_0 #(init_val,
464
                        "1",
465
                0,
466
                        init_val,
467
                        c_enable_rlocs,
468
                        no,
469
                        yes,
470
                        no,
471
                        yes,
472
                        no,
473
                        no,
474
                        no,
475
                        no,
476
                        no,
477
                        no,
478
                        no,
479
                        no,
480
                        no,
481
                        no,
482
                        no,
483
                        0,
484
                        0,
485
                        1,
486
                        0,
487
                        init_val,
488
                        1,
489
                        1,
490
                        init_val,
491
                        init_val,
492
                        cnt_size
493
                        )
494
 
495
        count_bin       (.Q(cnt),
496
                        .CLK(clk),
497
                        .UP(vcc),
498
                        .THRESH0(unused_1),
499
                        .Q_THRESH0(unused_2),
500
                        .THRESH1(unused_3),
501
                        .Q_THRESH1(unused_4),
502
                        .CE(cen),
503
                        .LOAD(gnd),
504
                        .L(dummy_val),
505
                        .IV(dummy_val),
506
                        .ACLR(gnd),
507
                        .ASET(gnd),
508
                        .AINIT(init),
509
                        .SCLR(gnd),
510
                        .SSET(gnd),
511
                        .SINIT(gnd)
512
                        );
513
 
514
endmodule
515
 
516
 
517
/* Behavioral description of binary_to_gray */
518
module binary_to_gray_v2 (rst, clk, cen, bin, gray);
519
 
520
parameter reg_size = 6;
521
parameter init_val = "";
522
parameter c_enable_rlocs = 1;
523
 
524
input rst;
525
input clk;
526
input cen;
527
input [reg_size-1:0] bin;
528
output [reg_size-1:0] gray;
529
 
530
reg [reg_size-1:0] AIV;
531
reg [reg_size-1:0] gray;
532
 
533
 
534
initial
535
begin
536
        AIV = to_bits(init_val);
537
end
538
 
539
 
540
always @(posedge clk or posedge rst)
541
begin
542
if (rst == 1'b1)
543
                gray =  AIV;
544
else if (cen == 1'b1)
545
        begin : loop
546
        integer i;
547
                for (i=0; i<=reg_size-1; i=i+1)
548
                if (i == reg_size-1)
549
                        gray[i] = bin[i];
550
                else
551
                        gray[i] = bin[i+1] ^ bin[i];
552
        end
553
end
554
 
555
 
556
function [reg_size-1 : 0] to_bits;
557
        input [reg_size*8 : 1] instring;
558
        integer i;
559
        integer non_null_string;
560
        begin
561
                non_null_string = 0;
562
                for(i = reg_size; i > 0; i = i - 1)
563
                begin // Is the string empty?
564
                        if(instring[(i*8)] == 0 &&
565
                                instring[(i*8)-1] == 0 &&
566
                                instring[(i*8)-2] == 0 &&
567
                                instring[(i*8)-3] == 0 &&
568
                                instring[(i*8)-4] == 0 &&
569
                                instring[(i*8)-5] == 0 &&
570
                                instring[(i*8)-6] == 0 &&
571
                                instring[(i*8)-7] == 0 &&
572
                                non_null_string == 0)
573
                                        non_null_string = 0; // Use the return value to flag a non-empty string
574
                        else
575
                                        non_null_string = 1; // Non-null character!
576
                end
577
                if(non_null_string == 0) // String IS empty! Just return the value to be all '0's
578
                begin
579
                        for(i = reg_size; i > 0; i = i - 1)
580
                                to_bits[i-1] = 0;
581
                end
582
                else
583
                begin
584
                        for(i = reg_size; i > 0; i = i - 1)
585
                        begin // Is this character a '0'? (ASCII = 48 = 00110000)
586
                                if(instring[(i*8)] == 0 &&
587
                                        instring[(i*8)-1] == 0 &&
588
                                        instring[(i*8)-2] == 1 &&
589
                                        instring[(i*8)-3] == 1 &&
590
                                        instring[(i*8)-4] == 0 &&
591
                                        instring[(i*8)-5] == 0 &&
592
                                        instring[(i*8)-6] == 0 &&
593
                                        instring[(i*8)-7] == 0)
594
                                                to_bits[i-1] = 0;
595
                                  // Or is it a '1'? 
596
                                else if(instring[(i*8)] == 0 &&
597
                                        instring[(i*8)-1] == 0 &&
598
                                        instring[(i*8)-2] == 1 &&
599
                                        instring[(i*8)-3] == 1 &&
600
                                        instring[(i*8)-4] == 0 &&
601
                                        instring[(i*8)-5] == 0 &&
602
                                        instring[(i*8)-6] == 0 &&
603
                                        instring[(i*8)-7] == 1)
604
                                                to_bits[i-1] = 1;
605
                                  // Or is it a ' '? (a null char - in which case insert a '0')
606
                                else if(instring[(i*8)] == 0 &&
607
                                        instring[(i*8)-1] == 0 &&
608
                                        instring[(i*8)-2] == 0 &&
609
                                        instring[(i*8)-3] == 0 &&
610
                                        instring[(i*8)-4] == 0 &&
611
                                        instring[(i*8)-5] == 0 &&
612
                                        instring[(i*8)-6] == 0 &&
613
                                        instring[(i*8)-7] == 0)
614
                                                to_bits[i-1] = 0;
615
                                else
616
                                begin
617
                                        $display("Error: non-binary digit in string \"%s\"\nExiting simulation...", instring);
618
                                        $finish;
619
                                end
620
                        end
621
                end
622
        end
623
        endfunction
624
 
625
endmodule
626
/* End Behavioral Description of Binary To Gray Module */
627
 
628
 
629
/* Equality Comparator Module (eq_compare.v) */
630
module eq_compare_v2 (a, b, eq);
631
 
632
parameter c_width       =6;
633
parameter c_enable_rlocs=1;
634
 
635
input [c_width-1 : 0] a;
636
input [c_width-1 : 0] b;
637
output eq;
638
 
639
wire gnd = 1'b0;
640
wire vcc = 1'b1;
641
parameter no    =0;
642
parameter yes   =1;
643
parameter zero=1'b0;
644
parameter dummy_val={c_width-1{zero}};
645
 
646
 
647
wire dummy_out_1;
648
wire dummy_out_2;
649
wire dummy_out_3;
650
wire dummy_out_4;
651
wire dummy_out_5;
652
wire dummy_out_6;
653
wire dummy_out_7;
654
wire dummy_out_8;
655
wire dummy_out_9;
656
wire dummy_out_10;
657
wire dummy_out_11;
658
 
659
C_COMPARE_V3_0 #( "",
660
                no,
661
                dummy_val,
662
                1,
663
                c_enable_rlocs,
664
                no,
665
                no,
666
                yes,
667
                no,
668
                no,
669
                no,
670
                no,
671
                no,
672
                no,
673
                no,
674
                no,
675
                no,
676
                no,
677
                no,
678
                no,
679
                no,
680
                no,
681
                1,
682
                1,
683
                1,
684
                c_width)
685
 
686
  eq_comp       (.A(a),
687
                .B(b),
688
                .A_EQ_B(eq),
689
                .CLK(gnd),
690
                .CE(gnd),
691
                .ACLR(gnd),
692
                .ASET(gnd),
693
                .SCLR(gnd),
694
                .SSET(gnd),
695
                .A_GT_B(dummy_out_1),
696
                .A_GE_B(dummy_out_2),
697
                .A_LT_B(dummy_out_3),
698
                .A_LE_B(dummy_out_4),
699
                .A_NE_B(dummy_out_5),
700
                .QA_GT_B(dummy_out_6),
701
                .QA_GE_B(dummy_out_7),
702
                .QA_LT_B(dummy_out_8),
703
                .QA_LE_B(dummy_out_9),
704
                .QA_EQ_B(dummy_out_10),
705
                .QA_NE_B(dummy_out_11)
706
                );
707
 
708
endmodule
709
/* End Equality Comparator Module */
710
 
711
 
712
/* reg_ainit.v Module */
713
module reg_ainit_v2 (rst, clk, cen, din, qout);
714
 
715
parameter reg_size      =6;
716
parameter init_val      ="000000";
717
parameter c_enable_rlocs=1;
718
 
719
input rst;
720
input clk;
721
input cen;
722
input [reg_size-1 : 0] din;
723
output [reg_size-1 :0] qout;
724
 
725
parameter no    =0;
726
parameter yes   =1;
727
wire gnd = 1'b0;
728
wire vcc = 1'b1;
729
 
730
C_REG_FD_V3_0 #(init_val,
731
                c_enable_rlocs,
732
                no,
733
                yes,
734
                no,
735
                yes,
736
                no,
737
                no,
738
                no,
739
                init_val,
740
                1,
741
                1,
742
                reg_size)
743
   reg_fd       (.D(din),
744
                .Q(qout),
745
                .CLK(clk),
746
                .CE(cen),
747
                .ACLR(gnd),
748
                .ASET(gnd),
749
                .AINIT(rst),
750
                .SCLR(gnd),
751
                .SSET(gnd),
752
                .SINIT(gnd)
753
                );
754
endmodule
755
/* End reg_ainit.v */
756
 
757
 
758
/* and_a_b.v */
759
module and_a_b_v2 (a_in, b_in, and_out);
760
 
761
input a_in;
762
input b_in;
763
output and_out;
764
 
765
parameter no    =0;
766
parameter yes   =1;
767
wire fake_in = 0;
768
wire fake_out;
769
wire [1: 0] and_in = {a_in, b_in};
770
 
771
C_GATE_BIT_V3_0 #("0",
772
                  0,
773
                  0,
774
                  no,
775
                  no,
776
                  no,
777
                  no,
778
                  yes,
779
                  no,
780
                  no,
781
                  no,
782
                  no,
783
                  2,
784
                  "00",
785
                  0,
786
                  "0",
787
                  0,
788
                  1)
789
 
790
 and_a_b        (.I(and_in),
791
                .O(and_out),
792
                .CLK(fake_in),
793
                .Q(fake_out),
794
                .CE(fake_in),
795
                .AINIT(fake_in),
796
                .ASET(fake_in),
797
                .ACLR(fake_in),
798
                .SINIT(fake_in),
799
                .SSET(fake_in),
800
                .SCLR(fake_in)
801
                );
802
endmodule
803
/* End and_a_b.v */
804
 
805
 
806
/* Behvioral Model of or_a_b.v */
807
module or_a_b_v2 (a_in, b_in, or_out);
808
 
809
input a_in;
810
input b_in;
811
output or_out;
812
 
813
wire or_out = a_in | b_in;
814
 
815
endmodule
816
/* End Behavioral of or_a_b.v */
817
 
818
 
819
/* Behavioral Model of and_a_notb */
820
module and_a_notb_v2 (a_in, b_in, and_out);
821
 
822
parameter c_enable_rlocs        =1;
823
input a_in;
824
input b_in;
825
output and_out;
826
 
827
assign and_out = a_in & !b_in;
828
 
829
endmodule
830
/* End Behavioral of and_a_notb */
831
 
832
 
833
/* and_a_notb_fd */
834
module and_a_notb_fd_v2 (a_in, b_in, clk, rst, q_out);
835
 
836
parameter init_val      ="0";
837
parameter c_enable_rlocs        = 1;
838
 
839
input a_in;
840
input b_in;
841
input clk;
842
input rst;
843
output q_out;
844
 
845
parameter no    =0;
846
parameter yes   =1;
847
 
848
wire vcc = 1'b1;
849
wire fake_in =0;
850
wire fake_out;
851
wire [1 : 0] and_in;
852
 
853
assign and_in = {b_in, a_in};
854
 
855
C_GATE_BIT_V3_0 #(init_val,
856
                 c_enable_rlocs,
857
                  0,
858
                  no,
859
                  yes,
860
                  no,
861
                  no,
862
                  no,
863
                  yes,
864
                  no,
865
                  no,
866
                  no,
867
                  2,
868
                  "10",
869
                  1,            //c_pipe_stages ? 
870
                  "0",
871
                  0,
872
                  1
873
                )
874
  and_fd        (.I(and_in),
875
                .O(fake_out),
876
                .CLK(clk),
877
                .Q(q_out),
878
                .CE(vcc),
879
                .AINIT(rst),
880
                .ASET(fake_in),
881
                .ACLR(fake_in),
882
                .SINIT(fake_in),
883
                .SSET(fake_in),
884
                .SCLR(fake_in)
885
                );
886
endmodule
887
/* End and_a_notb_fd */
888
 
889
 
890
/* nand_a_notb_fd */
891
module nand_a_notb_fd_v2 (a_in, b_in, clk, rst, q_out);
892
 
893
parameter init_val      ="0";
894
parameter no    =0;
895
parameter yes   =1;
896
 
897
input a_in;
898
input b_in;
899
input clk;
900
input rst;
901
output q_out;
902
 
903
wire vcc =1;
904
wire fake_in =0;
905
wire fake_out;
906
wire [1 : 0] nand_in;
907
 
908
assign nand_in = {b_in, a_in};
909
 
910
C_GATE_BIT_V3_0 #(init_val,
911
                yes,
912
                  1,
913
                  no,
914
                 yes,
915
                 no,
916
                  no,
917
                  no,
918
                  yes,
919
                  no,
920
                  no,
921
                  no,
922
                  2,
923
                  "10",
924
                  1,
925
                 "0",
926
                 0,
927
                 1
928
                 )
929
  nand_fd       (.I(nand_in),
930
                .O(fake_out),
931
                .CLK(clk),
932
                .Q(q_out),
933
                .CE(vcc),
934
                .AINIT(rst),
935
                .ASET(fake_in),
936
                .ACLR(fake_in),
937
                .SINIT(fake_in),
938
                .SSET(fake_in),
939
                .SCLR(fake_in)
940
                );
941
endmodule
942
/* end nand_a_notb_fd */
943
 
944
 
945
/* Behavioral Model of and_a_b_notc */
946
module and_a_b_notc_v2 (a_in, b_in, c_in, and_out);
947
 
948
input a_in;
949
input b_in;
950
input c_in;
951
output and_out;
952
 
953
 
954
wire and_out = a_in & b_in & !c_in;
955
 
956
endmodule
957
/* End Behavioral of end and_a_b_notc */
958
 
959
 
960
/* Behavioral Model of and_a_b_c_notd */
961
module and_a_b_c_notd_v2 (a_in, b_in, c_in, d_in, and_out);
962
 
963
input a_in;
964
input b_in;
965
input c_in;
966
input d_in;
967
output and_out;
968
 
969
wire and_out = a_in & b_in & c_in & !d_in;
970
 
971
endmodule
972
/* End Behavioral Model of and_a_b_c_notd */
973
 
974
        /* or_fd */
975
module or_fd_v2 (a_in, b_in, clk, rst, q_out);
976
 
977
parameter init_val      ="0";
978
 
979
input a_in;
980
input b_in;
981
input clk;
982
input rst;
983
output q_out;
984
 
985
parameter no    =0;
986
parameter yes   =1;
987
 
988
wire vcc = 1'b1;
989
wire fake_in =0;
990
wire fake_out;
991
wire [1 : 0] or_in;
992
 
993
assign or_in = {b_in, a_in};
994
 
995
C_GATE_BIT_V3_0 #(init_val,
996
                  yes,
997
                  2,
998
                  no,
999
                  yes,
1000
                  no,
1001
                  no,
1002
                  no,
1003
                  yes,
1004
                  no,
1005
                  no,
1006
                  no,
1007
                  2,
1008
                  "00",
1009
                  1,
1010
                  "0",
1011
                  0,
1012
                  1
1013
                  )
1014
 or_fd          (.I(or_in),
1015
                .O(fake_out),
1016
                .CLK(clk),
1017
                .Q(q_out),
1018
                .CE(vcc),
1019
                .AINIT(rst),
1020
                .ASET(fake_in),
1021
                .ACLR(fake_in),
1022
                .SINIT(fake_in),
1023
                .SSET(fake_in),
1024
                .SCLR(fake_in)
1025
                );
1026
endmodule
1027
/* end or_fd */
1028
 
1029
 
1030
/* and_fd */
1031
module and_fd_v2 (a_in, b_in, clk, rst, q_out);
1032
 
1033
parameter init_val      ="0";
1034
parameter c_enable_rlocs        =1;
1035
 
1036
input a_in;
1037
input b_in;
1038
input clk;
1039
input rst;
1040
output q_out;
1041
 
1042
parameter no    =0;
1043
parameter yes   =1;
1044
 
1045
wire vcc = 1'b1;
1046
wire fake_in =0;
1047
wire fake_out;
1048
wire [1 : 0] and_in;
1049
 
1050
assign and_in = {b_in, a_in};
1051
 
1052
C_GATE_BIT_V3_0 #(init_val,
1053
                c_enable_rlocs,
1054
                  0,
1055
                  no,
1056
                  yes,
1057
                  no,
1058
                  no,
1059
                  no,
1060
                  yes,
1061
                  no,
1062
                  no,
1063
                  no,
1064
                  2,
1065
                  "00",
1066
                  1,
1067
                  "0",
1068
                   0,
1069
                  1
1070
                        )
1071
 and_fd         (.I(and_in),
1072
                .O(fake_out),
1073
                .CLK(clk),
1074
                .Q(q_out),
1075
                .CE(vcc),
1076
                .AINIT(rst),
1077
                .ASET(fake_in),
1078
                .ACLR(fake_in),
1079
                .SINIT(fake_in),
1080
                .SSET(fake_in),
1081
                .SCLR(fake_in)
1082
                );
1083
 
1084
endmodule
1085
/* end and_fd */
1086
 
1087
 
1088
/* nand_fd */
1089
module nand_fd_v2 (a_in, b_in, clk, rst, q_out);
1090
 
1091
parameter init_val      ="0";
1092
parameter c_enable_rlocs        =1;
1093
 
1094
input a_in;
1095
input b_in;
1096
input clk;
1097
input rst;
1098
output q_out;
1099
 
1100
parameter no    =0;
1101
parameter yes   =1;
1102
 
1103
wire vcc= 1'b1;
1104
wire fake_in=0;
1105
wire fake_out;
1106
wire [1 : 0] nand_in;
1107
 
1108
assign nand_in = {b_in, a_in};
1109
 
1110
C_GATE_BIT_V3_0 #(init_val,
1111
                c_enable_rlocs,
1112
                  1,
1113
                  no,
1114
                  yes,
1115
                  no,
1116
                  no,
1117
                  no,
1118
                  yes,
1119
                  no,
1120
                  no,
1121
                  no,
1122
                  2,
1123
                  "00",
1124
                  1,
1125
                  "0",
1126
                  0,
1127
                  1
1128
                  )
1129
 nand_fd        (.I(nand_in),
1130
                .O(fake_out),
1131
                .CLK(clk),
1132
                .Q(q_out),
1133
                .CE(vcc),
1134
                .AINIT(rst),
1135
                .ASET(fake_in),
1136
                .ACLR(fake_in),
1137
                .SINIT(fake_in),
1138
                .SSET(fake_in),
1139
                .SCLR(fake_in)
1140
                );
1141
endmodule
1142
/* end nand_fd */
1143
 
1144
 
1145
/* or3_fd */
1146
module or3_fd_v2 (a_in, b_in, c_in, clk, rst, q_out);
1147
 
1148
parameter init_val      ="0";
1149
 
1150
input a_in;
1151
input b_in;
1152
input c_in;
1153
input clk;
1154
input rst;
1155
output q_out;
1156
 
1157
parameter no    =0;
1158
parameter yes   =1;
1159
 
1160
wire vcc = 1'b1;
1161
wire fake_in =0;
1162
wire fake_out;
1163
wire [2 : 0] or_in;
1164
 
1165
assign or_in = {a_in, b_in, c_in};
1166
 
1167
C_GATE_BIT_V3_0 #(init_val,
1168
                yes,
1169
                  2,
1170
                  no,
1171
                  yes,
1172
                  no,
1173
                  no,
1174
                  no,
1175
                  yes,
1176
                  no,
1177
                  no,
1178
                  no,
1179
                  3,
1180
                  "000",
1181
                  1,
1182
                  "0",
1183
                  0,
1184
                  1
1185
                )
1186
 or3_fd         (.I(or_in),
1187
                .O(fake_out),
1188
                .CLK(clk),
1189
                .Q(q_out),
1190
                .CE(vcc),
1191
                .AINIT(rst),
1192
                .ASET(fake_in),
1193
                .ACLR(fake_in),
1194
                .SINIT(fake_in),
1195
                .SSET(fake_in),
1196
                .SCLR(fake_in)
1197
                );
1198
endmodule
1199
/* end or3_fd */
1200
 
1201
 
1202
/* almost_reg */
1203
module almost_reg_v2 (a_in, b_in, c_in, d_in, clk, rst, q_out);
1204
 
1205
parameter init_val      ="0";
1206
 
1207
input a_in;
1208
input b_in;
1209
input c_in;
1210
input d_in;
1211
input clk;
1212
input rst;
1213
output q_out;
1214
 
1215
and_a_b_v2 and_gate (.a_in(c_in),
1216
                .b_in(d_in),
1217
                .and_out(and_out)
1218
                );
1219
 
1220
or3_fd_v2 #(init_val)
1221
 or3_reg (.a_in(a_in),
1222
        .b_in(b_in),
1223
        .c_in(and_out),
1224
        .clk(clk),
1225
        .rst(rst),
1226
        .q_out(q_out)
1227
        );
1228
 
1229
endmodule
1230
/* end almost_reg */
1231
 
1232
 
1233
/*count_sub_reg */
1234
module count_sub_reg_v2 (a_in, b_in, clk, rst_a, rst_b, q_out);
1235
 
1236
parameter width         =6;
1237
parameter a_width       =6;
1238
parameter b_width       =6;
1239
parameter q_width       =2;
1240
parameter c_enable_rlocs=1;
1241
 
1242
input [a_width-1 : 0] a_in;
1243
input [b_width-1 : 0] b_in;
1244
input clk;
1245
input rst_a;
1246
input rst_b;
1247
output [q_width-1 : 0] q_out;
1248
 
1249
parameter no    =0;
1250
parameter yes   =1;
1251
parameter zero  =1'b0;
1252
parameter zerostring    ={(width+1){zero}};
1253
parameter initstring    ={q_width{zero}};
1254
 
1255
parameter a_pad =width-a_width;
1256
parameter b_pad =width-b_width;
1257
 
1258
wire dummy_in =0;
1259
wire [q_width-1 : 0] load_0;
1260
wire load_1;
1261
wire load_2;
1262
wire load_3;
1263
wire load_4;
1264
wire load_5;
1265
wire load_6;
1266
wire reset;
1267
wire [width : 0] a;
1268
wire [width : 0] b;
1269
wire [q_width-1 : 0] addsub_out;
1270
wire gnd = 1'b0;
1271
wire vcc = 1'b1;
1272
wire [q_width-1 : 0] q_out = addsub_out;
1273
 
1274
integer i;
1275
 
1276
assign a = {vcc, a_in} ;
1277
assign b = {gnd, b_in};
1278
 
1279
 C_ADDSUB_V3_0 #(1,
1280
                initstring,
1281
                1,
1282
                width +1,
1283
                no,
1284
                no,
1285
                no,
1286
                1,
1287
                zerostring,
1288
                width +1,
1289
                c_enable_rlocs,
1290
                no,
1291
                no,
1292
                yes,
1293
                no,
1294
                no,
1295
                no,
1296
                no,
1297
                no,
1298
                no,
1299
                no,
1300
                no,
1301
                no,
1302
                no,
1303
                yes,
1304
                no,
1305
                no,
1306
                no,
1307
                no,
1308
                no,
1309
                no,
1310
                no,
1311
                width-1,
1312
                1,              // Add this for C_LATENCY in version 3, robertle
1313
                width-q_width,
1314
                width+1,
1315
                1,
1316
                initstring,
1317
                1,
1318
                1)
1319
  count_sub_reg         (.A(a),
1320
                .B(b),
1321
                .Q(addsub_out),
1322
                .S(load_0),
1323
                .CLK(clk),
1324
                .ADD(dummy_in),
1325
                .OVFL(load_1),
1326
                .Q_OVFL(load_2),
1327
                .C_IN(dummy_in),
1328
                .C_OUT(load_3),
1329
                .Q_C_OUT(load_4),
1330
                .B_IN(dummy_in),
1331
                .B_OUT(load_5),
1332
                .Q_B_OUT(load_6),
1333
                .CE(dummy_in),
1334
                .BYPASS(dummy_in),
1335
                .A_SIGNED(dummy_in),
1336
                .B_SIGNED(dummy_in),
1337
                .ACLR(dummy_in),
1338
                .ASET(dummy_in),
1339
                .AINIT(reset),
1340
                .SCLR(dummy_in),
1341
                .SSET(dummy_in),
1342
                .SINIT(dummy_in)
1343
                );
1344
 
1345
or_a_b_v2 or_gate (.a_in(rst_a),
1346
                .b_in(rst_b),
1347
                .or_out(reset)
1348
                );
1349
endmodule
1350
/* end count_sub_reg */
1351
 
1352
 
1353
/* ***************************************************************************
1354
 * This block removed 09/26/00 by jogden to fix CR 126807 where empty flag
1355
 *  was causing wr_count to reset.
1356
 * **************************************************************************/
1357
 
1358
 /* pulse_reg  */
1359
 
1360
//module pulse_reg_v2 (sclr_in, sset_in, clk, rst, q_out);
1361
//
1362
//input sclr_in;
1363
//input sset_in;
1364
//input clk;
1365
//input rst;
1366
//output q_out;
1367
//
1368
//wire gnd = 1'b0;
1369
//wire vcc = 1'b1;
1370
//parameter no  =0;
1371
//parameter yes =1;
1372
//wire sclr;
1373
//wire [0:0] reg_out;
1374
//wire b_tmp = reg_out[0];
1375
//wire q_out = reg_out[0];
1376
//
1377
//and_a_b_v2 and_gate (.a_in(sclr_in),
1378
//              .b_in(b_tmp),
1379
//              .and_out(sclr)
1380
//              );
1381
//
1382
//C_REG_FD_V3_0         #("0",
1383
//                      no,
1384
//                      no,
1385
//                      yes,
1386
//                      no,
1387
//                      no,
1388
//                      yes,
1389
//                      no,
1390
//                      yes,
1391
//                      "0",
1392
//                      1,      
1393
//                      1,      
1394
//                      1
1395
//                      )
1396
//  reg_fd              (.D(reg_out),
1397
//                      .Q(reg_out),
1398
//                      .CLK(clk),
1399
//                      .CE(vcc),
1400
//                      .ACLR(gnd),
1401
//                      .ASET(gnd),
1402
//                      .AINIT(rst),
1403
//                      .SCLR(sclr),
1404
//                      .SSET(sset_in),
1405
//                      .SINIT(gnd)
1406
//                      );
1407
//endmodule
1408
 
1409
/* end pulse_reg */
1410
 
1411
 
1412
/* xor_gate_bit */
1413
module xor_gate_bit_v2 (a, xor_out);
1414
 
1415
parameter input_width   = 6;
1416
input [input_width-1 : 0] a;
1417
output xor_out;
1418
 
1419
parameter zero  =1'b0;
1420
parameter zerostring    ={input_width{zero}};
1421
 
1422
wire sourceless_net =0;
1423
wire dummy_load_0;
1424
 
1425
C_GATE_BIT_V3_0 #("0",
1426
                0,
1427
                4,
1428
                0,
1429
                0,
1430
                0,
1431
                0,
1432
                1,
1433
                0,
1434
                0,
1435
                0,
1436
                0,
1437
                input_width,
1438
                zerostring,
1439
                0,
1440
                "0",
1441
                0,
1442
                1
1443
                )
1444
  xor_mod       (.I(a),
1445
                .CLK(sourceless_net),
1446
                .CE(sourceless_net),
1447
                .AINIT(sourceless_net),
1448
                .ASET(sourceless_net),
1449
                .ACLR(sourceless_net),
1450
                .SINIT(sourceless_net),
1451
                .SSET(sourceless_net),
1452
                .SCLR(sourceless_net),
1453
                .Q(dummy_load_0),
1454
                .O(xor_out)
1455
                );
1456
endmodule
1457
/* end xor_gate_bit */
1458
 
1459
 
1460
/* Behavioral Model of gray_to_binary */
1461
module gray_to_binary_v2 (bin_reg, grey_reg, reset, clk);
1462
 
1463
parameter num_of_bits = 6;
1464
parameter init_val = "";
1465
parameter c_enable_rlocs = 1;
1466
 
1467
input reset;
1468
input clk;
1469
input [num_of_bits-1:0] grey_reg;
1470
output [num_of_bits-1:0] bin_reg;
1471
 
1472
reg [num_of_bits-1 : 0] AIV;
1473
reg [num_of_bits-1 : 0] bin_reg;
1474
reg [num_of_bits-1 : 0] bin_reg_d;
1475
reg temp;
1476
 
1477
initial
1478
        begin
1479
        AIV = to_bits(init_val);
1480
        end
1481
 
1482
always @(grey_reg)
1483
        begin : temp_loop
1484
        integer i;
1485
                for (i=num_of_bits-1; i>=0; i=i-1)
1486
                if (i == num_of_bits-1)
1487
                        begin
1488
                        temp = grey_reg[i];
1489
                        bin_reg_d[i] = temp;
1490
                        end
1491
                else
1492
                        begin
1493
                        temp = grey_reg[i] ^ temp;
1494
                        bin_reg_d[i] = temp;
1495
                        end
1496
        end
1497
 
1498
 
1499
 
1500
always @(posedge clk or posedge reset)
1501
begin
1502
        if (reset == 1)
1503
                bin_reg =  AIV;
1504
        else
1505
                bin_reg = bin_reg_d;
1506
end
1507
 
1508
 
1509
function [num_of_bits - 1 : 0] to_bits;
1510
        input [num_of_bits*8 : 1] instring;
1511
        integer i;
1512
        integer non_null_string;
1513
        begin
1514
                non_null_string = 0;
1515
                for(i = num_of_bits; i > 0; i = i - 1)
1516
                begin // Is the string empty?
1517
                        if(instring[(i*8)] == 0 &&
1518
                                instring[(i*8)-1] == 0 &&
1519
                                instring[(i*8)-2] == 0 &&
1520
                                instring[(i*8)-3] == 0 &&
1521
                                instring[(i*8)-4] == 0 &&
1522
                                instring[(i*8)-5] == 0 &&
1523
                                instring[(i*8)-6] == 0 &&
1524
                                instring[(i*8)-7] == 0 &&
1525
                                non_null_string == 0)
1526
                                        non_null_string = 0; // Use the return value to flag a non-empty string
1527
                        else
1528
                                        non_null_string = 1; // Non-null character!
1529
                end
1530
                if(non_null_string == 0) // String IS empty! Just return the value to be all '0's
1531
                begin
1532
                        for(i = num_of_bits; i > 0; i = i - 1)
1533
                                to_bits[i-1] = 0;
1534
                end
1535
                else
1536
                begin
1537
                        for(i = num_of_bits; i > 0; i = i - 1)
1538
                        begin // Is this character a '0'? (ASCII = 48 = 00110000)
1539
                                if(instring[(i*8)] == 0 &&
1540
                                        instring[(i*8)-1] == 0 &&
1541
                                        instring[(i*8)-2] == 1 &&
1542
                                        instring[(i*8)-3] == 1 &&
1543
                                        instring[(i*8)-4] == 0 &&
1544
                                        instring[(i*8)-5] == 0 &&
1545
                                        instring[(i*8)-6] == 0 &&
1546
                                        instring[(i*8)-7] == 0)
1547
                                                to_bits[i-1] = 0;
1548
                                  // Or is it a '1'? 
1549
                                else if(instring[(i*8)] == 0 &&
1550
                                        instring[(i*8)-1] == 0 &&
1551
                                        instring[(i*8)-2] == 1 &&
1552
                                        instring[(i*8)-3] == 1 &&
1553
                                        instring[(i*8)-4] == 0 &&
1554
                                        instring[(i*8)-5] == 0 &&
1555
                                        instring[(i*8)-6] == 0 &&
1556
                                        instring[(i*8)-7] == 1)
1557
                                                to_bits[i-1] = 1;
1558
                                  // Or is it a ' '? (a null char - in which case insert a '0')
1559
                                else if(instring[(i*8)] == 0 &&
1560
                                        instring[(i*8)-1] == 0 &&
1561
                                        instring[(i*8)-2] == 0 &&
1562
                                        instring[(i*8)-3] == 0 &&
1563
                                        instring[(i*8)-4] == 0 &&
1564
                                        instring[(i*8)-5] == 0 &&
1565
                                        instring[(i*8)-6] == 0 &&
1566
                                        instring[(i*8)-7] == 0)
1567
                                                to_bits[i-1] = 0;
1568
                                else
1569
                                begin
1570
                                        $display("Error: non-binary digit in string \"%s\"\nExiting simulation...", instring);
1571
                                        $finish;
1572
                                end
1573
                        end
1574
                end
1575
        end
1576
        endfunction
1577
endmodule
1578
/* End Behavioral of gray_to_binary */
1579
 
1580
 
1581
/* full_flag */
1582
module full_flag_reg_v2 (rst, flag_clk, flag_ce1, flag_ce2, reg_clk, reg_ce, a_in, b_in, dlyd_out, flag_out, to_almost_logic);
1583
 
1584
parameter addr_width    =6;
1585
parameter c_enable_rlocs=0;
1586
 
1587
input rst;
1588
input flag_clk;
1589
input flag_ce1;
1590
input flag_ce2;
1591
input reg_clk   ;
1592
input reg_ce    ;
1593
input [addr_width-1 : 0]  a_in;
1594
input [addr_width-1 : 0] b_in;
1595
output [addr_width-1 : 0] dlyd_out;
1596
output flag_out ;
1597
output to_almost_logic;
1598
 
1599
 
1600
wire gnd = 0;
1601
wire pwr =1;
1602
wire flag_d;
1603
reg flag_q;
1604
reg [addr_width-1 : 0] b_dlyd;
1605
 
1606
wire flag_ce;
1607
integer i;
1608
 
1609
 
1610
assign dlyd_out = b_dlyd;
1611
assign #1 flag_out = flag_q;
1612
assign to_almost_logic = flag_d;
1613
assign flag_ce = flag_ce1 || flag_ce2;
1614
assign flag_d = ( ( (a_in== b_in)&&(flag_q == 1) ) || ((a_in == b_dlyd)&&(flag_q == 0)) ) ? 1 : 0;
1615
 
1616
initial
1617
begin
1618
        flag_q <= 1'b1;
1619
end
1620
 
1621
always @(posedge rst or posedge flag_clk)
1622
begin
1623
        if (rst == 1)
1624
                flag_q <= 1'b1;
1625
        else
1626
                flag_q <= (flag_ce) ? flag_d : flag_q;
1627
end
1628
 
1629
 
1630
always @(posedge rst or posedge reg_clk)
1631
begin
1632
        if (rst == 1)
1633
        begin
1634
          for (i=0; i <= addr_width-1; i=i+1)
1635
                begin
1636
                b_dlyd[i] <= (i==0 || i==1 || i==addr_width-1) ?  1 : 0;
1637
                end //for
1638
        end
1639
        else
1640
          b_dlyd <= (reg_ce ) ? b_in : b_dlyd;
1641
end
1642
endmodule
1643
/* end full_flag */
1644
 
1645
 
1646
/* empty_flag */
1647
module empty_flag_reg_v2 (rst, flag_clk, flag_ce1, flag_ce2, reg_clk, reg_ce, a_in, b_in, dlyd_out, flag_out, to_almost_logic);
1648
 
1649
parameter addr_width    =6;
1650
parameter c_enable_rlocs=0;
1651
 
1652
input rst;
1653
input flag_clk;
1654
input flag_ce1;
1655
input flag_ce2;
1656
input reg_clk   ;
1657
input reg_ce    ;
1658
input [addr_width-1 : 0]  a_in;
1659
input [addr_width-1 : 0] b_in;
1660
output [addr_width-1 : 0] dlyd_out;
1661
output flag_out ;
1662
output to_almost_logic;
1663
 
1664
 
1665
wire flag_d;
1666
reg flag_q;
1667
reg [addr_width-1 : 0] b_dlyd;
1668
 
1669
wire flag_ce;
1670
integer i;
1671
 
1672
assign dlyd_out = b_dlyd;
1673
assign #1 flag_out = flag_q;
1674
assign to_almost_logic = flag_d;
1675
assign flag_ce = flag_ce1 || flag_ce2;
1676
assign flag_d = ( ( (a_in== b_in)&&(flag_q == 1) ) || ((a_in == b_dlyd)&&(flag_q == 0)) ) ? 1 : 0;
1677
 
1678
initial
1679
begin
1680
        flag_q <= 1'b1;
1681
end
1682
 
1683
always @(posedge rst or posedge flag_clk)
1684
begin
1685
        if (rst == 1)
1686
                flag_q <= 1'b1;
1687
        else
1688
        flag_q <= (flag_ce) ? flag_d : flag_q;
1689
end
1690
 
1691
 
1692
always @(posedge rst or posedge reg_clk)
1693
begin
1694
        if (rst == 1)
1695
        begin
1696
          for (i=0; i <= addr_width-1; i=i+1)
1697
                begin
1698
                b_dlyd[i] <= (i==0 || i==addr_width-1) ?  1 : 0;
1699
                end //for
1700
        end
1701
        else
1702
          b_dlyd <= (reg_ce ) ? b_in : b_dlyd;
1703
end
1704
endmodule
1705
/* end empty_flag */
1706
 
1707
 
1708
/* almst_full flag */
1709
module almst_full_v2 (rst, flag_clk, flag_ce, reg_clk, reg_ce, a_in, b_in, rqst_in, flag_comb_in, flag_q_in, flag_out);
1710
 
1711
parameter addr_width    = 6;
1712
parameter c_enable_rlocs = 0;
1713
 
1714
input rst;
1715
input flag_clk;
1716
input flag_ce;
1717
input reg_clk;
1718
input reg_ce;
1719
input [addr_width-1 : 0] a_in;
1720
input [addr_width-1 : 0] b_in;
1721
input rqst_in;
1722
input flag_comb_in;
1723
input flag_q_in;
1724
output flag_out;
1725
 
1726
 
1727
wire flag_d;
1728
reg flag_q;
1729
reg [addr_width-1 : 0] b_dlyd;
1730
 
1731
wire comp_mux;
1732
wire rqst_mux;
1733
wire comb_or;
1734
 
1735
assign #1 flag_out = flag_q;
1736
 
1737
integer i;
1738
 
1739
assign comp_mux = ( ( (a_in == b_in) && (flag_q_in== 1) ) || ( (a_in == b_dlyd ) && (flag_q_in== 0 ) ) ) ? 1: 0;
1740
assign rqst_mux = ( (comp_mux==1) && ((rqst_in==1) || (flag_q_in==1)) ) ? 1 : 0;
1741
assign comb_or = ( (rqst_mux==1) || (flag_comb_in==1) ) ? 1: 0;
1742
assign flag_d = comb_or;
1743
 
1744
initial
1745
begin
1746
        flag_q <= 1'b1;
1747
end
1748
 
1749
always @(posedge rst or posedge flag_clk)
1750
begin
1751
        if (rst == 1)
1752
                flag_q <= 1'b1;
1753
        else
1754
                flag_q <= (flag_ce == 1) ? flag_d : flag_q;
1755
end
1756
 
1757
always @(posedge rst or posedge reg_clk)
1758
begin
1759
        if (rst == 1)
1760
        begin
1761
                for (i=0; i<=addr_width-1; i=i+1)
1762
                begin
1763
                b_dlyd[i] <= (i==1 || i==addr_width-1) ? 1 : 0;
1764
                end //for
1765
        end
1766
        else
1767
                b_dlyd <= (reg_ce == 1) ? b_in : b_dlyd;
1768
end
1769
endmodule
1770
/* end almst_full flag */
1771
 
1772
 
1773
/* almst_empty flag */
1774
module almst_empty_v2 (rst, flag_clk, flag_ce, reg_clk, reg_ce, a_in, b_in, rqst_in, flag_comb_in, flag_q_in, flag_out);
1775
 
1776
parameter addr_width    = 6;
1777
parameter c_enable_rlocs = 0;
1778
 
1779
input rst;
1780
input flag_clk;
1781
input flag_ce;
1782
input reg_clk;
1783
input reg_ce;
1784
input [addr_width-1 : 0] a_in;
1785
input [addr_width-1 : 0] b_in;
1786
input rqst_in;
1787
input flag_comb_in;
1788
input flag_q_in;
1789
output flag_out;
1790
 
1791
 
1792
wire flag_d;
1793
reg flag_q;
1794
reg [addr_width-1 : 0] b_dlyd;
1795
 
1796
wire comp_mux;
1797
wire rqst_mux;
1798
wire comb_or;
1799
 
1800
integer i;
1801
 
1802
assign #1 flag_out = flag_q;
1803
 
1804
assign comp_mux = ( ( (a_in == b_in) && (flag_q_in== 1) ) || ( (a_in == b_dlyd ) && (flag_q_in== 0 ) ) ) ? 1: 0;
1805
assign rqst_mux = ( (comp_mux==1) && ((rqst_in==1) || (flag_q_in==1)) ) ? 1 : 0;
1806
assign comb_or = ( (rqst_mux==1) || (flag_comb_in==1) ) ? 1: 0;
1807
assign flag_d = comb_or;
1808
 
1809
initial
1810
begin
1811
        flag_q <= 1'b1;
1812
end
1813
 
1814
always @(posedge rst or posedge flag_clk)
1815
begin
1816
        if (rst == 1)
1817
                flag_q <= 1'b1;
1818
        else
1819
                flag_q <= (flag_ce == 1) ? flag_d : flag_q;
1820
end
1821
 
1822
always @(posedge rst or posedge reg_clk)
1823
begin
1824
        if (rst == 1)
1825
        begin
1826
                for (i=0; i<=addr_width-1; i=i+1)
1827
                begin
1828
                b_dlyd[i] <= (i==0 || i==1 || i==addr_width-1) ? 1 : 0;
1829
                end //for
1830
        end
1831
        else
1832
                b_dlyd <= (reg_ce == 1) ? b_in : b_dlyd;
1833
end
1834
endmodule
1835
/* end almst_empty flag */
1836
 
1837
 
1838
/*  Fifo Control Module. fifoctlr_ns.v */
1839
module fifoctlr_ns_v2 (fifo_reset_in, read_clock_in, write_clock_in, read_request_in,
1840
                write_request_in,  read_enable_out, write_enable_out, full_flag_out,
1841
                empty_flag_out, almost_full_out, almost_empty_out, read_addr_out,
1842
                write_addr_out, wrsync_count_out, rdsync_count_out, read_ack,
1843
                read_error, write_ack, write_error);
1844
 
1845
 
1846
parameter width                 =6;
1847
parameter wr_width              =6;
1848
parameter rd_width              =6;
1849
parameter c_enable_rlocs        =1;
1850
parameter c_has_almost_full     =1;
1851
parameter c_has_almost_empty    =1;
1852
parameter c_has_wrsync_dcount   =1;
1853
parameter wrsync_dcount_width   =6;
1854
parameter c_has_rdsync_dcount   =1;
1855
parameter rdsync_dcount_width   =6;
1856
parameter c_has_rd_ack          =1;
1857
parameter c_rd_ack_low          =0;
1858
parameter c_has_rd_error        =1;
1859
parameter c_rd_error_low        =0;
1860
parameter c_has_wr_ack          =1;
1861
parameter c_wr_ack_low          =0;
1862
parameter c_has_wr_error        =1;
1863
parameter c_wr_error_low        =0;
1864
 
1865
 
1866
input fifo_reset_in;
1867
input read_clock_in;
1868
input write_clock_in;
1869
input read_request_in;
1870
input write_request_in;
1871
output read_enable_out;
1872
output write_enable_out;
1873
output full_flag_out;
1874
output empty_flag_out;
1875
output almost_full_out;
1876
output almost_empty_out;
1877
output [rd_width-1 : 0] read_addr_out;
1878
output [wr_width-1 : 0] write_addr_out;
1879
output [wrsync_dcount_width-1 : 0] wrsync_count_out;
1880
output [rdsync_dcount_width-1  : 0] rdsync_count_out;
1881
output read_ack;
1882
output read_error;
1883
output write_ack;
1884
output write_error;
1885
 
1886
parameter no    = 0;
1887
parameter yes   =1;
1888
 
1889
parameter greater_width = (wr_width > rd_width ) ? wr_width : rd_width;
1890
 
1891
wire gnd = 0;
1892
wire vcc = 1;
1893
wire reset;
1894
wire rd_clk;
1895
wire wr_clk;
1896
wire rd_en;
1897
wire rd_en_ram;
1898
wire wr_en;
1899
wire wr_en_ram;
1900
wire full_flag;
1901
wire almost_full;
1902
wire rdsync_full_flag;
1903
wire cond_full;
1904
wire cond_full_less1;
1905
wire cond_full_less2;
1906
wire  empty_flag;
1907
wire almost_empty;
1908
wire cond_empty;
1909
wire cond_empty_plus1;
1910
wire cond_empty_plus2;
1911
//wire wrsync_empty_pulse;    //removed 9-26-00 by jogden for CR 126807
1912
wire [rd_width-1 : 0] rd_addr_bin;
1913
wire [rd_width-1 : 0] rd_last_bin;
1914
wire [rd_width-1 : 0] rd_last_gray;
1915
wire [width-1 : 0] rd_last_trunc;
1916
wire [width-1 : 0] rd_dly1_gray;
1917
wire [width-1 : 0] rd_dly2_gray;
1918
wire [rd_width-1 : 0] wrsync_rd_last_gray;
1919
wire [rd_width-1 : 0] wrsync_rd_last_bin;
1920
wire [wr_width-1 : 0] wr_addr_bin;
1921
wire [wr_width-1 : 0] wr_last_bin;
1922
wire [wr_width-1 : 0] wr_last_gray;
1923
wire [width-1 : 0] wr_last_trunc;
1924
 
1925
wire [width-1 : 0] wr_dly1_gray;
1926
wire [wr_width-1 : 0] rdsync_wr_last_gray;
1927
wire [wr_width-1 : 0] rdsync_wr_last_bin;
1928
wire [rdsync_dcount_width-1 : 0] rdsync_data_count;
1929
wire [wrsync_dcount_width-1 : 0] wrsync_data_count;
1930
 
1931
wire fflag_comb;
1932
wire eflag_comb;
1933
 
1934
wire read_error_low;
1935
wire read_error_high;
1936
wire read_ack_high;
1937
wire read_ack_low;
1938
wire almost_empty_temp;
1939
wire write_error_low;
1940
wire write_error_high;
1941
wire write_ack_high;
1942
wire write_ack_low;
1943
wire almost_full_temp;
1944
wire [wrsync_dcount_width-1 : 0] wrsync_data_count_temp;
1945
wire [rdsync_dcount_width-1 : 0] rdsync_data_count_temp;
1946
wire read_error;
1947
wire write_error;
1948
wire read_ack;
1949
wire write_ack;
1950
 
1951
 
1952
/*  Fifoctlr_ns functions */
1953
parameter ascii_zero            = 8'b00110000;
1954
parameter ascii_one             = 8'b00110001;
1955
parameter zeros_width           = {width{ascii_zero}};
1956
parameter ones_width            = {width{ascii_one}};
1957
parameter gray_tc_width         = {ascii_one,{(width-1){ascii_zero}}};
1958
parameter tc_less1_width        = {ascii_one,{(width-2){ascii_zero}},ascii_one};
1959
parameter tc_less2_width        = {{2{ascii_one}},{(width-3){ascii_zero}},ascii_one};
1960
parameter tc_less3_width        = {{3{ascii_one}},{(width-4){ascii_zero}},ascii_one};
1961
 
1962
/* End Fifoctlr_ns functions */
1963
 
1964
 
1965
assign reset            = fifo_reset_in;
1966
assign rd_clk           = read_clock_in;
1967
assign wr_clk           = write_clock_in;
1968
assign read_enable_out  = rd_en_ram;
1969
assign write_enable_out = wr_en_ram;
1970
assign full_flag_out    = full_flag;
1971
assign empty_flag_out   = empty_flag;
1972
assign almost_full_out  = almost_full;
1973
assign almost_empty_out = almost_empty;
1974
assign read_addr_out    = rd_addr_bin;
1975
assign write_addr_out   = wr_addr_bin;
1976
assign rdsync_count_out = rdsync_data_count;
1977
assign wrsync_count_out = wrsync_data_count;
1978
 
1979
 
1980
integer i;
1981
 
1982
assign rd_last_trunc = rd_last_gray[rd_width-1 : rd_width-width];
1983
assign wr_last_trunc = wr_last_gray[wr_width-1 : wr_width-width];
1984
 
1985
and_a_notb_v2 #(c_enable_rlocs)
1986
   rd_en_and (.a_in(read_request_in),
1987
              .b_in(empty_flag),
1988
              .and_out(rd_en)
1989
              );
1990
 
1991
and_a_notb_v2 #(c_enable_rlocs)
1992
   rd_en_to_ram (.a_in(read_request_in),
1993
                .b_in(empty_flag),
1994
                .and_out(rd_en_ram)
1995
                );
1996
/*
1997
----------------------------------------------------------------
1998
--  Generate read handshake signals (ACK/ERROR) if requested
1999
----------------------------------------------------------------
2000
*/
2001
 
2002
//      if (c_has_rd_error == 1 &&  c_rd_error_low == 0) begin  //rd_error_hi
2003
                and_fd_v2 #("0",
2004
                        c_enable_rlocs)
2005
                  rd_error_fd_hi (.a_in(read_request_in),
2006
                                .b_in(empty_flag),
2007
                                .clk(rd_clk),
2008
                                .rst(reset),
2009
                                .q_out(read_error_high)
2010
                                );
2011
//      end //if rd_error_hi
2012
 
2013
//      if (c_has_rd_error == 1 && c_rd_error_low == 1)  begin //rd_error_lo
2014
                nand_fd_v2 #("1",
2015
                        c_enable_rlocs)
2016
                 rd_error_fd_lo (.a_in(read_request_in),
2017
                                .b_in(empty_flag),
2018
                                .clk(rd_clk),
2019
                                .rst(reset),
2020
                                .q_out(read_error_low)
2021
                                );
2022
//      end //if rd_error_lo
2023
 
2024
 
2025
 
2026
//      if (c_has_rd_ack == 1 && c_rd_ack_low == 0) begin //rd_ack_hi
2027
                and_a_notb_fd_v2 #("0",
2028
                                c_enable_rlocs)
2029
                   rd_ack_fd_hi (.a_in(read_request_in),
2030
                                .b_in(empty_flag),
2031
                                .clk(rd_clk),
2032
                                .rst(reset),
2033
                                .q_out(read_ack_high)
2034
                                );
2035
//      end // if 
2036
 
2037
//      if (c_has_rd_ack == 1 && c_rd_ack_low == 1) begin //rd_ack_lo
2038
                nand_a_notb_fd_v2 #("1",                //CR124696
2039
 
2040
                                c_enable_rlocs)
2041
                        rd_ack_fd_lo(.a_in(read_request_in),
2042
                                .b_in(empty_flag),
2043
                                .clk(rd_clk),
2044
                                .rst(reset),
2045
                                .q_out(read_ack_low)
2046
                                );
2047
//      end //if rd_ack_lo
2048
 
2049
 
2050
 
2051
 
2052
 
2053
/*
2054
----------------------------------------------------------------
2055
--                                                            --
2056
--  Generation of Read address pointers.  The primary one is  --
2057
--  binary (rd_addr_bin), and the Gray-code derivatives are   --
2058
--  generated via pipelining the binary-to-Gray-code result.  --
2059
--  The initial values are important, so they're in sequence. --
2060
--  Gray-code addresses are used so that the registered       --
2061
--  Full and Empty flags are always clean, and never in an    --
2062
--  unknown state due to the asynchonous relationship of the  --
2063
--  Read and Write clocks.  In the worst case scenario, Full  --
2064
--  and Empty would simply stay active one cycle longer, but  --
2065
--  it would not generate an error or give false values.      --
2066
--                                                            --
2067
----------------------------------------------------------------
2068
*/
2069
 
2070
 
2071
        bcount_up_ainit_v2 #(rd_width,
2072
                        zeros_width, //changed to rd_width
2073
                        c_enable_rlocs
2074
                        )
2075
          rd_addr_counter (.init(reset),
2076
                        .cen(rd_en),
2077
                        .clk(rd_clk),
2078
                        .cnt(rd_addr_bin)
2079
                        );
2080
 
2081
 
2082
 
2083
        binary_to_gray_v2 #(rd_width,
2084
                         gray_tc_width, //gray_tc_string(rd_width),
2085
                        c_enable_rlocs
2086
                        )
2087
           rd_last_gray_reg(.rst(reset),
2088
                                .clk(rd_clk),
2089
                                .cen(rd_en),
2090
                                .bin(rd_addr_bin),
2091
                                .gray(rd_last_gray)
2092
                                );
2093
/*
2094
---------------------------------------------------------------
2095
--                                                           --
2096
--  Empty flag is set on reset (initial), or when gray       --
2097
--  code counters are equal, or when there is one word in    --
2098
--  the FIFO, and a Read operation will be performed on the  --
2099
--  next read clock                                          --
2100
--                                                           --
2101
---------------------------------------------------------------
2102
*/
2103
 
2104
        empty_flag_reg_v2 #(width,
2105
                        c_enable_rlocs)
2106
         empty_flag_logic (.rst(reset),
2107
                        .flag_clk(rd_clk),
2108
                        .flag_ce1(read_request_in),
2109
                        .flag_ce2(empty_flag),
2110
                        .reg_clk(wr_clk),
2111
                        .reg_ce ( wr_en),
2112
                        .a_in(rd_last_trunc),
2113
                        .b_in(wr_last_trunc),
2114
                        .dlyd_out(wr_dly1_gray),
2115
                        .flag_out(empty_flag),
2116
                        .to_almost_logic(eflag_comb )
2117
                        );
2118
 
2119
 
2120
/*
2121
---------------------------------------------------------------
2122
--                                                           --
2123
--  Almost Empty flag is set on reset (initial). Or when the --
2124
--  read gray code counter (rd_last_gray) is equal or one    --
2125
--  behind the last write gray code address(wr_lasy_gray,    --
2126
--  wr_dly1_gray). Or when the rd_last_gray is equal to      --
2127
--  wr_dly2_gray and a read operation is about to be per-    --
2128
--  formed. (Note that the next two process and              --
2129
--  wr_dly2_gray_grey represent the overhead for this        --
2130
--  function                                                 --
2131
--                                                           --
2132
---------------------------------------------------------------
2133
*/
2134
 
2135
//      if (c_has_almost_empty == 1) begin //almost_empty_gen
2136
                almst_empty_v2 #(width,
2137
                                c_enable_rlocs)
2138
                  almst_empty_logic(.rst(reset),
2139
                                        .flag_clk(rd_clk),
2140
                                        .flag_ce(vcc),
2141
                                        .reg_clk(wr_clk),
2142
                                        .reg_ce(wr_en),
2143
                                        .a_in(rd_last_trunc),
2144
                                        .b_in(wr_dly1_gray),
2145
                                        .rqst_in(read_request_in),
2146
                                        .flag_comb_in(eflag_comb),
2147
                                        .flag_q_in(empty_flag),
2148
                                        .flag_out(almost_empty_temp)
2149
                                        );
2150
//      end //if almost_empty_gen
2151
/*
2152
----------------------------------------------------------------
2153
--  wr_en <= (write_request_in AND NOT full_flag);
2154
----------------------------------------------------------------
2155
*/
2156
 
2157
        and_a_notb_v2 #(c_enable_rlocs)
2158
         wr_en_and (.a_in(write_request_in),
2159
                    .b_in(full_flag),
2160
                    .and_out(wr_en)
2161
                   );
2162
/*
2163
----------------------------------------------------------------
2164
--  wr_en_ram <= (write_request_in AND NOT full_flag);
2165
--  This is a shadow of wr_en to reduce fanout for performance
2166
----------------------------------------------------------------
2167
*/
2168
 
2169
        and_a_notb_v2 #(c_enable_rlocs)
2170
           wr_en_to_ram (.a_in(write_request_in),
2171
                        .b_in(full_flag),
2172
                        .and_out(wr_en_ram)
2173
                        );
2174
/*----------------------------------------------------------------
2175
--  Generate write handshake signals (ACK/ERROR) if requested
2176
----------------------------------------------------------------
2177
*/
2178
 
2179
//      if (c_has_wr_error == 1 && c_wr_error_low == 0) begin
2180
                and_fd_v2 #("0",
2181
                        c_enable_rlocs)
2182
                wr_error_fd_hi (.a_in(write_request_in),
2183
                                .b_in(full_flag),
2184
                                .clk(wr_clk),
2185
                                .rst(reset),
2186
                                .q_out(write_error_high)
2187
                                );
2188
//      end // if
2189
//      if (c_has_wr_error == 1 && c_wr_error_low == 1) begin // wr_eror_lo
2190
                nand_fd_v2 #("1",
2191
                        c_enable_rlocs)
2192
                  wr_error_fd_lo (.a_in(write_request_in),
2193
                                .b_in(full_flag),
2194
                                .clk(wr_clk),
2195
                                .rst(reset),
2196
                                .q_out(write_error_low)
2197
                                );
2198
//      end // if wr_error_lo
2199
 
2200
//      if (c_has_wr_ack == 1 && c_wr_ack_low == 0)  begin //wr_ack_hi
2201
                and_a_notb_fd_v2 #("0",
2202
                                c_enable_rlocs)
2203
                        wr_ack_fd_hi (.a_in(write_request_in),
2204
                                   .b_in(full_flag),
2205
                                   .clk(wr_clk),
2206
                                   .rst(reset),
2207
                                   .q_out(write_ack_high)
2208
                                );
2209
//      end //if wr_ack_hi
2210
 
2211
//      if (c_has_wr_ack == 1 && c_wr_ack_low == 1)  begin  //wr_ack_lo
2212
                nand_a_notb_fd_v2 #("1",                        //CR124696
2213
                                c_enable_rlocs)
2214
                  wr_ack_fd_lo (.a_in(write_request_in),
2215
                                .b_in(full_flag),
2216
                                .clk(wr_clk),
2217
                                .rst(reset),
2218
                                .q_out(write_ack_low)
2219
                                );
2220
//      end // if wr_ack_lo
2221
 
2222
 
2223
        bcount_up_ainit_v2 #(wr_width,
2224
                        zeros_width, //zero_string, //(wr_width),
2225
                        c_enable_rlocs)
2226
          wr_addr_counter (.init(reset),
2227
                                .cen(wr_en),
2228
                                .clk(wr_clk),
2229
                                .cnt(wr_addr_bin)
2230
                        );
2231
 
2232
        binary_to_gray_v2 #(wr_width,
2233
                        gray_tc_width, //gray_tc_string(wr_width),
2234
                        c_enable_rlocs)
2235
                wr_last_gray_reg (.rst(reset),
2236
                                .clk(wr_clk),
2237
                                .cen(wr_en),
2238
                                .bin(wr_addr_bin),
2239
                                .gray(wr_last_gray)
2240
                                );
2241
 
2242
/*
2243
---------------------------------------------------------------
2244
--                                                           --
2245
--  Full flag is set on reset (initial, but it is cleared    --
2246
--  on the first valid write clock edge after reset is       --
2247
--  de-asserted), or when Gray-code counters are one away    --
2248
--  from being equal (the Write Gray-code address is equal   --
2249
--  to the Last Read Gray-code address), or when the Next    --
2250
--  Write Gray-code address is equal to the Last Read Gray-  --
2251
--  code address, and a Write operation is about to be       --
2252
--  performed.                                               --
2253
--                                                           --
2254
---------------------------------------------------------------
2255
*/
2256
 
2257
        reg_ainit_v2 #(width,
2258
                tc_less1_width, //gray_tc_less1(width),
2259
                c_enable_rlocs)
2260
         rd_dly1_gray_reg (.rst(reset),
2261
                                .clk(rd_clk),
2262
                                .cen(rd_en),
2263
                                .din(rd_last_trunc),
2264
                                .qout(rd_dly1_gray)
2265
                                );
2266
/*
2267
---------------------------------------------------------------
2268
--                                                           --
2269
--  Almost Full flag is set on reset (initial, but it is     --
2270
--  cleared on the first valid write clock edge after reset  --
2271
--  is de-asserted). Or when the write Gray-code address     --
2272
--  (wr_last_gray) is equal one behind the Last Read Gray-   --
2273
--  code address(rd_dly1_gray, rd_dly2_gray). Or when the    --
2274
--  write_last_gray is equal to rd_dly3_gray and a Write     --
2275
--  operation is about to be performed. Note that the next   --
2276
--  two process and rd_dly3_grag_reg represent the overhead  --
2277
--  for this function.                                       --
2278
--                                                           --
2279
---------------------------------------------------------------
2280
*/
2281
 
2282
//      if (c_has_almost_full == 1) begin //gen_almost_full
2283
                almst_full_v2 #(width,
2284
                                c_enable_rlocs)
2285
                  almst_full_logic (.rst(reset),
2286
                                        .flag_clk(wr_clk),
2287
                                        .flag_ce(vcc),
2288
                                        .reg_clk(rd_clk),
2289
                                        .reg_ce(rd_en),
2290
                                        .a_in(wr_last_trunc),
2291
                                        .b_in(rd_dly2_gray),
2292
                                        .rqst_in(write_request_in),
2293
                                        .flag_comb_in(fflag_comb),
2294
                                        .flag_q_in(full_flag),
2295
                                        .flag_out(almost_full_temp)
2296
                                        );
2297
//      end //if gen_almost_full
2298
 
2299
                full_flag_reg_v2 #(width,
2300
                                c_enable_rlocs)
2301
                  full_flag_logic (.rst(reset),
2302
                                        .flag_clk(wr_clk),
2303
                                        .flag_ce1(write_request_in),
2304
                                        .flag_ce2(full_flag),
2305
                                        .reg_clk(rd_clk),
2306
                                        .reg_ce(rd_en),
2307
                                        .a_in(wr_last_trunc),
2308
                                        .b_in(rd_dly1_gray),
2309
                                        .dlyd_out(rd_dly2_gray),
2310
                                        .flag_out(full_flag),
2311
                                        .to_almost_logic(fflag_comb)
2312
                                        );
2313
 
2314
 
2315
 
2316
 
2317
 
2318
/*
2319
----------------------------------------------------------------
2320
--                                                            --
2321
--  Generation of data_count output.  data_count reflects how --
2322
--  full FIFO is, based on how far the Write pointer is ahead --
2323
--  of the Read pointer. data_count will lag true FIFO state  --
2324
--  by a couple of clock cycles, if the enables are inactive  --
2325
--  for a few cycles data_count will converge to match FIFO's --
2326
--  data_count could be made synchronous to either clock      --
2327
--  domain. The following code uses the write clock domain    --
2328
--                                                            --
2329
----------------------------------------------------------------
2330
*/
2331
 
2332
//      if (c_has_wrsync_dcount == 1)  begin
2333
 
2334
reg_ainit_v2 #(wr_width,
2335
            ones_width, //ones_string_wr, //(wr_width),
2336
            c_enable_rlocs)
2337
  wr_last_bin_reg  (.rst(reset),
2338
                .clk(wr_clk),
2339
                .cen(wr_en),
2340
                .din(wr_addr_bin),
2341
                .qout(wr_last_bin)
2342
                );
2343
 
2344
reg_ainit_v2 #(rd_width,
2345
            gray_tc_width, // gray_tc_string(rd_width),
2346
            c_enable_rlocs)
2347
 wrsync_rd_last_gray_reg (.rst(reset),
2348
                           .clk(wr_clk),
2349
                          .cen(vcc),
2350
                          .din(rd_last_gray),
2351
                          .qout(wrsync_rd_last_gray)
2352
                         );
2353
 
2354
gray_to_binary_v2 #(rd_width,
2355
                ones_width,
2356
                c_enable_rlocs)
2357
 wrsync_rd_last_bin_reg (.bin_reg(wrsync_rd_last_bin),
2358
                        .grey_reg(wrsync_rd_last_gray),
2359
                        .reset(reset),
2360
                        .clk(wr_clk)
2361
                        );
2362
 
2363
/* ***************************************************************************
2364
 * This block removed 09/26/00 by jogden to fix CR 126807 where empty flag
2365
 *  was causing wr_count to reset.
2366
 * **************************************************************************/
2367
//pulse_reg_v2 wrsync_empty_pulse_fd (.sclr_in(wr_en),
2368
//                              .sset_in(empty_flag),
2369
//                              .clk(wr_clk),
2370
//                              .rst(reset),
2371
//                              .q_out(wrsync_empty_pulse)
2372
//                              );
2373
 
2374
count_sub_reg_v2 #(greater_width,
2375
                wr_width,
2376
                rd_width,
2377
                wrsync_dcount_width,
2378
                c_enable_rlocs)
2379
  wrsync_data_count_sub (.a_in(wr_last_bin),
2380
                         .b_in(wrsync_rd_last_bin),
2381
                         .clk(wr_clk),
2382
                         .rst_a(reset),
2383
                         //.rst_b(wrsync_empty_pulse),
2384
                         .rst_b(gnd),  //Connection removed 9-26-00
2385
                                       //by jogden to fix CR 126807
2386
                                       //regarding empty_pulse 
2387
                                       //resetting wrsync_data_count
2388
                         .q_out(wrsync_data_count_temp)
2389
                         );
2390
 
2391
 
2392
//      end //if 
2393
//------------------------------------------------------------//
2394
//                                                            //
2395
//  Generation of data_count output.  data_count reflects how //
2396
//  full FIFO is, based on how far the Write pointer is ahead //
2397
//  of the Read pointer. data_count will lag true FIFO state  //
2398
//  by a couple of clock cycles, if the enables are inactive  //
2399
//  for a few cycles data_count will converge to match FIFO's //
2400
//  data_count could be made synchronous to either clock      //
2401
//  domain. The following code uses the read clock domain     //
2402
//                                                            //
2403
//------------------------------------------------------------//
2404
 
2405
 
2406
 
2407
 
2408
reg_ainit_v2 #(rd_width,
2409
            ones_width,
2410
            c_enable_rlocs)
2411
  rd_last_bin_reg  (.rst(reset),
2412
                .clk(rd_clk),
2413
                .cen(rd_en),
2414
                .din(rd_addr_bin),
2415
                .qout(rd_last_bin)
2416
                );
2417
 
2418
 
2419
reg_ainit_v2 #(wr_width,
2420
            gray_tc_width,
2421
            c_enable_rlocs)
2422
 rdsync_wr_last_gray_reg (.rst(reset),
2423
                           .clk(rd_clk),
2424
                          .cen(vcc),
2425
                          .din(wr_last_gray),
2426
                          .qout(rdsync_wr_last_gray)
2427
                         );
2428
 
2429
gray_to_binary_v2 #(wr_width,
2430
                ones_width,
2431
                c_enable_rlocs)
2432
  rdsync_wr_last_bin_reg (.bin_reg(rdsync_wr_last_bin),
2433
                          .grey_reg(rdsync_wr_last_gray),
2434
                          .reset(reset),
2435
                          .clk(rd_clk)
2436
                         );
2437
count_sub_reg_v2 #(greater_width,
2438
                wr_width,
2439
                rd_width,
2440
                rdsync_dcount_width,
2441
                c_enable_rlocs)
2442
 rdsync_data_count_sub(.a_in(rdsync_wr_last_bin),
2443
                        .b_in(rd_last_bin),
2444
                        .clk(rd_clk),
2445
                        .rst_a(reset),
2446
                        .rst_b(reset),
2447
                        .q_out(rdsync_data_count_temp)
2448
                        );
2449
 
2450
//------------------------------------------------------------//
2451
//                                                            //
2452
//  The four conditions decoded with special carry logic are  //
2453
//  cond_empty, cond_empty_plus1, cond_full, cond_full_less1. //
2454
//  These are used to determine the next state of the         //
2455
//  Full/Empty flags.                                         //
2456
//                                                            //
2457
//  When the Write/Read Gray-code addresses are equal, the    //
2458
//  FIFO is Empty, and cond_empty (combinatorial) is asserted.//
2459
//  When the Write Gray-code address is equal to the Next     //
2460
//  Read Gray-code address (1 word in the FIFO), then the     //
2461
//  FIFO potentially could be going Empty (if rd_en is        //
2462
//  asserted, which is used in the logic that generates the   //
2463
//  registered version of Empty(empty_flag)).                 //
2464
//                                                            //
2465
//  Similarly, when the Write Gray-code address is equal to   //
2466
//  the Last Read Gray-code address, the FIFO is full.  To    //
2467
//  have utilized the full address space (512 addresses)      //
2468
//  would have required extra logic to determine Full/Empty   //
2469
//  on equal addresses, and this would have slowed down the   //
2470
//  overall performance.  Lastly, when the Next Write Gray-   //
2471
//  code address is equal to the Last Read Gray-code address  //
2472
//  the FIFO is Almost Full, with only one word left, and     //
2473
//  it is conditional on write_enable being asserted.         //
2474
//                                                            //
2475
//------------------------------------------------------------//
2476
 
2477
 
2478
assign read_error = (c_has_rd_error == 0 )? 1'bX :c_rd_error_low? read_error_low : read_error_high;
2479
assign read_ack = (c_has_rd_ack == 0 )? 1'bX :c_rd_ack_low? read_ack_low : read_ack_high;
2480
assign almost_empty = (c_has_almost_empty == 0 )? 1'bX   : almost_empty_temp;
2481
assign write_error = (c_has_wr_error == 0 )? 1'bX : c_wr_error_low? write_error_low : write_error_high;
2482
assign write_ack = (c_has_wr_ack == 0 )? 1'bX : c_wr_ack_low ? write_ack_low : write_ack_high;
2483
assign almost_full = (c_has_almost_full == 0 )? 1'bX : almost_full_temp;
2484
assign wrsync_data_count = (c_has_wrsync_dcount == 0)? {wrsync_dcount_width{1'bX}} : wrsync_data_count_temp;
2485
assign rdsync_data_count = (c_has_rdsync_dcount == 0)? {rdsync_dcount_width{1'bX}} :rdsync_data_count_temp;
2486
 
2487
endmodule
2488
/*  End Fifo Control Module. fifoctlr_ns.v */
2489
 
2490
 
2491
/****************************************************************************/
2492
/* Top Level async_fifo */
2493
/****************************************************************************/
2494
 
2495
 
2496
module ASYNC_FIFO_V3_0 (DIN, WR_EN, WR_CLK, RD_EN, RD_CLK, AINIT, DOUT, FULL, EMPTY, ALMOST_FULL, ALMOST_EMPTY, WR_COUNT, RD_COUNT, RD_ACK, RD_ERR, WR_ACK, WR_ERR);
2497
 
2498
 
2499
/* Functions */
2500
 
2501
function log2roundup;
2502
        input data_value ;
2503
        integer lower_limit;
2504
        integer upper_limit;
2505
        integer i;
2506
        begin
2507
                lower_limit=4;
2508
                upper_limit=16;
2509
                for (i=lower_limit-1; i<=upper_limit; i=i+1) begin
2510
                  if (data_value <=0) begin
2511
                        log2roundup=0;
2512
                  end
2513
                  else if (data_value > (1 << i)) begin
2514
                        log2roundup = i + 1;
2515
                  end
2516
                end
2517
        end
2518
endfunction
2519
/* End Functions */
2520
 
2521
parameter C_DATA_WIDTH          = 8;
2522
parameter C_ENABLE_RLOCS        = 0;
2523
parameter C_FIFO_DEPTH          = 511;
2524
parameter C_HAS_ALMOST_EMPTY    = 1;
2525
parameter C_HAS_ALMOST_FULL     = 1;
2526
parameter C_HAS_RD_ACK          = 1;
2527
parameter C_HAS_RD_COUNT        = 1;
2528
parameter C_HAS_RD_ERR          = 1;
2529
parameter C_HAS_WR_ACK          = 1;
2530
parameter C_HAS_WR_COUNT        = 1;
2531
parameter C_HAS_WR_ERR          = 1;
2532
parameter C_RD_ACK_LOW          = 0;
2533
parameter C_RD_COUNT_WIDTH      = 6;
2534
parameter C_RD_ERR_LOW          = 0;
2535
parameter C_USE_BLOCKMEM        = 1;
2536
parameter C_WR_ACK_LOW          = 0;
2537
parameter C_WR_COUNT_WIDTH      = 6;
2538
parameter C_WR_ERR_LOW          = 0;
2539
 
2540
 
2541
input  [C_DATA_WIDTH-1 : 0] DIN;
2542
input  WR_EN;
2543
input  WR_CLK;
2544
input  RD_EN;
2545
input  RD_CLK;
2546
input  AINIT;
2547
output [C_DATA_WIDTH-1 : 0] DOUT;
2548
output FULL;
2549
output EMPTY;
2550
output ALMOST_FULL;
2551
output ALMOST_EMPTY;
2552
output [C_WR_COUNT_WIDTH-1 : 0] WR_COUNT;
2553
output [C_RD_COUNT_WIDTH-1 : 0] RD_COUNT;
2554
output RD_ACK;
2555
output RD_ERR;
2556
output WR_ACK;
2557
output WR_ERR;
2558
 
2559
parameter depth_of_mem = C_FIFO_DEPTH +1;
2560
parameter address_width = (depth_of_mem == 16 ? 4:
2561
                          (depth_of_mem == 32 ? 5:
2562
                          (depth_of_mem == 64 ? 6 :
2563
                          (depth_of_mem == 128 ? 7 :
2564
                          (depth_of_mem == 256 ? 8 :
2565
                          (depth_of_mem == 512 ? 9 :
2566
                          (depth_of_mem == 1024 ? 10 :
2567
                          (depth_of_mem == 2048 ? 11 :
2568
                          (depth_of_mem == 4096 ? 12 :
2569
                          (depth_of_mem == 8192 ? 13 :
2570
                          (depth_of_mem == 16384 ? 14 :
2571
                          (depth_of_mem == 32768 ? 15 :
2572
                          (depth_of_mem == 65536 ? 16 : 6)))))))))))));
2573
 
2574
 
2575
wire [address_width-1 :0] read_address;
2576
wire [address_width-1 : 0] write_address;
2577
wire qualified_read_enable;
2578
wire qualified_write_request;
2579
 
2580
wire #1 WR_EN_DLY = WR_EN ;             //Delay WR_EN so a 1ns setup is enforced (CR124109)
2581
wire #1 RD_EN_DLY = RD_EN ;             //Delay RD_EN so a 1ns setup is enforced (CR124109) 
2582
 
2583
 
2584
        memory_v2       #(C_USE_BLOCKMEM,
2585
                C_ENABLE_RLOCS,
2586
                address_width,
2587
                address_width,
2588
                C_FIFO_DEPTH+1,
2589
                C_FIFO_DEPTH+1,
2590
                C_DATA_WIDTH,
2591
                C_DATA_WIDTH
2592
                )
2593
        mem     (.d(DIN),
2594
                .wa(write_address),
2595
                .we(qualified_write_request),
2596
                .wclk(WR_CLK),
2597
                .re(qualified_read_enable),
2598
                .rclk(RD_CLK),
2599
                .ra(read_address),
2600
                .q(DOUT)
2601
                );
2602
 
2603
        fifoctlr_ns_v2  #(
2604
                        address_width,
2605
                        address_width,
2606
                        address_width,
2607
                        C_ENABLE_RLOCS,
2608
                        C_HAS_ALMOST_FULL,
2609
                        C_HAS_ALMOST_EMPTY,
2610
                        C_HAS_WR_COUNT,
2611
                        C_WR_COUNT_WIDTH,
2612
                        C_HAS_RD_COUNT,
2613
                        C_RD_COUNT_WIDTH,
2614
                        C_HAS_RD_ACK,
2615
                        C_RD_ACK_LOW,
2616
                        C_HAS_RD_ERR,
2617
                        C_RD_ERR_LOW,
2618
                        C_HAS_WR_ACK,
2619
                        C_WR_ACK_LOW,
2620
                        C_HAS_WR_ERR,
2621
                        C_WR_ERR_LOW
2622
                        )
2623
      control           (.fifo_reset_in(AINIT),
2624
                        .read_clock_in(RD_CLK),
2625
                        .write_clock_in(WR_CLK),
2626
                        .read_request_in(RD_EN_DLY),
2627
                        .write_request_in(WR_EN_DLY),
2628
                        .read_enable_out(qualified_read_enable),
2629
                        .write_enable_out(qualified_write_request),
2630
                        .full_flag_out(FULL),
2631
                        .empty_flag_out(EMPTY),
2632
                        .almost_full_out(ALMOST_FULL),
2633
                        .almost_empty_out(ALMOST_EMPTY),
2634
                        .read_addr_out(read_address),
2635
                        .write_addr_out(write_address),
2636
                        .wrsync_count_out(WR_COUNT),
2637
                        .rdsync_count_out(RD_COUNT),
2638
                        .read_ack(RD_ACK),
2639
                        .read_error(RD_ERR),
2640
                        .write_ack(WR_ACK),
2641
                        .write_error(WR_ERR)
2642
                        );
2643
 
2644
 
2645
 
2646
endmodule
2647
/* End Top Level async_fifo */
2648
 
2649
`endif

powered by: WebSVN 2.1.0

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