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

Subversion Repositories mem_ctrl

[/] [mem_ctrl/] [trunk/] [bench/] [richard/] [verilog/] [models/] [mt48lc16m16a2.v] - Blame information for rev 29

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

Line No. Rev Author Line
1 26 rherveille
/****************************************************************************************
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'b0;                          // 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("RP_chk0: %t, tRP: %t", RP_chk0, tRP);
400
                    $display ("at time %t ERROR: tRP violation during Activate bank 0", $time);
401
                end
402
            end else if (Ba == 2'b01 && Pc_b1 == 1'b1) begin
403
                {Act_b1, Pc_b1} = 2'b10;
404
                B1_row_addr = Addr [addr_bits - 1 : 0];
405
                RCD_chk1 = $time;
406
                RAS_chk1 = $time;
407
                if (Debug) $display ("at time %t ACT  : Bank = 1 Row = %d",$time, Addr);
408
                // Precharge to Activate Bank 1
409
                if ($time - RP_chk1 < tRP) begin
410
                    $display ("at time %t ERROR: tRP violation during Activate bank 1", $time);
411
                end
412
            end else if (Ba == 2'b10 && Pc_b2 == 1'b1) begin
413
                {Act_b2, Pc_b2} = 2'b10;
414
                B2_row_addr = Addr [addr_bits - 1 : 0];
415
                RCD_chk2 = $time;
416
                RAS_chk2 = $time;
417
                if (Debug) $display ("at time %t ACT  : Bank = 2 Row = %d",$time, Addr);
418
                // Precharge to Activate Bank 2
419
                if ($time - RP_chk2 < tRP) begin
420
                    $display ("at time %t ERROR: tRP violation during Activate bank 2", $time);
421
                end
422
            end else if (Ba == 2'b11 && Pc_b3 == 1'b1) begin
423
                {Act_b3, Pc_b3} = 2'b10;
424
                B3_row_addr = Addr [addr_bits - 1 : 0];
425
                RCD_chk3 = $time;
426
                RAS_chk3 = $time;
427
                if (Debug) $display ("at time %t ACT  : Bank = 3 Row = %d",$time, Addr);
428
                // Precharge to Activate Bank 3
429
                if ($time - RP_chk3 < tRP) begin
430
                    $display ("at time %t ERROR: tRP violation during Activate bank 3", $time);
431
                end
432
            end else if (Ba == 2'b00 && Pc_b0 == 1'b0) begin
433
                $display ("at time %t ERROR: Bank 0 is already Activated (not Precharged)", $time);
434
            end else if (Ba == 2'b01 && Pc_b1 == 1'b0) begin
435
                $display ("at time %t ERROR: Bank 1 is already Activated (not Precharged)", $time);
436
            end else if (Ba == 2'b10 && Pc_b2 == 1'b0) begin
437
                $display ("at time %t ERROR: Bank 2 is already Activated (not Precharged)", $time);
438
            end else if (Ba == 2'b11 && Pc_b3 == 1'b0) begin
439
                $display ("at time %t ERROR: Bank 3 is already Activated (not Precharged)", $time);
440
            end
441
 
442
            // Active Bank A to Active Bank B
443
            if ((Previous_bank != Ba) && ($time - RRD_chk < tRRD)) begin
444
                $display ("at time %t ERROR: tRRD violation during Activate bank = %d", $time, Ba);
445
            end
446
 
447
            // Load Mode Register to Active
448
            if (MRD_chk < tMRD ) begin
449
                $display ("at time %t ERROR: tMRD violation during Activate bank = %d", $time, Ba);
450
            end
451
 
452
            // Auto Refresh to Activate
453
            if ($time - RC_chk < tRC) begin
454
                $display ("at time %t ERROR: tRC violation during Activate bank = %d", $time, Ba);
455
            end
456
 
457
            // Record variables for checking violation
458
            RRD_chk = $time;
459
            Previous_bank = Ba;
460
        end
461
 
462
        // Precharge Block
463
        if (Prech_enable == 1'b1) begin
464
            if (Addr[10] == 1'b1) begin
465
                {Pc_b0, Pc_b1, Pc_b2, Pc_b3} = 4'b1111;
466
                {Act_b0, Act_b1, Act_b2, Act_b3} = 4'b0000;
467
                RP_chk0 = $time;
468
                RP_chk1 = $time;
469
                RP_chk2 = $time;
470
                RP_chk3 = $time;
471
                if (Debug) $display ("at time %t PRE  : Bank = ALL",$time);
472
                // Activate to Precharge all banks
473
                if (($time - RAS_chk0 < tRAS) || ($time - RAS_chk1 < tRAS) ||
474
                    ($time - RAS_chk2 < tRAS) || ($time - RAS_chk3 < tRAS)) begin
475
                    $display ("at time %t ERROR: tRAS violation during Precharge all banks", $time);
476
                end
477
                // tWR violation check for write
478
                if (($time - WR_chkp[0] < tWRp) || ($time - WR_chkp[1] < tWRp) ||
479
                    ($time - WR_chkp[2] < tWRp) || ($time - WR_chkp[3] < tWRp)) begin
480
                    $display ("at time %t ERROR: tWR violation during Precharge all banks", $time);
481
                end
482
            end else if (Addr[10] == 1'b0) begin
483
                if (Ba == 2'b00) begin
484
                    {Pc_b0, Act_b0} = 2'b10;
485
                    RP_chk0 = $time;
486
                    if (Debug) $display ("at time %t PRE  : Bank = 0",$time);
487
                    // Activate to Precharge Bank 0
488
                    if ($time - RAS_chk0 < tRAS) begin
489
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 0", $time);
490
                    end
491
                end else if (Ba == 2'b01) begin
492
                    {Pc_b1, Act_b1} = 2'b10;
493
                    RP_chk1 = $time;
494
                    if (Debug) $display ("at time %t PRE  : Bank = 1",$time);
495
                    // Activate to Precharge Bank 1
496
                    if ($time - RAS_chk1 < tRAS) begin
497
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 1", $time);
498
                    end
499
                end else if (Ba == 2'b10) begin
500
                    {Pc_b2, Act_b2} = 2'b10;
501
                    RP_chk2 = $time;
502
                    if (Debug) $display ("at time %t PRE  : Bank = 2",$time);
503
                    // Activate to Precharge Bank 2
504
                    if ($time - RAS_chk2 < tRAS) begin
505
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 2", $time);
506
                    end
507
                end else if (Ba == 2'b11) begin
508
                    {Pc_b3, Act_b3} = 2'b10;
509
                    RP_chk3 = $time;
510
                    if (Debug) $display ("at time %t PRE  : Bank = 3",$time);
511
                    // Activate to Precharge Bank 3
512
                    if ($time - RAS_chk3 < tRAS) begin
513
                        $display ("at time %t ERROR: tRAS violation during Precharge bank 3", $time);
514
                    end
515
                end
516
                // tWR violation check for write
517
                if ($time - WR_chkp[Ba] < tWRp) begin
518
                    $display ("at time %t ERROR: tWR violation during Precharge bank %d", $time, Ba);
519
                end
520
            end
521
            // Terminate a Write Immediately (if same bank or all banks)
522
            if (Data_in_enable == 1'b1 && (Bank == Ba || Addr[10] == 1'b1)) begin
523
                Data_in_enable = 1'b0;
524
                if (Debug) $display ("at time %t NOTE : Precharge interrupt Write Bank %d.", $time, Bank);
525
                if (Debug) $display ("at time %t NOTE : Make sure DQM is HIGH two cycles to meet tWR.", $time);
526
                if (Debug) $display ("at time %t NOTE : We suggest to use Burst Terminate command instead.", $time);
527
            end
528
            // Precharge Command Pipeline for Read
529
            if (Cas_latency_3 == 1'b1) begin
530
                Command[2] = `PRECH;
531
                Bank_precharge[2] = Ba;
532
                A10_precharge[2] = Addr[10];
533
            end else if (Cas_latency_2 == 1'b1) begin
534
                Command[1] = `PRECH;
535
                Bank_precharge[1] = Ba;
536
                A10_precharge[1] = Addr[10];
537
            end
538
        end
539
 
540
        // Burst terminate
541
        if (Burst_term == 1'b1) begin
542
            // Terminate a Write Immediately
543
            if (Data_in_enable == 1'b1) begin
544
                Data_in_enable = 1'b0;
545
            end
546
            // Terminate a Read Depend on CAS Latency
547
            if (Cas_latency_3 == 1'b1) begin
548
                Command[2] = `BST;
549
            end else if (Cas_latency_2 == 1'b1) begin
550
                Command[1] = `BST;
551
            end
552
            if (Debug) $display ("at time %t BST  : Burst Terminate",$time);
553
        end
554
 
555
        // Read, Write, Column Latch
556
        if (Read_enable == 1'b1 || Write_enable == 1'b1) begin
557
            // Check to see if bank is open (ACT)
558
            if ((Ba == 2'b00 && Pc_b0 == 1'b1) || (Ba == 2'b01 && Pc_b1 == 1'b1) ||
559
                (Ba == 2'b10 && Pc_b2 == 1'b1) || (Ba == 2'b11 && Pc_b3 == 1'b1)) begin
560
                $display("at time %t ERROR: Cannot Read or Write - Bank %d is not Activated", $time, Ba);
561
            end
562
 
563
            // Activate to Read or Write
564
            if ((Ba == 2'b00) && ($time - RCD_chk0 < tRCD))
565
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 0", $time);
566
            if ((Ba == 2'b01) && ($time - RCD_chk1 < tRCD))
567
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 1", $time);
568
            if ((Ba == 2'b10) && ($time - RCD_chk2 < tRCD))
569
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 2", $time);
570
            if ((Ba == 2'b11) && ($time - RCD_chk3 < tRCD))
571
                $display("at time %t ERROR: tRCD violation during Read or Write to Bank 3", $time);
572
 
573
            // Read Command
574
            if (Read_enable == 1'b1) begin
575
                // CAS Latency pipeline
576
                if (Cas_latency_3 == 1'b1) begin
577
                    if (Addr[10] == 1'b1) begin
578
                        Command[2] = `READ_A;
579
                    end else begin
580
                        Command[2] = `READ;
581
                    end
582
                    Col_addr[2] = Addr;
583
                    Bank_addr[2] = Ba;
584
                end else if (Cas_latency_2 == 1'b1) begin
585
                    if (Addr[10] == 1'b1) begin
586
                        Command[1] = `READ_A;
587
                    end else begin
588
                        Command[1] = `READ;
589
                    end
590
                    Col_addr[1] = Addr;
591
                    Bank_addr[1] = Ba;
592
                end
593
 
594
                // Read interrupt Write (terminate Write immediately)
595
                if (Data_in_enable == 1'b1) begin
596
                    Data_in_enable = 1'b0;
597
                    // Interrupting a Write with Autoprecharge
598
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Write_precharge[RW_interrupt_bank] == 1'b1) begin
599
                        RW_interrupt_write[RW_interrupt_bank] = 1'b1;
600
                        WR_time[RW_interrupt_bank] = $time;
601
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Write Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
602
                    else
603
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Write Bank %d", $time, Ba, Bank);
604
                    end
605
                end
606
 
607
                // Read interrupt Read (terminate Read after CL-1)
608
                if (Data_out_enable == 1'b1 && ((Cas_latency_2 == 1'b1 && ((Burst_length_2 == 1'b1 && Burst_counter < 1) ||
609
                                                                           (Burst_length_4 == 1'b1 && Burst_counter < 3) ||
610
                                                                           (Burst_length_8 == 1'b1 && Burst_counter < 7))) ||
611
                                                (Cas_latency_3 == 1'b1 && ((Burst_length_4 == 1'b1 && Burst_counter < 2) ||
612
                                                                           (Burst_length_8 == 1'b1 && Burst_counter < 6))))) begin
613
                    // Interrupting a Read with Autoprecharge
614
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Read_precharge[RW_interrupt_bank] == 1'b1) begin
615
                        RW_interrupt_read[RW_interrupt_bank] = 1'b1;
616
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Read Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
617
                    else
618
                        if (Debug) $display ("at time %t NOTE : Read Bank %d interrupt Read Bank %d", $time, Ba, Bank);
619
                    end
620
                end
621
 
622
            // Write Command
623
            end else if (Write_enable == 1'b1) begin
624
                if (Addr[10] == 1'b1) begin
625
                    Command[0] = `WRITE_A;
626
                end else begin
627
                    Command[0] = `WRITE;
628
                end
629
                Col_addr[0] = Addr;
630
                Bank_addr[0] = Ba;
631
 
632
                // Write interrupt Write (terminate Write immediately)
633
                if (Data_in_enable == 1'b1) begin
634
                    Data_in_enable = 1'b0;
635
                    // Interrupting a Write with Autoprecharge
636
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Write_precharge[RW_interrupt_bank] == 1'b1) begin
637
                        RW_interrupt_write[RW_interrupt_bank] = 1'b1;
638
                        WR_time[RW_interrupt_bank] = $time;
639
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Write Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
640
                    else
641
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Write Bank %d", $time, Ba, Bank);
642
                    end
643
                end
644
 
645
                // Write interrupt Read (terminate Read immediately)
646
                if (Data_out_enable == 1'b1) begin
647
                    Data_out_enable = 1'b0;
648
                    // Interrupting a Read with Autoprecharge
649
                    if (Auto_precharge[RW_interrupt_bank] == 1'b1 && Read_precharge[RW_interrupt_bank] == 1'b1) begin
650
                        RW_interrupt_read[RW_interrupt_bank] = 1'b1;
651
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Read Bank %d with Autoprecharge", $time, Ba, RW_interrupt_bank);
652
                    else
653
                        if (Debug) $display ("at time %t NOTE : Write Bank %d interrupt Read Bank %d", $time, Ba, Bank);
654
                    end
655
                end
656
            end
657
 
658
            // Read or Write with Auto Precharge
659
            if (Addr[10] == 1'b1) begin
660
                Auto_precharge[Ba] = 1'b1;
661
                Count_precharge[Ba] = 0;
662
                RW_interrupt_bank = Ba;
663
                if (Read_enable == 1'b1) begin
664
                    Read_precharge[Ba] = 1'b1;
665
                end else if (Write_enable == 1'b1) begin
666
                    Write_precharge[Ba] = 1'b1;
667
                end
668
            end
669
        end
670
 
671
        //  Read with Auto Precharge Calculation
672
        //      The device start internal precharge:
673
        //          1.  CAS Latency - 1 cycles before last burst
674
        //      and 2.  Meet minimum tRAS requirement
675
        //       or 3.  Interrupt by a Read or Write (with or without AutoPrecharge)
676
        if ((Auto_precharge[0] == 1'b1) && (Read_precharge[0] == 1'b1)) begin
677
            if ((($time - RAS_chk0 >= tRAS) &&                                                      // Case 2
678
                ((Burst_length_1 == 1'b1 && Count_precharge[0] >= 1) ||                             // Case 1
679
                 (Burst_length_2 == 1'b1 && Count_precharge[0] >= 2) ||
680
                 (Burst_length_4 == 1'b1 && Count_precharge[0] >= 4) ||
681
                 (Burst_length_8 == 1'b1 && Count_precharge[0] >= 8))) ||
682
                 (RW_interrupt_read[0] == 1'b1)) begin                                              // Case 3
683
                    Pc_b0 = 1'b1;
684
                    Act_b0 = 1'b0;
685
                    RP_chk0 = $time;
686
                    Auto_precharge[0] = 1'b0;
687
                    Read_precharge[0] = 1'b0;
688
                    RW_interrupt_read[0] = 1'b0;
689
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 0", $time);
690
            end
691
        end
692
        if ((Auto_precharge[1] == 1'b1) && (Read_precharge[1] == 1'b1)) begin
693
            if ((($time - RAS_chk1 >= tRAS) &&
694
                ((Burst_length_1 == 1'b1 && Count_precharge[1] >= 1) ||
695
                 (Burst_length_2 == 1'b1 && Count_precharge[1] >= 2) ||
696
                 (Burst_length_4 == 1'b1 && Count_precharge[1] >= 4) ||
697
                 (Burst_length_8 == 1'b1 && Count_precharge[1] >= 8))) ||
698
                 (RW_interrupt_read[1] == 1'b1)) begin
699
                    Pc_b1 = 1'b1;
700
                    Act_b1 = 1'b0;
701
                    RP_chk1 = $time;
702
                    Auto_precharge[1] = 1'b0;
703
                    Read_precharge[1] = 1'b0;
704
                    RW_interrupt_read[1] = 1'b0;
705
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 1", $time);
706
            end
707
        end
708
        if ((Auto_precharge[2] == 1'b1) && (Read_precharge[2] == 1'b1)) begin
709
            if ((($time - RAS_chk2 >= tRAS) &&
710
                ((Burst_length_1 == 1'b1 && Count_precharge[2] >= 1) ||
711
                 (Burst_length_2 == 1'b1 && Count_precharge[2] >= 2) ||
712
                 (Burst_length_4 == 1'b1 && Count_precharge[2] >= 4) ||
713
                 (Burst_length_8 == 1'b1 && Count_precharge[2] >= 8))) ||
714
                 (RW_interrupt_read[2] == 1'b1)) begin
715
                    Pc_b2 = 1'b1;
716
                    Act_b2 = 1'b0;
717
                    RP_chk2 = $time;
718
                    Auto_precharge[2] = 1'b0;
719
                    Read_precharge[2] = 1'b0;
720
                    RW_interrupt_read[2] = 1'b0;
721
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 2", $time);
722
            end
723
        end
724
        if ((Auto_precharge[3] == 1'b1) && (Read_precharge[3] == 1'b1)) begin
725
            if ((($time - RAS_chk3 >= tRAS) &&
726
                ((Burst_length_1 == 1'b1 && Count_precharge[3] >= 1) ||
727
                 (Burst_length_2 == 1'b1 && Count_precharge[3] >= 2) ||
728
                 (Burst_length_4 == 1'b1 && Count_precharge[3] >= 4) ||
729
                 (Burst_length_8 == 1'b1 && Count_precharge[3] >= 8))) ||
730
                 (RW_interrupt_read[3] == 1'b1)) begin
731
                    Pc_b3 = 1'b1;
732
                    Act_b3 = 1'b0;
733
                    RP_chk3 = $time;
734
                    Auto_precharge[3] = 1'b0;
735
                    Read_precharge[3] = 1'b0;
736
                    RW_interrupt_read[3] = 1'b0;
737
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 3", $time);
738
            end
739
        end
740
 
741
        // Internal Precharge or Bst
742
        if (Command[0] == `PRECH) begin                         // Precharge terminate a read with same bank or all banks
743
            if (Bank_precharge[0] == Bank || A10_precharge[0] == 1'b1) begin
744
                if (Data_out_enable == 1'b1) begin
745
                    Data_out_enable = 1'b0;
746
                end
747
            end
748
        end else if (Command[0] == `BST) begin                  // BST terminate a read to current bank
749
            if (Data_out_enable == 1'b1) begin
750
                Data_out_enable = 1'b0;
751
            end
752
        end
753
 
754
        if (Data_out_enable == 1'b0) begin
755
            Dq_reg <= #tOH {data_bits{1'bz}};
756
        end
757
 
758
        // Detect Read or Write command
759
        if (Command[0] == `READ || Command[0] == `READ_A) begin
760
            Bank = Bank_addr[0];
761
            Col = Col_addr[0];
762
            Col_brst = Col_addr[0];
763
            if (Bank_addr[0] == 2'b00) begin
764
                Row = B0_row_addr;
765
            end else if (Bank_addr[0] == 2'b01) begin
766
                Row = B1_row_addr;
767
            end else if (Bank_addr[0] == 2'b10) begin
768
                Row = B2_row_addr;
769
            end else if (Bank_addr[0] == 2'b11) begin
770
                Row = B3_row_addr;
771
            end
772
            Burst_counter = 0;
773
            Data_in_enable = 1'b0;
774
            Data_out_enable = 1'b1;
775
        end else if (Command[0] == `WRITE || Command[0] == `WRITE_A) begin
776
            Bank = Bank_addr[0];
777
            Col = Col_addr[0];
778
            Col_brst = Col_addr[0];
779
            if (Bank_addr[0] == 2'b00) begin
780
                Row = B0_row_addr;
781
            end else if (Bank_addr[0] == 2'b01) begin
782
                Row = B1_row_addr;
783
            end else if (Bank_addr[0] == 2'b10) begin
784
                Row = B2_row_addr;
785
            end else if (Bank_addr[0] == 2'b11) begin
786
                Row = B3_row_addr;
787
            end
788
            Burst_counter = 0;
789
            Data_in_enable = 1'b1;
790
            Data_out_enable = 1'b0;
791
        end
792
 
793
        // DQ buffer (Driver/Receiver)
794
        if (Data_in_enable == 1'b1) begin                                   // Writing Data to Memory
795
            // Array buffer
796
            if (Bank == 2'b00) Dq_dqm [15 : 0] = Bank0 [{Row, Col}];
797
            if (Bank == 2'b01) Dq_dqm [15 : 0] = Bank1 [{Row, Col}];
798
            if (Bank == 2'b10) Dq_dqm [15 : 0] = Bank2 [{Row, Col}];
799
            if (Bank == 2'b11) Dq_dqm [15 : 0] = Bank3 [{Row, Col}];
800
            // Dqm operation
801
            if (Dqm[0] == 1'b0) Dq_dqm [ 7 : 0] = Dq [ 7 : 0];
802
            if (Dqm[1] == 1'b0) Dq_dqm [15 : 8] = Dq [15 : 8];
803
            // Write to memory
804
            if (Bank == 2'b00) Bank0 [{Row, Col}] = Dq_dqm [15 : 0];
805
            if (Bank == 2'b01) Bank1 [{Row, Col}] = Dq_dqm [15 : 0];
806
            if (Bank == 2'b10) Bank2 [{Row, Col}] = Dq_dqm [15 : 0];
807
            if (Bank == 2'b11) Bank3 [{Row, Col}] = Dq_dqm [15 : 0];
808
            // Output result
809
            if (Dqm == 2'b11) begin
810
                if (Debug) $display("at time %t WRITE: Bank = %d Row = %d, Col = %d, Data = Hi-Z due to DQM", $time, Bank, Row, Col);
811
            end else begin
812
                if (Debug) $display("at time %t WRITE: Bank = %d Row = %d, Col = %d, Data = %d, Dqm = %b", $time, Bank, Row, Col, Dq_dqm, Dqm);
813
                // Record tWR time and reset counter
814
                WR_chkp [Bank] = $time;
815
                WR_counter [Bank] = 0;
816
            end
817
            // Advance burst counter subroutine
818
            #tHZ Burst;
819
        end else if (Data_out_enable == 1'b1) begin                         // Reading Data from Memory
820
            // Array buffer
821
            if (Bank == 2'b00) Dq_dqm [15 : 0] = Bank0 [{Row, Col}];
822
            if (Bank == 2'b01) Dq_dqm [15 : 0] = Bank1 [{Row, Col}];
823
            if (Bank == 2'b10) Dq_dqm [15 : 0] = Bank2 [{Row, Col}];
824
            if (Bank == 2'b11) Dq_dqm [15 : 0] = Bank3 [{Row, Col}];
825
            // Dqm operation
826
            if (Dqm_reg0[0] == 1'b1) Dq_dqm [ 7 : 0] = 8'bz;
827
            if (Dqm_reg0[1] == 1'b1) Dq_dqm [15 : 8] = 8'bz;
828
            // Display result
829
            Dq_reg [15 : 0] = #tAC Dq_dqm [15 : 0];
830
            if (Dqm_reg0 == 2'b11) begin
831
                if (Debug) $display("at time %t READ : Bank = %d Row = %d, Col = %d, Data = Hi-Z due to DQM", $time, Bank, Row, Col);
832
            end else begin
833
                if (Debug) $display("at time %t READ : Bank = %d Row = %d, Col = %d, Data = %d, Dqm = %b", $time, Bank, Row, Col, Dq_reg, Dqm_reg0);
834
            end
835
            // Advance burst counter subroutine
836
            Burst;
837
        end
838
    end
839
 
840
    //  Write with Auto Precharge Calculation
841
    //      The device start internal precharge:
842
    //          1.  tWR Clock after last burst
843
    //      and 2.  Meet minimum tRAS requirement
844
    //       or 3.  Interrupt by a Read or Write (with or without AutoPrecharge)
845
    always @ (RAS_clk) begin
846
        if ((Auto_precharge[0] == 1'b1) && (Write_precharge[0] == 1'b1)) begin
847
            if ((($time - RAS_chk0 >= tRAS) &&                                                          // Case 2
848
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [0] >= 1 && $time - Count_time[0] >= tWRa) ||   // Case 1
849
                 (Burst_length_2 == 1'b1 && Count_precharge [0] >= 2 && $time - Count_time[0] >= tWRa) ||
850
                 (Burst_length_4 == 1'b1 && Count_precharge [0] >= 4 && $time - Count_time[0] >= tWRa) ||
851
                 (Burst_length_8 == 1'b1 && Count_precharge [0] >= 8 && $time - Count_time[0] >= tWRa))) ||
852
                 (RW_interrupt_write[0] == 1'b1 && WR_counter[0] >= 1 && $time - WR_time[0] >= tWRa)) begin                           // Case 3 (stop count when interrupt)
853
                    Auto_precharge[0] = 1'b0;
854
                    Write_precharge[0] = 1'b0;
855
                    RW_interrupt_write[0] = 1'b0;
856
                    Pc_b0 = 1'b1;
857
                    Act_b0 = 1'b0;
858
                    RP_chk0 = $time;
859
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 0", $time);
860
            end
861
        end
862
        if ((Auto_precharge[1] == 1'b1) && (Write_precharge[1] == 1'b1)) begin
863
            if ((($time - RAS_chk1 >= tRAS) &&
864
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [1] >= 1 && $time - Count_time[1] >= tWRa) ||
865
                 (Burst_length_2 == 1'b1 && Count_precharge [1] >= 2 && $time - Count_time[1] >= tWRa) ||
866
                 (Burst_length_4 == 1'b1 && Count_precharge [1] >= 4 && $time - Count_time[1] >= tWRa) ||
867
                 (Burst_length_8 == 1'b1 && Count_precharge [1] >= 8 && $time - Count_time[1] >= tWRa))) ||
868
                 (RW_interrupt_write[1] == 1'b1 && WR_counter[1] >= 1 && $time - WR_time[1] >= tWRa)) begin
869
                    Auto_precharge[1] = 1'b0;
870
                    Write_precharge[1] = 1'b0;
871
                    RW_interrupt_write[1] = 1'b0;
872
                    Pc_b1 = 1'b1;
873
                    Act_b1 = 1'b0;
874
                    RP_chk1 = $time;
875
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 1", $time);
876
            end
877
        end
878
        if ((Auto_precharge[2] == 1'b1) && (Write_precharge[2] == 1'b1)) begin
879
            if ((($time - RAS_chk2 >= tRAS) &&
880
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [2] >= 1 && $time - Count_time[2] >= tWRa) ||
881
                 (Burst_length_2 == 1'b1 && Count_precharge [2] >= 2 && $time - Count_time[2] >= tWRa) ||
882
                 (Burst_length_4 == 1'b1 && Count_precharge [2] >= 4 && $time - Count_time[2] >= tWRa) ||
883
                 (Burst_length_8 == 1'b1 && Count_precharge [2] >= 8 && $time - Count_time[2] >= tWRa))) ||
884
                 (RW_interrupt_write[2] == 1'b1 && WR_counter[2] >= 1 && $time - WR_time[2] >= tWRa)) begin
885
                    Auto_precharge[2] = 1'b0;
886
                    Write_precharge[2] = 1'b0;
887
                    RW_interrupt_write[2] = 1'b0;
888
                    Pc_b2 = 1'b1;
889
                    Act_b2 = 1'b0;
890
                    RP_chk2 = $time;
891
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 2", $time);
892
            end
893
        end
894
        if ((Auto_precharge[3] == 1'b1) && (Write_precharge[3] == 1'b1)) begin
895
            if ((($time - RAS_chk3 >= tRAS) &&
896
               (((Burst_length_1 == 1'b1 || Write_burst_mode == 1'b1) && Count_precharge [3] >= 1 && $time - Count_time[3] >= tWRa) ||
897
                 (Burst_length_2 == 1'b1 && Count_precharge [3] >= 2 && $time - Count_time[3] >= tWRa) ||
898
                 (Burst_length_4 == 1'b1 && Count_precharge [3] >= 4 && $time - Count_time[3] >= tWRa) ||
899
                 (Burst_length_8 == 1'b1 && Count_precharge [3] >= 8 && $time - Count_time[3] >= tWRa))) ||
900
                 (RW_interrupt_write[3] == 1'b1 && WR_counter[3] >= 1 && $time - WR_time[3] >= tWRa)) begin
901
                    Auto_precharge[3] = 1'b0;
902
                    Write_precharge[3] = 1'b0;
903
                    RW_interrupt_write[3] = 1'b0;
904
                    Pc_b3 = 1'b1;
905
                    Act_b3 = 1'b0;
906
                    RP_chk3 = $time;
907
                    if (Debug) $display ("at time %t NOTE : Start Internal Auto Precharge for Bank 3", $time);
908
            end
909
        end
910
    end
911
 
912
    task Burst;
913
        begin
914
            // Advance Burst Counter
915
            Burst_counter = Burst_counter + 1;
916
 
917
            // Burst Type
918
            if (Mode_reg[3] == 1'b0) begin                                  // Sequential Burst
919
                Col_temp = Col + 1;
920
            end else if (Mode_reg[3] == 1'b1) begin                         // Interleaved Burst
921
                Col_temp[2] =  Burst_counter[2] ^  Col_brst[2];
922
                Col_temp[1] =  Burst_counter[1] ^  Col_brst[1];
923
                Col_temp[0] =  Burst_counter[0] ^  Col_brst[0];
924
            end
925
 
926
            // Burst Length
927
            if (Burst_length_2) begin                                       // Burst Length = 2
928
                Col [0] = Col_temp [0];
929
            end else if (Burst_length_4) begin                              // Burst Length = 4
930
                Col [1 : 0] = Col_temp [1 : 0];
931
            end else if (Burst_length_8) begin                              // Burst Length = 8
932
                Col [2 : 0] = Col_temp [2 : 0];
933
            end else begin                                                  // Burst Length = FULL
934
                Col = Col_temp;
935
            end
936
 
937
            // Burst Read Single Write            
938
            if (Write_burst_mode == 1'b1) begin
939
                Data_in_enable = 1'b0;
940
            end
941
 
942
            // Data Counter
943
            if (Burst_length_1 == 1'b1) begin
944
                if (Burst_counter >= 1) begin
945
                    Data_in_enable = 1'b0;
946
                    Data_out_enable = 1'b0;
947
                end
948
            end else if (Burst_length_2 == 1'b1) begin
949
                if (Burst_counter >= 2) begin
950
                    Data_in_enable = 1'b0;
951
                    Data_out_enable = 1'b0;
952
                end
953
            end else if (Burst_length_4 == 1'b1) begin
954
                if (Burst_counter >= 4) begin
955
                    Data_in_enable = 1'b0;
956
                    Data_out_enable = 1'b0;
957
                end
958
            end else if (Burst_length_8 == 1'b1) begin
959
                if (Burst_counter >= 8) begin
960
                    Data_in_enable = 1'b0;
961
                    Data_out_enable = 1'b0;
962
                end
963
            end
964
        end
965
    endtask
966
 
967
    // Timing Parameters for -7E and CAS Latency = 2
968
    specify
969
        specparam
970
            tAH  =  0.8,                                        // Addr, Ba Hold Time
971
            tAS  =  1.5,                                        // Addr, Ba Setup Time
972
            tCH  =  2.5,                                        // Clock High-Level Width
973
            tCL  =  2.5,                                        // Clock Low-Level Width
974
            tCK  =  7.5,                                        // Clock Cycle Time
975
            tDH  =  0.8,                                        // Data-in Hold Time
976
            tDS  =  1.5,                                        // Data-in Setup Time
977
            tCKH =  0.8,                                        // CKE Hold  Time
978
            tCKS =  1.5,                                        // CKE Setup Time
979
            tCMH =  0.8,                                        // CS#, RAS#, CAS#, WE#, DQM# Hold  Time
980
            tCMS =  1.5;                                        // CS#, RAS#, CAS#, WE#, DQM# Setup Time
981
        $width    (posedge Clk,           tCH);
982
        $width    (negedge Clk,           tCL);
983
        $period   (negedge Clk,           tCK);
984
        $period   (posedge Clk,           tCK);
985
        $setuphold(posedge Clk,    Cke,   tCKS, tCKH);
986
        $setuphold(posedge Clk,    Cs_n,  tCMS, tCMH);
987
        $setuphold(posedge Clk,    Cas_n, tCMS, tCMH);
988
        $setuphold(posedge Clk,    Ras_n, tCMS, tCMH);
989
        $setuphold(posedge Clk,    We_n,  tCMS, tCMH);
990
        $setuphold(posedge Clk,    Addr,  tAS,  tAH);
991
        $setuphold(posedge Clk,    Ba,    tAS,  tAH);
992
        $setuphold(posedge Clk,    Dqm,   tCMS, tCMH);
993
        $setuphold(posedge Dq_chk, Dq,    tDS,  tDH);
994
    endspecify
995
 
996
endmodule
997
 
998
 
999
 
1000
 
1001
 

powered by: WebSVN 2.1.0

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