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

Subversion Repositories mem_ctrl

[/] [mem_ctrl/] [trunk/] [bench/] [verilog/] [sdram_models/] [16Mx16/] [mt48lc16m16a2.v] - Blame information for rev 15

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

Line No. Rev Author Line
1 4 rudi
/****************************************************************************************
2
*
3
*    File Name:  MT48LC16M16A2.V
4
*      Version:  1.0a
5
*         Date:  August 4th, 2000
6
*        Model:  BUS Functional
7
*    Simulator:  Model Technology
8
*
9
* Dependencies:  None
10
*
11
*       Author:  Son P. Huynh
12
*        Email:  sphuynh@micron.com
13
*        Phone:  (208) 368-3825
14
*      Company:  Micron Technology, Inc.
15
*        Model:  MT48LC16M16A2 (4Meg x 16 x 4 Banks)
16
*
17
*  Description:  Micron 256Mb SDRAM Verilog model
18
*
19
*   Limitation:  - Doesn't check for 4096 cycle refresh
20
*
21
*         Note:  - Set simulator resolution to "ps" timescale
22
*                - Set Debug = 0 to disable $display messages
23
*
24
*   Disclaimer:  THESE DESIGNS ARE PROVIDED "AS IS" WITH NO WARRANTY
25
*                WHATSOEVER AND MICRON SPECIFICALLY DISCLAIMS ANY
26
*                IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
27
*                A PARTICULAR PURPOSE, OR AGAINST INFRINGEMENT.
28
*
29
*                Copyright © 1998 Micron Semiconductor Products, Inc.
30
*                All rights researved
31
*
32
* Rev   Author          Phone         Date        Changes
33
* ----  ----------------------------  ----------  ---------------------------------------
34
* 1.0a  Son Huynh       208-368-3825  08/04/2000  - Improve alternate banks read/write
35
*       Micron Technology Inc.                      access with auto precharge enable
36
*
37
* 0.0a  Son Huynh       208-368-3825  04/29/1999  - First Release (from 64Mb rev 0.0e)
38
*       Micron Technology Inc.                    - Simple testbench included
39
*
40
****************************************************************************************/
41
 
42
`timescale 1ns / 100ps
43
 
44
module mt48lc16m16a2 (Dq, Addr, Ba, Clk, Cke, Cs_n, Ras_n, Cas_n, We_n, Dqm);
45
 
46
    parameter addr_bits =      13;                          // 13 bits
47
    parameter data_bits =      16;                          // 16 bits
48
    parameter col_bits  =       9;                          //  9 bits
49
    parameter mem_sizes = 4194303;                          //  4 Mb
50
 
51
    inout     [data_bits - 1 : 0] Dq;
52
    input     [addr_bits - 1 : 0] Addr;
53
    input                 [1 : 0] Ba;
54
    input                         Clk;
55
    input                         Cke;
56
    input                         Cs_n;
57
    input                         Ras_n;
58
    input                         Cas_n;
59
    input                         We_n;
60
    input                 [1 : 0] Dqm;
61
 
62
    reg       [data_bits - 1 : 0] Bank0 [0 : mem_sizes];
63
    reg       [data_bits - 1 : 0] Bank1 [0 : mem_sizes];
64
    reg       [data_bits - 1 : 0] Bank2 [0 : mem_sizes];
65
    reg       [data_bits - 1 : 0] Bank3 [0 : mem_sizes];
66
 
67
    reg                   [1 : 0] Bank_addr [0 : 3];                // Bank Address Pipeline
68
    reg        [col_bits - 1 : 0] Col_addr [0 : 3];                 // Column Address Pipeline
69
    reg                   [3 : 0] Command [0 : 3];                  // Command Operation Pipeline
70
    reg                   [1 : 0] Dqm_reg0, Dqm_reg1;               // DQM Operation Pipeline
71
    reg       [addr_bits - 1 : 0] B0_row_addr, B1_row_addr, B2_row_addr, B3_row_addr;
72
 
73
    reg       [addr_bits - 1 : 0] Mode_reg;
74
    reg       [data_bits - 1 : 0] Dq_reg, Dq_dqm;
75
    reg        [col_bits - 1 : 0] Col_temp, Burst_counter;
76
 
77
    reg                           Act_b0, Act_b1, Act_b2, Act_b3;   // Bank Activate
78
    reg                           Pc_b0, Pc_b1, Pc_b2, Pc_b3;       // Bank Precharge
79
 
80
    reg                   [1 : 0] Bank_precharge     [0 : 3];       // Precharge Command
81
    reg                           A10_precharge      [0 : 3];       // Addr[10] = 1 (All banks)
82
    reg                           Auto_precharge     [0 : 3];       // RW AutoPrecharge (Bank)
83
    reg                           Read_precharge     [0 : 3];       // R  AutoPrecharge
84
    reg                           Write_precharge    [0 : 3];       //  W AutoPrecharge
85
    reg                           RW_interrupt_read  [0 : 3];       // RW Interrupt Read with Auto Precharge
86
    reg                           RW_interrupt_write [0 : 3];       // RW Interrupt Write with Auto Precharge
87
    reg                   [1 : 0] RW_interrupt_bank;                // RW interrupt Bank
88
    time                          Count_time         [0 : 3];       // RW AutoPrecharge (time after tWR = 1)
89
    integer                       Count_precharge    [0 : 3];       // RW AutoPrecharge (Counter)
90
 
91
    reg                           Data_in_enable;
92
    reg                           Data_out_enable;
93
 
94
    reg                   [1 : 0] Bank, Previous_bank;
95
    reg       [addr_bits - 1 : 0] Row;
96
    reg        [col_bits - 1 : 0] Col, Col_brst;
97
 
98
    // Internal system clock
99
    reg                           CkeZ, Sys_clk, RAS_clk;
100
 
101
    // Commands Decode
102
    wire      Active_enable    = ~Cs_n & ~Ras_n &  Cas_n &  We_n;
103
    wire      Aref_enable      = ~Cs_n & ~Ras_n & ~Cas_n &  We_n;
104
    wire      Burst_term       = ~Cs_n &  Ras_n &  Cas_n & ~We_n;
105
    wire      Mode_reg_enable  = ~Cs_n & ~Ras_n & ~Cas_n & ~We_n;
106
    wire      Prech_enable     = ~Cs_n & ~Ras_n &  Cas_n & ~We_n;
107
    wire      Read_enable      = ~Cs_n &  Ras_n & ~Cas_n &  We_n;
108
    wire      Write_enable     = ~Cs_n &  Ras_n & ~Cas_n & ~We_n;
109
 
110
    // Burst Length Decode
111
    wire      Burst_length_1   = ~Mode_reg[2] & ~Mode_reg[1] & ~Mode_reg[0];
112
    wire      Burst_length_2   = ~Mode_reg[2] & ~Mode_reg[1] &  Mode_reg[0];
113
    wire      Burst_length_4   = ~Mode_reg[2] &  Mode_reg[1] & ~Mode_reg[0];
114
    wire      Burst_length_8   = ~Mode_reg[2] &  Mode_reg[1] &  Mode_reg[0];
115
 
116
    // CAS Latency Decode
117
    wire      Cas_latency_2    = ~Mode_reg[6] &  Mode_reg[5] & ~Mode_reg[4];
118
    wire      Cas_latency_3    = ~Mode_reg[6] &  Mode_reg[5] &  Mode_reg[4];
119
 
120
    // Write Burst Mode
121
    wire      Write_burst_mode = Mode_reg[9];
122
 
123
    wire      Debug            = 1'b1;                          // Debug messages : 1 = On
124
    wire      Dq_chk           = Sys_clk & Data_in_enable;      // Check setup/hold time for DQ
125
 
126
    assign    Dq               = Dq_reg;                        // DQ buffer
127
 
128
    // Commands Operation
129
    `define   ACT       0
130
    `define   NOP       1
131
    `define   READ      2
132
    `define   READ_A    3
133
    `define   WRITE     4
134
    `define   WRITE_A   5
135
    `define   PRECH     6
136
    `define   A_REF     7
137
    `define   BST       8
138
    `define   LMR       9
139
 
140
    // Timing Parameters for -7E and CAS Latency = 2
141
    parameter tAC  =   5.4;
142
    parameter tHZ  =   5.4;
143
    parameter tOH  =   2.7;
144
    parameter tMRD =   2.0;     // 2 Clk Cycles
145
    parameter tRAS =  37.0;
146
    parameter tRC  =  60.0;
147
    parameter tRCD =  15.0;
148
    parameter tRP  =  15.0;
149
    parameter tRRD =  14.0;
150
    parameter tWRa =   7.0;     // A2 Version - Auto precharge mode (1 Clk + 7 ns)
151
    parameter tWRp =  14.0;     // A2 Version - Manual precharge mode (14 ns)
152
 
153
    // Timing Check variable
154
    integer   MRD_chk;
155
    integer   WR_counter [0 : 3];
156
    time      WR_time [0 : 3];
157
    time      WR_chkp [0 : 3];
158
    time      RC_chk, RRD_chk;
159
    time      RAS_chk0, RAS_chk1, RAS_chk2, RAS_chk3;
160
    time      RCD_chk0, RCD_chk1, RCD_chk2, RCD_chk3;
161
    time      RP_chk0, RP_chk1, RP_chk2, RP_chk3;
162
 
163
    initial begin
164
        Dq_reg = {data_bits{1'bz}};
165
        {Data_in_enable, Data_out_enable} = 0;
166
        {Act_b0, Act_b1, Act_b2, Act_b3} = 4'b0000;
167
        {Pc_b0, Pc_b1, Pc_b2, Pc_b3} = 4'b0000;
168
        {WR_chkp[0], WR_chkp[1], WR_chkp[2], WR_chkp[3]} = 0;
169
        {WR_counter[0], WR_counter[1], WR_counter[2], WR_counter[3]} = 0;
170
        {WR_time[0], WR_time[1], WR_time[2], WR_time[3]} = 0;
171
        {RW_interrupt_read[0], RW_interrupt_read[1], RW_interrupt_read[2], RW_interrupt_read[3]} = 0;
172
        {RW_interrupt_write[0], RW_interrupt_write[1], RW_interrupt_write[2], RW_interrupt_write[3]} = 0;
173
        {MRD_chk, RC_chk, RRD_chk} = 0;
174
        {RAS_chk0, RAS_chk1, RAS_chk2, RAS_chk3} = 0;
175
        {RCD_chk0, RCD_chk1, RCD_chk2, RCD_chk3} = 0;
176
        {RP_chk0, RP_chk1, RP_chk2, RP_chk3} = 0;
177
        $timeformat (-9, 1, " ns", 12);
178
        //$readmemh("bank0.txt", Bank0);
179
        //$readmemh("bank1.txt", Bank1);
180
        //$readmemh("bank2.txt", Bank2);
181
        //$readmemh("bank3.txt", Bank3);
182
        RAS_clk = 1'b0;
183
    end
184
 
185 15 rudi
 
186
 
187
integer n;
188
 
189
task mem_fill;
190
input   size;
191
 
192
integer         size;
193
 
194
begin
195
        for(n=0;n<size;n=n+1)
196
           begin
197
                Bank0[n] = $random;
198
                Bank1[n] = $random;
199
                Bank2[n] = $random;
200
                Bank3[n] = $random;
201
           end
202
 
203
end
204
endtask
205
 
206
 
207 4 rudi
    // RAS Clk for checking tWR
208
    always RAS_clk = #0.5 ~RAS_clk;
209
 
210
    // System clock generator
211
    always begin
212
        @ (posedge Clk) begin
213
            Sys_clk = CkeZ;
214
            CkeZ = Cke;
215
            if (Cke == 1'b0 && (Data_in_enable == 1'b1 || Data_out_enable == 1'b1)) begin
216
                $display ("at time %t ERROR: Illegal power down or self refresh.  Please make sure data bus is idle.", $time);
217
            end
218
        end
219
        @ (negedge Clk) begin
220
            Sys_clk = 1'b0;
221
        end
222
    end
223
 
224
    always @ (posedge Sys_clk) begin
225
        // Internal Commamd Pipelined
226
        Command[0] = Command[1];
227
        Command[1] = Command[2];
228
        Command[2] = Command[3];
229
        Command[3] = `NOP;
230
 
231
        Col_addr[0] = Col_addr[1];
232
        Col_addr[1] = Col_addr[2];
233
        Col_addr[2] = Col_addr[3];
234
        Col_addr[3] = {col_bits{1'b0}};
235
 
236
        Bank_addr[0] = Bank_addr[1];
237
        Bank_addr[1] = Bank_addr[2];
238
        Bank_addr[2] = Bank_addr[3];
239
        Bank_addr[3] = 2'b0;
240
 
241
        Bank_precharge[0] = Bank_precharge[1];
242
        Bank_precharge[1] = Bank_precharge[2];
243
        Bank_precharge[2] = Bank_precharge[3];
244
        Bank_precharge[3] = 2'b0;
245
 
246
        A10_precharge[0] = A10_precharge[1];
247
        A10_precharge[1] = A10_precharge[2];
248
        A10_precharge[2] = A10_precharge[3];
249
        A10_precharge[3] = 1'b0;
250
 
251
        // Dqm pipeline for Read
252
        Dqm_reg0 = Dqm_reg1;
253
        Dqm_reg1 = Dqm;
254
 
255
        // Read or Write with Auto Precharge Counter
256
        if (Auto_precharge[0] == 1'b1) begin
257
            Count_precharge[0] = Count_precharge[0] + 1;
258
        end
259
        if (Auto_precharge[1] == 1'b1) begin
260
            Count_precharge[1] = Count_precharge[1] + 1;
261
        end
262
        if (Auto_precharge[2] == 1'b1) begin
263
            Count_precharge[2] = Count_precharge[2] + 1;
264
        end
265
        if (Auto_precharge[3] == 1'b1) begin
266
            Count_precharge[3] = Count_precharge[3] + 1;
267
        end
268
 
269
        // Auto Precharge Timer for tWR
270
        if (Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) begin
271
            if (Count_precharge[0] == 1) begin
272
                Count_time[0] = $time;
273
            end
274
            if (Count_precharge[1] == 1) begin
275
                Count_time[1] = $time;
276
            end
277
            if (Count_precharge[2] == 1) begin
278
                Count_time[2] = $time;
279
            end
280
            if (Count_precharge[3] == 1) begin
281
                Count_time[3] = $time;
282
            end
283
        end else if (Burst_length_2 == 1'b1) begin
284
            if (Count_precharge[0] == 2) begin
285
                Count_time[0] = $time;
286
            end
287
            if (Count_precharge[1] == 2) begin
288
                Count_time[1] = $time;
289
            end
290
            if (Count_precharge[2] == 2) begin
291
                Count_time[2] = $time;
292
            end
293
            if (Count_precharge[3] == 2) begin
294
                Count_time[3] = $time;
295
            end
296
        end else if (Burst_length_4 == 1'b1) begin
297
            if (Count_precharge[0] == 4) begin
298
                Count_time[0] = $time;
299
            end
300
            if (Count_precharge[1] == 4) begin
301
                Count_time[1] = $time;
302
            end
303
            if (Count_precharge[2] == 4) begin
304
                Count_time[2] = $time;
305
            end
306
            if (Count_precharge[3] == 4) begin
307
                Count_time[3] = $time;
308
            end
309
        end else if (Burst_length_8 == 1'b1) begin
310
            if (Count_precharge[0] == 8) begin
311
                Count_time[0] = $time;
312
            end
313
            if (Count_precharge[1] == 8) begin
314
                Count_time[1] = $time;
315
            end
316
            if (Count_precharge[2] == 8) begin
317
                Count_time[2] = $time;
318
            end
319
            if (Count_precharge[3] == 8) begin
320
                Count_time[3] = $time;
321
            end
322
        end
323
 
324
        // tMRD Counter
325
        MRD_chk = MRD_chk + 1;
326
 
327
        // tWR Counter for Write
328
        WR_counter[0] = WR_counter[0] + 1;
329
        WR_counter[1] = WR_counter[1] + 1;
330
        WR_counter[2] = WR_counter[2] + 1;
331
        WR_counter[3] = WR_counter[3] + 1;
332
 
333
        // Auto Refresh
334
        if (Aref_enable == 1'b1) begin
335
            if (Debug) $display ("at time %t AREF : Auto Refresh", $time);
336
            // Auto Refresh to Auto Refresh
337
            if ($time - RC_chk < tRC) begin
338
                $display ("at time %t ERROR: tRC violation during Auto Refresh", $time);
339
            end
340
 
341
            // Precharge to Auto Refresh
342
            if ($time - RP_chk0 < tRP || $time - RP_chk1 < tRP || $time - RP_chk2 < tRP || $time - RP_chk3 < tRP) begin
343
                $display ("at time %t ERROR: tRP violation during Auto Refresh", $time);
344
            end
345
 
346
            // Precharge to Refresh
347
            if (Pc_b0 == 1'b0 || Pc_b1 == 1'b0 || Pc_b2 == 1'b0 || Pc_b3 == 1'b0) begin
348
                $display ("at time %t ERROR: All banks must be Precharge before Auto Refresh", $time);
349
            end
350
 
351
            // Record Current tRC time
352
            RC_chk = $time;
353
        end
354
 
355
        // Load Mode Register
356
        if (Mode_reg_enable == 1'b1) begin
357
            // Decode CAS Latency, Burst Length, Burst Type, and Write Burst Mode
358
            if (Pc_b0 == 1'b1 && Pc_b1 == 1'b1 && Pc_b2 == 1'b1 && Pc_b3 == 1'b1) begin
359
                Mode_reg = Addr;
360
                if (Debug) begin
361
                    $display ("at time %t LMR  : Load Mode Register", $time);
362
                    // CAS Latency
363
                    if (Addr[6 : 4] == 3'b010)
364
                        $display ("                            CAS Latency      = 2");
365
                    else if (Addr[6 : 4] == 3'b011)
366
                        $display ("                            CAS Latency      = 3");
367
                    else
368
                        $display ("                            CAS Latency      = Reserved");
369
                    // Burst Length
370
                    if (Addr[2 : 0] == 3'b000)
371
                        $display ("                            Burst Length     = 1");
372
                    else if (Addr[2 : 0] == 3'b001)
373
                        $display ("                            Burst Length     = 2");
374
                    else if (Addr[2 : 0] == 3'b010)
375
                        $display ("                            Burst Length     = 4");
376
                    else if (Addr[2 : 0] == 3'b011)
377
                        $display ("                            Burst Length     = 8");
378
                    else if (Addr[3 : 0] == 4'b0111)
379
                        $display ("                            Burst Length     = Full");
380
                    else
381
                        $display ("                            Burst Length     = Reserved");
382
                    // Burst Type
383
                    if (Addr[3] == 1'b0)
384
                        $display ("                            Burst Type       = Sequential");
385
                    else if (Addr[3] == 1'b1)
386
                        $display ("                            Burst Type       = Interleaved");
387
                    else
388
                        $display ("                            Burst Type       = Reserved");
389
                    // Write Burst Mode
390
                    if (Addr[9] == 1'b0)
391
                        $display ("                            Write Burst Mode = Programmed Burst Length");
392
                    else if (Addr[9] == 1'b1)
393
                        $display ("                            Write Burst Mode = Single Location Access");
394
                    else
395
                        $display ("                            Write Burst Mode = Reserved");
396
                end
397
            end else begin
398
                $display ("at time %t ERROR: all banks must be Precharge before Load Mode Register", $time);
399
            end
400
            // REF to LMR
401
            if ($time - RC_chk < tRC) begin
402
                $display ("at time %t ERROR: tRC violation during Load Mode Register", $time);
403
            end
404
            // LMR to LMR
405
            if (MRD_chk < tMRD) begin
406
                $display ("at time %t ERROR: tMRD violation during Load Mode Register", $time);
407
            end
408
            MRD_chk = 0;
409
        end
410
 
411
        // Active Block (Latch Bank Address and Row Address)
412
        if (Active_enable == 1'b1) begin
413
            if (Ba == 2'b00 && Pc_b0 == 1'b1) begin
414
                {Act_b0, Pc_b0} = 2'b10;
415
                B0_row_addr = Addr [addr_bits - 1 : 0];
416
                RCD_chk0 = $time;
417
                RAS_chk0 = $time;
418
                if (Debug) $display ("at time %t ACT  : Bank = 0 Row = %d",$time, Addr);
419
                // Precharge to Activate Bank 0
420
                if ($time - RP_chk0 < tRP) begin
421
                    $display ("at time %t ERROR: tRP violation during Activate bank 0", $time);
422
                end
423
            end else if (Ba == 2'b01 && Pc_b1 == 1'b1) begin
424
                {Act_b1, Pc_b1} = 2'b10;
425
                B1_row_addr = Addr [addr_bits - 1 : 0];
426
                RCD_chk1 = $time;
427
                RAS_chk1 = $time;
428
                if (Debug) $display ("at time %t ACT  : Bank = 1 Row = %d",$time, Addr);
429
                // Precharge to Activate Bank 1
430
                if ($time - RP_chk1 < tRP) begin
431
                    $display ("at time %t ERROR: tRP violation during Activate bank 1", $time);
432
                end
433
            end else if (Ba == 2'b10 && Pc_b2 == 1'b1) begin
434
                {Act_b2, Pc_b2} = 2'b10;
435
                B2_row_addr = Addr [addr_bits - 1 : 0];
436
                RCD_chk2 = $time;
437
                RAS_chk2 = $time;
438
                if (Debug) $display ("at time %t ACT  : Bank = 2 Row = %d",$time, Addr);
439
                // Precharge to Activate Bank 2
440
                if ($time - RP_chk2 < tRP) begin
441
                    $display ("at time %t ERROR: tRP violation during Activate bank 2", $time);
442
                end
443
            end else if (Ba == 2'b11 && Pc_b3 == 1'b1) begin
444
                {Act_b3, Pc_b3} = 2'b10;
445
                B3_row_addr = Addr [addr_bits - 1 : 0];
446
                RCD_chk3 = $time;
447
                RAS_chk3 = $time;
448
                if (Debug) $display ("at time %t ACT  : Bank = 3 Row = %d",$time, Addr);
449
                // Precharge to Activate Bank 3
450
                if ($time - RP_chk3 < tRP) begin
451
                    $display ("at time %t ERROR: tRP violation during Activate bank 3", $time);
452
                end
453
            end else if (Ba == 2'b00 && Pc_b0 == 1'b0) begin
454
                $display ("at time %t ERROR: Bank 0 is already Activated (not Precharged)", $time);
455
            end else if (Ba == 2'b01 && Pc_b1 == 1'b0) begin
456
                $display ("at time %t ERROR: Bank 1 is already Activated (not Precharged)", $time);
457
            end else if (Ba == 2'b10 && Pc_b2 == 1'b0) begin
458
                $display ("at time %t ERROR: Bank 2 is already Activated (not Precharged)", $time);
459
            end else if (Ba == 2'b11 && Pc_b3 == 1'b0) begin
460
                $display ("at time %t ERROR: Bank 3 is already Activated (not Precharged)", $time);
461
            end
462
 
463
            // Active Bank A to Active Bank B
464
            if ((Previous_bank != Ba) && ($time - RRD_chk < tRRD)) begin
465
                $display ("at time %t ERROR: tRRD violation during Activate bank = %d", $time, Ba);
466
            end
467
 
468
            // Load Mode Register to Active
469
            if (MRD_chk < tMRD ) begin
470
                $display ("at time %t ERROR: tMRD violation during Activate bank = %d", $time, Ba);
471
            end
472
 
473
            // Auto Refresh to Activate
474
            if ($time - RC_chk < tRC) begin
475
                $display ("at time %t ERROR: tRC violation during Activate bank = %d", $time, Ba);
476
            end
477
 
478
            // Record variables for checking violation
479
            RRD_chk = $time;
480
            Previous_bank = Ba;
481
        end
482
 
483
        // Precharge Block
484
        if (Prech_enable == 1'b1) begin
485
            if (Addr[10] == 1'b1) begin
486
                {Pc_b0, Pc_b1, Pc_b2, Pc_b3} = 4'b1111;
487
                {Act_b0, Act_b1, Act_b2, Act_b3} = 4'b0000;
488
                RP_chk0 = $time;
489
                RP_chk1 = $time;
490
                RP_chk2 = $time;
491
                RP_chk3 = $time;
492
                if (Debug) $display ("at time %t PRE  : Bank = ALL",$time);
493
                // Activate to Precharge all banks
494
                if (($time - RAS_chk0 < tRAS) || ($time - RAS_chk1 < tRAS) ||
495
                    ($time - RAS_chk2 < tRAS) || ($time - RAS_chk3 < tRAS)) begin
496
                    $display ("at time %t ERROR: tRAS violation during Precharge all banks", $time);
497
                end
498
                // tWR violation check for write
499
                if (($time - WR_chkp[0] < tWRp) || ($time - WR_chkp[1] < tWRp) ||
500
                    ($time - WR_chkp[2] < tWRp) || ($time - WR_chkp[3] < tWRp)) begin
501
                    $display ("at time %t ERROR: tWR violation during Precharge all banks", $time);
502
                end
503
            end else if (Addr[10] == 1'b0) begin
504
                if (Ba == 2'b00) begin
505
                    {Pc_b0, Act_b0} = 2'b10;
506
                    RP_chk0 = $time;
507
                    if (Debug) $display ("at time %t PRE  : Bank = 0",$time);
508
                    // Activate to Precharge Bank 0
509
                    if ($time - RAS_chk0 < tRAS) begin
510
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 0", $time);
511
                    end
512
                end else if (Ba == 2'b01) begin
513
                    {Pc_b1, Act_b1} = 2'b10;
514
                    RP_chk1 = $time;
515
                    if (Debug) $display ("at time %t PRE  : Bank = 1",$time);
516
                    // Activate to Precharge Bank 1
517
                    if ($time - RAS_chk1 < tRAS) begin
518
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 1", $time);
519
                    end
520
                end else if (Ba == 2'b10) begin
521
                    {Pc_b2, Act_b2} = 2'b10;
522
                    RP_chk2 = $time;
523
                    if (Debug) $display ("at time %t PRE  : Bank = 2",$time);
524
                    // Activate to Precharge Bank 2
525
                    if ($time - RAS_chk2 < tRAS) begin
526
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 2", $time);
527
                    end
528
                end else if (Ba == 2'b11) begin
529
                    {Pc_b3, Act_b3} = 2'b10;
530
                    RP_chk3 = $time;
531
                    if (Debug) $display ("at time %t PRE  : Bank = 3",$time);
532
                    // Activate to Precharge Bank 3
533
                    if ($time - RAS_chk3 < tRAS) begin
534
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 3", $time);
535
                    end
536
                end
537
                // tWR violation check for write
538
                if ($time - WR_chkp[Ba] < tWRp) begin
539
                    $display ("at time %t ERROR: tWR violation during Precharge bank %d", $time, Ba);
540
                end
541
            end
542
            // Terminate a Write Immediately (if same bank or all banks)
543
            if (Data_in_enable == 1'b1 && (Bank == Ba || Addr[10] == 1'b1)) begin
544
                Data_in_enable = 1'b0;
545
                if (Debug) $display ("at time %t NOTE : Precharge interrupt Write Bank %d.", $time, Bank);
546
                if (Debug) $display ("at time %t NOTE : Make sure DQM is HIGH two cycles to meet tWR.", $time);
547
                if (Debug) $display ("at time %t NOTE : We suggest to use Burst Terminate command instead.", $time);
548
            end
549
            // Precharge Command Pipeline for Read
550
            if (Cas_latency_3 == 1'b1) begin
551
                Command[2] = `PRECH;
552
                Bank_precharge[2] = Ba;
553
                A10_precharge[2] = Addr[10];
554
            end else if (Cas_latency_2 == 1'b1) begin
555
                Command[1] = `PRECH;
556
                Bank_precharge[1] = Ba;
557
                A10_precharge[1] = Addr[10];
558
            end
559
        end
560
 
561
        // Burst terminate
562
        if (Burst_term == 1'b1) begin
563
            // Terminate a Write Immediately
564
            if (Data_in_enable == 1'b1) begin
565
                Data_in_enable = 1'b0;
566
            end
567
            // Terminate a Read Depend on CAS Latency
568
            if (Cas_latency_3 == 1'b1) begin
569
                Command[2] = `BST;
570
            end else if (Cas_latency_2 == 1'b1) begin
571
                Command[1] = `BST;
572
            end
573
            if (Debug) $display ("at time %t BST  : Burst Terminate",$time);
574
        end
575
 
576
        // Read, Write, Column Latch
577
        if (Read_enable == 1'b1 || Write_enable == 1'b1) begin
578
            // Check to see if bank is open (ACT)
579
            if ((Ba == 2'b00 && Pc_b0 == 1'b1) || (Ba == 2'b01 && Pc_b1 == 1'b1) ||
580
                (Ba == 2'b10 && Pc_b2 == 1'b1) || (Ba == 2'b11 && Pc_b3 == 1'b1)) begin
581
                $display("at time %t ERROR: Cannot Read or Write - Bank %d is not Activated", $time, Ba);
582
            end
583
 
584
            // Activate to Read or Write
585
            if ((Ba == 2'b00) && ($time - RCD_chk0 < tRCD))
586
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 0", $time);
587
            if ((Ba == 2'b01) && ($time - RCD_chk1 < tRCD))
588
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 1", $time);
589
            if ((Ba == 2'b10) && ($time - RCD_chk2 < tRCD))
590
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 2", $time);
591
            if ((Ba == 2'b11) && ($time - RCD_chk3 < tRCD))
592
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 3", $time);
593
 
594
            // Read Command
595
            if (Read_enable == 1'b1) begin
596
                // CAS Latency pipeline
597
                if (Cas_latency_3 == 1'b1) begin
598
                    if (Addr[10] == 1'b1) begin
599
                        Command[2] = `READ_A;
600
                    end else begin
601
                        Command[2] = `READ;
602
                    end
603
                    Col_addr[2] = Addr;
604
                    Bank_addr[2] = Ba;
605
                end else if (Cas_latency_2 == 1'b1) begin
606
                    if (Addr[10] == 1'b1) begin
607
                        Command[1] = `READ_A;
608
                    end else begin
609
                        Command[1] = `READ;
610
                    end
611
                    Col_addr[1] = Addr;
612
                    Bank_addr[1] = Ba;
613
                end
614
 
615
                // Read interrupt Write (terminate Write immediately)
616
                if (Data_in_enable == 1'b1) begin
617
                    Data_in_enable = 1'b0;
618
                    // Interrupting a Write with Autoprecharge
619
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Write_precharge[RW_interrupt_bank] == 1'b1) begin
620
                        RW_interrupt_write[RW_interrupt_bank] = 1'b1;
621
                        WR_time[RW_interrupt_bank] = $time;
622
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Write Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
623
                    else
624
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Write Bank %d", $time, Ba, Bank);
625
                    end
626
                end
627
 
628
                // Read interrupt Read (terminate Read after CL-1)
629
                if (Data_out_enable == 1'b1 && ((Cas_latency_2 == 1'b1 && ((Burst_length_2 == 1'b1 && Burst_counter < 1) ||
630
                                                                           (Burst_length_4 == 1'b1 && Burst_counter < 3) ||
631
                                                                           (Burst_length_8 == 1'b1 && Burst_counter < 7))) ||
632
                                                (Cas_latency_3 == 1'b1 && ((Burst_length_4 == 1'b1 && Burst_counter < 2) ||
633
                                                                           (Burst_length_8 == 1'b1 && Burst_counter < 6))))) begin
634
                    // Interrupting a Read with Autoprecharge
635
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Read_precharge[RW_interrupt_bank] == 1'b1) begin
636
                        RW_interrupt_read[RW_interrupt_bank] = 1'b1;
637
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Read Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
638
                    else
639
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Read Bank %d", $time, Ba, Bank);
640
                    end
641
                end
642
 
643
            // Write Command
644
            end else if (Write_enable == 1'b1) begin
645
                if (Addr[10] == 1'b1) begin
646
                    Command[0] = `WRITE_A;
647
                end else begin
648
                    Command[0] = `WRITE;
649
                end
650
                Col_addr[0] = Addr;
651
                Bank_addr[0] = Ba;
652
 
653
                // Write interrupt Write (terminate Write immediately)
654
                if (Data_in_enable == 1'b1) begin
655
                    Data_in_enable = 1'b0;
656
                    // Interrupting a Write with Autoprecharge
657
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Write_precharge[RW_interrupt_bank] == 1'b1) begin
658
                        RW_interrupt_write[RW_interrupt_bank] = 1'b1;
659
                        WR_time[RW_interrupt_bank] = $time;
660
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Write Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
661
                    else
662
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Write Bank %d", $time, Ba, Bank);
663
                    end
664
                end
665
 
666
                // Write interrupt Read (terminate Read immediately)
667
                if (Data_out_enable == 1'b1) begin
668
                    Data_out_enable = 1'b0;
669
                    // Interrupting a Read with Autoprecharge
670
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Read_precharge[RW_interrupt_bank] == 1'b1) begin
671
                        RW_interrupt_read[RW_interrupt_bank] = 1'b1;
672
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Read Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
673
                    else
674
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Read Bank %d", $time, Ba, Bank);
675
                    end
676
                end
677
            end
678
 
679
            // Read or Write with Auto Precharge
680
            if (Addr[10] == 1'b1) begin
681
                Auto_precharge[Ba] = 1'b1;
682
                Count_precharge[Ba] = 0;
683
                RW_interrupt_bank = Ba;
684
                if (Read_enable == 1'b1) begin
685
                    Read_precharge[Ba] = 1'b1;
686
                end else if (Write_enable == 1'b1) begin
687
                    Write_precharge[Ba] = 1'b1;
688
                end
689
            end
690
        end
691
 
692
        //  Read with Auto Precharge Calculation
693
        //      The device start internal precharge:
694
        //          1.  CAS Latency - 1 cycles before last burst
695
        //      and 2.  Meet minimum tRAS requirement
696
        //       or 3.  Interrupt by a Read or Write (with or without AutoPrecharge)
697
        if ((Auto_precharge[0] == 1'b1) && (Read_precharge[0] == 1'b1)) begin
698
            if ((($time - RAS_chk0 >= tRAS) &&                                                      // Case 2
699
                ((Burst_length_1 == 1'b1 && Count_precharge[0] >= 1) ||                             // Case 1
700
                 (Burst_length_2 == 1'b1 && Count_precharge[0] >= 2) ||
701
                 (Burst_length_4 == 1'b1 && Count_precharge[0] >= 4) ||
702
                 (Burst_length_8 == 1'b1 && Count_precharge[0] >= 8))) ||
703
                 (RW_interrupt_read[0] == 1'b1)) begin                                              // Case 3
704
                    Pc_b0 = 1'b1;
705
                    Act_b0 = 1'b0;
706
                    RP_chk0 = $time;
707
                    Auto_precharge[0] = 1'b0;
708
                    Read_precharge[0] = 1'b0;
709
                    RW_interrupt_read[0] = 1'b0;
710
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 0", $time);
711
            end
712
        end
713
        if ((Auto_precharge[1] == 1'b1) && (Read_precharge[1] == 1'b1)) begin
714
            if ((($time - RAS_chk1 >= tRAS) &&
715
                ((Burst_length_1 == 1'b1 && Count_precharge[1] >= 1) ||
716
                 (Burst_length_2 == 1'b1 && Count_precharge[1] >= 2) ||
717
                 (Burst_length_4 == 1'b1 && Count_precharge[1] >= 4) ||
718
                 (Burst_length_8 == 1'b1 && Count_precharge[1] >= 8))) ||
719
                 (RW_interrupt_read[1] == 1'b1)) begin
720
                    Pc_b1 = 1'b1;
721
                    Act_b1 = 1'b0;
722
                    RP_chk1 = $time;
723
                    Auto_precharge[1] = 1'b0;
724
                    Read_precharge[1] = 1'b0;
725
                    RW_interrupt_read[1] = 1'b0;
726
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 1", $time);
727
            end
728
        end
729
        if ((Auto_precharge[2] == 1'b1) && (Read_precharge[2] == 1'b1)) begin
730
            if ((($time - RAS_chk2 >= tRAS) &&
731
                ((Burst_length_1 == 1'b1 && Count_precharge[2] >= 1) ||
732
                 (Burst_length_2 == 1'b1 && Count_precharge[2] >= 2) ||
733
                 (Burst_length_4 == 1'b1 && Count_precharge[2] >= 4) ||
734
                 (Burst_length_8 == 1'b1 && Count_precharge[2] >= 8))) ||
735
                 (RW_interrupt_read[2] == 1'b1)) begin
736
                    Pc_b2 = 1'b1;
737
                    Act_b2 = 1'b0;
738
                    RP_chk2 = $time;
739
                    Auto_precharge[2] = 1'b0;
740
                    Read_precharge[2] = 1'b0;
741
                    RW_interrupt_read[2] = 1'b0;
742
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 2", $time);
743
            end
744
        end
745
        if ((Auto_precharge[3] == 1'b1) && (Read_precharge[3] == 1'b1)) begin
746
            if ((($time - RAS_chk3 >= tRAS) &&
747
                ((Burst_length_1 == 1'b1 && Count_precharge[3] >= 1) ||
748
                 (Burst_length_2 == 1'b1 && Count_precharge[3] >= 2) ||
749
                 (Burst_length_4 == 1'b1 && Count_precharge[3] >= 4) ||
750
                 (Burst_length_8 == 1'b1 && Count_precharge[3] >= 8))) ||
751
                 (RW_interrupt_read[3] == 1'b1)) begin
752
                    Pc_b3 = 1'b1;
753
                    Act_b3 = 1'b0;
754
                    RP_chk3 = $time;
755
                    Auto_precharge[3] = 1'b0;
756
                    Read_precharge[3] = 1'b0;
757
                    RW_interrupt_read[3] = 1'b0;
758
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 3", $time);
759
            end
760
        end
761
 
762
        // Internal Precharge or Bst
763
        if (Command[0] == `PRECH) begin                         // Precharge terminate a read with same bank or all banks
764
            if (Bank_precharge[0] == Bank || A10_precharge[0] == 1'b1) begin
765
                if (Data_out_enable == 1'b1) begin
766
                    Data_out_enable = 1'b0;
767
                end
768
            end
769
        end else if (Command[0] == `BST) begin                  // BST terminate a read to current bank
770
            if (Data_out_enable == 1'b1) begin
771
                Data_out_enable = 1'b0;
772
            end
773
        end
774
 
775
        if (Data_out_enable == 1'b0) begin
776
            Dq_reg <= #tOH {data_bits{1'bz}};
777
        end
778
 
779
        // Detect Read or Write command
780
        if (Command[0] == `READ || Command[0] == `READ_A) begin
781
            Bank = Bank_addr[0];
782
            Col = Col_addr[0];
783
            Col_brst = Col_addr[0];
784
            if (Bank_addr[0] == 2'b00) begin
785
                Row = B0_row_addr;
786
            end else if (Bank_addr[0] == 2'b01) begin
787
                Row = B1_row_addr;
788
            end else if (Bank_addr[0] == 2'b10) begin
789
                Row = B2_row_addr;
790
            end else if (Bank_addr[0] == 2'b11) begin
791
                Row = B3_row_addr;
792
            end
793
            Burst_counter = 0;
794
            Data_in_enable = 1'b0;
795
            Data_out_enable = 1'b1;
796
        end else if (Command[0] == `WRITE || Command[0] == `WRITE_A) begin
797
            Bank = Bank_addr[0];
798
            Col = Col_addr[0];
799
            Col_brst = Col_addr[0];
800
            if (Bank_addr[0] == 2'b00) begin
801
                Row = B0_row_addr;
802
            end else if (Bank_addr[0] == 2'b01) begin
803
                Row = B1_row_addr;
804
            end else if (Bank_addr[0] == 2'b10) begin
805
                Row = B2_row_addr;
806
            end else if (Bank_addr[0] == 2'b11) begin
807
                Row = B3_row_addr;
808
            end
809
            Burst_counter = 0;
810
            Data_in_enable = 1'b1;
811
            Data_out_enable = 1'b0;
812
        end
813
 
814
        // DQ buffer (Driver/Receiver)
815
        if (Data_in_enable == 1'b1) begin                                   // Writing Data to Memory
816
            // Array buffer
817
            if (Bank == 2'b00) Dq_dqm [15 : 0] = Bank0 [{Row, Col}];
818
            if (Bank == 2'b01) Dq_dqm [15 : 0] = Bank1 [{Row, Col}];
819
            if (Bank == 2'b10) Dq_dqm [15 : 0] = Bank2 [{Row, Col}];
820
            if (Bank == 2'b11) Dq_dqm [15 : 0] = Bank3 [{Row, Col}];
821
            // Dqm operation
822
            if (Dqm[0] == 1'b0) Dq_dqm [ 7 : 0] = Dq [ 7 : 0];
823
            if (Dqm[1] == 1'b0) Dq_dqm [15 : 8] = Dq [15 : 8];
824
            // Write to memory
825
            if (Bank == 2'b00) Bank0 [{Row, Col}] = Dq_dqm [15 : 0];
826
            if (Bank == 2'b01) Bank1 [{Row, Col}] = Dq_dqm [15 : 0];
827
            if (Bank == 2'b10) Bank2 [{Row, Col}] = Dq_dqm [15 : 0];
828
            if (Bank == 2'b11) Bank3 [{Row, Col}] = Dq_dqm [15 : 0];
829
            // Output result
830
            if (Dqm == 2'b11) begin
831
                if (Debug) $display("at time %t WRITE: Bank = %d Row = %d, Col = %d, Data = Hi-Z due to DQM", $time, Bank, Row, Col);
832
            end else begin
833
                if (Debug) $display("at time %t WRITE: Bank = %d Row = %d, Col = %d, Data = %d, Dqm = %b", $time, Bank, Row, Col, Dq_dqm, Dqm);
834
                // Record tWR time and reset counter
835
                WR_chkp [Bank] = $time;
836
                WR_counter [Bank] = 0;
837
            end
838
            // Advance burst counter subroutine
839
            #tHZ Burst;
840
        end else if (Data_out_enable == 1'b1) begin                         // Reading Data from Memory
841
            // Array buffer
842
            if (Bank == 2'b00) Dq_dqm [15 : 0] = Bank0 [{Row, Col}];
843
            if (Bank == 2'b01) Dq_dqm [15 : 0] = Bank1 [{Row, Col}];
844
            if (Bank == 2'b10) Dq_dqm [15 : 0] = Bank2 [{Row, Col}];
845
            if (Bank == 2'b11) Dq_dqm [15 : 0] = Bank3 [{Row, Col}];
846
            // Dqm operation
847
            if (Dqm_reg0[0] == 1'b1) Dq_dqm [ 7 : 0] = 8'bz;
848
            if (Dqm_reg0[1] == 1'b1) Dq_dqm [15 : 8] = 8'bz;
849
            // Display result
850
            Dq_reg [15 : 0] = #tAC Dq_dqm [15 : 0];
851
            if (Dqm_reg0 == 2'b11) begin
852
                if (Debug) $display("at time %t READ : Bank = %d Row = %d, Col = %d, Data = Hi-Z due to DQM", $time, Bank, Row, Col);
853
            end else begin
854
                if (Debug) $display("at time %t READ : Bank = %d Row = %d, Col = %d, Data = %d, Dqm = %b", $time, Bank, Row, Col, Dq_reg, Dqm_reg0);
855
            end
856
            // Advance burst counter subroutine
857
            Burst;
858
        end
859
    end
860
 
861
    //  Write with Auto Precharge Calculation
862
    //      The device start internal precharge:
863
    //          1.  tWR Clock after last burst
864
    //      and 2.  Meet minimum tRAS requirement
865
    //       or 3.  Interrupt by a Read or Write (with or without AutoPrecharge)
866
    always @ (RAS_clk) begin
867
        if ((Auto_precharge[0] == 1'b1) && (Write_precharge[0] == 1'b1)) begin
868
            if ((($time - RAS_chk0 >= tRAS) &&                                                          // Case 2
869
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [0] >= 1 && $time - Count_time[0] >= tWRa) ||   // Case 1
870
                 (Burst_length_2 == 1'b1 && Count_precharge [0] >= 2 && $time - Count_time[0] >= tWRa) ||
871
                 (Burst_length_4 == 1'b1 && Count_precharge [0] >= 4 && $time - Count_time[0] >= tWRa) ||
872
                 (Burst_length_8 == 1'b1 && Count_precharge [0] >= 8 && $time - Count_time[0] >= tWRa))) ||
873
                 (RW_interrupt_write[0] == 1'b1 && WR_counter[0] >= 1 && $time - WR_time[0] >= tWRa)) begin                           // Case 3 (stop count when interrupt)
874
                    Auto_precharge[0] = 1'b0;
875
                    Write_precharge[0] = 1'b0;
876
                    RW_interrupt_write[0] = 1'b0;
877
                    Pc_b0 = 1'b1;
878
                    Act_b0 = 1'b0;
879
                    RP_chk0 = $time;
880
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 0", $time);
881
            end
882
        end
883
        if ((Auto_precharge[1] == 1'b1) && (Write_precharge[1] == 1'b1)) begin
884
            if ((($time - RAS_chk1 >= tRAS) &&
885
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [1] >= 1 && $time - Count_time[1] >= tWRa) ||
886
                 (Burst_length_2 == 1'b1 && Count_precharge [1] >= 2 && $time - Count_time[1] >= tWRa) ||
887
                 (Burst_length_4 == 1'b1 && Count_precharge [1] >= 4 && $time - Count_time[1] >= tWRa) ||
888
                 (Burst_length_8 == 1'b1 && Count_precharge [1] >= 8 && $time - Count_time[1] >= tWRa))) ||
889
                 (RW_interrupt_write[1] == 1'b1 && WR_counter[1] >= 1 && $time - WR_time[1] >= tWRa)) begin
890
                    Auto_precharge[1] = 1'b0;
891
                    Write_precharge[1] = 1'b0;
892
                    RW_interrupt_write[1] = 1'b0;
893
                    Pc_b1 = 1'b1;
894
                    Act_b1 = 1'b0;
895
                    RP_chk1 = $time;
896
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 1", $time);
897
            end
898
        end
899
        if ((Auto_precharge[2] == 1'b1) && (Write_precharge[2] == 1'b1)) begin
900
            if ((($time - RAS_chk2 >= tRAS) &&
901
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [2] >= 1 && $time - Count_time[2] >= tWRa) ||
902
                 (Burst_length_2 == 1'b1 && Count_precharge [2] >= 2 && $time - Count_time[2] >= tWRa) ||
903
                 (Burst_length_4 == 1'b1 && Count_precharge [2] >= 4 && $time - Count_time[2] >= tWRa) ||
904
                 (Burst_length_8 == 1'b1 && Count_precharge [2] >= 8 && $time - Count_time[2] >= tWRa))) ||
905
                 (RW_interrupt_write[2] == 1'b1 && WR_counter[2] >= 1 && $time - WR_time[2] >= tWRa)) begin
906
                    Auto_precharge[2] = 1'b0;
907
                    Write_precharge[2] = 1'b0;
908
                    RW_interrupt_write[2] = 1'b0;
909
                    Pc_b2 = 1'b1;
910
                    Act_b2 = 1'b0;
911
                    RP_chk2 = $time;
912
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 2", $time);
913
            end
914
        end
915
        if ((Auto_precharge[3] == 1'b1) && (Write_precharge[3] == 1'b1)) begin
916
            if ((($time - RAS_chk3 >= tRAS) &&
917
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [3] >= 1 && $time - Count_time[3] >= tWRa) ||
918
                 (Burst_length_2 == 1'b1 && Count_precharge [3] >= 2 && $time - Count_time[3] >= tWRa) ||
919
                 (Burst_length_4 == 1'b1 && Count_precharge [3] >= 4 && $time - Count_time[3] >= tWRa) ||
920
                 (Burst_length_8 == 1'b1 && Count_precharge [3] >= 8 && $time - Count_time[3] >= tWRa))) ||
921
                 (RW_interrupt_write[3] == 1'b1 && WR_counter[3] >= 1 && $time - WR_time[3] >= tWRa)) begin
922
                    Auto_precharge[3] = 1'b0;
923
                    Write_precharge[3] = 1'b0;
924
                    RW_interrupt_write[3] = 1'b0;
925
                    Pc_b3 = 1'b1;
926
                    Act_b3 = 1'b0;
927
                    RP_chk3 = $time;
928
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 3", $time);
929
            end
930
        end
931
    end
932
 
933
    task Burst;
934
        begin
935
            // Advance Burst Counter
936
            Burst_counter = Burst_counter + 1;
937
 
938
            // Burst Type
939
            if (Mode_reg[3] == 1'b0) begin                                  // Sequential Burst
940
                Col_temp = Col + 1;
941
            end else if (Mode_reg[3] == 1'b1) begin                         // Interleaved Burst
942
                Col_temp[2] =  Burst_counter[2] ^  Col_brst[2];
943
                Col_temp[1] =  Burst_counter[1] ^  Col_brst[1];
944
                Col_temp[0] =  Burst_counter[0] ^  Col_brst[0];
945
            end
946
 
947
            // Burst Length
948
            if (Burst_length_2) begin                                       // Burst Length = 2
949
                Col [0] = Col_temp [0];
950
            end else if (Burst_length_4) begin                              // Burst Length = 4
951
                Col [1 : 0] = Col_temp [1 : 0];
952
            end else if (Burst_length_8) begin                              // Burst Length = 8
953
                Col [2 : 0] = Col_temp [2 : 0];
954
            end else begin                                                  // Burst Length = FULL
955
                Col = Col_temp;
956
            end
957
 
958
            // Burst Read Single Write            
959
            if (Write_burst_mode == 1'b1) begin
960
                Data_in_enable = 1'b0;
961
            end
962
 
963
            // Data Counter
964
            if (Burst_length_1 == 1'b1) begin
965
                if (Burst_counter >= 1) begin
966
                    Data_in_enable = 1'b0;
967
                    Data_out_enable = 1'b0;
968
                end
969
            end else if (Burst_length_2 == 1'b1) begin
970
                if (Burst_counter >= 2) begin
971
                    Data_in_enable = 1'b0;
972
                    Data_out_enable = 1'b0;
973
                end
974
            end else if (Burst_length_4 == 1'b1) begin
975
                if (Burst_counter >= 4) begin
976
                    Data_in_enable = 1'b0;
977
                    Data_out_enable = 1'b0;
978
                end
979
            end else if (Burst_length_8 == 1'b1) begin
980
                if (Burst_counter >= 8) begin
981
                    Data_in_enable = 1'b0;
982
                    Data_out_enable = 1'b0;
983
                end
984
            end
985
        end
986
    endtask
987
 
988
    // Timing Parameters for -7E and CAS Latency = 2
989
    specify
990
        specparam
991
            tAH  =  0.8,                                        // Addr, Ba Hold Time
992
            tAS  =  1.5,                                        // Addr, Ba Setup Time
993
            tCH  =  2.5,                                        // Clock High-Level Width
994
            tCL  =  2.5,                                        // Clock Low-Level Width
995
            tCK  =  7.5,                                        // Clock Cycle Time
996
            tDH  =  0.8,                                        // Data-in Hold Time
997
            tDS  =  1.5,                                        // Data-in Setup Time
998
            tCKH =  0.8,                                        // CKE Hold  Time
999
            tCKS =  1.5,                                        // CKE Setup Time
1000
            tCMH =  0.8,                                        // CS#, RAS#, CAS#, WE#, DQM# Hold  Time
1001
            tCMS =  1.5;                                        // CS#, RAS#, CAS#, WE#, DQM# Setup Time
1002
        $width    (posedge Clk,           tCH);
1003
        $width    (negedge Clk,           tCL);
1004
        $period   (negedge Clk,           tCK);
1005
        $period   (posedge Clk,           tCK);
1006
        $setuphold(posedge Clk,    Cke,   tCKS, tCKH);
1007
        $setuphold(posedge Clk,    Cs_n,  tCMS, tCMH);
1008
        $setuphold(posedge Clk,    Cas_n, tCMS, tCMH);
1009
        $setuphold(posedge Clk,    Ras_n, tCMS, tCMH);
1010
        $setuphold(posedge Clk,    We_n,  tCMS, tCMH);
1011
        $setuphold(posedge Clk,    Addr,  tAS,  tAH);
1012
        $setuphold(posedge Clk,    Ba,    tAS,  tAH);
1013
        $setuphold(posedge Clk,    Dqm,   tCMS, tCMH);
1014
        $setuphold(posedge Dq_chk, Dq,    tDS,  tDH);
1015
    endspecify
1016
 
1017
endmodule

powered by: WebSVN 2.1.0

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