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

Subversion Repositories mem_ctrl

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

powered by: WebSVN 2.1.0

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