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 29

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 16 rudi
 
216 4 rudi
            if (Cke == 1'b0 && (Data_in_enable == 1'b1 || Data_out_enable == 1'b1)) begin
217
                $display ("at time %t ERROR: Illegal power down or self refresh.  Please make sure data bus is idle.", $time);
218
            end
219 16 rudi
 
220 4 rudi
        end
221
        @ (negedge Clk) begin
222
            Sys_clk = 1'b0;
223
        end
224
    end
225
 
226
    always @ (posedge Sys_clk) begin
227
        // Internal Commamd Pipelined
228
        Command[0] = Command[1];
229
        Command[1] = Command[2];
230
        Command[2] = Command[3];
231
        Command[3] = `NOP;
232
 
233
        Col_addr[0] = Col_addr[1];
234
        Col_addr[1] = Col_addr[2];
235
        Col_addr[2] = Col_addr[3];
236
        Col_addr[3] = {col_bits{1'b0}};
237
 
238
        Bank_addr[0] = Bank_addr[1];
239
        Bank_addr[1] = Bank_addr[2];
240
        Bank_addr[2] = Bank_addr[3];
241
        Bank_addr[3] = 2'b0;
242
 
243
        Bank_precharge[0] = Bank_precharge[1];
244
        Bank_precharge[1] = Bank_precharge[2];
245
        Bank_precharge[2] = Bank_precharge[3];
246
        Bank_precharge[3] = 2'b0;
247
 
248
        A10_precharge[0] = A10_precharge[1];
249
        A10_precharge[1] = A10_precharge[2];
250
        A10_precharge[2] = A10_precharge[3];
251
        A10_precharge[3] = 1'b0;
252
 
253
        // Dqm pipeline for Read
254
        Dqm_reg0 = Dqm_reg1;
255
        Dqm_reg1 = Dqm;
256
 
257
        // Read or Write with Auto Precharge Counter
258
        if (Auto_precharge[0] == 1'b1) begin
259
            Count_precharge[0] = Count_precharge[0] + 1;
260
        end
261
        if (Auto_precharge[1] == 1'b1) begin
262
            Count_precharge[1] = Count_precharge[1] + 1;
263
        end
264
        if (Auto_precharge[2] == 1'b1) begin
265
            Count_precharge[2] = Count_precharge[2] + 1;
266
        end
267
        if (Auto_precharge[3] == 1'b1) begin
268
            Count_precharge[3] = Count_precharge[3] + 1;
269
        end
270
 
271
        // Auto Precharge Timer for tWR
272
        if (Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) begin
273
            if (Count_precharge[0] == 1) begin
274
                Count_time[0] = $time;
275
            end
276
            if (Count_precharge[1] == 1) begin
277
                Count_time[1] = $time;
278
            end
279
            if (Count_precharge[2] == 1) begin
280
                Count_time[2] = $time;
281
            end
282
            if (Count_precharge[3] == 1) begin
283
                Count_time[3] = $time;
284
            end
285
        end else if (Burst_length_2 == 1'b1) begin
286
            if (Count_precharge[0] == 2) begin
287
                Count_time[0] = $time;
288
            end
289
            if (Count_precharge[1] == 2) begin
290
                Count_time[1] = $time;
291
            end
292
            if (Count_precharge[2] == 2) begin
293
                Count_time[2] = $time;
294
            end
295
            if (Count_precharge[3] == 2) begin
296
                Count_time[3] = $time;
297
            end
298
        end else if (Burst_length_4 == 1'b1) begin
299
            if (Count_precharge[0] == 4) begin
300
                Count_time[0] = $time;
301
            end
302
            if (Count_precharge[1] == 4) begin
303
                Count_time[1] = $time;
304
            end
305
            if (Count_precharge[2] == 4) begin
306
                Count_time[2] = $time;
307
            end
308
            if (Count_precharge[3] == 4) begin
309
                Count_time[3] = $time;
310
            end
311
        end else if (Burst_length_8 == 1'b1) begin
312
            if (Count_precharge[0] == 8) begin
313
                Count_time[0] = $time;
314
            end
315
            if (Count_precharge[1] == 8) begin
316
                Count_time[1] = $time;
317
            end
318
            if (Count_precharge[2] == 8) begin
319
                Count_time[2] = $time;
320
            end
321
            if (Count_precharge[3] == 8) begin
322
                Count_time[3] = $time;
323
            end
324
        end
325
 
326
        // tMRD Counter
327
        MRD_chk = MRD_chk + 1;
328
 
329
        // tWR Counter for Write
330
        WR_counter[0] = WR_counter[0] + 1;
331
        WR_counter[1] = WR_counter[1] + 1;
332
        WR_counter[2] = WR_counter[2] + 1;
333
        WR_counter[3] = WR_counter[3] + 1;
334
 
335
        // Auto Refresh
336
        if (Aref_enable == 1'b1) begin
337
            if (Debug) $display ("at time %t AREF : Auto Refresh", $time);
338
            // Auto Refresh to Auto Refresh
339
            if ($time - RC_chk < tRC) begin
340
                $display ("at time %t ERROR: tRC violation during Auto Refresh", $time);
341
            end
342
 
343
            // Precharge to Auto Refresh
344
            if ($time - RP_chk0 < tRP || $time - RP_chk1 < tRP || $time - RP_chk2 < tRP || $time - RP_chk3 < tRP) begin
345
                $display ("at time %t ERROR: tRP violation during Auto Refresh", $time);
346
            end
347
 
348
            // Precharge to Refresh
349
            if (Pc_b0 == 1'b0 || Pc_b1 == 1'b0 || Pc_b2 == 1'b0 || Pc_b3 == 1'b0) begin
350
                $display ("at time %t ERROR: All banks must be Precharge before Auto Refresh", $time);
351
            end
352
 
353
            // Record Current tRC time
354
            RC_chk = $time;
355
        end
356
 
357
        // Load Mode Register
358
        if (Mode_reg_enable == 1'b1) begin
359
            // Decode CAS Latency, Burst Length, Burst Type, and Write Burst Mode
360
            if (Pc_b0 == 1'b1 && Pc_b1 == 1'b1 && Pc_b2 == 1'b1 && Pc_b3 == 1'b1) begin
361
                Mode_reg = Addr;
362
                if (Debug) begin
363
                    $display ("at time %t LMR  : Load Mode Register", $time);
364
                    // CAS Latency
365
                    if (Addr[6 : 4] == 3'b010)
366
                        $display ("                            CAS Latency      = 2");
367
                    else if (Addr[6 : 4] == 3'b011)
368
                        $display ("                            CAS Latency      = 3");
369
                    else
370
                        $display ("                            CAS Latency      = Reserved");
371
                    // Burst Length
372
                    if (Addr[2 : 0] == 3'b000)
373
                        $display ("                            Burst Length     = 1");
374
                    else if (Addr[2 : 0] == 3'b001)
375
                        $display ("                            Burst Length     = 2");
376
                    else if (Addr[2 : 0] == 3'b010)
377
                        $display ("                            Burst Length     = 4");
378
                    else if (Addr[2 : 0] == 3'b011)
379
                        $display ("                            Burst Length     = 8");
380
                    else if (Addr[3 : 0] == 4'b0111)
381
                        $display ("                            Burst Length     = Full");
382
                    else
383
                        $display ("                            Burst Length     = Reserved");
384
                    // Burst Type
385
                    if (Addr[3] == 1'b0)
386
                        $display ("                            Burst Type       = Sequential");
387
                    else if (Addr[3] == 1'b1)
388
                        $display ("                            Burst Type       = Interleaved");
389
                    else
390
                        $display ("                            Burst Type       = Reserved");
391
                    // Write Burst Mode
392
                    if (Addr[9] == 1'b0)
393
                        $display ("                            Write Burst Mode = Programmed Burst Length");
394
                    else if (Addr[9] == 1'b1)
395
                        $display ("                            Write Burst Mode = Single Location Access");
396
                    else
397
                        $display ("                            Write Burst Mode = Reserved");
398
                end
399
            end else begin
400
                $display ("at time %t ERROR: all banks must be Precharge before Load Mode Register", $time);
401
            end
402
            // REF to LMR
403
            if ($time - RC_chk < tRC) begin
404
                $display ("at time %t ERROR: tRC violation during Load Mode Register", $time);
405
            end
406
            // LMR to LMR
407
            if (MRD_chk < tMRD) begin
408
                $display ("at time %t ERROR: tMRD violation during Load Mode Register", $time);
409
            end
410
            MRD_chk = 0;
411
        end
412
 
413
        // Active Block (Latch Bank Address and Row Address)
414
        if (Active_enable == 1'b1) begin
415
            if (Ba == 2'b00 && Pc_b0 == 1'b1) begin
416
                {Act_b0, Pc_b0} = 2'b10;
417
                B0_row_addr = Addr [addr_bits - 1 : 0];
418
                RCD_chk0 = $time;
419
                RAS_chk0 = $time;
420
                if (Debug) $display ("at time %t ACT  : Bank = 0 Row = %d",$time, Addr);
421
                // Precharge to Activate Bank 0
422
                if ($time - RP_chk0 < tRP) begin
423
                    $display ("at time %t ERROR: tRP violation during Activate bank 0", $time);
424
                end
425
            end else if (Ba == 2'b01 && Pc_b1 == 1'b1) begin
426
                {Act_b1, Pc_b1} = 2'b10;
427
                B1_row_addr = Addr [addr_bits - 1 : 0];
428
                RCD_chk1 = $time;
429
                RAS_chk1 = $time;
430
                if (Debug) $display ("at time %t ACT  : Bank = 1 Row = %d",$time, Addr);
431
                // Precharge to Activate Bank 1
432
                if ($time - RP_chk1 < tRP) begin
433
                    $display ("at time %t ERROR: tRP violation during Activate bank 1", $time);
434
                end
435
            end else if (Ba == 2'b10 && Pc_b2 == 1'b1) begin
436
                {Act_b2, Pc_b2} = 2'b10;
437
                B2_row_addr = Addr [addr_bits - 1 : 0];
438
                RCD_chk2 = $time;
439
                RAS_chk2 = $time;
440
                if (Debug) $display ("at time %t ACT  : Bank = 2 Row = %d",$time, Addr);
441
                // Precharge to Activate Bank 2
442
                if ($time - RP_chk2 < tRP) begin
443
                    $display ("at time %t ERROR: tRP violation during Activate bank 2", $time);
444
                end
445
            end else if (Ba == 2'b11 && Pc_b3 == 1'b1) begin
446
                {Act_b3, Pc_b3} = 2'b10;
447
                B3_row_addr = Addr [addr_bits - 1 : 0];
448
                RCD_chk3 = $time;
449
                RAS_chk3 = $time;
450
                if (Debug) $display ("at time %t ACT  : Bank = 3 Row = %d",$time, Addr);
451
                // Precharge to Activate Bank 3
452
                if ($time - RP_chk3 < tRP) begin
453
                    $display ("at time %t ERROR: tRP violation during Activate bank 3", $time);
454
                end
455
            end else if (Ba == 2'b00 && Pc_b0 == 1'b0) begin
456
                $display ("at time %t ERROR: Bank 0 is already Activated (not Precharged)", $time);
457
            end else if (Ba == 2'b01 && Pc_b1 == 1'b0) begin
458
                $display ("at time %t ERROR: Bank 1 is already Activated (not Precharged)", $time);
459
            end else if (Ba == 2'b10 && Pc_b2 == 1'b0) begin
460
                $display ("at time %t ERROR: Bank 2 is already Activated (not Precharged)", $time);
461
            end else if (Ba == 2'b11 && Pc_b3 == 1'b0) begin
462
                $display ("at time %t ERROR: Bank 3 is already Activated (not Precharged)", $time);
463
            end
464
 
465
            // Active Bank A to Active Bank B
466
            if ((Previous_bank != Ba) && ($time - RRD_chk < tRRD)) begin
467
                $display ("at time %t ERROR: tRRD violation during Activate bank = %d", $time, Ba);
468
            end
469
 
470
            // Load Mode Register to Active
471
            if (MRD_chk < tMRD ) begin
472
                $display ("at time %t ERROR: tMRD violation during Activate bank = %d", $time, Ba);
473
            end
474
 
475
            // Auto Refresh to Activate
476
            if ($time - RC_chk < tRC) begin
477
                $display ("at time %t ERROR: tRC violation during Activate bank = %d", $time, Ba);
478
            end
479
 
480
            // Record variables for checking violation
481
            RRD_chk = $time;
482
            Previous_bank = Ba;
483
        end
484
 
485
        // Precharge Block
486
        if (Prech_enable == 1'b1) begin
487
            if (Addr[10] == 1'b1) begin
488
                {Pc_b0, Pc_b1, Pc_b2, Pc_b3} = 4'b1111;
489
                {Act_b0, Act_b1, Act_b2, Act_b3} = 4'b0000;
490
                RP_chk0 = $time;
491
                RP_chk1 = $time;
492
                RP_chk2 = $time;
493
                RP_chk3 = $time;
494
                if (Debug) $display ("at time %t PRE  : Bank = ALL",$time);
495
                // Activate to Precharge all banks
496
                if (($time - RAS_chk0 < tRAS) || ($time - RAS_chk1 < tRAS) ||
497
                    ($time - RAS_chk2 < tRAS) || ($time - RAS_chk3 < tRAS)) begin
498
                    $display ("at time %t ERROR: tRAS violation during Precharge all banks", $time);
499
                end
500
                // tWR violation check for write
501
                if (($time - WR_chkp[0] < tWRp) || ($time - WR_chkp[1] < tWRp) ||
502
                    ($time - WR_chkp[2] < tWRp) || ($time - WR_chkp[3] < tWRp)) begin
503
                    $display ("at time %t ERROR: tWR violation during Precharge all banks", $time);
504
                end
505
            end else if (Addr[10] == 1'b0) begin
506
                if (Ba == 2'b00) begin
507
                    {Pc_b0, Act_b0} = 2'b10;
508
                    RP_chk0 = $time;
509
                    if (Debug) $display ("at time %t PRE  : Bank = 0",$time);
510
                    // Activate to Precharge Bank 0
511
                    if ($time - RAS_chk0 < tRAS) begin
512
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 0", $time);
513
                    end
514
                end else if (Ba == 2'b01) begin
515
                    {Pc_b1, Act_b1} = 2'b10;
516
                    RP_chk1 = $time;
517
                    if (Debug) $display ("at time %t PRE  : Bank = 1",$time);
518
                    // Activate to Precharge Bank 1
519
                    if ($time - RAS_chk1 < tRAS) begin
520
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 1", $time);
521
                    end
522
                end else if (Ba == 2'b10) begin
523
                    {Pc_b2, Act_b2} = 2'b10;
524
                    RP_chk2 = $time;
525
                    if (Debug) $display ("at time %t PRE  : Bank = 2",$time);
526
                    // Activate to Precharge Bank 2
527
                    if ($time - RAS_chk2 < tRAS) begin
528
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 2", $time);
529
                    end
530
                end else if (Ba == 2'b11) begin
531
                    {Pc_b3, Act_b3} = 2'b10;
532
                    RP_chk3 = $time;
533
                    if (Debug) $display ("at time %t PRE  : Bank = 3",$time);
534
                    // Activate to Precharge Bank 3
535
                    if ($time - RAS_chk3 < tRAS) begin
536
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 3", $time);
537
                    end
538
                end
539
                // tWR violation check for write
540
                if ($time - WR_chkp[Ba] < tWRp) begin
541
                    $display ("at time %t ERROR: tWR violation during Precharge bank %d", $time, Ba);
542
                end
543
            end
544
            // Terminate a Write Immediately (if same bank or all banks)
545
            if (Data_in_enable == 1'b1 && (Bank == Ba || Addr[10] == 1'b1)) begin
546
                Data_in_enable = 1'b0;
547
                if (Debug) $display ("at time %t NOTE : Precharge interrupt Write Bank %d.", $time, Bank);
548
                if (Debug) $display ("at time %t NOTE : Make sure DQM is HIGH two cycles to meet tWR.", $time);
549
                if (Debug) $display ("at time %t NOTE : We suggest to use Burst Terminate command instead.", $time);
550
            end
551
            // Precharge Command Pipeline for Read
552
            if (Cas_latency_3 == 1'b1) begin
553
                Command[2] = `PRECH;
554
                Bank_precharge[2] = Ba;
555
                A10_precharge[2] = Addr[10];
556
            end else if (Cas_latency_2 == 1'b1) begin
557
                Command[1] = `PRECH;
558
                Bank_precharge[1] = Ba;
559
                A10_precharge[1] = Addr[10];
560
            end
561
        end
562
 
563
        // Burst terminate
564
        if (Burst_term == 1'b1) begin
565
            // Terminate a Write Immediately
566
            if (Data_in_enable == 1'b1) begin
567
                Data_in_enable = 1'b0;
568
            end
569
            // Terminate a Read Depend on CAS Latency
570
            if (Cas_latency_3 == 1'b1) begin
571
                Command[2] = `BST;
572
            end else if (Cas_latency_2 == 1'b1) begin
573
                Command[1] = `BST;
574
            end
575
            if (Debug) $display ("at time %t BST  : Burst Terminate",$time);
576
        end
577
 
578
        // Read, Write, Column Latch
579
        if (Read_enable == 1'b1 || Write_enable == 1'b1) begin
580
            // Check to see if bank is open (ACT)
581
            if ((Ba == 2'b00 && Pc_b0 == 1'b1) || (Ba == 2'b01 && Pc_b1 == 1'b1) ||
582
                (Ba == 2'b10 && Pc_b2 == 1'b1) || (Ba == 2'b11 && Pc_b3 == 1'b1)) begin
583
                $display("at time %t ERROR: Cannot Read or Write - Bank %d is not Activated", $time, Ba);
584
            end
585
 
586
            // Activate to Read or Write
587
            if ((Ba == 2'b00) && ($time - RCD_chk0 < tRCD))
588
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 0", $time);
589
            if ((Ba == 2'b01) && ($time - RCD_chk1 < tRCD))
590
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 1", $time);
591
            if ((Ba == 2'b10) && ($time - RCD_chk2 < tRCD))
592
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 2", $time);
593
            if ((Ba == 2'b11) && ($time - RCD_chk3 < tRCD))
594
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 3", $time);
595
 
596
            // Read Command
597
            if (Read_enable == 1'b1) begin
598
                // CAS Latency pipeline
599
                if (Cas_latency_3 == 1'b1) begin
600
                    if (Addr[10] == 1'b1) begin
601
                        Command[2] = `READ_A;
602
                    end else begin
603
                        Command[2] = `READ;
604
                    end
605
                    Col_addr[2] = Addr;
606
                    Bank_addr[2] = Ba;
607
                end else if (Cas_latency_2 == 1'b1) begin
608
                    if (Addr[10] == 1'b1) begin
609
                        Command[1] = `READ_A;
610
                    end else begin
611
                        Command[1] = `READ;
612
                    end
613
                    Col_addr[1] = Addr;
614
                    Bank_addr[1] = Ba;
615
                end
616
 
617
                // Read interrupt Write (terminate Write immediately)
618
                if (Data_in_enable == 1'b1) begin
619
                    Data_in_enable = 1'b0;
620
                    // Interrupting a Write with Autoprecharge
621
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Write_precharge[RW_interrupt_bank] == 1'b1) begin
622
                        RW_interrupt_write[RW_interrupt_bank] = 1'b1;
623
                        WR_time[RW_interrupt_bank] = $time;
624
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Write Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
625
                    else
626
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Write Bank %d", $time, Ba, Bank);
627
                    end
628
                end
629
 
630
                // Read interrupt Read (terminate Read after CL-1)
631
                if (Data_out_enable == 1'b1 && ((Cas_latency_2 == 1'b1 && ((Burst_length_2 == 1'b1 && Burst_counter < 1) ||
632
                                                                           (Burst_length_4 == 1'b1 && Burst_counter < 3) ||
633
                                                                           (Burst_length_8 == 1'b1 && Burst_counter < 7))) ||
634
                                                (Cas_latency_3 == 1'b1 && ((Burst_length_4 == 1'b1 && Burst_counter < 2) ||
635
                                                                           (Burst_length_8 == 1'b1 && Burst_counter < 6))))) begin
636
                    // Interrupting a Read with Autoprecharge
637
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Read_precharge[RW_interrupt_bank] == 1'b1) begin
638
                        RW_interrupt_read[RW_interrupt_bank] = 1'b1;
639
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Read Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
640
                    else
641
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Read Bank %d", $time, Ba, Bank);
642
                    end
643
                end
644
 
645
            // Write Command
646
            end else if (Write_enable == 1'b1) begin
647
                if (Addr[10] == 1'b1) begin
648
                    Command[0] = `WRITE_A;
649
                end else begin
650
                    Command[0] = `WRITE;
651
                end
652
                Col_addr[0] = Addr;
653
                Bank_addr[0] = Ba;
654
 
655
                // Write interrupt Write (terminate Write immediately)
656
                if (Data_in_enable == 1'b1) begin
657
                    Data_in_enable = 1'b0;
658
                    // Interrupting a Write with Autoprecharge
659
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Write_precharge[RW_interrupt_bank] == 1'b1) begin
660
                        RW_interrupt_write[RW_interrupt_bank] = 1'b1;
661
                        WR_time[RW_interrupt_bank] = $time;
662
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Write Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
663
                    else
664
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Write Bank %d", $time, Ba, Bank);
665
                    end
666
                end
667
 
668
                // Write interrupt Read (terminate Read immediately)
669
                if (Data_out_enable == 1'b1) begin
670
                    Data_out_enable = 1'b0;
671
                    // Interrupting a Read with Autoprecharge
672
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Read_precharge[RW_interrupt_bank] == 1'b1) begin
673
                        RW_interrupt_read[RW_interrupt_bank] = 1'b1;
674
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Read Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
675
                    else
676
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Read Bank %d", $time, Ba, Bank);
677
                    end
678
                end
679
            end
680
 
681
            // Read or Write with Auto Precharge
682
            if (Addr[10] == 1'b1) begin
683
                Auto_precharge[Ba] = 1'b1;
684
                Count_precharge[Ba] = 0;
685
                RW_interrupt_bank = Ba;
686
                if (Read_enable == 1'b1) begin
687
                    Read_precharge[Ba] = 1'b1;
688
                end else if (Write_enable == 1'b1) begin
689
                    Write_precharge[Ba] = 1'b1;
690
                end
691
            end
692
        end
693
 
694
        //  Read with Auto Precharge Calculation
695
        //      The device start internal precharge:
696
        //          1.  CAS Latency - 1 cycles before last burst
697
        //      and 2.  Meet minimum tRAS requirement
698
        //       or 3.  Interrupt by a Read or Write (with or without AutoPrecharge)
699
        if ((Auto_precharge[0] == 1'b1) && (Read_precharge[0] == 1'b1)) begin
700
            if ((($time - RAS_chk0 >= tRAS) &&                                                      // Case 2
701
                ((Burst_length_1 == 1'b1 && Count_precharge[0] >= 1) ||                             // Case 1
702
                 (Burst_length_2 == 1'b1 && Count_precharge[0] >= 2) ||
703
                 (Burst_length_4 == 1'b1 && Count_precharge[0] >= 4) ||
704
                 (Burst_length_8 == 1'b1 && Count_precharge[0] >= 8))) ||
705
                 (RW_interrupt_read[0] == 1'b1)) begin                                              // Case 3
706
                    Pc_b0 = 1'b1;
707
                    Act_b0 = 1'b0;
708
                    RP_chk0 = $time;
709
                    Auto_precharge[0] = 1'b0;
710
                    Read_precharge[0] = 1'b0;
711
                    RW_interrupt_read[0] = 1'b0;
712
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 0", $time);
713
            end
714
        end
715
        if ((Auto_precharge[1] == 1'b1) && (Read_precharge[1] == 1'b1)) begin
716
            if ((($time - RAS_chk1 >= tRAS) &&
717
                ((Burst_length_1 == 1'b1 && Count_precharge[1] >= 1) ||
718
                 (Burst_length_2 == 1'b1 && Count_precharge[1] >= 2) ||
719
                 (Burst_length_4 == 1'b1 && Count_precharge[1] >= 4) ||
720
                 (Burst_length_8 == 1'b1 && Count_precharge[1] >= 8))) ||
721
                 (RW_interrupt_read[1] == 1'b1)) begin
722
                    Pc_b1 = 1'b1;
723
                    Act_b1 = 1'b0;
724
                    RP_chk1 = $time;
725
                    Auto_precharge[1] = 1'b0;
726
                    Read_precharge[1] = 1'b0;
727
                    RW_interrupt_read[1] = 1'b0;
728
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 1", $time);
729
            end
730
        end
731
        if ((Auto_precharge[2] == 1'b1) && (Read_precharge[2] == 1'b1)) begin
732
            if ((($time - RAS_chk2 >= tRAS) &&
733
                ((Burst_length_1 == 1'b1 && Count_precharge[2] >= 1) ||
734
                 (Burst_length_2 == 1'b1 && Count_precharge[2] >= 2) ||
735
                 (Burst_length_4 == 1'b1 && Count_precharge[2] >= 4) ||
736
                 (Burst_length_8 == 1'b1 && Count_precharge[2] >= 8))) ||
737
                 (RW_interrupt_read[2] == 1'b1)) begin
738
                    Pc_b2 = 1'b1;
739
                    Act_b2 = 1'b0;
740
                    RP_chk2 = $time;
741
                    Auto_precharge[2] = 1'b0;
742
                    Read_precharge[2] = 1'b0;
743
                    RW_interrupt_read[2] = 1'b0;
744
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 2", $time);
745
            end
746
        end
747
        if ((Auto_precharge[3] == 1'b1) && (Read_precharge[3] == 1'b1)) begin
748
            if ((($time - RAS_chk3 >= tRAS) &&
749
                ((Burst_length_1 == 1'b1 && Count_precharge[3] >= 1) ||
750
                 (Burst_length_2 == 1'b1 && Count_precharge[3] >= 2) ||
751
                 (Burst_length_4 == 1'b1 && Count_precharge[3] >= 4) ||
752
                 (Burst_length_8 == 1'b1 && Count_precharge[3] >= 8))) ||
753
                 (RW_interrupt_read[3] == 1'b1)) begin
754
                    Pc_b3 = 1'b1;
755
                    Act_b3 = 1'b0;
756
                    RP_chk3 = $time;
757
                    Auto_precharge[3] = 1'b0;
758
                    Read_precharge[3] = 1'b0;
759
                    RW_interrupt_read[3] = 1'b0;
760
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 3", $time);
761
            end
762
        end
763
 
764
        // Internal Precharge or Bst
765
        if (Command[0] == `PRECH) begin                         // Precharge terminate a read with same bank or all banks
766
            if (Bank_precharge[0] == Bank || A10_precharge[0] == 1'b1) begin
767
                if (Data_out_enable == 1'b1) begin
768
                    Data_out_enable = 1'b0;
769
                end
770
            end
771
        end else if (Command[0] == `BST) begin                  // BST terminate a read to current bank
772
            if (Data_out_enable == 1'b1) begin
773
                Data_out_enable = 1'b0;
774
            end
775
        end
776
 
777
        if (Data_out_enable == 1'b0) begin
778
            Dq_reg <= #tOH {data_bits{1'bz}};
779
        end
780
 
781
        // Detect Read or Write command
782
        if (Command[0] == `READ || Command[0] == `READ_A) begin
783
            Bank = Bank_addr[0];
784
            Col = Col_addr[0];
785
            Col_brst = Col_addr[0];
786
            if (Bank_addr[0] == 2'b00) begin
787
                Row = B0_row_addr;
788
            end else if (Bank_addr[0] == 2'b01) begin
789
                Row = B1_row_addr;
790
            end else if (Bank_addr[0] == 2'b10) begin
791
                Row = B2_row_addr;
792
            end else if (Bank_addr[0] == 2'b11) begin
793
                Row = B3_row_addr;
794
            end
795
            Burst_counter = 0;
796
            Data_in_enable = 1'b0;
797
            Data_out_enable = 1'b1;
798
        end else if (Command[0] == `WRITE || Command[0] == `WRITE_A) begin
799
            Bank = Bank_addr[0];
800
            Col = Col_addr[0];
801
            Col_brst = Col_addr[0];
802
            if (Bank_addr[0] == 2'b00) begin
803
                Row = B0_row_addr;
804
            end else if (Bank_addr[0] == 2'b01) begin
805
                Row = B1_row_addr;
806
            end else if (Bank_addr[0] == 2'b10) begin
807
                Row = B2_row_addr;
808
            end else if (Bank_addr[0] == 2'b11) begin
809
                Row = B3_row_addr;
810
            end
811
            Burst_counter = 0;
812
            Data_in_enable = 1'b1;
813
            Data_out_enable = 1'b0;
814
        end
815
 
816
        // DQ buffer (Driver/Receiver)
817
        if (Data_in_enable == 1'b1) begin                                   // Writing Data to Memory
818
            // Array buffer
819
            if (Bank == 2'b00) Dq_dqm [15 : 0] = Bank0 [{Row, Col}];
820
            if (Bank == 2'b01) Dq_dqm [15 : 0] = Bank1 [{Row, Col}];
821
            if (Bank == 2'b10) Dq_dqm [15 : 0] = Bank2 [{Row, Col}];
822
            if (Bank == 2'b11) Dq_dqm [15 : 0] = Bank3 [{Row, Col}];
823
            // Dqm operation
824
            if (Dqm[0] == 1'b0) Dq_dqm [ 7 : 0] = Dq [ 7 : 0];
825
            if (Dqm[1] == 1'b0) Dq_dqm [15 : 8] = Dq [15 : 8];
826
            // Write to memory
827
            if (Bank == 2'b00) Bank0 [{Row, Col}] = Dq_dqm [15 : 0];
828
            if (Bank == 2'b01) Bank1 [{Row, Col}] = Dq_dqm [15 : 0];
829
            if (Bank == 2'b10) Bank2 [{Row, Col}] = Dq_dqm [15 : 0];
830
            if (Bank == 2'b11) Bank3 [{Row, Col}] = Dq_dqm [15 : 0];
831
            // Output result
832
            if (Dqm == 2'b11) begin
833
                if (Debug) $display("at time %t WRITE: Bank = %d Row = %d, Col = %d, Data = Hi-Z due to DQM", $time, Bank, Row, Col);
834
            end else begin
835
                if (Debug) $display("at time %t WRITE: Bank = %d Row = %d, Col = %d, Data = %d, Dqm = %b", $time, Bank, Row, Col, Dq_dqm, Dqm);
836
                // Record tWR time and reset counter
837
                WR_chkp [Bank] = $time;
838
                WR_counter [Bank] = 0;
839
            end
840
            // Advance burst counter subroutine
841
            #tHZ Burst;
842
        end else if (Data_out_enable == 1'b1) begin                         // Reading Data from Memory
843
            // Array buffer
844
            if (Bank == 2'b00) Dq_dqm [15 : 0] = Bank0 [{Row, Col}];
845
            if (Bank == 2'b01) Dq_dqm [15 : 0] = Bank1 [{Row, Col}];
846
            if (Bank == 2'b10) Dq_dqm [15 : 0] = Bank2 [{Row, Col}];
847
            if (Bank == 2'b11) Dq_dqm [15 : 0] = Bank3 [{Row, Col}];
848
            // Dqm operation
849
            if (Dqm_reg0[0] == 1'b1) Dq_dqm [ 7 : 0] = 8'bz;
850
            if (Dqm_reg0[1] == 1'b1) Dq_dqm [15 : 8] = 8'bz;
851
            // Display result
852
            Dq_reg [15 : 0] = #tAC Dq_dqm [15 : 0];
853
            if (Dqm_reg0 == 2'b11) begin
854
                if (Debug) $display("at time %t READ : Bank = %d Row = %d, Col = %d, Data = Hi-Z due to DQM", $time, Bank, Row, Col);
855
            end else begin
856
                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);
857
            end
858
            // Advance burst counter subroutine
859
            Burst;
860
        end
861
    end
862
 
863
    //  Write with Auto Precharge Calculation
864
    //      The device start internal precharge:
865
    //          1.  tWR Clock after last burst
866
    //      and 2.  Meet minimum tRAS requirement
867
    //       or 3.  Interrupt by a Read or Write (with or without AutoPrecharge)
868
    always @ (RAS_clk) begin
869
        if ((Auto_precharge[0] == 1'b1) && (Write_precharge[0] == 1'b1)) begin
870
            if ((($time - RAS_chk0 >= tRAS) &&                                                          // Case 2
871
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [0] >= 1 && $time - Count_time[0] >= tWRa) ||   // Case 1
872
                 (Burst_length_2 == 1'b1 && Count_precharge [0] >= 2 && $time - Count_time[0] >= tWRa) ||
873
                 (Burst_length_4 == 1'b1 && Count_precharge [0] >= 4 && $time - Count_time[0] >= tWRa) ||
874
                 (Burst_length_8 == 1'b1 && Count_precharge [0] >= 8 && $time - Count_time[0] >= tWRa))) ||
875
                 (RW_interrupt_write[0] == 1'b1 && WR_counter[0] >= 1 && $time - WR_time[0] >= tWRa)) begin                           // Case 3 (stop count when interrupt)
876
                    Auto_precharge[0] = 1'b0;
877
                    Write_precharge[0] = 1'b0;
878
                    RW_interrupt_write[0] = 1'b0;
879
                    Pc_b0 = 1'b1;
880
                    Act_b0 = 1'b0;
881
                    RP_chk0 = $time;
882
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 0", $time);
883
            end
884
        end
885
        if ((Auto_precharge[1] == 1'b1) && (Write_precharge[1] == 1'b1)) begin
886
            if ((($time - RAS_chk1 >= tRAS) &&
887
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [1] >= 1 && $time - Count_time[1] >= tWRa) ||
888
                 (Burst_length_2 == 1'b1 && Count_precharge [1] >= 2 && $time - Count_time[1] >= tWRa) ||
889
                 (Burst_length_4 == 1'b1 && Count_precharge [1] >= 4 && $time - Count_time[1] >= tWRa) ||
890
                 (Burst_length_8 == 1'b1 && Count_precharge [1] >= 8 && $time - Count_time[1] >= tWRa))) ||
891
                 (RW_interrupt_write[1] == 1'b1 && WR_counter[1] >= 1 && $time - WR_time[1] >= tWRa)) begin
892
                    Auto_precharge[1] = 1'b0;
893
                    Write_precharge[1] = 1'b0;
894
                    RW_interrupt_write[1] = 1'b0;
895
                    Pc_b1 = 1'b1;
896
                    Act_b1 = 1'b0;
897
                    RP_chk1 = $time;
898
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 1", $time);
899
            end
900
        end
901
        if ((Auto_precharge[2] == 1'b1) && (Write_precharge[2] == 1'b1)) begin
902
            if ((($time - RAS_chk2 >= tRAS) &&
903
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [2] >= 1 && $time - Count_time[2] >= tWRa) ||
904
                 (Burst_length_2 == 1'b1 && Count_precharge [2] >= 2 && $time - Count_time[2] >= tWRa) ||
905
                 (Burst_length_4 == 1'b1 && Count_precharge [2] >= 4 && $time - Count_time[2] >= tWRa) ||
906
                 (Burst_length_8 == 1'b1 && Count_precharge [2] >= 8 && $time - Count_time[2] >= tWRa))) ||
907
                 (RW_interrupt_write[2] == 1'b1 && WR_counter[2] >= 1 && $time - WR_time[2] >= tWRa)) begin
908
                    Auto_precharge[2] = 1'b0;
909
                    Write_precharge[2] = 1'b0;
910
                    RW_interrupt_write[2] = 1'b0;
911
                    Pc_b2 = 1'b1;
912
                    Act_b2 = 1'b0;
913
                    RP_chk2 = $time;
914
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 2", $time);
915
            end
916
        end
917
        if ((Auto_precharge[3] == 1'b1) && (Write_precharge[3] == 1'b1)) begin
918
            if ((($time - RAS_chk3 >= tRAS) &&
919
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [3] >= 1 && $time - Count_time[3] >= tWRa) ||
920
                 (Burst_length_2 == 1'b1 && Count_precharge [3] >= 2 && $time - Count_time[3] >= tWRa) ||
921
                 (Burst_length_4 == 1'b1 && Count_precharge [3] >= 4 && $time - Count_time[3] >= tWRa) ||
922
                 (Burst_length_8 == 1'b1 && Count_precharge [3] >= 8 && $time - Count_time[3] >= tWRa))) ||
923
                 (RW_interrupt_write[3] == 1'b1 && WR_counter[3] >= 1 && $time - WR_time[3] >= tWRa)) begin
924
                    Auto_precharge[3] = 1'b0;
925
                    Write_precharge[3] = 1'b0;
926
                    RW_interrupt_write[3] = 1'b0;
927
                    Pc_b3 = 1'b1;
928
                    Act_b3 = 1'b0;
929
                    RP_chk3 = $time;
930
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 3", $time);
931
            end
932
        end
933
    end
934
 
935
    task Burst;
936
        begin
937
            // Advance Burst Counter
938
            Burst_counter = Burst_counter + 1;
939
 
940
            // Burst Type
941
            if (Mode_reg[3] == 1'b0) begin                                  // Sequential Burst
942
                Col_temp = Col + 1;
943
            end else if (Mode_reg[3] == 1'b1) begin                         // Interleaved Burst
944
                Col_temp[2] =  Burst_counter[2] ^  Col_brst[2];
945
                Col_temp[1] =  Burst_counter[1] ^  Col_brst[1];
946
                Col_temp[0] =  Burst_counter[0] ^  Col_brst[0];
947
            end
948
 
949
            // Burst Length
950
            if (Burst_length_2) begin                                       // Burst Length = 2
951
                Col [0] = Col_temp [0];
952
            end else if (Burst_length_4) begin                              // Burst Length = 4
953
                Col [1 : 0] = Col_temp [1 : 0];
954
            end else if (Burst_length_8) begin                              // Burst Length = 8
955
                Col [2 : 0] = Col_temp [2 : 0];
956
            end else begin                                                  // Burst Length = FULL
957
                Col = Col_temp;
958
            end
959
 
960
            // Burst Read Single Write            
961
            if (Write_burst_mode == 1'b1) begin
962
                Data_in_enable = 1'b0;
963
            end
964
 
965
            // Data Counter
966
            if (Burst_length_1 == 1'b1) begin
967
                if (Burst_counter >= 1) begin
968
                    Data_in_enable = 1'b0;
969
                    Data_out_enable = 1'b0;
970
                end
971
            end else if (Burst_length_2 == 1'b1) begin
972
                if (Burst_counter >= 2) begin
973
                    Data_in_enable = 1'b0;
974
                    Data_out_enable = 1'b0;
975
                end
976
            end else if (Burst_length_4 == 1'b1) begin
977
                if (Burst_counter >= 4) begin
978
                    Data_in_enable = 1'b0;
979
                    Data_out_enable = 1'b0;
980
                end
981
            end else if (Burst_length_8 == 1'b1) begin
982
                if (Burst_counter >= 8) begin
983
                    Data_in_enable = 1'b0;
984
                    Data_out_enable = 1'b0;
985
                end
986
            end
987
        end
988
    endtask
989
 
990
    // Timing Parameters for -7E and CAS Latency = 2
991
    specify
992
        specparam
993
            tAH  =  0.8,                                        // Addr, Ba Hold Time
994
            tAS  =  1.5,                                        // Addr, Ba Setup Time
995
            tCH  =  2.5,                                        // Clock High-Level Width
996
            tCL  =  2.5,                                        // Clock Low-Level Width
997
            tCK  =  7.5,                                        // Clock Cycle Time
998
            tDH  =  0.8,                                        // Data-in Hold Time
999
            tDS  =  1.5,                                        // Data-in Setup Time
1000
            tCKH =  0.8,                                        // CKE Hold  Time
1001
            tCKS =  1.5,                                        // CKE Setup Time
1002
            tCMH =  0.8,                                        // CS#, RAS#, CAS#, WE#, DQM# Hold  Time
1003
            tCMS =  1.5;                                        // CS#, RAS#, CAS#, WE#, DQM# Setup Time
1004
        $width    (posedge Clk,           tCH);
1005
        $width    (negedge Clk,           tCL);
1006
        $period   (negedge Clk,           tCK);
1007
        $period   (posedge Clk,           tCK);
1008
        $setuphold(posedge Clk,    Cke,   tCKS, tCKH);
1009
        $setuphold(posedge Clk,    Cs_n,  tCMS, tCMH);
1010
        $setuphold(posedge Clk,    Cas_n, tCMS, tCMH);
1011
        $setuphold(posedge Clk,    Ras_n, tCMS, tCMH);
1012
        $setuphold(posedge Clk,    We_n,  tCMS, tCMH);
1013
        $setuphold(posedge Clk,    Addr,  tAS,  tAH);
1014
        $setuphold(posedge Clk,    Ba,    tAS,  tAH);
1015
        $setuphold(posedge Clk,    Dqm,   tCMS, tCMH);
1016
        $setuphold(posedge Dq_chk, Dq,    tDS,  tDH);
1017
    endspecify
1018
 
1019
endmodule

powered by: WebSVN 2.1.0

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