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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [micron/] [sdram/] [mobile_sdr.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
/**************************************************************************
2
*
3
*    File Name:  model.v
4
*      Version:  4.0
5
*         Date:  Jul 12 2006
6
*        Model:  BUS Functional
7
*    Simulator:  Model Technology
8
*
9
* Dependencies:  None
10
*
11
*        Email:  modelsupport@micron.com
12
*      Company:  Micron Technology, Inc.
13
*        Model:  Mobile SDR
14
*
15
*  Description:  Micron Mobile SDRAM Verilog model
16
*
17
*   Limitation:  - Doesn't check for 4096 cycle refresh
18
*
19
*         Note:  - Set simulator resolution to "ps" accuracy
20
*                - Set Debug = 0 to disable $display messages
21
*
22
*  [Disclaimer]
23
*  This software code and all associated documentation, comments
24
*  or other information (collectively "Software") is provided
25
*  "AS IS" without warranty of any kind. MICRON TECHNOLOGY, INC.
26
*  ("MTI") EXPRESSLY DISCLAIMS ALL WARRANTIES EXPRESS OR IMPLIED,
27
*  INCLUDING BUT NOT LIMITED TO, NONINFRINGEMENT OF THIRD PARTY
28
*  RIGHTS, AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
29
*  FOR ANY PARTICULAR PURPOSE. MTI DOES NOT WARRANT THAT THE
30
*  SOFTWARE WILL MEET YOUR REQUIREMENTS, OR THAT THE OPERATION OF
31
*  THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE. FURTHERMORE,
32
*  MTI DOES NOT MAKE ANY REPRESENTATIONS REGARDING THE USE OR THE
33
*  RESULTS OF THE USE OF THE SOFTWARE IN TERMS OF ITS CORRECTNESS,
34
*  ACCURACY, RELIABILITY, OR OTHERWISE. THE ENTIRE RISK ARISING OUT
35
*  OF USE OR PERFORMANCE OF THE SOFTWARE REMAINS WITH YOU. IN NO
36
*  EVENT SHALL MTI, ITS AFFILIATED COMPANIES OR THEIR SUPPLIERS BE
37
*  LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR
38
*  SPECIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS
39
*  OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION)
40
*  ARISING OUT OF YOUR USE OF OR INABILITY TO USE THE SOFTWARE,
41
*  EVEN IF MTI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
42
*  Because some jurisdictions prohibit the exclusion or limitation
43
*  of liability for consequential or incidental damages, the above
44
*  limitation may not apply to you.
45
*
46
*  Copyright © 2001-2006 Micron Technology, Inc. All rights reserved.
47
*
48
*
49
* Rev  Author          Date        Changes
50
* ---  --------------------------  ---------------------------------------
51
* 4.20 bas             10/11/2006  - Changed tRRD check to use tCK min based on CL
52
* 4.17 bas             10/10/2006  - fixed read problem during CL3 BL1 related to read w/autoprecharge followed by activate to the same bank causing read from incorrect row, updated parameter sheets
53
* 4.16 bas             09/27/2006  - fixed tRRD check for parts spec using # of clks instead of ns delay
54
* 4.15 bas             09/26/2006  - Wrote WRap & RDap code to use #delay due to non-freerunning clock operation, fixed tRP, fixed WRap/RDap interrupt operation
55
* 4.12 bas             09/08/2006  - Removed realtime array instantiations of variables for NCVerilog
56
* 4.11 bas             09/07/2006  - tHZ issue, read DQM issue, write/read to precharged bank error(data was still being written), tRP during WRaP issue, RP option added, part selection added
57
* 4.1  bas             08/23/2006  - fixed masking and tHZ timing issue
58
* 4.0  bh              07/12/2006  - merged MT48H16M16LF & MT48H32M16LF to create single model file for all types & densities
59
* 3.2  dritz           11/04/2005  - Fixed Driver Strength bits
60
* 3.1  dritz           09/22/2005  - Fixed dqm bits to be [1:0] and tb.v as well
61
* 3.0  dritz           06/28/2005  - MT48H32M16LF
62
* 2.1  dritz           03/23/2005  - MT48LC8M32LF Fixed dqm mask bits and functionality
63
* 2.0  dritz           01/11/2005  - MT48LC8M32B2
64
* 1.0  NB              07/14/2004  - MT48M16LF
65
*
66
**************************************************************************/
67
 
68
`timescale 1ps / 1ps
69
 
70
module mobile_sdr (
71
    clk   ,
72
    cke   ,
73
    addr  ,
74
    ba    ,
75
    cs_n  ,
76
    ras_n ,
77
    cas_n ,
78
    we_n  ,
79
    dq    ,
80
    dqm
81
    );
82
 
83
//------------- Include Statements -------------
84
 
85
//`include "mobile_sdr_parameters.vh"
86
/****************************************************************************************
87
*
88
*   Disclaimer   This software code and all associated documentation, comments or other
89
*  of Warranty:  information (collectively "Software") is provided "AS IS" without
90
*                warranty of any kind. MICRON TECHNOLOGY, INC. ("MTI") EXPRESSLY
91
*                DISCLAIMS ALL WARRANTIES EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
92
*                TO, NONINFRINGEMENT OF THIRD PARTY RIGHTS, AND ANY IMPLIED WARRANTIES
93
*                OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. MTI DOES NOT
94
*                WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS, OR THAT THE
95
*                OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE.
96
*                FURTHERMORE, MTI DOES NOT MAKE ANY REPRESENTATIONS REGARDING THE USE OR
97
*                THE RESULTS OF THE USE OF THE SOFTWARE IN TERMS OF ITS CORRECTNESS,
98
*                ACCURACY, RELIABILITY, OR OTHERWISE. THE ENTIRE RISK ARISING OUT OF USE
99
*                OR PERFORMANCE OF THE SOFTWARE REMAINS WITH YOU. IN NO EVENT SHALL MTI,
100
*                ITS AFFILIATED COMPANIES OR THEIR SUPPLIERS BE LIABLE FOR ANY DIRECT,
101
*                INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR SPECIAL DAMAGES (INCLUDING,
102
*                WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION,
103
*                OR LOSS OF INFORMATION) ARISING OUT OF YOUR USE OF OR INABILITY TO USE
104
*                THE SOFTWARE, EVEN IF MTI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
105
*                DAMAGES. Because some jurisdictions prohibit the exclusion or
106
*                limitation of liability for consequential or incidental damages, the
107
*                above limitation may not apply to you.
108
*
109
*                Copyright 2005 Micron Technology, Inc. All rights reserved.
110
*
111
****************************************************************************************/
112
 
113
    // Timing parameters based on Speed Grade and part type (Y47M) 03/07
114
 
115
`define sg6
116
                                          // SYMBOL UNITS DESCRIPTION
117
                                          // ------ ----- -----------
118
`ifdef sg6                                 //              Timing Parameters for -75 (CL = 3)
119
    parameter tCK              =     6000; // tCK    ps    Nominal Clock Cycle Time
120
    parameter tCK3_min         =     6000; // tCK    ps    Nominal Clock Cycle Time
121
    parameter tCK2_min         =     9600; // tCK    ps    Nominal Clock Cycle Time
122
    parameter tCK1_min         =        0; // tCK    ps    Nominal Clock Cycle Time
123
    parameter tAC3             =     5000; // tAC3   ps    Access time from CLK (pos edge) CL = 3
124
    parameter tAC2             =     8000; // tAC2   ps    Access time from CLK (pos edge) CL = 2
125
    parameter tAC1             =        0; // tAC1   ps    Parameter definition for compilation - CL = 1 illegal for sg75
126
    parameter tHZ3             =     5000; // tHZ3   ps    Data Out High Z time - CL = 3
127
    parameter tHZ2             =     8000; // tHZ2   ps    Data Out High Z time - CL = 2
128
    parameter tHZ1             =        0; // tHZ1   ps    Parameter definition for compilation - CL = 1 illegal for sg75
129
    parameter tOH              =     2500; // tOH    ps    Data Out Hold time
130
    parameter tMRD             =        2; // tMRD   tCK   Load Mode Register command cycle time (2 * tCK)
131
    parameter tRAS             =    42000; // tRAS   ps    Active to Precharge command time
132
    parameter tRC              =    60000; // tRC    ps    Active to Active/Auto Refresh command time
133
    parameter tRFC             =    97500; // tRFC   ps    Refresh to Refresh Command interval time
134
    parameter tRCD             =    18000; // tRCD   ps    Active to Read/Write command time
135
    parameter tRP              =    18000; // tRP    ps    Precharge command period
136
    parameter tRRD             =        2; // tRRD   tCK   Active bank a to Active bank b command time
137
    parameter tWRa             =     7500; // tWR    ps    Write recovery time (auto-precharge mode - must add 1 CLK)
138
    parameter tWRm             =    15000; // tWR    ps    Write recovery time
139
    parameter tCH              =     2600; // tCH    ps    Clock high level width
140
    parameter tCL              =     2600; // tCL    ps    Clock low level width
141
    parameter tXSR             =   120000; // tXSR   ps    Clock low level width
142
`else `ifdef sg75                          //              Timing Parameters for -8 (CL = 3)
143
    parameter tCK              =     7500; // tCK    ps    Nominal Clock Cycle Time
144
    parameter tCK3_min         =     7500; // tCK    ps    Nominal Clock Cycle Time
145
    parameter tCK2_min         =     9600; // tCK    ps    Nominal Clock Cycle Time
146
    parameter tCK1_min         =        0; // tCK    ps    Nominal Clock Cycle Time
147
    parameter tAC3             =     5400; // tAC3   ps    Access time from CLK (pos edge) CL = 3
148
    parameter tAC2             =     8000; // tAC2   ps    Access time from CLK (pos edge) CL = 2
149
    parameter tAC1             =        0; // tAC1   ps    Access time from CLK (pos edge) CL = 1
150
    parameter tHZ3             =     5400; // tHZ3   ps    Data Out High Z time - CL = 3
151
    parameter tHZ2             =     8000; // tHZ2   ps    Data Out High Z time - CL = 2
152
    parameter tHZ1             =        0; // tHZ1   ps    Data Out High Z time - CL = 1
153
    parameter tOH              =     2500; // tOH    ps    Data Out Hold time
154
    parameter tMRD             =        2; // tMRD   tCK   Load Mode Register command cycle time (2 * tCK)
155
    parameter tRAS             =    45000; // tRAS   ps    Active to Precharge command time
156
    parameter tRC              =    67500; // tRC    ps    Active to Active/Auto Refresh command time
157
    parameter tRFC             =    97500; // tRFC   ps    Refresh to Refresh Command interval time
158
    parameter tRCD             =    19200; // tRCD   ps    Active to Read/Write command time
159
    parameter tRP              =    19200; // tRP    ps    Precharge command period
160
    parameter tRRD             =        2; // tRRD   tCK   Active bank a to Active bank b command time (2 * tCK)
161
    parameter tWRa             =     7500; // tWR    ps    Write recovery time (auto-precharge mode - must add 1 CLK)
162
    parameter tWRm             =    15000; // tWR    ps    Write recovery time
163
    parameter tCH              =     3000; // tCH    ps    Clock high level width
164
    parameter tCL              =     3000; // tCL    ps    Clock low level width
165
    parameter tXSR             =   120000; // tXSR   ps    Clock low level width
166
`endif `endif
167
 
168
    // Size Parameters based on Part Width
169
 
170
`define x16
171
 
172
`ifdef x32
173
    parameter ADDR_BITS        =      13; // Set this parameter to control how many Address bits are used
174
    parameter ROW_BITS         =      13; // Set this parameter to control how many Row bits are used
175
    parameter DQ_BITS          =      32; // Set this parameter to control how many Data bits are used
176
    parameter DM_BITS          =       4; // Set this parameter to control how many DM bits are used
177
    parameter COL_BITS         =       9; // Set this parameter to control how many Column bits are used
178
    parameter BA_BITS          =       2; // Bank bits
179
`else `ifdef x16
180
    parameter ADDR_BITS        =      13; // Set this parameter to control how many Address bits are used
181
    parameter ROW_BITS         =      13; // Set this parameter to control how many Row bits are used
182
    parameter DQ_BITS          =      16; // Set this parameter to control how many Data bits are used
183
    parameter DM_BITS          =       2; // Set this parameter to control how many DM bits are used
184
    parameter COL_BITS         =      10; // Set this parameter to control how many Column bits are used
185
    parameter BA_BITS          =       2; // Bank bits
186
`endif `endif
187
 
188
    // Other Parameters
189
 
190
    parameter full_mem_bits    = BA_BITS+ADDR_BITS+COL_BITS; // Set this parameter to control how many unique addresses are used
191
    parameter part_mem_bits    = 10;                         // For fast sim load
192
    parameter part_size        = 256;                        // Set this parameter to indicate part size(512Mb, 256Mb, 128Mb)
193
 
194
 
195
 
196
 
197
//------------- Define Statements --------------
198
 
199
`define BANKS      (1<<BA_BITS)
200
`define PAGE_SIZE  (1<<COL_BITS)
201
 
202
//------------- Parameters (cke, addr[10], cs_n, ras_n, cas_n, we_n) --------------
203
    parameter NOP              = 6'b100111 ;
204
    parameter ACTIVATE         = 6'b100011 ;
205
    parameter READ             = 6'b100101 ;
206
    parameter READ_AP          = 6'b110101 ;
207
    parameter READ_SUSPEND     = 6'b000101 ;
208
    parameter READ_AP_SUSPEND  = 6'b010101 ;
209
    parameter WRITE            = 6'b100100 ;
210
    parameter WRITE_AP         = 6'b110100 ;
211
    parameter WRITE_SUSPEND    = 6'b000100 ;
212
    parameter WRITE_AP_SUSPEND = 6'b010100 ;
213
    parameter BURST_TERMINATE  = 6'b100110 ;
214
    parameter POWER_DOWN_CI    = 6'b001111 ;
215
    parameter POWER_DOWN_NOP   = 6'b000111 ;
216
    parameter DEEP_POWER_DOWN  = 6'b000110 ;
217
    parameter PRECHARGE        = 6'b100010 ;
218
    parameter PRECHARGE_ALL    = 6'b110010 ;
219
    parameter AUTO_REFRESH     = 6'b100001 ;
220
    parameter SELF_REFRESH     = 6'b000001 ;
221
    parameter LOAD_MODE        = 6'b100000 ;
222
    parameter CKE_DISABLE      = 6'b011111 ;
223
 
224
    parameter DEBUG = 1             ;
225
 
226
//----------------------------------------
227
// Error codes and reporting
228
//----------------------------------------
229
 
230
    parameter   ERR_MAX_REPORTED =       -1; // >0 = report errors up to ERR_MAX_REPORTED, <0 = report all errors
231
    parameter   ERR_MAX          =       -1; // >0 = stop the simulation after ERR_MAX has been reached, <0 = never stop the simulation
232
    parameter   MSGLENGTH        =      256;
233
    parameter   ERR_CODES        =       16; // track up to 44 different error codes
234
    // Enumerated error codes (0 = unused)
235
    parameter   ERR_MISC         =        1;
236
    parameter   ERR_CMD          =        2;
237
    parameter   ERR_STATUS       =        3;
238
    parameter   ERR_tMRD         =        4;
239
    parameter   ERR_tRAS         =        5;
240
    parameter   ERR_tRC          =        6;
241
    parameter   ERR_tRFC         =        7;
242
    parameter   ERR_tRCD         =        8;
243
    parameter   ERR_tRP          =        9;
244
    parameter   ERR_tRRD         =       11;
245
    parameter   ERR_tWR          =       12;
246
    parameter   ERR_tCH          =       13;
247
    parameter   ERR_tCL          =       14;
248
    parameter   ERR_tXSR         =       15;
249
    parameter   ERR_tCK_MIN      =       16;
250
 
251
    wire [ERR_CODES : 1] EXP_ERR                  ;
252
    reg  [ERR_CODES : 1] errcount                 ;
253
    reg       [8*12-1:0] err_strings [1:ERR_CODES];
254
    integer     ERR_MAX_INT      =  ERR_MAX;
255
 
256
    assign EXP_ERR     = {ERR_CODES {1'b0}}; // the model expects no errors.  Can only be changed for debug by 'force' statement in testbench.
257
 
258
//------------- Port Declarations --------------
259
 
260
    input                        clk   ;
261
    input                        cke   ;
262
    input    [ADDR_BITS - 1 : 0] addr  ;
263
    input    [BA_BITS - 1 : 0]   ba    ;
264
    input                        cs_n  ;
265
    input                        ras_n ;
266
    input                        cas_n ;
267
    input                        we_n  ;
268
    input    [DM_BITS - 1 : 0]   dqm   ;
269
    inout    [DQ_BITS - 1 : 0]   dq    ;
270
 
271
//------------- Register Declarations --------------
272
 
273
    reg      [8*MSGLENGTH:1]     msg                                      ;
274
    reg      [`BANKS - 1 :0]     active_bank                              ;
275
    reg   [ADDR_BITS - 1 :0]     activate_row            [`BANKS - 1 : 0] ;
276
    reg                          auto_refresh1_done                       ;
277
    reg  [ COL_BITS - 1 : 0]     burst_count                              ;
278
    reg   [COL_BITS - 1 : 0]     col_addr_burst_order  [`PAGE_SIZE-1 : 0] ;
279
 
280
    reg    [BA_BITS - 1 : 0]     bank_access_q         [`PAGE_SIZE+2 : 0] ;
281
    reg   [ROW_BITS - 1 : 0]     row_access_q          [`PAGE_SIZE+2 : 0] ;
282
    reg   [COL_BITS - 1 : 0]     column_access_q       [`PAGE_SIZE+2 : 0] ;
283
    reg             [ 1 : 0]     column_access_valid_q [`PAGE_SIZE+2 : 0] ;
284
    reg             [ 2 : 0]     cas_latency                              ;
285
    reg                          write_burst_mode                         ;
286
    reg    [BA_BITS - 1 : 0]     interrupt_bank                           ;
287
    reg                          burst_type                               ;
288
 
289
    reg      [DQ_BITS-1 : 0]     Dq_out                                   ;
290
    reg      [DQ_BITS-1 : 0]     Dq_out_tAC                               ;
291
    reg    [DQ_BITS - 1 : 0]     mdata                                    ;
292
    reg         [`BANKS-1:0]     ap_set                                   ;
293
    reg                          cke_q                                    ;
294
    reg    [DM_BITS - 1 : 0]     dqm_q                                    ;
295
    reg             [ 1 : 0]     dqm_rtw_chk                              ;
296
    reg                          Sys_clk                                  ;
297
    reg              [3 : 0]     initialization_state                     ;
298
    reg                          self_refresh_enter                       ;
299
    reg                          power_down_enter                         ;
300
    reg                          command_sequence_error                   ;
301
    reg                          read_write_in_progress                   ;
302
 
303
    // Memory Banks
304
    `ifdef FULL_MEM
305
        reg  [DQ_BITS - 1 : 0] mem_array  [0 : (1<<full_mem_bits)-1];
306
    `else
307
        reg   [DQ_BITS - 1 : 0] mem_array  [0 : (1<<part_mem_bits)-1];
308
        reg   [full_mem_bits - 1 : 0] addr_array [0 : (1<<part_mem_bits)-1];
309
        reg   [part_mem_bits     : 0] mem_used;
310
        reg   [part_mem_bits     : 0] memory_index;
311
        initial mem_used = 0;
312
    `endif
313
 
314
//------------- Integer Declarations --------------
315
    integer                      ck_cntr_initial                          ;
316
    integer                      ck_cntr_activate                         ;
317
    integer                      ck_cntr_read                             ;
318
    integer                      ck_cntr_read_ap                          ;
319
    integer                      ck_cntr_write                            ;
320
    integer                      ck_cntr_write_ap                         ;
321
    integer                      ck_cntr_burst_terminate                  ;
322
    integer                      ck_cntr_precharge                        ;
323
    integer                      ck_cntr_auto_refresh                     ;
324
    integer                      ck_cntr_self_refresh                     ;
325
    integer                      ck_cntr_power_down                       ;
326
    integer                      ck_cntr_clock_suspend                    ;
327
    integer                      ck_cntr_deep_power_down                  ;
328
    integer                      ck_cntr_load_mode                        ;
329
    integer                      ck_cntr_cke                              ;
330
    integer                      ck_cntr_cke_n                            ;
331
    integer                      ck_cntr_cke_high                         ;
332
    integer                      ck_cntr_bank_precharge      [`BANKS-1:0] ;
333
    integer                      ck_cntr_bank_activate       [`BANKS-1:0] ;
334
    integer                      ck_cntr_bank_write          [`BANKS-1:0] ;
335
    integer                      ck_cntr_bank_read           [`BANKS-1:0] ;
336
    integer                      ck_cntr_write_dq            [`BANKS-1:0] ;
337
    integer                      interrupt_write_ap_n        [`BANKS-1:0] ;
338
    integer                      interrupt_read_ap_n         [`BANKS-1:0] ;
339
    integer                      pasr                                     ;
340
    integer                      warnings                                 ;
341
    integer                      errors                                   ;
342
    integer                      burst_length                             ;
343
 
344
    integer                      i                                        ;
345
 
346
//------------- Time Declarations --------------
347
 
348
    time                         tm_initial                     ;
349
    time                         tm_activate                    ;
350
    time                         tm_read                        ;
351
    time                         tm_write                       ;
352
    time                         tm_burst_terminate             ;
353
    time                         tm_precharge                   ;
354
    time                         tm_auto_refresh                ;
355
    time                         tm_self_refresh                ;
356
    time                         tm_power_down                  ;
357
    time                         tm_clock_suspend               ;
358
    time                         tm_deep_power_down             ;
359
    time                         tm_load_mode                   ;
360
    time                         tm_bank_precharge [`BANKS-1:0] ;
361
    time                         tm_bank_activate  [`BANKS-1:0] ;
362
    time                         tm_bank_write     [`BANKS-1:0] ;
363
    time                         tm_bank_read      [`BANKS-1:0] ;
364
    time                         tm_write_dq       [`BANKS-1:0] ;
365
    time                         tm_cke                         ;
366
    time                         tm_cke_n                       ;
367
    time                         tm_cke_high                    ;
368
 
369
    time                         tm_clk_high_pulse_width        ;
370
    time                         tm_clk_low_pulse_width         ;
371
    time                         tm_clk_period                  ;
372
    time                         tm_clk_negedge                 ;
373
    time                         tm_clk_posedge                 ;
374
 
375
 
376
//------------- Wire Declarations --------------
377
 
378
    wire                         addr_10                        ;
379
    wire      [ 5 : 0]           command                        ;
380
 
381
//--------------------- Outputs -----------------------
382
 
383
    assign dq = Dq_out_tAC ;
384
 
385
//--------------------- Initialization -----------------------
386
 
387
    initial begin
388
        auto_refresh1_done = 1'b0           ;
389
        initialization_state = 4'h0         ;
390
        active_bank        = {`BANKS{1'b1}} ;
391
        Dq_out_tAC         = 'bz            ;
392
 
393
        tm_initial         = 0 ;
394
        tm_activate        = 0 ;
395
        tm_read            = 0 ;
396
        tm_write           = 0 ;
397
        tm_burst_terminate = 0 ;
398
        tm_precharge       = 0 ;
399
        tm_auto_refresh    = 0 ;
400
        tm_self_refresh    = 0 ;
401
        tm_power_down      = 0 ;
402
        tm_clock_suspend   = 0 ;
403
        tm_deep_power_down = 0 ;
404
        tm_load_mode       = 0 ;
405
        for (i=0; i<`BANKS; i=i+1) begin
406
            tm_bank_precharge[i] = 0 ;
407
            tm_bank_activate[i]  = 0 ;
408
            tm_bank_write[i]     = 0 ;
409
            tm_bank_read[i]      = 0 ;
410
            tm_write_dq[i]       = 0 ;
411
        end
412
        tm_cke                 = 0 ;
413
        tm_cke_n               = 0 ;
414
        tm_cke_high            = 0 ;
415
        tm_clk_period          = 0 ;
416
        tm_clk_low_pulse_width = 0 ;
417
        tm_clk_high_pulse_width= 0 ;
418
        tm_clk_negedge         = 0 ;
419
        tm_clk_posedge         = 0 ;
420
        tm_clk_low_pulse_width = 0 ;
421
        for (i=0; i<`BANKS; i=i+1) begin
422
            ap_set[i] = 1'b0 ;
423
        end
424
        ck_cntr_initial         = 100;
425
        ck_cntr_activate        = 100;
426
        ck_cntr_read            = 100;
427
        ck_cntr_read_ap         = 100;
428
        ck_cntr_write           = 100;
429
        ck_cntr_write_ap        = 100;
430
        ck_cntr_burst_terminate = 100;
431
        ck_cntr_precharge       = 100;
432
        ck_cntr_auto_refresh    = 100;
433
        ck_cntr_self_refresh    = 100;
434
        ck_cntr_power_down      = 100;
435
        ck_cntr_clock_suspend   = 100;
436
        ck_cntr_deep_power_down = 100;
437
        ck_cntr_load_mode       = 100;
438
        ck_cntr_cke             = 100;
439
        ck_cntr_cke_n           = 100;
440
        ck_cntr_cke_high        = 100;
441
        for (i=0; i<`BANKS; i=i+1) begin
442
            ck_cntr_bank_precharge[i] = 100;
443
            ck_cntr_bank_activate[i]  = 100;
444
            ck_cntr_bank_write[i]     = 100;
445
            ck_cntr_bank_read[i]      = 100;
446
            ck_cntr_write_dq[i]       = 100;
447
            interrupt_write_ap_n[i]   = 2;
448
            interrupt_read_ap_n[i]    = 1;
449
        end
450
        for (i=0; i<`PAGE_SIZE+3;i=i+1) begin
451
            bank_access_q[i] = 'bz ;
452
            row_access_q[i] = 'bz ;
453
            column_access_q[i] = 'bz ;
454
            column_access_valid_q[i] = 2'b00 ;
455
        end
456
        for (i=0; i<`PAGE_SIZE+3; i=i+1) begin
457
            column_access_valid_q[i] = 2'b00 ;
458
        end
459
        warnings = 0;
460
        errors = 0;
461
        for (i=1; i<=ERR_CODES; i=i+1) begin
462
            errcount[i] = 0;
463
        end
464
        self_refresh_enter      = 0;
465
        power_down_enter        = 0;
466
        command_sequence_error  = 0;
467
        read_write_in_progress  = 0;
468
        pasr                    = 0;
469
    end
470
 
471
//---------------------- Command Selection ----------------------
472
 
473
    assign addr_10 = addr[10] & ((cke_q & ~cs_n &  ras_n & ~cas_n &  we_n & ~(burst_length == `PAGE_SIZE) ) |  // Read w/ap
474
                                 (cke_q & ~cs_n &  ras_n & ~cas_n & ~we_n & ~(burst_length == `PAGE_SIZE) ) |  // Write w/ap
475
                                 (cke_q & ~cs_n & ~ras_n &  cas_n & ~we_n                                 ) ); // Precharge all
476
 
477
//    assign command = ({cke, addr_10, cs_n, (ras_n | cs_n), (cas_n | cs_n), (we_n | cs_n)} & {cke_q, {5{1'b1}}}) | {1'b0, {5{~cke_q}}};
478
 
479
    assign command = {cke, addr_10, cs_n, (ras_n | cs_n), (cas_n | cs_n), (we_n | cs_n)} ;
480
 
481
 
482
 
483
 
484
//---------------------- Mode Register Selection ----------------------
485
 
486
    task set_mode_reg;
487
    begin
488
        // Burst Length selection
489
        if (addr[2:0] == 3'b000) begin
490
            burst_length = 1 ;
491
        end else if (addr[2:0] == 3'b001) begin
492
            burst_length = 2 ;
493
        end else if (addr[2:0] == 3'b010) begin
494
            burst_length = 4 ;
495
        end else if (addr[2:0] == 3'b011) begin
496
            burst_length = 8 ;
497
        end else if (addr[2:0] == 3'b111) begin
498
            burst_length = `PAGE_SIZE ;
499
        end else begin
500
            burst_length = 0 ;
501
        end
502
        burst_type = addr[3] ;
503
        cas_latency = addr[6:4] ;
504
        write_burst_mode = addr[9] ;
505
    end
506
    endtask
507
 
508
    task set_ext_mode_reg;
509
    begin
510
        // PASR selection
511
        if (addr[2:0] == 3'b000) begin
512
            pasr = 0 ;
513
        end else if (addr[2:0] == 3'b001) begin
514
            pasr = 1 ;
515
        end else if (addr[2:0] == 3'b010) begin
516
            pasr = 2 ;
517
        end else if (addr[2:0] == 3'b101) begin
518
            pasr = 3 ;
519
        end else if (addr[2:0] == 3'b110) begin
520
            pasr = 4 ;
521
        end else begin
522
            pasr = 5 ;
523
        end
524
    end
525
    endtask
526
 
527
    task column_burst_order;
528
    begin
529
        burst_count = 0 ;
530
        for (i=0; i<burst_length; i=i+1) begin
531
            if (burst_length == `PAGE_SIZE) begin
532
                if (burst_type == 1'b0) begin
533
                    col_addr_burst_order[i] = addr[COL_BITS-1:0] + burst_count ;
534
                end else if (burst_type == 1'b1) begin
535
                    col_addr_burst_order[i] = {COL_BITS{1'bx}} ;
536
                end
537
            end else if (burst_length == 1) begin
538
                if (burst_type == 1'b0) begin
539
                    col_addr_burst_order[i] = {addr[COL_BITS-1:3], addr[2:0]} ;
540
                end else if (burst_type == 1'b1) begin
541
                    col_addr_burst_order[i] = {addr[COL_BITS-1:3], addr[2:0]} ;
542
                end
543
            end else if (burst_length == 2) begin
544
                if (burst_type == 1'b0) begin
545
                    col_addr_burst_order[i] = {addr[COL_BITS-1:3], addr[2:1], (burst_count[0] + addr[0])} ;
546
                end else if (burst_type == 1'b1) begin
547
                    col_addr_burst_order[i] = {addr[COL_BITS-1:3], addr[2:1], (burst_count[0] ^ addr[0])} ;
548
                end
549
            end else if (burst_length == 4) begin
550
                if (burst_type == 1'b0) begin
551
                    col_addr_burst_order[i] = {addr[COL_BITS-1:3], addr[2], (burst_count[1:0] + addr[1:0])} ;
552
                end else if (burst_type == 1'b1) begin
553
                    col_addr_burst_order[i] = {addr[COL_BITS-1:3], addr[2], (burst_count[1:0] ^ addr[1:0])} ;
554
                end
555
            end else if (burst_length == 8) begin
556
                if (burst_type == 1'b0) begin
557
                    col_addr_burst_order[i] = {addr[COL_BITS-1:3], (burst_count[2:0] + addr[2:0])} ;
558
                end else if (burst_type == 1'b1) begin
559
                    col_addr_burst_order[i] = {addr[COL_BITS-1:3], (burst_count[2:0] ^ addr[2:0])} ;
560
                end
561
            end
562
            burst_count = burst_count + 1'b1 ;
563
        end
564
    end
565
    endtask
566
 
567
//---------------------- Memory Address Queue ----------------------
568
 
569
 
570
    task column_address_read_queue;
571
    begin
572
        for (i=0; i<burst_length;i=i+1) begin
573
            bank_access_q[cas_latency-1+i] = ba ;
574
            row_access_q[cas_latency-1+i] = activate_row[ba] ;
575
            column_access_q[cas_latency-1+i] = col_addr_burst_order[i] ;
576
            column_access_valid_q[cas_latency-1+i] = 2'b10 ;
577
        end
578
        if (burst_length < `PAGE_SIZE) begin
579
            for (i=burst_length; i< (burst_length+cas_latency-1);i=i+1) begin
580
                bank_access_q[cas_latency-1+i] = 'bz ;
581
                row_access_q[cas_latency-1+i] = 'bz ;
582
                column_access_q[cas_latency-1+i] = 'bz ;
583
                column_access_valid_q[cas_latency-1+i] = 2'b00 ;
584
            end
585
        end
586
    end
587
    endtask
588
 
589
    task column_address_write_queue;
590
    begin
591
        for (i=0; i<burst_length;i=i+1) begin
592
            bank_access_q[i] = ba ;
593
            row_access_q[i] = activate_row[ba] ;
594
            column_access_q[i] = col_addr_burst_order[i] ;
595
            column_access_valid_q[i] = 2'b01 ;
596
        end
597
        if (burst_length < `PAGE_SIZE) begin
598
            for (i=burst_length; i<(burst_length+cas_latency-1);i=i+1) begin
599
                bank_access_q[i] = 'bz ;
600
                row_access_q[i] = 'bz ;
601
                column_access_q[i] = 'bz ;
602
                column_access_valid_q[i] = 2'b00 ;
603
            end
604
        end
605
    end
606
    endtask
607
 
608
    task burst_term_read_queue;
609
    begin
610
        for (i=0; i<burst_length;i=i+1) begin
611
            bank_access_q[cas_latency-1+i]         =   'bz ;
612
            row_access_q[cas_latency-1+i]          =   'bz ;
613
            column_access_q[cas_latency-1+i]       =   'bz ;
614
            column_access_valid_q[cas_latency-1+i] = 2'b00 ;
615
        end
616
    end
617
    endtask
618
 
619
    task burst_term_write_queue;
620
    begin
621
        for (i=0; i<burst_length;i=i+1) begin
622
            bank_access_q[i]         =   'bz ;
623
            row_access_q[i]          =   'bz ;
624
            column_access_q[i]       =   'bz ;
625
            column_access_valid_q[i] = 2'b00 ;
626
        end
627
    end
628
    endtask
629
 
630
//---------------------- Read Data suppression ----------------------
631
 
632
    task read_data_suppression;
633
        input       [DQ_BITS - 1 : 0] data      ;
634
        input       [DM_BITS - 1 : 0] dqm       ;
635
        output      [DQ_BITS - 1 : 0] mdata     ;
636
    begin
637
        for (i=0; i<DQ_BITS; i=i+1) begin
638
            if (~dqm[i/8]) begin
639
                mdata[i] = data[i];
640
            end else if (dqm[i/8]) begin
641
                mdata[i] = 1'bz;
642
            end
643
        end
644
    end
645
    endtask
646
 
647
//---------------------- Mask Data ----------------------
648
 
649
    task mask_data;
650
        input       [BA_BITS - 1 : 0] bank      ;
651
        input     [ADDR_BITS - 1 : 0] row       ;
652
        input      [COL_BITS - 1 : 0] col       ;
653
        input       [DQ_BITS - 1 : 0] data      ;
654
        input       [DM_BITS - 1 : 0] dqm       ;
655
        output      [DQ_BITS - 1 : 0] mdata     ;
656
        reg         [DQ_BITS - 1 : 0] read_data ;
657
    begin
658
        read_mem({bank, row, col}, read_data);
659
        for (i=0; i<DQ_BITS; i=i+1) begin
660
            if (~dqm[i/8]) begin
661
                mdata[i] = data[i];
662
            end else if (dqm[i/8]) begin
663
                mdata[i] = read_data[i];
664
            end
665
        end
666
    end
667
    endtask
668
 
669
//---------------------- Check for active read/write command task ----------------------
670
 
671
    task active_read_write;
672
    begin
673
        read_write_in_progress = 1'b0 ;
674
        for (i=0; i<cas_latency; i=i+1) begin
675
            if (|column_access_valid_q[i] != 1'b0) begin
676
                read_write_in_progress = 1'b1 ;
677
            end
678
        end
679
    end
680
    endtask
681
 
682
//---------------------- Auto-Precharge tasks ----------------------
683
 
684
    task interrupt_auto_precharge;
685
        input       [BA_BITS - 1 : 0] bank ;
686
    begin
687
        if (ap_set[bank]) begin
688
            if (interrupt_write_ap_n[bank] < 2) begin
689
                if ((interrupt_write_ap_n[bank]             == 1   ) &
690
                    (($time - tm_bank_activate[bank]) >= tRAS)  ) begin
691
                    ap_set[bank] = 1'b0 ;
692
                    precharge_cmd_func(bank, tWRa) ;
693
                    interrupt_write_ap_n[bank] = 2    ;
694
                end else begin
695
                    interrupt_write_ap_n[bank]   = 1    ;
696
                    ck_cntr_write_dq[bank] = 0    ;
697
                    tm_write_dq[bank]      = $time;
698
                end
699
            end else if (interrupt_read_ap_n[bank] == 0) begin
700
                if (($time - tm_bank_activate[bank]) >= tRAS) begin
701
                    ap_set[bank] = 1'b0 ;
702
                    precharge_cmd_func(bank, 0) ;
703
                    interrupt_read_ap_n[bank] = 1 ;
704
                end
705
            end
706
        end
707
    end
708
    endtask
709
 
710
    task auto_precharge_management;
711
    begin
712
        for (i=0; i<`BANKS; i=i+1) begin
713
            if (ap_set[i]) begin
714
                if (tm_bank_write[i] > tm_bank_read[i]) begin
715
                    if ((ck_cntr_bank_write[i]         >= burst_length) &
716
                        (($time - tm_bank_activate[i]) >= tRAS        )  ) begin
717
                        precharge_cmd_func(i, tWRa) ;
718
                    end
719
                end else begin
720
                    if ((ck_cntr_bank_read[i]          >= burst_length) &
721
                        (($time - tm_bank_activate[i]) >= tRAS        )  ) begin
722
                        precharge_cmd_func(i, 0) ;
723
                    end
724
                end
725
            end
726
        end
727
    end
728
    endtask
729
 
730
//---------------------- DQ Management ----------------------
731
 
732
    task data_management;
733
        output  [DQ_BITS - 1 :0] Dq_out                            ;
734
        reg     [DQ_BITS - 1 :0] rdata_out                         ;
735
    begin
736
        if (column_access_valid_q[0] == 2'b01) begin
737
            mask_data ( bank_access_q[0], row_access_q[0], column_access_q[0] , dq, dqm, mdata );
738
            write_mem ({bank_access_q[0], row_access_q[0], column_access_q[0]}, mdata   );
739
            if (~(|dqm == 1'b1)) begin
740
                ck_cntr_write_dq[bank_access_q[0]] = 0     ;
741
                tm_write_dq[bank_access_q[0]]      = $time ;
742
            end
743
        end
744
        if (column_access_valid_q[0] == 2'b10)  begin
745
            read_mem ({bank_access_q[0], row_access_q[0], column_access_q[0]}, rdata_out );
746
            read_data_suppression(rdata_out, dqm_q, Dq_out );
747
        end else begin
748
            Dq_out = 'bz ;
749
        end
750
    end
751
    endtask
752
//--------------------- dq buffer Output -----------------------
753
 
754
    task Dq_buffer_output;
755
    begin
756
        if (cas_latency == 3) begin
757
            Dq_out_tAC <= #tAC3 Dq_out ;
758
        end else if (cas_latency == 2) begin
759
            Dq_out_tAC <= #tAC2 Dq_out ;
760
        end else if (cas_latency == 1) begin
761
            Dq_out_tAC <= #tAC1 Dq_out ;
762
        end
763
    end
764
    endtask
765
 
766
//-------------------------------- Clk Stabilization Error Check -------------------------------
767
 
768
    task clk_stabilization_func;
769
    begin
770
        if (clk) begin
771
            tm_clk_low_pulse_width  = $time - tm_clk_negedge ;
772
            tm_clk_period           = $time - tm_clk_posedge ;
773
            tm_clk_posedge          = $time                  ;
774
        end else if (~clk) begin
775
            tm_clk_high_pulse_width = $time - tm_clk_posedge ;
776
            tm_clk_negedge          = $time                  ;
777
        end
778
    end
779
    endtask
780
 
781
    task clk_stabilization_err_chk;
782
    begin
783
        if (cke) begin
784
            if (tm_clk_high_pulse_width < tCH) begin
785
                if (DEBUG == 1'b1) begin
786
                    $sformat (msg, " : tCH violation, High Pulse Width = %t", tm_clk_high_pulse_width); ERROR(ERR_tCH, msg);
787
                end
788
            end
789
            if (tm_clk_low_pulse_width < tCL) begin
790
                if (DEBUG == 1'b1) begin
791
                    $sformat (msg, " : tCL violation, Low Pulse Width = %t", tm_clk_low_pulse_width); ERROR(ERR_tCL, msg);
792
                end
793
            end
794
            if (cas_latency == 3) begin
795
                if (tm_clk_period < tCK3_min) begin
796
                    if (DEBUG == 1'b1) begin
797
                        $sformat (msg, " : tCK Min violation, Clock Period = %t", tm_clk_period); ERROR(ERR_tCK_MIN, msg);
798
                    end
799
                end
800
            end else if (cas_latency == 2) begin
801
                if (tm_clk_period < tCK2_min) begin
802
                    if (DEBUG == 1'b1) begin
803
                        $sformat (msg, " : tCK Min violation, Clock Period = %t", tm_clk_period); ERROR(ERR_tCK_MIN, msg);
804
                    end
805
                end
806
            end else if (cas_latency == 1) begin
807
                if (tm_clk_period < tCK1_min) begin
808
                    if (DEBUG == 1'b1) begin
809
                        $sformat (msg, " : tCK Min violation, Clock Period = %t", tm_clk_period); ERROR(ERR_tCK_MIN, msg);
810
                    end
811
                end
812
            end
813
        end
814
    end
815
    endtask
816
 
817
//-------------------------------- Initialization tasks -------------------------------
818
 
819
    task initialization_cmd_func;                        // ************************** INITIALIZATION STATES ********************************
820
    begin                                                // initialization_state 0 - waiting for power up and stable clock
821
        if (initialization_state == 4'h0) begin          // initialization_state 1 - chip powered up and stable clock applied
822
            if (cke & ~cke_q) begin                      // initialization_state 2 - all banks precharged
823
                initialization_state = 4'h1 ;            // initialization_state 3 - one auto refresh command executed
824
            end                                          // initialization_state 4 - two auto refresh commands executed
825
        end else if (initialization_state == 4'h1) begin // initialization_state 5 - load mode command executed
826
            if (~(|active_bank)) begin                   // initialization_state 6 - extended load mode command executed
827
                initialization_state = 4'h2 ;            // initialization_state 7 - both load mode and extended load mode command executed
828
            end                                          // initialization_state 8 - tRFC after the second auto refresh command has expired
829
        end else if (initialization_state == 4'h2) begin // initialization_state 9 - Initialization message printed to the screen
830
            if (command == AUTO_REFRESH) begin
831
                initialization_state = 4'h3 ;
832
            end
833
        end else if (initialization_state == 4'h3) begin
834
            if (command == AUTO_REFRESH) begin
835
                initialization_state = 4'h4 ;
836
            end
837
        end else if (initialization_state == 4'h4) begin
838
            if ((command == LOAD_MODE) &
839
                (ba      == 0        )  ) begin
840
                initialization_state = 4'h5 ;
841
            end
842
            if ((command == LOAD_MODE) &
843
                (ba      == 2        )  ) begin
844
                initialization_state = 4'h6 ;
845
            end
846
        end else if (initialization_state == 4'h5) begin
847
            if ((command == LOAD_MODE) &
848
                (ba      == 2        )  ) begin
849
                initialization_state = 4'h7 ;
850
            end
851
        end else if (initialization_state == 4'h6) begin
852
            if ((command == LOAD_MODE) &
853
                (ba      == 0        )  ) begin
854
                initialization_state = 4'h7 ;
855
            end
856
        end else if (initialization_state == 4'h7) begin
857
            if (($time - tm_auto_refresh) > tRFC) begin
858
                initialization_state = 4'h8 ;
859
            end
860
        end else if (initialization_state == 4'h8) begin
861
            initialization_state = 4'h9 ;
862
        end
863
    end
864
    endtask
865
 
866
     task initialization_err_chk;
867
     begin
868
        if ((cke & ~cke_q) &
869
            (initialization_state != 4'h9)) begin
870
            $sformat (msg, "WARNING: SDRAM requires a 100us delay prior to issuing any command other than COMMAND INHIBIT or NOP"); WARN(msg);
871
        end
872
        if (((command == ACTIVATE  ) |
873
             (command == ACTIVATE  ) |
874
             (command == READ      ) |
875
             (command == READ_AP   ) |
876
             (command == WRITE     ) |
877
             (command == WRITE_AP  ) ) &
878
            (initialization_state < 8)  ) begin
879
            $sformat (msg, " ERROR: Initialization incomplete"); ERROR(ERR_MISC, msg);
880
        end
881
     end
882
     endtask
883
 
884
     task initialization_cmd_display;
885
     begin
886
        if (DEBUG == 1'b1) begin
887
            if (initialization_state == 8) begin
888
                $sformat (msg, " INIT : INITIALIZATION COMPLETE"); NOTE(msg);
889
            end
890
        end
891
     end
892
     endtask
893
 
894
//-------------------------------- Load Mode Tasks -------------------------------
895
 
896
    task load_mode_cmd_func;
897
    begin
898
        if (ba == 2'b10) begin
899
            set_ext_mode_reg;
900
//            Ext_mode_reg  = addr  ;
901
        end else if (ba == 2'b00) begin
902
//            Mode_reg      = addr  ;
903
            set_mode_reg;
904
        end
905
        ck_cntr_load_mode = 0     ;
906
        tm_load_mode      = $time ;
907
    end
908
    endtask
909
 
910
    task load_mode_err_chk;
911
    begin
912
        if (|active_bank) begin
913
            if (ba == 0) begin
914
                $sformat (msg, " ERROR: Bank is not Precharged for Lode Mode command, Bank = %d", i); ERROR(ERR_CMD, msg);
915
                $sformat (msg, " NOTE : Lode Mode command will be ignored"); NOTE(msg);
916
            end else if (ba == 2) begin
917
                $sformat (msg, " ERROR: Bank is not Precharged for Extended Lode Mode command, Bank = %d", i); ERROR(ERR_CMD, msg);
918
                $sformat (msg, " NOTE : Extended Lode Mode command will be ignored"); NOTE(msg);
919
            end
920
        end else begin
921
            if ((addr[3]   == 1'b1  ) &
922
                (addr[2:0] == 3'b111) ) begin
923
                $sformat (msg, " ERROR: Burst Type Interleaved is illegal with Full Page Mode, Bank = %d", i); ERROR(ERR_MISC, msg);
924
            end
925
            if ($time - tm_precharge  < tRP) begin
926
                $sformat (msg, " ERROR: tRP violation"); ERROR(ERR_tRP, msg);
927
            end
928
            if ($time - tm_auto_refresh  < tRFC) begin
929
                $sformat (msg, " ERROR: tRFC violation"); ERROR(ERR_tRFC, msg);
930
            end
931
            if (ck_cntr_load_mode  < tMRD) begin
932
                $sformat (msg, " ERROR: tMRD violation"); ERROR(ERR_tMRD, msg);
933
            end
934
        end
935
    end
936
    endtask
937
 
938
    task load_mode_cmd_display;
939
        input [BA_BITS - 1 : 0]   bank ;
940
        input [ADDR_BITS - 1 : 0] address ;
941
    begin
942
        if (bank == 2'b10) begin
943
            $sformat (msg, " LMR  :        EXTENDED LOAD MODE REGISTER"); NOTE(msg);
944
 
945
            // Self Refresh Coverage
946
            case (address[2 : 0])
947
                3'b000  : $sformat (msg, " EMR  :        Self Refresh Cov = 4 banks") ;
948
                3'b001  : $sformat (msg, " EMR  :        Self Refresh Cov = 2 banks") ;
949
                3'b010  : $sformat (msg, " EMR  :        Self Refresh Cov = 1 bank")  ;
950
                3'b101  : $sformat (msg, " EMR  :        Self Refresh Cov = 1/2 bank");
951
                3'b110  : $sformat (msg, " EMR  :        Self Refresh Cov = 1/4 bank");
952
                default : $sformat (msg, " EMR  : Error: Self Refresh Cov = Reserved");
953
            endcase
954
            NOTE(msg);
955
            // Maximum Case Temp
956
            //case (address[4 : 3])
957
                //2'b11    : $sformat (msg, " EMR  : Maximum Case Temp = 85C");
958
                //2'b00    : $sformat (msg, " EMR  : Maximum Case Temp = 70C");
959
                //2'b01    : $sformat (msg, " EMR  : Maximum Case Temp = 45C");
960
                //2'b10    : $sformat (msg, " EMR  : Maximum Case Temp = 15C");
961
            //endcase
962
            //NOTE(msg);
963
            // Drive Strength
964
            case (address[6 : 5])
965
                2'b00    : $sformat (msg, " EMR  :        Drive Strength    = Full Strength")   ;
966
                2'b01    : $sformat (msg, " EMR  :        Drive Strength    = Half Strength")   ;
967
                2'b10    : $sformat (msg, " EMR  :        Drive Strength    = Quarter Strength");
968
                2'b11    : $sformat (msg, " EMR  :        Drive Strength    = Eighth Strength") ;
969
                default  : $sformat (msg, " EMR  : Error: Drive Strength    = Reserved")        ;
970
            endcase
971
            NOTE(msg);
972
            // Reserved
973
            case (address[11 : 7])
974
                5'b00000  : begin end //do nothing
975
                default   : $sformat (msg, " EMR  : Error: Ext_mode_Reg[11:7] are Reserved");
976
            endcase
977
            NOTE(msg);
978
            set_ext_mode_reg;
979
        end else if (bank == 2'b00) begin
980
            $sformat (msg, " LMR  :        LOAD MODE REGISTER"); NOTE(msg);
981
 
982
            // Burst Length
983
            case (address[2 : 0])
984
                3'b000  : $sformat (msg, " LMR  :        Burst Length     = 1")       ;
985
                3'b001  : $sformat (msg, " LMR  :        Burst Length     = 2")       ;
986
                3'b010  : $sformat (msg, " LMR  :        Burst Length     = 4")       ;
987
                3'b011  : $sformat (msg, " LMR  :        Burst Length     = 8")       ;
988
                3'b111  : $sformat (msg, " LMR  :        Burst Length     = Full")    ;
989
                default : $sformat (msg, " LMR  : Error: Burst Length     = Reserved");
990
            endcase
991
            NOTE(msg);
992
            // Burst Type
993
            if (address[3] === 1'b0) begin
994
                $sformat (msg, " LMR  :        Burst Type       = Sequential"); NOTE(msg);
995
            end else if (address[3] === 1'b1) begin
996
                $sformat (msg, " LMR  :        Burst Type       = Interleaved"); NOTE(msg);
997
            end else begin
998
                $sformat (msg, " LMR  : Error: Burst Type       = Reserved"); NOTE(msg);
999
            end
1000
 
1001
            // CAS Latency
1002
            case (address[6 : 4])
1003
                3'b001  : $sformat (msg, " LMR  :        CAS Latency      = 1")       ;
1004
                3'b010  : $sformat (msg, " LMR  :        CAS Latency      = 2")       ;
1005
                3'b011  : $sformat (msg, " LMR  :        CAS Latency      = 3")       ;
1006
                default : $sformat (msg, " LMR  : Error: CAS Latency      = Reserved");
1007
            endcase
1008
            NOTE(msg);
1009
            // Op Mode
1010
            case (address[8 : 7])
1011
                2'b00  : begin end  // do nothing
1012
                default : $sformat (msg, " LMR  : Error: CAS Latency      = Reserved");
1013
            endcase
1014
            NOTE(msg);
1015
            // Write Burst Mode
1016
            if (address[9] === 1'b0) begin
1017
                $sformat (msg, " LMR  :        Write Burst Mode = Programmed Burst Length"); NOTE(msg);
1018
            end else if (address[9] === 1'b1) begin
1019
                $sformat (msg, " LMR  :        Write Burst Mode = Single Location Access"); NOTE(msg);
1020
            end else begin
1021
                $sformat (msg, " LMR  : Error: Write Burst Mode = Reserved"); NOTE(msg);
1022
            end
1023
            // Reserved
1024
            case (address[11 : 10])
1025
                5'b00000  : begin end //do nothing
1026
                default   : $sformat (msg, " LMR  : Error: Ext_mode_Reg[11:10] should be 0");
1027
            endcase
1028
            NOTE(msg);
1029
            set_mode_reg;
1030
        end
1031
    end
1032
    endtask
1033
 
1034
//-------------------------------- Activate Tasks -------------------------------
1035
 
1036
    task activate_cmd_func;
1037
        input    [BA_BITS-1 : 0] bank ;
1038
        input  [ADDR_BITS-1 : 0] address ;
1039
    begin
1040
        activate_row[bank]          = address  ;
1041
        active_bank[bank]           = 1'b1  ;
1042
        ck_cntr_activate[bank]      = 0     ;
1043
        tm_activate[bank]           = $time ;
1044
        ck_cntr_bank_activate[bank] = 0     ;
1045
        tm_bank_activate[bank]      = $time ;
1046
    end
1047
    endtask
1048
 
1049
    task activate_err_chk;
1050
    begin
1051
        if (active_bank[ba] == 1'b1) begin
1052
            $sformat (msg, " ERROR: Bank already activated -- data can be corrupted"); ERROR(ERR_CMD, msg);
1053
            $sformat (msg, " NOTE : Activate command will be ignored :  Bank = %d", ba); NOTE(msg);
1054
            command_sequence_error = 1;
1055
        end else begin
1056
 
1057
`ifdef Y15W
1058
            for (i=0; i<`BANKS; i=i+1) begin
1059
                if (i != ba) begin
1060
                    if (ck_cntr_bank_activate[i]  < tRRD) begin
1061
                        $sformat (msg, " ERROR: tRRD violation :  Bank = %d", ba); ERROR(ERR_tRRD, msg);
1062
                    end
1063
                end
1064
            end
1065
`else `ifdef Y25M
1066
            for (i=0; i<`BANKS; i=i+1) begin
1067
                if (i != ba) begin
1068
                    if ($time - tm_bank_activate[i]  < tRRD) begin
1069
                        $sformat (msg, " ERROR: tRRD violation :  Bank = %d", ba); ERROR(ERR_tRRD, msg);
1070
                    end
1071
                end
1072
            end
1073
`else `ifdef Y26W
1074
            for (i=0; i<`BANKS; i=i+1) begin
1075
                if (i != ba) begin
1076
                    if ($time - tm_bank_activate[i]  < tRRD) begin
1077
                        $sformat (msg, " ERROR: tRRD violation :  Bank = %d", ba); ERROR(ERR_tRRD, msg);
1078
                    end
1079
                end
1080
            end
1081
`else
1082
            if ((part_size == 128) |
1083
                (part_size == 64 ) ) begin
1084
                for (i=0; i<`BANKS; i=i+1) begin
1085
                    if (i != ba) begin
1086
                        if ($time - tm_bank_activate[i]  < tRRD) begin
1087
                            $sformat (msg, " ERROR: tRRD violation :  Bank = %d", ba); ERROR(ERR_tRRD, msg);
1088
                        end
1089
                    end
1090
                end
1091
            end else begin
1092
                for (i=0; i<`BANKS; i=i+1) begin
1093
                    if (i != ba) begin
1094
                        if (ck_cntr_bank_activate[i]  < tRRD) begin
1095
                            $sformat (msg, " ERROR: tRRD violation :  Bank = %d", ba); ERROR(ERR_tRRD, msg);
1096
                        end
1097
                    end
1098
                end
1099
            end
1100
`endif `endif `endif
1101
 
1102
            if ($time - tm_bank_activate[ba]  < tRC) begin
1103
                $sformat (msg, " ERROR: tRC violation :  Bank = %d", ba); ERROR(ERR_tRC, msg);
1104
            end
1105
            if ($time - tm_bank_precharge[ba]  < tRP) begin
1106
                $sformat (msg, " ERROR: tRP violation :  Bank = %d", ba); ERROR(ERR_tRP, msg);
1107
            end
1108
            if ($time - tm_auto_refresh  < tRFC) begin
1109
                $sformat (msg, " ERROR: tRFC violation :  Bank = %d", ba); ERROR(ERR_tRFC, msg);
1110
            end
1111
            if (($time - tm_cke_high < tXSR) &
1112
                (self_refresh_enter == 1   )  ) begin
1113
                $sformat (msg, " ERROR: tXSR violation"); ERROR(ERR_tXSR, msg);
1114
            end
1115
            if (ck_cntr_load_mode  < tMRD) begin
1116
                $sformat (msg, " ERROR: tMRD violation"); ERROR(ERR_tMRD, msg);
1117
            end
1118
            if (active_bank[ba] == 1'b1) begin
1119
                $sformat (msg, " ERROR: Bank already activated -- data can be corrupted"); ERROR(ERR_CMD, msg);
1120
            end
1121
            self_refresh_enter = 0 ;
1122
        end
1123
    end
1124
    endtask
1125
 
1126
    task activate_cmd_display;
1127
    begin
1128
        if (DEBUG == 1'b1) begin
1129
            $sformat (msg, " ACT  : ACTIVATE - Bank = %d Row = %h", ba, addr); NOTE(msg);
1130
        end
1131
    end
1132
    endtask
1133
 
1134
//-------------------------------- Precharge Tasks -------------------------------
1135
 
1136
    task precharge_cmd_func;
1137
        input  [BA_BITS-1 : 0] bank ;
1138
        input  integer         delay;
1139
    begin
1140
        if (delay > 0) begin
1141
            active_bank[bank]              <= #delay 1'b0            ;
1142
            ck_cntr_bank_precharge[bank]   <= #delay 0               ;
1143
            ck_cntr_precharge              <= #delay 0               ;
1144
            tm_bank_precharge[bank]        <= #delay ($time + delay) ;
1145
            tm_precharge                   <= #delay ($time + delay) ;
1146
            ap_set[bank]                   <= #delay 1'b0            ;
1147
        end else begin
1148
            active_bank[bank]              = 1'b0                    ;
1149
            ck_cntr_bank_precharge[bank]   = 0                       ;
1150
            ck_cntr_precharge              = 0                       ;
1151
            tm_bank_precharge[bank]        = $time                   ;
1152
            tm_precharge                   = $time                   ;
1153
            ap_set[bank]                   = 1'b0                    ;
1154
            // Precharge interrupt a read command to the same bank
1155
            if (bank_access_q[0] == bank) begin
1156
                for (i=(cas_latency-1); i<((cas_latency-1)+burst_length); i=i+1) begin
1157
                    if (bank_access_q[i] == bank) begin
1158
                        column_access_valid_q[i] = 2'b00 ;
1159
                    end
1160
                end
1161
            end
1162
            // Precharge interrupt a write command to the same bank
1163
            if ((bank_access_q[0] == bank         ) &
1164
                (column_access_valid_q[0] == 2'b01) ) begin
1165
                for (i=0; i<burst_length; i=i+1) begin
1166
                    if (bank_access_q[i] == bank) begin
1167
                        column_access_valid_q[i] = 2'b00 ;
1168
                    end
1169
                end
1170
            end
1171
        end
1172
    end
1173
    endtask
1174
 
1175
    task precharge_err_chk;
1176
        input  [BA_BITS-1 : 0] bank ;
1177
    begin
1178
        if (active_bank[bank] == 1'b1) begin
1179
            if ($time - tm_bank_activate[bank] < tRAS) begin
1180
                $sformat (msg, " ERROR: tRAS violation :  Bank = %d", bank); ERROR(ERR_tRAS, msg);
1181
            end
1182
            if ($time - tm_write_dq[bank] < tWRm) begin
1183
                $sformat (msg, " ERROR: tWR violation :  Bank = %d", bank); ERROR(ERR_tWR, msg);
1184
            end
1185
            if ($time - tm_auto_refresh < tRFC) begin
1186
                $sformat (msg, " ERROR: tRFC violation"); ERROR(ERR_tRFC, msg);
1187
            end
1188
            if (ck_cntr_load_mode < tMRD) begin
1189
                $sformat (msg, " ERROR: tMRD violation"); ERROR(ERR_tMRD, msg);
1190
            end
1191
            if ((ap_set[bank] == 1'b1) &
1192
                (ba == bank          )  ) begin
1193
                $sformat (msg, " ERROR: Precharge issued to bank currently in auto precharge mode :  Bank = %d", bank); ERROR(ERR_CMD, msg);
1194
                $sformat (msg, " NOTE : Precharge command will be ignored :  Bank = %d", ba); NOTE(msg);
1195
                command_sequence_error = 1 ;
1196
            end
1197
            if ((column_access_valid_q[0] == 2'b01  ) &
1198
                (ap_set[bank] == 1'b0               ) &
1199
                (dqm != {DM_BITS{1'b1}}             ) ) begin
1200
                $sformat (msg, " ERROR: Incorrect assertion of data masks during write to precharge, Bank = %d", bank); ERROR(ERR_MISC, msg);
1201
            end
1202
        end
1203
    end
1204
    endtask
1205
 
1206
    task precharge_cmd_display;
1207
        input  [BA_BITS-1 : 0] bank ;
1208
    begin
1209
        if (DEBUG == 1'b1) begin
1210
            $sformat (msg, " PRE  : PRECHARGE - Bank = %d", bank); NOTE(msg);
1211
        end
1212
    end
1213
    endtask
1214
 
1215
//-------------------------------- Precharge All Tasks -------------------------------
1216
 
1217
    task precharge_all_cmd_func;
1218
    begin
1219
        for (i=0; i<`BANKS; i=i+1) begin
1220
            precharge_cmd_func(i, 0);
1221
        end
1222
    end
1223
    endtask
1224
 
1225
    task precharge_all_err_chk;
1226
    begin
1227
        for (i=0; i<`BANKS; i=i+1) begin
1228
            precharge_err_chk(i);
1229
        end
1230
    end
1231
    endtask
1232
 
1233
    task precharge_all_cmd_display;
1234
    begin
1235
        if (DEBUG == 1'b1) begin
1236
            $sformat (msg, "PREALL: PRECHARGE ALL"); NOTE(msg);
1237
        end
1238
    end
1239
    endtask
1240
 
1241
//-------------------------------- Write Tasks -------------------------------
1242
 
1243
    task write_cmd_func;
1244
    begin
1245
        column_burst_order             ;
1246
        column_address_write_queue     ;
1247
        tm_write               = $time ;
1248
        tm_bank_write[ba]      = $time ;
1249
        ck_cntr_write          = 0     ;
1250
        ck_cntr_bank_write[ba] = 0     ;
1251
        // write interrupt write ap
1252
        if ((column_access_valid_q[0] == 2'b01) &
1253
            (bank_access_q[0]    != ba        ) &
1254
            (|ap_set                          )  ) begin
1255
            interrupt_write_ap_n[ba]  = 0               ;
1256
            interrupt_bank            = bank_access_q[0];
1257
        end
1258
        // write interrupt read ap
1259
        if ((column_access_valid_q[0] == 2'b10) &
1260
            (bank_access_q[0]  != ba          ) &
1261
            (|ap_set                          )  ) begin
1262
            interrupt_read_ap_n[ba] = 0               ;
1263
            interrupt_bank          = bank_access_q[0];
1264
        end
1265
    end
1266
    endtask
1267
 
1268
    task write_err_chk;
1269
    begin
1270
        if (active_bank[ba] == 1'b0) begin
1271
            $sformat (msg, " ERROR: Bank is not Activated for Write, Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1272
            $sformat (msg, " NOTE : Write command will be ignored :  Bank = %d", ba); NOTE(msg);
1273
            command_sequence_error = 1 ;
1274
        end else begin
1275
            if (($time - tm_bank_activate[ba]) < tRCD) begin
1276
                $sformat (msg, " ERROR: tRCD violation :  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_tRCD, msg);
1277
            end
1278
            if ((ap_set[ba] == 1'b1        ) &
1279
                (tm_bank_write[ba] > tm_bank_read[ba])  ) begin
1280
                $sformat (msg, " ERROR: Write interrupt Write with autoprecharge to the same bank:  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1281
                $sformat (msg, " NOTE : Write command will be ignored :  Bank = %d", ba); NOTE(msg);
1282
                command_sequence_error = 1'b1 ;
1283
            end
1284
            if ((ap_set[ba] == 1'b1        ) &
1285
                (tm_bank_write[ba] < tm_bank_read[ba])  ) begin
1286
                $sformat (msg, " ERROR: Write interrupt Read with autoprecharge to the same bank:  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1287
                $sformat (msg, " NOTE : Write command will be ignored :  Bank = %d", ba); NOTE(msg);
1288
                command_sequence_error = 1'b1 ;
1289
            end
1290
            if (((dqm_rtw_chk[0] == 1'b1        ) |
1291
                 (dqm_rtw_chk[1] == 1'b1        ) ) &
1292
                (ap_set[ba] == 1'b0               )  ) begin
1293
                $sformat (msg, " ERROR: DQ contention caused by incorrect assertion of data masks during read to write, Bank = %d", ba); ERROR(ERR_MISC, msg);
1294
            end
1295
        end
1296
    end
1297
    endtask
1298
 
1299
    task write_cmd_display;
1300
    begin
1301
        if (DEBUG == 1'b1) begin
1302
            $sformat (msg, " WR   : WRITE - Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); NOTE(msg);
1303
        end
1304
    end
1305
    endtask
1306
 
1307
//-------------------------------- Read Tasks -------------------------------
1308
 
1309
    task read_cmd_func;
1310
    begin
1311
        column_burst_order             ;
1312
        if (column_access_valid_q[0] == 2'b01) begin
1313
            for (i=0; i<(burst_length+cas_latency-1); i=i+1) begin
1314
                column_access_valid_q[i] = 2'b00 ;
1315
            end
1316
        end
1317
        column_address_read_queue      ;
1318
        tm_read               = $time  ;
1319
        tm_bank_read[ba]      = $time  ;
1320
        ck_cntr_read          = 0      ;
1321
        ck_cntr_bank_read[ba] = 0      ;
1322
        // read interrupt write ap
1323
        if ((column_access_valid_q[0] == 2'b01) &
1324
            (|ap_set                          )  ) begin
1325
            interrupt_write_ap_n[ba] = 0               ;
1326
            interrupt_bank           = bank_access_q[0];
1327
        end
1328
        // read interrupt read ap
1329
        if ((column_access_valid_q[0] == 2'b10) &
1330
            (|ap_set                          )  ) begin
1331
            interrupt_read_ap_n[ba] = 0               ;
1332
            interrupt_bank          = bank_access_q[0];
1333
        end
1334
    end
1335
    endtask
1336
 
1337
    task read_err_chk;
1338
    begin
1339
        if (active_bank[ba] == 1'b0) begin
1340
            $sformat (msg, " ERROR: Bank is not Activated for Read, Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1341
            $sformat (msg, " NOTE : Read command will be ignored :  Bank = %d", ba); NOTE(msg);
1342
            command_sequence_error = 1 ;
1343
        end else begin
1344
            if (($time - tm_bank_activate[ba]) < tRCD) begin
1345
                $sformat (msg, " ERROR: tRCD violation :  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_tRCD, msg);
1346
            end
1347
            if ((ap_set[ba] == 1'b1                  ) &
1348
                (tm_bank_write[ba] > tm_bank_read[ba])  ) begin
1349
                $sformat (msg, " ERROR: Read interrupt Write with autoprecharge to the same bank:  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1350
                $sformat (msg, " NOTE : Read command will be ignored :  Bank = %d", ba); NOTE(msg);
1351
                command_sequence_error = 1 ;
1352
            end
1353
            if ((ap_set[ba] == 1'b1                  ) &
1354
                (tm_bank_write[ba] < tm_bank_read[ba])  ) begin
1355
                $sformat (msg, " ERROR: Read interrupt Read with autoprecharge to the same bank:  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1356
                $sformat (msg, " NOTE : Read command will be ignored :  Bank = %d", ba); NOTE(msg);
1357
                command_sequence_error = 1 ;
1358
            end
1359
        end
1360
    end
1361
    endtask
1362
 
1363
    task read_cmd_display;
1364
    begin
1365
        if (DEBUG == 1'b1) begin
1366
            $sformat (msg, " RD   : READ - Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); NOTE(msg);
1367
        end
1368
    end
1369
    endtask
1370
 
1371
//-------------------------------- Write with auto-precharge Tasks -------------------------------
1372
 
1373
    task write_ap_cmd_func;
1374
    begin
1375
        column_burst_order             ;
1376
        column_address_write_queue     ;
1377
        tm_write               = $time ;
1378
        tm_bank_write[ba]      = $time ;
1379
        ck_cntr_write          = 0     ;
1380
        ck_cntr_bank_write[ba] = 0     ;
1381
        // write ap interrupt write ap
1382
        if ((column_access_valid_q[0] == 2'b01) &
1383
            (|ap_set                          )  ) begin
1384
            interrupt_write_ap_n[ba] = 0               ;
1385
            interrupt_bank           = bank_access_q[0];
1386
        end
1387
        // write ap interrupt read ap
1388
        if ((column_access_valid_q[0] == 2'b10) &
1389
            (|ap_set                          )  ) begin
1390
            interrupt_read_ap_n[ba] = 0               ;
1391
            interrupt_bank          = bank_access_q[0];
1392
        end
1393
        ap_set[ba]             = 1     ;
1394
    end
1395
    endtask
1396
 
1397
    task write_ap_err_chk;
1398
    begin
1399
        if (active_bank[ba] == 1'b0) begin
1400
            $sformat (msg, " ERROR: Bank is not Activated for Write with autoprecharge, Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1401
            $sformat (msg, " NOTE : Write with autoprecharge command will be ignored :  Bank = %d", ba); NOTE(msg);
1402
            command_sequence_error = 1'b1 ;
1403
        end else begin
1404
            if (($time - tm_bank_activate[ba]) < tRCD) begin
1405
                $sformat (msg, " ERROR: tRCD violation :  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_tRCD, msg);
1406
            end
1407
            if ((ap_set[ba] == 1'b1        ) &
1408
                (tm_bank_write[ba] > tm_bank_read[ba])  ) begin
1409
                $sformat (msg, " ERROR: Write with autoprecharge  interrupt Write with autoprecharge to the same bank:  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1410
                $sformat (msg, " NOTE : Write with autoprecharge command will be ignored :  Bank = %d", ba); NOTE(msg);
1411
                command_sequence_error = 1'b1 ;
1412
            end
1413
            if ((ap_set[ba] == 1'b1        ) &
1414
                (tm_bank_write[ba] < tm_bank_read[ba])  ) begin
1415
                $sformat (msg, " ERROR: Write with autoprecharge  interrupt Read with autoprecharge to the same bank:  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1416
                $sformat (msg, " NOTE : Write with autoprecharge command will be ignored :  Bank = %d", ba); NOTE(msg);
1417
                command_sequence_error = 1'b1 ;
1418
            end
1419
            if (((dqm_rtw_chk[0] == 1'b1        ) |
1420
                 (dqm_rtw_chk[1] == 1'b1        ) ) &
1421
                (ap_set[ba] == 1'b0               )  ) begin
1422
                $sformat (msg, " ERROR: DQ contention caused by incorrect assertion of data masks during read to write, Bank = %d", ba); ERROR(ERR_CMD, msg);
1423
            end
1424
        end
1425
    end
1426
    endtask
1427
 
1428
    task write_ap_cmd_display;
1429
    begin
1430
        if (DEBUG == 1'b1) begin
1431
            $sformat (msg, " WRAP : WRITE WITH AUTOPRECHARGE - Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); NOTE(msg);
1432
        end
1433
    end
1434
    endtask
1435
 
1436
//-------------------------------- Read with auto-precharge Tasks -------------------------------
1437
 
1438
    task read_ap_cmd_func;
1439
    begin
1440
        column_burst_order             ;
1441
        if (column_access_valid_q[0] == 2'b01) begin
1442
            for (i=0; i<(burst_length+cas_latency-1); i=i+1) begin
1443
                column_access_valid_q[i] = 2'b00 ;
1444
            end
1445
        end
1446
        column_address_read_queue      ;
1447
        tm_read                = $time ;
1448
        tm_bank_read[ba]       = $time ;
1449
        ck_cntr_read           = 0     ;
1450
        ck_cntr_bank_read[ba]  = 0     ;
1451
        // read interrupt write ap
1452
        if ((column_access_valid_q[0] == 2'b01) &
1453
            (bank_access_q[0]    != ba        ) &
1454
            (|ap_set                          )  ) begin
1455
            interrupt_write_ap_n[ba] = 0               ;
1456
            interrupt_bank           = bank_access_q[0];
1457
        end
1458
        // read interrupt read ap
1459
        if ((column_access_valid_q[0] == 2'b10) &
1460
            (bank_access_q[0]    != ba        ) &
1461
            (|ap_set                          )  ) begin
1462
            interrupt_read_ap_n[ba] = 0               ;
1463
            interrupt_bank          = bank_access_q[0];
1464
        end
1465
        ap_set[ba]             = 1     ;
1466
    end
1467
    endtask
1468
 
1469
    task read_ap_err_chk;
1470
    begin
1471
        if (active_bank[ba] == 1'b0) begin
1472
            $sformat (msg, " ERROR: Bank is not Activated for Read with autoprecharge, Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1473
            $sformat (msg, " NOTE : Read with autoprecharge command will be ignored :  Bank = %d", ba); NOTE(msg);
1474
            command_sequence_error = 1'b1 ;
1475
        end else begin
1476
            if (($time - tm_bank_activate[ba]) < tRCD) begin
1477
                $sformat (msg, " ERROR: tRCD violation :  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_tRCD, msg);
1478
            end
1479
            if ((ap_set[ba] == 1'b1                  ) &
1480
                (tm_bank_write[ba] > tm_bank_read[ba])  ) begin
1481
                $sformat (msg, " ERROR: Read with autoprecharge interrupt Write with autoprecharge to the same bank:  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1482
                $sformat (msg, " NOTE : Read with autoprecharge command will be ignored :  Bank = %d", ba); NOTE(msg);
1483
                command_sequence_error = 1'b1 ;
1484
            end
1485
            if ((ap_set[ba] == 1'b1                  ) &
1486
                (tm_bank_write[ba] < tm_bank_read[ba])  ) begin
1487
                $sformat (msg, " ERROR: Read with autoprecharge interrupt Read with autoprecharge to the same bank:  Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); ERROR(ERR_CMD, msg);
1488
                $sformat (msg, " NOTE : Read with autoprecharge command will be ignored :  Bank = %d", ba); NOTE(msg);
1489
                command_sequence_error = 1'b1 ;
1490
            end
1491
        end
1492
    end
1493
    endtask
1494
 
1495
    task read_ap_cmd_display;
1496
    begin
1497
        if (DEBUG == 1'b1) begin
1498
            $sformat (msg, " RDAP : READ WITH AUTOPRECHARGE - Bank = %d, Row = %h, Col = %h", ba, activate_row[ba], addr); NOTE(msg);
1499
        end
1500
    end
1501
    endtask
1502
 
1503
//-------------------------------- Auto-refresh Tasks -------------------------------
1504
 
1505
    task auto_refresh_cmd_func;
1506
    begin
1507
        tm_auto_refresh      = $time ;
1508
        ck_cntr_auto_refresh = 0     ;
1509
    end
1510
    endtask
1511
 
1512
    task auto_refresh_err_chk;
1513
    begin
1514
        if (|active_bank) begin
1515
            $sformat (msg, " ERROR: Banks are not precharged for auto refresh"); ERROR(ERR_CMD, msg);
1516
            $sformat (msg, " NOTE : Auto refresh command will be ignored :  Bank = %d", ba); NOTE(msg);
1517
            command_sequence_error = 1'b1 ;
1518
        end else begin
1519
            if (($time - tm_precharge) < tRP) begin
1520
                $sformat (msg, " ERROR: tRP violation during auto refresh"); ERROR(ERR_tRP, msg);
1521
            end
1522
            if (($time - tm_auto_refresh) < tRFC) begin
1523
                $sformat (msg, " ERROR: tRFC violation during auto refresh"); ERROR(ERR_tRFC, msg);
1524
            end
1525
            if (ck_cntr_load_mode < tMRD) begin
1526
                $sformat (msg, " ERROR: tMRD violation during auto refresh"); ERROR(ERR_tMRD, msg);
1527
            end
1528
        end
1529
    end
1530
    endtask
1531
 
1532
    task auto_refresh_cmd_display;
1533
    begin
1534
        if (DEBUG == 1'b1) begin
1535
            $sformat (msg, " AREF : AUTO REFRESH"); NOTE(msg);
1536
        end
1537
    end
1538
    endtask
1539
 
1540
//-------------------------------- Self-refresh Tasks -------------------------------
1541
 
1542
    task self_refresh_cmd_func;
1543
    begin
1544
        erase_mem(pasr);
1545
        tm_self_refresh      = $time ;
1546
        ck_cntr_self_refresh = 0     ;
1547
        self_refresh_enter   = 1     ;
1548
    end
1549
    endtask
1550
 
1551
    task self_refresh_err_chk;
1552
    begin
1553
        if (|active_bank) begin
1554
            $sformat (msg, " ERROR: Banks are not precharged for self refresh command"); ERROR(ERR_CMD, msg);
1555
        end else begin
1556
            if (($time - tm_precharge) < tRP) begin
1557
                $sformat (msg, " ERROR: tRP violation during self refresh command"); ERROR(ERR_tRP, msg);
1558
            end
1559
            if (($time - tm_auto_refresh) < tRFC) begin
1560
                $sformat (msg, " ERROR: tRFC violation during self refresh command"); ERROR(ERR_tRFC, msg);
1561
            end
1562
            if (ck_cntr_load_mode < tMRD) begin
1563
                $sformat (msg, " ERROR: tMRD violation during self refresh command"); ERROR(ERR_tMRD, msg);
1564
            end
1565
        end
1566
    end
1567
    endtask
1568
 
1569
    task self_refresh_cmd_display;
1570
    begin
1571
        if (DEBUG == 1'b1) begin
1572
            $sformat (msg, " SREF : SELF REFRESH"); NOTE(msg);
1573
        end
1574
    end
1575
    endtask
1576
 
1577
//-------------------------------- ???????????????? -------------------------------
1578
 
1579
 
1580
    task clock_suspend_cmd_func;
1581
    begin
1582
        tm_clock_suspend      = $time ;
1583
        ck_cntr_clock_suspend = 0     ;
1584
    end
1585
    endtask
1586
 
1587
    task clock_suspend_err_chk;
1588
    begin
1589
    end
1590
    endtask
1591
 
1592
    task clock_suspend_cmd_display;
1593
    begin
1594
        if (DEBUG == 1'b1) begin
1595
            $sformat (msg, " CKSM : CLOCK SUSPEND MODE"); NOTE(msg);
1596
        end
1597
    end
1598
    endtask
1599
 
1600
//-------------------------------- Exit Power Down Tasks -------------------------------
1601
 
1602
//------------- Parameters (cke, addr[10], cs_n, ras_n, cas_n, we_n) --------------
1603
 
1604
    task exit_power_down_err_chk;
1605
    begin
1606
        if (cke & ~cke_q) begin
1607
            if ((power_down_enter == 1'b1  ) |
1608
                (self_refresh_enter == 1'b1) ) begin
1609
                if (~( (command == NOP) |
1610
                       (cke & cs_n    ) ) ) begin
1611
                    $sformat (msg, " ERROR: exit powerdown violation"); ERROR(ERR_CMD, msg);
1612
                end
1613
                power_down_enter = 1'b0;
1614
            end
1615
        end
1616
    end
1617
    endtask
1618
 
1619
//-------------------------------- Power Down Tasks -------------------------------
1620
 
1621
    task power_down_cmd_func;
1622
    begin
1623
        tm_power_down      = $time ;
1624
        ck_cntr_power_down = 0     ;
1625
    end
1626
    endtask
1627
 
1628
    task power_down_err_chk;
1629
    begin
1630
        if (|active_bank) begin
1631
            $sformat (msg, " ERROR: All banks need to be precharged before powerdown"); ERROR(ERR_CMD, msg);
1632
        end else begin
1633
            if (ck_cntr_precharge < 2) begin
1634
                $sformat (msg, " ERROR: precharge to powerdown violation"); ERROR(ERR_MISC, msg);
1635
            end
1636
            if (($time - tm_auto_refresh) < tRFC) begin
1637
                $sformat (msg, " ERROR: tRFC violation"); ERROR(ERR_tRFC, msg);
1638
            end
1639
            if (ck_cntr_load_mode < tMRD) begin
1640
                $sformat (msg, " ERROR: tMRD violation"); ERROR(ERR_tMRD, msg);
1641
            end
1642
            power_down_enter = 1'b1 ;
1643
        end
1644
    end
1645
    endtask
1646
 
1647
    task power_down_cmd_display;
1648
    begin
1649
        if (DEBUG == 1'b1) begin
1650
            $sformat (msg, " PREPD: PRECHARGE POWERDOWN"); NOTE(msg);
1651
        end
1652
    end
1653
    endtask
1654
 
1655
 
1656
//-------------------------------- Deep Power Down Tasks -------------------------------
1657
 
1658
    task deep_power_down_cmd_func;
1659
    begin
1660
        if (cke_q) begin
1661
            erase_mem(0);
1662
        end
1663
        tm_deep_power_down      = $time ;
1664
        ck_cntr_deep_power_down = 0     ;
1665
    end
1666
    endtask
1667
 
1668
    task deep_power_down_err_chk;
1669
    begin
1670
        if (($time - ck_cntr_precharge) < 2) begin
1671
            $sformat (msg, " ERROR: precharge to deep power down violation"); ERROR(ERR_CMD, msg);
1672
        end
1673
        if (($time - tm_auto_refresh) < tRFC) begin
1674
            $sformat (msg, " ERROR: auto refresh to deep power down violation"); ERROR(ERR_tRFC, msg);
1675
        end
1676
        if (ck_cntr_load_mode < tMRD) begin
1677
            $sformat (msg, " ERROR: load mode to deep power down violation"); ERROR(ERR_tMRD, msg);
1678
        end
1679
    end
1680
    endtask
1681
 
1682
    task deep_power_down_cmd_display;
1683
    begin
1684
        if (DEBUG == 1'b1) begin
1685
            $sformat (msg, " DPD  : DEEP POWERDOWN"); NOTE(msg);
1686
        end
1687
    end
1688
    endtask
1689
 
1690
//-------------------------------- Deep Power Down Tasks -------------------------------
1691
 
1692
    task burst_term_cmd_func;
1693
        time tm_bank_burst_term ;
1694
    begin
1695
        tm_bank_burst_term = 0 ;
1696
        for (i=0; i<`BANKS; i=i+1) begin
1697
            if (tm_bank_read[i]  > tm_bank_burst_term) begin
1698
                tm_bank_burst_term    = tm_bank_read[i]  ;
1699
                burst_term_read_queue  ;
1700
            end
1701
            if (tm_bank_write[i] > tm_bank_burst_term) begin
1702
                tm_bank_burst_term    = tm_bank_write[i] ;
1703
                burst_term_write_queue ;
1704
            end
1705
        end
1706
        tm_burst_terminate      = $time ;
1707
        ck_cntr_burst_terminate = 0     ;
1708
    end
1709
    endtask
1710
 
1711
    task burst_term_err_chk;
1712
    begin
1713
    end
1714
    endtask
1715
 
1716
    task burst_term_cmd_display;
1717
    begin
1718
        if (DEBUG == 1'b1) begin
1719
            $sformat (msg, " BT   : BURST TERMINATE"); NOTE(msg);
1720
        end
1721
    end
1722
    endtask
1723
 
1724
//-------------------------------- Exit Power Down (cke high) Tasks -------------------------------
1725
 
1726
    task cke_cmd_func;
1727
    begin
1728
        if (cke & ~cke_q) begin
1729
            tm_cke      = $time ;
1730
            ck_cntr_cke = 0     ;
1731
        end
1732
    end
1733
    endtask
1734
 
1735
    task cke_err_chk;
1736
    begin
1737
        if (cke & ~cke_q) begin
1738
            if (tm_cke_high - tm_self_refresh < tRAS) begin
1739
                $sformat (msg, " ERROR: tRAS violation during self refresh command exit"); ERROR(ERR_tRAS, msg);
1740
            end
1741
        end
1742
    end
1743
    endtask
1744
 
1745
//---------------------- Error count ----------------------
1746
 
1747
task ERROR;
1748
   input [7:0] errcode;
1749
   input [MSGLENGTH*8:1] msg;
1750
begin
1751
 
1752
    errcount[errcode] = errcount[errcode] + 1;
1753
    errors = errors + 1;
1754
 
1755
    if ((errcount[errcode] <= ERR_MAX_REPORTED) || (ERR_MAX_REPORTED < 0))
1756
        if ((EXP_ERR[errcode] === 1) && ((errcount[errcode] <= ERR_MAX_INT) || (ERR_MAX_INT < 0))) begin
1757
            $display("Caught expected violation at time %t: %0s", $time, msg);
1758
        end else begin
1759
            $display("%m at time %t: %0s", $time, msg);
1760
        end
1761
    if (errcount[errcode] == ERR_MAX_REPORTED) begin
1762
        $sformat(msg, "Reporting for %s has been disabled because ERR_MAX_REPORTED has been reached.", err_strings[errcode]);
1763
        NOTE(msg);
1764
    end
1765
 
1766
    //overall model maximum error limit
1767
    if ((errcount[errcode] > ERR_MAX_INT) && (ERR_MAX_INT >= 0)) begin
1768
        STOP;
1769
    end
1770
end
1771
endtask
1772
 
1773
//-------------------------------- Display Tasks -------------------------------
1774
 
1775
    task NOTE;
1776
       input [MSGLENGTH*8:1] msg;
1777
    begin
1778
      $display("%m at time %t: %0s", $time, msg);
1779
    end
1780
    endtask
1781
 
1782
    task WARN;
1783
       input [MSGLENGTH*8:1] msg;
1784
    begin
1785
      $display("%m at time %t: %0s", $time, msg);
1786
      warnings = warnings + 1;
1787
    end
1788
    endtask
1789
 
1790
//---------------------------------------------------
1791
// TASK: Stop()
1792
//---------------------------------------------------
1793
 
1794
    task STOP;
1795
    begin
1796
      $display("%m at time %t: %d warnings, %d errors", $time, warnings, errors);
1797
      $stop(0);
1798
    end
1799
    endtask
1800
 
1801
//-------------------------------- Memory Storage Tasks -------------------------------
1802
 
1803
    // Erase Memory
1804
    task erase_mem;
1805
        input integer                 pasr ;
1806
        reg       [part_mem_bits : 0] i;
1807
        reg       [part_mem_bits : 0] j;
1808
        reg       [full_mem_bits : 0] k;
1809
        begin
1810
`ifdef FULL_MEM
1811
            if (pasr == 0) begin
1812
//                for (k = 0; k > {(full_mem_bits){1'b1}}; k = k + 1) begin
1813
//                    mem_array[k] = {DQ_BITS{1'bx}};
1814
//                end
1815
            end else if (pasr == 1) begin
1816
                for (k = {(full_mem_bits){1'b1}}; k > {(full_mem_bits-1){1'b1}}; k = k - 1) begin
1817
                    mem_array[k] = {DQ_BITS{1'bx}};
1818
                end
1819
            end else if (pasr == 2) begin
1820
                for (k = {(full_mem_bits){1'b1}}; k > {(full_mem_bits-2){1'b1}}; k = k - 1) begin
1821
                    mem_array[k] = {DQ_BITS{1'bx}};
1822
                end
1823
            end else if (pasr == 3) begin
1824
                for (k = {(full_mem_bits){1'b1}}; k > {(full_mem_bits-3){1'b1}}; k = k - 1) begin
1825
                    mem_array[k] = {DQ_BITS{1'bx}};
1826
                end
1827
            end else if (pasr == 4) begin
1828
                for (k = {(full_mem_bits){1'b1}}; k > {(full_mem_bits-4){1'b1}}; k = k - 1) begin
1829
                    mem_array[k] = {DQ_BITS{1'bx}};
1830
                end
1831
            end else begin
1832
                for (k = 0; k <= {(full_mem_bits){1'b1}}; k = k + 1) begin
1833
                    mem_array[k] = {DQ_BITS{1'bx}};
1834
                end
1835
                $display ("%m: At time %t ERROR: illegal PASR setting.\n  All Data will be lost.\n", $realtime);
1836
            end
1837
`else
1838
            if (pasr == 0) begin
1839
//                for (i = 0; i < mem_used; i = i + 1) begin
1840
//                    addr_array[i] = {full_mem_bits{1'bx}};
1841
//                    mem_array[i]  = {DQ_BITS{1'bx}};
1842
//                end
1843
            end else if (pasr == 1) begin
1844
                for (i = 0; i < mem_used; i = i + 1) begin
1845
                    if (addr_array[i][full_mem_bits - 1] != 1'b0) begin
1846
                        addr_array[i] = {full_mem_bits{1'bx}};
1847
                        mem_array[i]  = {DQ_BITS{1'bx}};
1848
                    end
1849
                end
1850
            end else if (pasr == 2) begin
1851
                for (i = 0; i < mem_used; i = i + 1) begin
1852
                    if (addr_array[i][full_mem_bits - 1: full_mem_bits - 2] != {2{1'b0}}) begin
1853
                        addr_array[i] = {full_mem_bits{1'bx}};
1854
                        mem_array[i]  = {DQ_BITS{1'bx}};
1855
                    end
1856
                end
1857
            end else if (pasr == 3) begin
1858
                for (i = 0; i < mem_used; i = i + 1) begin
1859
                    if (addr_array[i][full_mem_bits - 1: full_mem_bits - 3] != {3{1'b0}}) begin
1860
                        addr_array[i] = {full_mem_bits{1'bx}};
1861
                        mem_array[i]  = {DQ_BITS{1'bx}};
1862
                    end
1863
                end
1864
            end else if (pasr == 4) begin
1865
                for (i = 0; i < mem_used; i = i + 1) begin
1866
                    if (addr_array[i][full_mem_bits - 1: full_mem_bits - 4] != {4{1'b0}}) begin
1867
                        addr_array[i] = {full_mem_bits{1'bx}};
1868
                        mem_array[i]  = {DQ_BITS{1'bx}};
1869
                    end
1870
                end
1871
            end else begin
1872
                for (i = 0; i < mem_used; i = i + 1) begin
1873
                    addr_array[i] = {full_mem_bits{1'bx}};
1874
                    mem_array[i]  = {DQ_BITS{1'bx}};
1875
                end
1876
                mem_used = 0 ;
1877
                $display ("%m: At time %t ERROR: illegal PASR setting.\n  All Data will be lost.\n", $realtime);
1878
            end
1879
            for (i = 0; i < mem_used; i = i + 1) begin
1880
                if (addr_array[i] === {full_mem_bits{1'bx}}) begin
1881
                    for (j=i; j < mem_used; j=j+1) begin
1882
                        addr_array[j] = addr_array[j+1];
1883
                        mem_array[j]  = mem_array[j+1];
1884
                    end
1885
                    mem_used = mem_used - 1 ;
1886
                    i = i - 1 ;
1887
                end
1888
            end
1889
`endif
1890
        end
1891
    endtask
1892
 
1893
    // Write Memory
1894
    task write_mem;
1895
        input [full_mem_bits - 1 : 0] address;
1896
        input       [DQ_BITS - 1 : 0] data;
1897
        reg       [part_mem_bits : 0] i;
1898
        begin
1899
`ifdef FULL_MEM
1900
            mem_array[address] = data;
1901
`else
1902
            begin : loop
1903
                for (i = 0; i < mem_used; i = i + 1) begin
1904
                    if (addr_array[i] === address) begin
1905
                        disable loop;
1906
                    end
1907
                end
1908
            end
1909
            if (i === mem_used) begin
1910
                if (i === (1<<part_mem_bits)) begin
1911
                    $display ("%m: At time %t ERROR: Memory overflow.\n  Write to Address %d with Data %d will be lost.\n You must increase the part_mem_bits parameter or `define FULL_MEM.", $realtime, address, data);
1912
                end else begin
1913
                    mem_used = mem_used + 1;
1914
                    addr_array[i] = address;
1915
                end
1916
            end
1917
            mem_array[i] = data;
1918
`endif
1919
        end
1920
    endtask
1921
//test//
1922
    // Read Memory
1923
    task read_mem;
1924
        input [full_mem_bits - 1 : 0] address;
1925
        output      [DQ_BITS - 1 : 0] data;
1926
        reg       [part_mem_bits : 0] i;
1927
        begin
1928
`ifdef FULL_MEM
1929
            data = mem_array[address];
1930
`else
1931
            begin : loop
1932
                for (i = 0; i < mem_used; i = i + 1) begin
1933
                    if (addr_array[i] === address) begin
1934
                        disable loop;
1935
                    end
1936
                end
1937
            end
1938
            if (i <= mem_used) begin
1939
                data = mem_array[i];
1940
            end else begin
1941
                data = 'bx;
1942
            end
1943
`endif
1944
        end
1945
    endtask
1946
 
1947
 
1948
//------------- Access Registers --------------
1949
 
1950
    task clk_access_reg;
1951
    begin
1952
        for (i=0; i<`PAGE_SIZE+2; i=i+1) begin
1953
            bank_access_q[i]         = bank_access_q[i+1]         ;
1954
            row_access_q[i]          = row_access_q[i+1]          ;
1955
            column_access_q[i]       = column_access_q[i+1]       ;
1956
            column_access_valid_q[i] = column_access_valid_q[i+1] ;
1957
        end
1958
        bank_access_q[`PAGE_SIZE+2]         = 'bz   ;
1959
        row_access_q[`PAGE_SIZE+2]          = 'bz   ;
1960
        column_access_q[`PAGE_SIZE+2]       = 'bz   ;
1961
        column_access_valid_q[`PAGE_SIZE+2] = 2'b00 ;
1962
    end
1963
    endtask
1964
 
1965
//------------- clock counters --------------
1966
 
1967
    task clk_counters;
1968
    begin
1969
        if ((ck_cntr_self_refresh    + 1) > ck_cntr_self_refresh   ) begin ck_cntr_self_refresh    = ck_cntr_self_refresh    + 1 ; end
1970
        if ((ck_cntr_power_down      + 1) > ck_cntr_power_down     ) begin ck_cntr_power_down      = ck_cntr_power_down      + 1 ; end
1971
        if ((ck_cntr_cke             + 1) > ck_cntr_cke            ) begin ck_cntr_cke             = ck_cntr_cke             + 1 ; end
1972
        if ((ck_cntr_cke_n           + 1) > ck_cntr_cke_n          ) begin ck_cntr_cke_n           = ck_cntr_cke_n           + 1 ; end
1973
        if ((ck_cntr_activate        + 1) > ck_cntr_activate       ) begin ck_cntr_activate        = ck_cntr_activate        + 1 ; end
1974
        if ((ck_cntr_read            + 1) > ck_cntr_read           ) begin ck_cntr_read            = ck_cntr_read            + 1 ; end
1975
        if ((ck_cntr_read_ap         + 1) > ck_cntr_read_ap        ) begin ck_cntr_read_ap         = ck_cntr_read_ap         + 1 ; end
1976
        if ((ck_cntr_write           + 1) > ck_cntr_write          ) begin ck_cntr_write           = ck_cntr_write           + 1 ; end
1977
        if ((ck_cntr_write_ap        + 1) > ck_cntr_write_ap       ) begin ck_cntr_write_ap        = ck_cntr_write_ap        + 1 ; end
1978
        if ((ck_cntr_burst_terminate + 1) > ck_cntr_burst_terminate) begin ck_cntr_burst_terminate = ck_cntr_burst_terminate + 1 ; end
1979
        if ((ck_cntr_precharge       + 1) > ck_cntr_precharge      ) begin ck_cntr_precharge       = ck_cntr_precharge       + 1 ; end
1980
        if ((ck_cntr_auto_refresh    + 1) > ck_cntr_auto_refresh   ) begin ck_cntr_auto_refresh    = ck_cntr_auto_refresh    + 1 ; end
1981
        if ((ck_cntr_load_mode       + 1) > ck_cntr_load_mode      ) begin ck_cntr_load_mode       = ck_cntr_load_mode       + 1 ; end
1982
        for (i=0; i<`BANKS; i=i+1) begin
1983
            if ((ck_cntr_bank_precharge[i] + 1) > ck_cntr_bank_precharge[i]) begin ck_cntr_bank_precharge[i] = ck_cntr_bank_precharge[i] + 1 ; end
1984
            if ((ck_cntr_bank_activate[i]  + 1) > ck_cntr_bank_activate[i] ) begin ck_cntr_bank_activate[i]  = ck_cntr_bank_activate[i]  + 1 ; end
1985
            if ((ck_cntr_bank_write[i]     + 1) > ck_cntr_bank_write[i]    ) begin ck_cntr_bank_write[i]     = ck_cntr_bank_write[i]     + 1 ; end
1986
            if ((ck_cntr_bank_read[i]      + 1) > ck_cntr_bank_read[i]     ) begin ck_cntr_bank_read[i]      = ck_cntr_bank_read[i]      + 1 ; end
1987
            if ((ck_cntr_write_dq[i]       + 1) > ck_cntr_write_dq[i]      ) begin ck_cntr_write_dq[i]       = ck_cntr_write_dq[i]       + 1 ; end
1988
        end
1989
    end
1990
    endtask
1991
 
1992
//------------- Clock Enable --------------
1993
 
1994
    always@(posedge cke) begin
1995
        tm_cke_high      = $time ;
1996
        ck_cntr_cke_high = 0     ;
1997
    end
1998
 
1999
    always@(clk) begin
2000
        if (clk) begin
2001
            clk_counters               ;
2002
            exit_power_down_err_chk    ;
2003
            initialization_cmd_func    ;
2004
            initialization_err_chk     ;
2005
            initialization_cmd_display ;
2006
        end
2007
        clk_stabilization_func     ;
2008
        clk_stabilization_err_chk  ;
2009
        cke_err_chk                ;
2010
        cke_cmd_func               ;
2011
        if (cke_q == 1'b1) begin
2012
            Sys_clk <= clk         ;
2013
        end else begin
2014
            Sys_clk <= 1'b0        ;
2015
        end
2016
        if (clk) begin
2017
            cke_q = cke            ;
2018
        end
2019
    end
2020
 
2021
//------------- System clock --------------
2022
 
2023
    always@(posedge Sys_clk) begin
2024
        clk_access_reg;
2025
        active_read_write;
2026
        interrupt_auto_precharge(interrupt_bank);
2027
        auto_precharge_management;
2028
        if (command == ACTIVATE        ) begin activate_err_chk            ; end
2029
        if (command == READ            ) begin read_err_chk                ; end
2030
        if (command == READ_AP         ) begin read_ap_err_chk             ; end
2031
        if (command == READ_SUSPEND    ) begin read_err_chk                ; end
2032
        if (command == READ_AP_SUSPEND ) begin read_ap_err_chk             ; end
2033
        if (command == WRITE           ) begin write_err_chk               ; end
2034
        if (command == WRITE_AP        ) begin write_ap_err_chk            ; end
2035
        if (command == WRITE_SUSPEND   ) begin write_err_chk               ; end
2036
        if (command == WRITE_AP_SUSPEND) begin write_ap_err_chk            ; end
2037
        if (command == BURST_TERMINATE ) begin burst_term_err_chk          ; end
2038
        if (command == AUTO_REFRESH    ) begin auto_refresh_err_chk        ; end
2039
        if (command == PRECHARGE       ) begin precharge_err_chk(ba)       ; end
2040
        if (command == PRECHARGE_ALL   ) begin precharge_all_err_chk       ; end
2041
        if (command == LOAD_MODE       ) begin load_mode_err_chk           ; end
2042
        if ((~read_write_in_progress     ) &
2043
            (command != READ_SUSPEND     ) &
2044
            (command != READ_AP_SUSPEND  ) &
2045
            (command != WRITE_SUSPEND    ) &
2046
            (command != WRITE_AP_SUSPEND )  ) begin
2047
            if (command == SELF_REFRESH    ) begin self_refresh_err_chk    ; end
2048
            if (command == POWER_DOWN_CI   ) begin power_down_err_chk      ; end
2049
            if (command == POWER_DOWN_NOP  ) begin power_down_err_chk      ; end
2050
            if (command == DEEP_POWER_DOWN ) begin deep_power_down_err_chk ; end
2051
        end else begin
2052
            if (command == SELF_REFRESH    ) begin clock_suspend_err_chk   ; end
2053
            if (command == POWER_DOWN_CI   ) begin clock_suspend_err_chk   ; end
2054
            if (command == POWER_DOWN_NOP  ) begin clock_suspend_err_chk   ; end
2055
            if (command == DEEP_POWER_DOWN ) begin clock_suspend_err_chk   ; end
2056
        end
2057
        if (command_sequence_error == 0) begin
2058
            if (command == ACTIVATE              ) begin activate_cmd_func(ba, addr) ; end
2059
            if (command == READ                  ) begin read_cmd_func               ; end
2060
            if (command == READ_AP               ) begin read_ap_cmd_func            ; end
2061
            if (command == READ_SUSPEND          ) begin read_cmd_func               ; end
2062
            if (command == READ_AP_SUSPEND       ) begin read_ap_cmd_func            ; end
2063
            if (command == WRITE                 ) begin write_cmd_func              ; end
2064
            if (command == WRITE_AP              ) begin write_ap_cmd_func           ; end
2065
            if (command == WRITE_SUSPEND         ) begin write_cmd_func              ; end
2066
            if (command == WRITE_AP_SUSPEND      ) begin write_ap_cmd_func           ; end
2067
            if (command == BURST_TERMINATE       ) begin burst_term_cmd_func         ; end
2068
            if (command == AUTO_REFRESH          ) begin auto_refresh_cmd_func       ; end
2069
            if (command == PRECHARGE             ) begin precharge_cmd_func(ba, 0)   ; end
2070
            if (command == PRECHARGE_ALL         ) begin precharge_all_cmd_func      ; end
2071
            if (command == LOAD_MODE             ) begin load_mode_cmd_func          ; end
2072
            if ((~read_write_in_progress     ) &
2073
                (command != READ_SUSPEND     ) &
2074
                (command != READ_AP_SUSPEND  ) &
2075
                (command != WRITE_SUSPEND    ) &
2076
                (command != WRITE_AP_SUSPEND )  ) begin
2077
                if (command == SELF_REFRESH      ) begin self_refresh_cmd_func       ; end
2078
                if (command == POWER_DOWN_CI     ) begin power_down_cmd_func         ; end
2079
                if (command == POWER_DOWN_NOP    ) begin power_down_cmd_func         ; end
2080
                if (command == DEEP_POWER_DOWN   ) begin deep_power_down_cmd_func    ; end
2081
            end else begin
2082
                if (command == SELF_REFRESH      ) begin clock_suspend_cmd_func      ; end
2083
                if (command == POWER_DOWN_CI     ) begin clock_suspend_cmd_func      ; end
2084
                if (command == POWER_DOWN_NOP    ) begin clock_suspend_cmd_func      ; end
2085
                if (command == DEEP_POWER_DOWN   ) begin clock_suspend_cmd_func      ; end
2086
            end
2087
 
2088
            if ((command == ACTIVATE        ) & (DEBUG == 1'b1)) begin activate_cmd_display            ; end
2089
            if ((command == READ            ) & (DEBUG == 1'b1)) begin read_cmd_display                ; end
2090
            if ((command == READ_AP         ) & (DEBUG == 1'b1)) begin read_ap_cmd_display             ; end
2091
            if ((command == READ_SUSPEND    ) & (DEBUG == 1'b1)) begin clock_suspend_cmd_display       ; end
2092
            if ((command == READ_AP_SUSPEND ) & (DEBUG == 1'b1)) begin clock_suspend_cmd_display       ; end
2093
            if ((command == WRITE           ) & (DEBUG == 1'b1)) begin write_cmd_display               ; end
2094
            if ((command == WRITE_AP        ) & (DEBUG == 1'b1)) begin write_ap_cmd_display            ; end
2095
            if ((command == WRITE_SUSPEND   ) & (DEBUG == 1'b1)) begin clock_suspend_cmd_display       ; end
2096
            if ((command == WRITE_AP_SUSPEND) & (DEBUG == 1'b1)) begin clock_suspend_cmd_display       ; end
2097
            if ((command == BURST_TERMINATE ) & (DEBUG == 1'b1)) begin burst_term_cmd_display          ; end
2098
            if ((command == AUTO_REFRESH    ) & (DEBUG == 1'b1)) begin auto_refresh_cmd_display        ; end
2099
            if ((command == PRECHARGE       ) & (DEBUG == 1'b1)) begin precharge_cmd_display(ba)       ; end
2100
            if ((command == PRECHARGE_ALL   ) & (DEBUG == 1'b1)) begin precharge_all_cmd_display       ; end
2101
            if ((command == LOAD_MODE       ) & (DEBUG == 1'b1)) begin load_mode_cmd_display(ba, addr) ; end
2102
            if ((~read_write_in_progress     ) &
2103
                (command != READ_SUSPEND     ) &
2104
                (command != READ_AP_SUSPEND  ) &
2105
                (command != WRITE_SUSPEND    ) &
2106
                (command != WRITE_AP_SUSPEND )  ) begin
2107
                if ((command == SELF_REFRESH   ) & (DEBUG == 1'b1)) begin self_refresh_cmd_display    ; end
2108
                if ((command == POWER_DOWN_CI  ) & (DEBUG == 1'b1)) begin power_down_cmd_display      ; end
2109
                if ((command == POWER_DOWN_NOP ) & (DEBUG == 1'b1)) begin power_down_cmd_display      ; end
2110
                if ((command == DEEP_POWER_DOWN) & (DEBUG == 1'b1)) begin deep_power_down_cmd_display ; end
2111
            end else begin
2112
                if ((command == SELF_REFRESH   ) & (DEBUG == 1'b1)) begin clock_suspend_cmd_display   ; end
2113
                if ((command == POWER_DOWN_CI  ) & (DEBUG == 1'b1)) begin clock_suspend_cmd_display   ; end
2114
                if ((command == POWER_DOWN_NOP ) & (DEBUG == 1'b1)) begin clock_suspend_cmd_display   ; end
2115
                if ((command == DEEP_POWER_DOWN) & (DEBUG == 1'b1)) begin clock_suspend_cmd_display   ; end
2116
            end
2117
        end
2118
        command_sequence_error = 0 ;
2119
        data_management(Dq_out);
2120
        dqm_q <= dqm ;
2121
        dqm_rtw_chk[1] <= dqm_rtw_chk[0];
2122
        dqm_rtw_chk[0] <= (column_access_valid_q[0] == 2'b10) & (&dqm_q === 1'b0) & (Dq_out !== {DQ_BITS{1'bz}}) ;
2123
    end
2124
 
2125
    always@(Dq_out) begin
2126
        Dq_buffer_output ;
2127
    end
2128
 
2129
endmodule
2130
 
2131
 

powered by: WebSVN 2.1.0

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