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

Subversion Repositories ddr2_sdram

[/] [ddr2_sdram/] [trunk/] [ipcore_dir/] [DDR2_Ram_Core/] [user_design/] [rtl/] [DDR2_Ram_Core_controller_0.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 john_fpga
--*****************************************************************************
2
-- DISCLAIMER OF LIABILITY
3
--
4
-- This file contains proprietary and confidential information of
5
-- Xilinx, Inc. ("Xilinx"), that is distributed under a license
6
-- from Xilinx, and may be used, copied and/or disclosed only
7
-- pursuant to the terms of a valid license agreement with Xilinx.
8
--
9
-- XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION
10
-- ("MATERIALS") "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
11
-- EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING WITHOUT
12
-- LIMITATION, ANY WARRANTY WITH RESPECT TO NONINFRINGEMENT,
13
-- MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. Xilinx
14
-- does not warrant that functions included in the Materials will
15
-- meet the requirements of Licensee, or that the operation of the
16
-- Materials will be uninterrupted or error-free, or that defects
17
-- in the Materials will be corrected. Furthermore, Xilinx does
18
-- not warrant or make any representations regarding use, or the
19
-- results of the use, of the Materials in terms of correctness,
20
-- accuracy, reliability or otherwise.
21
--
22
-- Xilinx products are not designed or intended to be fail-safe,
23
-- or for use in any application requiring fail-safe performance,
24
-- such as life-support or safety devices or systems, Class III
25
-- medical devices, nuclear facilities, applications related to
26
-- the deployment of airbags, or any other applications that could
27
-- lead to death, personal injury or severe property or
28
-- environmental damage (individually and collectively, "critical
29
-- applications"). Customer assumes the sole risk and liability
30
-- of any use of Xilinx products in critical applications,
31
-- subject only to applicable laws and regulations governing
32
-- limitations on product liability.
33
--
34
-- Copyright 2005, 2006, 2007, 2008 Xilinx, Inc.
35
-- All rights reserved.
36
--
37
-- This disclaimer and copyright notice must be retained as part
38
-- of this file at all times.
39
--*****************************************************************************
40
--   ____  ____
41
--  /   /\/   /
42
-- /___/  \  /   Vendor             : Xilinx
43
-- \   \   \/    Version            : 3.6.1
44
--  \   \        Application        : MIG
45
--  /   /        Filename           : DDR2_Ram_Core_controller_0.vhd
46
-- /___/   /\    Date Last Modified : $Date: 2010/11/26 18:25:42 $
47
-- \   \  /  \   Date Created       : Mon May 2 2005
48
--  \___\/\___\
49
-- Device      : Spartan-3/3A/3A-DSP
50
-- Design Name : DDR2 SDRAM
51
-- Purpose     : THis is main controller block. This includes the following
52
--                  features:
53
--                - The controller state machine that controls the
54
--                  initialization process upon power up, as well as the
55
--                  read, write, and refresh commands.
56
--                - Accepts and decodes the user commands.
57
--                - Generates the address and Bank address and control signals
58
--                  to the memory    
59
--                - Generates control signals for other modules.
60
--*****************************************************************************
61
 
62
library ieee;
63
library UNISIM;
64
use ieee.std_logic_1164.all;
65
use ieee.std_logic_unsigned.all;
66
use UNISIM.VCOMPONENTS.all;
67
use work.DDR2_Ram_Core_parameters_0.all;
68
 
69
entity DDR2_Ram_Core_controller_0 is
70
  generic
71
    (
72
     COL_WIDTH : integer := COLUMN_ADDRESS;
73
     ROW_WIDTH : integer := ROW_ADDRESS
74
    );
75
  port(
76
    clk               : in  std_logic;
77
    rst0              : in  std_logic;
78
    rst180            : in  std_logic;
79
    address           : in  std_logic_vector(((ROW_ADDRESS + COLUMN_ADDRESS)-1)
80
                                            downto 0);
81
    bank_addr         : in  std_logic_vector((BANK_ADDRESS-1) downto 0);
82
    command_register  : in  std_logic_vector(2 downto 0);
83
    burst_done        : in  std_logic;
84
    ddr_rasb_cntrl    : out std_logic;
85
    ddr_casb_cntrl    : out std_logic;
86
    ddr_web_cntrl     : out std_logic;
87
    ddr_ba_cntrl      : out std_logic_vector((BANK_ADDRESS-1) downto 0);
88
    ddr_address_cntrl : out std_logic_vector((ROW_ADDRESS-1) downto 0);
89
    ddr_cke_cntrl     : out std_logic;
90
    ddr_csb_cntrl     : out std_logic;
91
    ddr_odt_cntrl     : out std_logic;
92
    dqs_enable        : out std_logic;
93
    dqs_reset         : out std_logic;
94
    write_enable      : out std_logic;
95
    rst_calib         : out std_logic;
96
    rst_dqs_div_int   : out std_logic;
97
    cmd_ack           : out std_logic;
98
    init              : out std_logic;
99
    ar_done           : out std_logic;
100
    wait_200us        : in  std_logic;
101
    auto_ref_req      : out std_logic;
102
    read_fifo_rden    : out std_logic -- Read Enable signal for read fifo(to data_read)
103
    );
104
end DDR2_Ram_Core_controller_0;
105
 
106
 
107
architecture arc of DDR2_Ram_Core_controller_0 is
108
 
109
  type s_m is (IDLE, PRECHARGE, AUTO_REFRESH, ACTIVE,
110
               FIRST_WRITE, WRITE_WAIT, BURST_WRITE,
111
               PRECHARGE_AFTER_WRITE, PRECHARGE_AFTER_WRITE_2, READ_WAIT,
112
               BURST_READ, ACTIVE_WAIT);
113
 
114
  type s_m1 is (INIT_IDLE, INIT_PRECHARGE,
115
                INIT_AUTO_REFRESH, INIT_LOAD_MODE_REG);
116
  signal next_state, current_state           : s_m;
117
  signal init_next_state, init_current_state : s_m1;
118
 
119
  signal ack_reg              : std_logic;
120
  signal ack_o                : std_logic;
121
  signal auto_ref             : std_logic;
122
  signal auto_ref1            : std_logic;
123
  signal autoref_value        : std_logic;
124
  signal auto_ref_detect1     : std_logic;
125
  signal autoref_count        : std_logic_vector((MAX_REF_WIDTH-1) downto 0);
126
  signal ar_done_p            : std_logic;
127
  signal auto_ref_issued      : std_logic;
128
  signal auto_ref_issued_p    : std_logic;
129
  signal ba_address_reg1      : std_logic_vector((BANK_ADDRESS-1) downto 0);
130
  signal ba_address_reg2      : std_logic_vector((BANK_ADDRESS-1) downto 0);
131
  signal burst_length         : std_logic_vector(2 downto 0);
132
  signal burst_cnt_max        : std_logic_vector(2 downto 0);
133
  signal cas_count            : std_logic_vector(2 downto 0);
134
  signal ras_count           : std_logic_vector(4 downto 0);
135
  signal column_address_reg   : std_logic_vector((ROW_ADDRESS-1) downto 0);
136
  signal ddr_rasb1            : std_logic;
137
  signal ddr_casb1            : std_logic;
138
  signal ddr_web1             : std_logic;
139
  signal ddr_ba1              : std_logic_vector((BANK_ADDRESS-1) downto 0);
140
  signal ddr_address1         : std_logic_vector((ROW_ADDRESS-1) downto 0);
141
  signal dqs_enable_out       : std_logic;
142
  signal dqs_reset_out        : std_logic;
143
  signal dll_rst_count        : std_logic_vector(7 downto 0);
144
  signal init_count           : std_logic_vector(3 downto 0);
145
  signal init_done            : std_logic;
146
  signal init_done_r1         : std_logic;
147
  signal init_done_dis        : std_logic;
148
  signal init_done_value      : std_logic;
149
  signal init_memory          : std_logic;
150
  signal init_mem             : std_logic;
151
  signal init_cmd_in    : std_logic;
152
  signal init_pre_count       : std_logic_vector(6 downto 0);
153
  signal ref_freq_cnt         : std_logic_vector((MAX_REF_WIDTH-1) downto 0);
154
  signal read_cmd_in             : std_logic;
155
  signal read_cmd1            : std_logic;
156
  signal read_cmd2            : std_logic;
157
  signal read_cmd3            : std_logic;
158
  signal rcd_count           : std_logic_vector(2 downto 0);
159
  signal rp_cnt_value         : std_logic_vector(2 downto 0);
160
  signal rfc_count_reg        : std_logic;
161
  signal ar_done_reg          : std_logic;
162
  signal rdburst_end_1        : std_logic;
163
  signal rdburst_end_2        : std_logic;
164
  signal rdburst_end          : std_logic;
165
  signal rp_count             : std_logic_vector(2 downto 0);
166
  signal rfc_count            : std_logic_vector(7 downto 0);
167
  signal row_address_reg      : std_logic_vector((ROW_ADDRESS-1) downto 0);
168
  signal column_address1      : std_logic_vector((ROW_ADDRESS -1) downto 0);
169
  signal rst_dqs_div_r        : std_logic;
170
  signal rst_dqs_div_r1       : std_logic;
171
  signal wrburst_end_cnt      : std_logic_vector(2 downto 0);
172
  signal wrburst_end          : std_logic;
173
  signal wrburst_end_1        : std_logic;
174
  signal wrburst_end_2        : std_logic;
175
  signal wrburst_end_3        : std_logic;
176
  signal wr_count             : std_logic_vector(2 downto 0);
177
  signal write_enable_out     : std_logic;
178
  signal write_cmd_in         : std_logic;
179
  signal write_cmd2           : std_logic;
180
  signal write_cmd3           : std_logic;
181
  signal write_cmd1           : std_logic;
182
  signal go_to_active_value   : std_logic;
183
  signal go_to_active         : std_logic;
184
  signal dqs_div_cascount     : std_logic_vector(2 downto 0);
185
  signal dqs_div_rdburstcount : std_logic_vector(2 downto 0);
186
  signal dqs_enable1          : std_logic;
187
  signal dqs_enable2          : std_logic;
188
  signal dqs_enable3          : std_logic;
189
  signal dqs_reset1_clk0      : std_logic;
190
  signal dqs_reset2_clk0      : std_logic;
191
  signal dqs_reset3_clk0      : std_logic;
192
  signal dqs_enable_int       : std_logic;
193
  signal dqs_reset_int        : std_logic;
194
  signal rst180_r             : std_logic;
195
  signal rst0_r               : std_logic;
196
  signal emr                  : std_logic_vector(ROW_ADDRESS - 1 downto 0);
197
  signal lmr                  : std_logic_vector(ROW_ADDRESS - 1 downto 0);
198
  signal lmr_dll_rst          : std_logic_vector(ROW_ADDRESS - 1 downto 0);
199
  signal lmr_dll_set          : std_logic_vector(ROW_ADDRESS - 1 downto 0);
200
  signal ddr_odt1             : std_logic;
201
  signal ddr_odt2             : std_logic;
202
  signal rst_dqs_div_int1     : std_logic;
203
  signal accept_cmd_in        : std_logic;
204
  signal dqs_enable_i         : std_logic;
205
  signal auto_ref_wait        : std_logic;
206
  signal auto_ref_wait1       : std_logic;
207
  signal auto_ref_wait2       : std_logic;
208
  signal address_reg          : std_logic_vector(((ROW_ADDRESS +
209
                                                   COLUMN_ADDRESS)-1) downto 0);
210
  signal ddr_rasb2            : std_logic;
211
  signal ddr_casb2            : std_logic;
212
  signal ddr_web2             : std_logic;
213
  signal count6               : std_logic_vector(7 downto 0);
214
  signal clk180               : std_logic;
215
  signal odt_deassert         : std_logic;
216
 
217
 
218
  constant addr_const1 : std_logic_vector(14 downto 0) := "000010000000000";
219
  constant addr_const2 : std_logic_vector(14 downto 0) := "000001110000000";  --380
220
  constant addr_const3 : std_logic_vector(14 downto 0) := "000110001111111";  --C7F
221
  constant ba_const1   : std_logic_vector(2 downto 0)  := "010";
222
  constant ba_const2   : std_logic_vector(2 downto 0)  := "011";
223
  constant ba_const3   : std_logic_vector(2 downto 0)  := "001";
224
 
225
  attribute iob                        : string;
226
  attribute syn_useioff                : boolean;
227
  attribute syn_preserve               : boolean;
228
  attribute syn_keep                   : boolean;
229
 
230
  attribute iob of rst_iob_out                 : label is "FORCE";
231
  attribute syn_useioff of rst_iob_out         : label is true;
232
  attribute syn_preserve of lmr_dll_rst        : signal is true;
233
  attribute syn_preserve of lmr_dll_set        : signal is true;
234
  attribute syn_preserve of ba_address_reg1    : signal is true;
235
  attribute syn_preserve of ba_address_reg2    : signal is true;
236
  attribute syn_preserve of column_address_reg : signal is true;
237
  attribute syn_preserve of row_address_reg    : signal is true;
238
 
239
begin
240
 
241
  clk180      <= not clk;
242
  emr         <= EXT_LOAD_MODE_REGISTER;
243
  lmr         <= LOAD_MODE_REGISTER;
244
  lmr_dll_rst <= lmr(ROW_ADDRESS - 1 downto 9) & '1' & lmr(7 downto 0);
245
  lmr_dll_set <= lmr(ROW_ADDRESS - 1 downto 9) & '0' & lmr(7 downto 0);
246
 
247
 
248
-- Input : COMMAND REGISTER FORMAT
249
-- 000 - NOP
250
-- 010 - Initialize memory
251
-- 100 - Write Request
252
-- 110 - Read request
253
 
254
 
255
-- Input : Address format
256
-- row address = address((ROW_ADDRESS + COLUMN_ADDRESS) -1 downto COLUMN_ADDRESS)
257
-- column address = address(COLUMN_ADDRESS-1 downto 0)
258
 
259
  ddr_csb_cntrl     <= '0';
260
  ddr_cke_cntrl     <= not wait_200us;
261
  init              <= init_done;
262
  ddr_rasb_cntrl    <= ddr_rasb2;
263
  ddr_casb_cntrl    <= ddr_casb2;
264
  ddr_web_cntrl     <= ddr_web2;
265
  rst_dqs_div_int   <= rst_dqs_div_int1;
266
  ddr_address_cntrl <= ddr_address1;
267
  ddr_ba_cntrl      <= ddr_ba1;
268
 
269
  -- turn off auto-precharge when issuing read/write commands (A10 = 0)
270
  -- mapping the column address for linear addressing.
271
  gen_ddr_addr_col_0: if (COL_WIDTH = ROW_WIDTH-1) generate
272
    column_address1 <= (address_reg(COL_WIDTH-1 downto 10) & '0' &
273
                        address_reg(9 downto 0));
274
  end generate;
275
 
276
  gen_ddr_addr_col_1: if ((COL_WIDTH > 10) and
277
                          not(COL_WIDTH = ROW_WIDTH-1)) generate
278
    column_address1(ROW_WIDTH-1 downto COL_WIDTH+1) <= (others => '0');
279
    column_address1(COL_WIDTH downto 0) <=
280
      (address_reg(COL_WIDTH-1 downto 10) & '0' & address_reg(9 downto 0));
281
  end generate;
282
 
283
  gen_ddr_addr_col_2: if (not((COL_WIDTH > 10) or
284
                              (COL_WIDTH = ROW_WIDTH-1))) generate
285
    column_address1(ROW_WIDTH-1 downto COL_WIDTH+1) <= (others => '0');
286
    column_address1(COL_WIDTH downto 0) <=
287
      ('0' & address_reg(COL_WIDTH-1 downto 0));
288
  end generate;
289
 
290
 
291
  process(clk)
292
  begin
293
    if clk'event and clk = '0' then
294
      rst180_r <= rst180;
295
    end if;
296
  end process;
297
 
298
  process(clk)
299
  begin
300
    if clk'event and clk = '1' then
301
      rst0_r <= rst0;
302
    end if;
303
  end process;
304
 
305
--******************************************************************************
306
-- Register user address
307
--******************************************************************************
308
 
309
  process(clk)
310
  begin
311
    if clk'event and clk = '0' then
312
      row_address_reg    <= address_reg(((ROW_ADDRESS + COLUMN_ADDRESS)-1) downto
313
                                        COLUMN_ADDRESS);
314
      column_address_reg <= column_address1;
315
      ba_address_reg1    <= bank_addr;
316
      ba_address_reg2    <= ba_address_reg1;
317
      address_reg        <= address;
318
    end if;
319
  end process;
320
 
321
  process(clk)
322
  begin
323
    if clk'event and clk = '0' then
324
      if rst180_r = '1' then
325
        burst_length <= "000";
326
      else
327
        burst_length <= lmr(2 downto 0);
328
      end if;
329
    end if;
330
  end process;
331
 
332
  process(clk)
333
  begin
334
    if (clk'event and clk = '0') then
335
      if rst180_r = '1' then
336
        accept_cmd_in <= '0';
337
      elsif (current_state = IDLE and (rp_count = "000"  and (rfc_count_reg and
338
                                        not(auto_ref_wait) and
339
                                        not(auto_ref_issued)) = '1')) then
340
        accept_cmd_in <= '1';
341
      else
342
        accept_cmd_in <= '0';
343
      end if;
344
    end if;
345
  end process;
346
--******************************************************************************
347
-- Commands from user.
348
--******************************************************************************
349
  init_cmd_in       <= '1' when (command_register = "010") else '0';
350
  write_cmd_in      <= '1' when (command_register = "100" and
351
                                 accept_cmd_in = '1') else '0';
352
  read_cmd_in       <= '1' when (command_register = "110" and
353
                                 accept_cmd_in = '1') else '0';
354
 
355
--******************************************************************************
356
-- write_cmd1 is asserted when user issued write command and the controller s/m
357
-- is in idle state and AUTO_REF is not asserted.
358
--******************************************************************************
359
 
360
  process(clk)
361
  begin
362
    if clk'event and clk = '0' then
363
      if rst180_r = '1' then
364
        write_cmd1   <= '0';
365
        write_cmd2   <= '0';
366
        write_cmd3   <= '0';
367
      else
368
        if (accept_cmd_in = '1') then
369
          write_cmd1 <= write_cmd_in;
370
        end if;
371
        write_cmd2   <= write_cmd1;
372
        write_cmd3   <= write_cmd2;
373
      end if;
374
    end if;
375
  end process;
376
 
377
--******************************************************************************
378
-- read_cmd1 is asserted when user issued read command and the controller s/m
379
-- is in idle state and AUTO_REF is not asserted.
380
--******************************************************************************
381
 
382
  process(clk)
383
  begin
384
    if clk'event and clk = '0' then
385
      if rst180_r = '1' then
386
        read_cmd1   <= '0';
387
        read_cmd2   <= '0';
388
        read_cmd3   <= '0';
389
      else
390
        if (accept_cmd_in = '1') then
391
          read_cmd1 <= read_cmd_in;
392
        end if;
393
        read_cmd2   <= read_cmd1;
394
        read_cmd3   <= read_cmd2;
395
      end if;
396
    end if;
397
  end process;
398
 
399
--******************************************************************************
400
-- ras_count- Active to Precharge time
401
-- Controller is giving tras violation when user issues a single read command for 
402
-- BL=4 and tRAS is more then 42ns.It uses a fixed clk count of 7 clocks which is 
403
-- 7*6(@166) = 42ns. Addded ras_count counter which will take care of tras timeout. 
404
-- RAS_COUNT_VALUE parameter is used to load the counter and it depends on the 
405
-- selected memory and frequency
406
--******************************************************************************
407
  process(clk)
408
  begin
409
    if clk'event and clk = '0' then
410
      if rst180_r = '1' then
411
        ras_count <= "00000";
412
      elsif(current_state = ACTIVE) then
413
        ras_count <= RAS_COUNT_VALUE - '1';
414
      elsif(ras_count /= "00000") then
415
        ras_count <= ras_count - '1';
416
      end if;
417
    end if;
418
  end process;
419
--******************************************************************************
420
-- rfc_count
421
-- An executable command can be issued only after Trfc period after a AUTOREFRESH
422
-- command is issued. rfc_count_value is set in the parameter file depending on
423
-- the memory device speed grade and the selected frequency.For example for 5B
424
-- speed grade, at 133Mhz, rfc_counter_value = 8'b00001001.
425
-- ( Trfc/clk_period= 75/7.5= 10)
426
--******************************************************************************
427
 
428
  process(clk)
429
  begin
430
    if clk'event and clk = '0' then
431
      if rst180_r = '1' then
432
        rfc_count <= "00000000";
433
      elsif(current_state = AUTO_REFRESH) then
434
        rfc_count <= RFC_COUNT_VALUE;
435
      elsif(rfc_count /= "00000000") then
436
        rfc_count <= rfc_count - '1';
437
      end if;
438
    end if;
439
  end process;
440
 
441
--******************************************************************************
442
-- rp_count
443
-- An executable command can be issued only after Trp period after a PRECHARGE
444
-- command is issued. 
445
--******************************************************************************
446
 
447
  process(clk)
448
  begin
449
    if clk'event and clk = '0' then
450
      if rst180_r = '1' then
451
        rp_count <= "000";
452
      elsif(current_state = PRECHARGE) then
453
        rp_count <= RP_COUNT_VALUE;
454
      elsif(rp_count /= "000") then
455
        rp_count <= rp_count - '1';
456
      end if;
457
    end if;
458
  end process;
459
 
460
 
461
 
462
--******************************************************************************
463
-- rcd_count
464
-- ACTIVE to READ/WRITE delay - Minimum interval between ACTIVE and READ/WRITE command. 
465
--******************************************************************************
466
 
467
  process(clk)
468
  begin
469
    if (clk'event and clk = '0') then
470
      if (rst180_r = '1') then
471
        rcd_count <= "000";
472
      elsif (current_state = ACTIVE) then
473
        rcd_count <= "001";
474
      elsif (rcd_count /= "000") then
475
        rcd_count <= rcd_count - '1';
476
      end if;
477
    end if;
478
  end process;
479
 
480
--******************************************************************************
481
-- WR Counter
482
-- a PRECHARGE command can be applied only after 2 cycles after a WRITE command
483
-- has finished executing
484
--******************************************************************************
485
 
486
  process (clk)
487
  begin
488
    if clk'event and clk = '0' then
489
      if rst180_r = '1' then
490
        wr_count   <= "000";
491
      else
492
        if (dqs_enable_int = '1') then
493
          wr_count <= TWR_COUNT_VALUE;
494
        elsif (wr_count /= "000") then
495
          wr_count <= wr_count - "001";
496
        end if;
497
      end if;
498
    end if;
499
  end process;
500
 
501
--******************************************************************************
502
-- autoref_count - This counter is used to issue AUTO REFRESH command to
503
-- the memory for every 7.8125us.
504
-- (Auto Refresh Request is raised for every 7.7 us to allow for termination
505
-- of any ongoing bus transfer).For example at 166MHz frequency
506
-- autoref_count = refresh_time_period/clock_period = 7.7us/6.02ns = 1279
507
--******************************************************************************
508
 
509
  ref_freq_cnt <= MAX_REF_CNT;
510
 
511
  process(clk)
512
  begin
513
    if clk'event and clk = '0' then
514
      if rst180_r = '1' then
515
        autoref_value <= '0';
516
      elsif (autoref_count = ref_freq_cnt) then
517
        autoref_value <= '1';
518
      else
519
        autoref_value <= '0';
520
      end if;
521
    end if;
522
  end process;
523
 
524
  process(clk)
525
  begin
526
    if clk'event and clk = '0' then
527
      if rst180_r = '1' then
528
        autoref_count <= (others => '0');
529
      elsif (autoref_value = '1') then
530
        autoref_count <= (others => '0');
531
      else
532
        autoref_count <= autoref_count + '1';
533
      end if;
534
    end if;
535
  end process;
536
 
537
  process(clk)
538
  begin
539
    if clk'event and clk = '0' then
540
      if rst180_r = '1' then
541
        auto_ref_detect1 <= '0';
542
        auto_ref1        <= '0';
543
      else
544
        auto_ref_detect1 <= autoref_value and init_done;
545
        auto_ref1        <= auto_ref_detect1;
546
      end if;
547
    end if;
548
  end process;
549
 
550
  ar_done_p <= '1' when ar_done_reg = '1' else '0';
551
 
552
  process(clk)
553
  begin
554
    if clk'event and clk = '0' then
555
      if rst180_r = '1' then
556
        auto_ref_wait   <= '0';
557
        ar_done         <= '0';
558
        auto_ref_issued <= '0';
559
      else
560
        if (auto_ref1 = '1' and auto_ref_wait = '0') then
561
          auto_ref_wait <= '1';
562
        elsif (auto_ref_issued = '1') then
563
          auto_ref_wait <= '0';
564
        else
565
          auto_ref_wait <= auto_ref_wait;
566
        end if;
567
        ar_done         <= ar_done_p;
568
        auto_ref_issued <= auto_ref_issued_p;
569
      end if;
570
    end if;
571
  end process;
572
 
573
  process(clk)
574
  begin
575
    if clk'event and clk = '0' then
576
      if rst180_r = '1' then
577
        auto_ref_wait1   <= '0';
578
        auto_ref_wait2   <= '0';
579
        auto_ref         <= '0';
580
      else
581
        if (auto_ref_issued_p = '1') then
582
          auto_ref_wait1 <= '0';
583
          auto_ref_wait2 <= '0';
584
          auto_ref       <= '0';
585
        else
586
          auto_ref_wait1 <= auto_ref_wait;
587
          auto_ref_wait2 <= auto_ref_wait1;
588
          auto_ref       <= auto_ref_wait2;
589
        end if;
590
      end if;
591
    end if;
592
  end process;
593
 
594
  auto_ref_req      <= auto_ref_wait;
595
  auto_ref_issued_p <= '1' when (current_state = AUTO_REFRESH) else '0';
596
 
597
--******************************************************************************
598
-- Common counter for the Initialization sequence
599
--******************************************************************************
600
 
601
  process(clk)
602
  begin
603
    if (clk'event and clk = '0') then
604
      if (rst180_r = '1') then
605
        count6 <= "00000000";
606
      elsif(init_current_state = INIT_AUTO_REFRESH or init_current_state
607
            = INIT_PRECHARGE or init_current_state = INIT_LOAD_MODE_REG) then
608
        count6 <= RFC_COUNT_VALUE;
609
      elsif(count6 /= "00000000") then
610
        count6 <= count6 - '1';
611
      else
612
        count6 <= "00000000";
613
      end if;
614
    end if;
615
  end process;
616
 
617
--******************************************************************************
618
-- While doing consecutive READs or WRITEs, the burst_cnt_max value determines
619
-- when the next READ or WRITE command should be issued. burst_cnt_max shows the
620
-- number of clock cycles for each burst. 
621
-- e.g burst_cnt_max = 2 for a burst length of 4
622
--                   = 4 for a burst length of 8
623
--******************************************************************************
624
 
625
  burst_cnt_max <= "010" when burst_length = "010" else
626
                   "100" when burst_length = "011" else
627
                   "000";
628
 
629
 
630
  process(clk)
631
  begin
632
    if (clk'event and clk = '0') then
633
      if (rst180_r = '1') then
634
        cas_count <= "000";
635
      elsif(current_state = BURST_READ) then
636
        cas_count <= burst_cnt_max - '1';
637
      elsif(cas_count /= "000") then
638
        cas_count <= cas_count - '1';
639
      end if;
640
    end if;
641
  end process;
642
 
643
 
644
  process(clk)
645
  begin
646
    if (clk'event and clk = '0') then
647
      if (rst180_r = '1') then
648
        wrburst_end_cnt <= "000";
649
      elsif ((current_state = FIRST_WRITE) or (current_state = BURST_WRITE)) then
650
        wrburst_end_cnt <= burst_cnt_max;
651
      elsif (wrburst_end_cnt /= "000") then
652
        wrburst_end_cnt <= wrburst_end_cnt - '1';
653
      end if;
654
    end if;
655
  end process;
656
 
657
  process(clk)
658
  begin
659
    if clk'event and clk = '0' then
660
      if rst180_r = '1' then
661
        rdburst_end_1   <= '0';
662
      else
663
        if(burst_done = '1') then
664
          rdburst_end_1 <= '1';
665
        else
666
          rdburst_end_1 <= '0';
667
        end if;
668
        rdburst_end_2   <= rdburst_end_1;
669
      end if;
670
    end if;
671
  end process;
672
 
673
  rdburst_end <= rdburst_end_1 or rdburst_end_2;
674
 
675
  process(clk)
676
  begin
677
    if clk'event and clk = '0' then
678
      if rst180_r = '1' then
679
        wrburst_end_1   <= '0';
680
      else
681
        if (burst_done = '1') then
682
          wrburst_end_1 <= '1';
683
        else
684
          wrburst_end_1 <= '0';
685
        end if;
686
        wrburst_end_2   <= wrburst_end_1;
687
        wrburst_end_3   <= wrburst_end_2;
688
      end if;
689
    end if;
690
  end process;
691
 
692
  wrburst_end <= wrburst_end_1 or wrburst_end_2 or wrburst_end_3;
693
 
694
--******************************************************************************
695
-- dqs_enable and dqs_reset signals are used to generate DQS signal during write
696
-- data.
697
--******************************************************************************
698
  dqs_enable_out <= '1' when ((current_state = FIRST_WRITE) or
699
                              (current_state = BURST_WRITE) or
700
                              (WRburst_end_cnt /= "000")) else '0';
701
  dqs_reset_out  <= '1' when current_state = FIRST_WRITE  else '0';
702
  dqs_enable     <= dqs_enable_i;
703
 
704
    dqs_enable_i   <= dqs_enable2;
705
  dqs_reset      <= dqs_reset2_clk0;
706
 
707
  process(clk)
708
  begin
709
    if clk'event and clk = '0' then
710
      if rst180_r = '1' then
711
        dqs_enable_int <= '0';
712
        dqs_reset_int  <= '0';
713
      else
714
        dqs_enable_int <= dqs_enable_out;
715
        dqs_reset_int  <= dqs_reset_out;
716
      end if;
717
    end if;
718
  end process;
719
 
720
  process(clk)
721
  begin
722
    if clk'event and clk = '1' then
723
      if rst0_r = '1' then
724
        dqs_enable1     <= '0';
725
        dqs_enable2     <= '0';
726
        dqs_enable3     <= '0';
727
        dqs_reset1_clk0 <= '0';
728
        dqs_reset2_clk0 <= '0';
729
        dqs_reset3_clk0 <= '0';
730
      else
731
        dqs_enable1     <= dqs_enable_int;
732
        dqs_enable2     <= dqs_enable1;
733
        dqs_enable3     <= dqs_enable2;
734
        dqs_reset1_clk0 <= dqs_reset_int;
735
        dqs_reset2_clk0 <= dqs_reset1_clk0;
736
        dqs_reset3_clk0 <= dqs_reset2_clk0;
737
      end if;
738
    end if;
739
  end process;
740
 
741
--******************************************************************************
742
--Write Enable signal to the datapath
743
--******************************************************************************
744
 
745
  write_enable_out <= '1' when (wrburst_end_cnt /= "000")else '0';
746
  cmd_ack          <= ack_reg;
747
  ack_o            <= '1' when ((write_cmd_in = '1') or (write_cmd1 = '1') or
748
                                (read_cmd_in = '1') or (read_cmd1 = '1')) else '0';
749
 
750
 
751
  process(clk)
752
  begin
753
   if clk'event and clk = '0' then
754
    if rst180_r = '1' then
755
     write_enable <= '0';
756
    else
757
     write_enable <= write_enable_out;
758
    end if;
759
   end if;
760
  end process;
761
 
762
 
763
  ACK_REG_INST1 : FD
764
    port map (
765
      Q => ack_reg,
766
      D => ack_o,
767
      C => clk180
768
      );
769
 
770
--******************************************************************************
771
-- init_done will be asserted when initialization sequence is complete
772
--******************************************************************************
773
 
774
  process(clk)
775
  begin
776
    if clk'event and clk = '0' then
777
      if rst180_r = '1' then
778
        init_memory  <= '0';
779
        init_done    <= '0';
780
        init_done_r1 <= '0';
781
      else
782
        init_memory  <= init_mem;
783
        init_done_r1 <= init_done;
784
        if ((init_done_value = '1')and (init_count = "1011")) then
785
          init_done  <= '1';
786
        else
787
          init_done  <= '0';
788
        end if;
789
      end if;
790
    end if;
791
  end process;
792
 
793
  init_done_dis <= '1' when ( init_done = '1' and init_done_r1 = '0') else
794
                   '0';
795
 
796
  process(clk)
797
  begin
798
    if(clk'event and clk = '0') then
799
      if rst180_r = '0' then
800
        --synthesis translate_off
801
        assert (init_done_dis = '0') report "INITIALIZATION_DONE" severity note;
802
        --synthesis translate_on
803
      end if;
804
    end if;
805
  end process;
806
 
807
  process (clk)
808
  begin
809
    if clk'event and clk = '0' then
810
      if init_cmd_in = '1' or rst180_r = '1' then
811
        init_pre_count <= "1010000";
812
      else
813
        init_pre_count <= init_pre_count - "0000001";
814
      end if;
815
    end if;
816
  end process;
817
 
818
  process(clk)
819
  begin
820
    if clk'event and clk = '0' then
821
      if rst180_r = '1' then
822
        init_mem <= '0';
823
      elsif (init_cmd_in = '1') then
824
        init_mem <= '1';
825
      elsif ((init_count = "1011") and (count6 = "00000000")) then
826
        init_mem <= '0';
827
      else
828
        init_mem <= init_mem;
829
      end if;
830
    end if;
831
  end process;
832
 
833
-- Counter for Memory Initialization sequence
834
 
835
 
836
 process(clk)
837
  begin
838
    if(clk'event and clk = '0') then
839
      if rst180_r = '1' then
840
        init_count <= "0000";
841
      elsif(((init_current_state = INIT_PRECHARGE) or
842
                (init_current_state = INIT_LOAD_MODE_REG) or
843
                (init_current_state = INIT_AUTO_REFRESH)) and init_memory = '1') then
844
        init_count <= init_count + '1';
845
      else
846
        init_count <= init_count;
847
      end if;
848
    end if;
849
  end process;
850
 
851
 
852
  init_done_value     <= '1' when ((init_count = "1011") and
853
                               (dll_rst_count = "00000001")) else '0';
854
 
855
-- Counter to count 200 clock cycles When DLL reset is issued during initialization.
856
 
857
 
858
 process(clk)
859
  begin
860
    if(clk'event and clk = '0') then
861
      if rst180_r = '1' then
862
        dll_rst_count <= "00000000";
863
      elsif(init_count = "0100") then
864
        dll_rst_count <= "11001000";
865
      elsif(dll_rst_count /= "00000001") then
866
        dll_rst_count <= dll_rst_count - '1';
867
      else
868
        dll_rst_count <= dll_rst_count;
869
      end if;
870
    end if;
871
  end process;
872
 
873
 
874
  go_to_active_value  <= '1' when ((write_cmd_in = '1') and (accept_cmd_in = '1'))
875
                         or ((read_cmd_in = '1') and (accept_cmd_in = '1'))
876
                         else '0';
877
 
878
  process(clk)
879
  begin
880
    if clk'event and clk = '0' then
881
      if rst180_r = '1' then
882
        go_to_active <= '0';
883
      else
884
        go_to_active <= go_to_active_value;
885
      end if;
886
    end if;
887
  end process;
888
 
889
--******************************************************************************
890
-- Register counter values
891
--******************************************************************************
892
 
893
  process(clk)
894
  begin
895
    if clk'event and clk = '0' then
896
      if rst180_r = '1' then
897
        ar_done_reg   <= '0';
898
        rfc_count_reg <= '0';
899
      else
900
        if(rfc_count = "00000010") then
901
          ar_done_reg <= '1';
902
        else
903
          ar_done_reg <= '0';
904
        end if;
905
        if(ar_done_reg = '1') then
906
          rfc_count_reg <= '1';
907
        elsif (init_done = '1' and init_mem = '0' and rfc_count = "00000000")
908
        then
909
          rfc_count_reg <= '1';
910
        elsif (auto_ref_issued = '1') then
911
          rfc_count_reg <= '0';
912
        else
913
          rfc_count_reg <= rfc_count_reg;
914
        end if;
915
      end if;
916
    end if;
917
  end process;
918
 
919
--******************************************************************************
920
-- Initialization state machine
921
--******************************************************************************
922
 
923
  process(clk)
924
  begin
925
    if clk'event and clk = '0' then
926
      if rst180_r = '1' then
927
        init_current_state <= INIT_IDLE;
928
      else
929
        init_current_state <= init_next_state;
930
      end if;
931
    end if;
932
  end process;
933
 
934
  process (rst180_r, init_count, init_current_state, init_memory, count6,
935
           init_pre_count)
936
  begin
937
    if rst180_r = '1' then
938
      init_next_state             <= INIT_IDLE;
939
    else
940
      case init_current_state is
941
        when INIT_IDLE    =>
942
          if init_memory = '1' then
943
            case init_count is
944
              when "0000" =>
945
                if(init_pre_count = "0000001") then
946
                  init_next_state <= INIT_PRECHARGE;
947
                else
948
                  init_next_state <= INIT_IDLE;
949
                end if;
950
              when "0001" =>
951
                if (count6 = "00000000") then
952
                  init_next_state <= INIT_LOAD_MODE_REG;
953
                else
954
                  init_next_state <= INIT_IDLE;
955
                end if;
956
              when "0010" =>
957
                -- for reseting DLL in Base Mode register
958
                if (count6 = "00000000") then
959
                  init_next_state <= INIT_LOAD_MODE_REG;
960
                else
961
                  init_next_state <= INIT_IDLE;
962
                end if;
963
              when "0011" =>
964
                if (count6 = "00000000") then
965
                  init_next_state <= INIT_LOAD_MODE_REG;  -- For EMR
966
                else
967
                  init_next_state <= INIT_IDLE;
968
                end if;
969
              when "0100" =>
970
                if (count6 = "00000000") then
971
                  init_next_state <= INIT_LOAD_MODE_REG;  -- For EMR
972
                else
973
                  init_next_state <= INIT_IDLE;
974
                end if;
975
              when "0101" =>
976
                if (count6 = "00000000") then
977
                  init_next_state <= INIT_PRECHARGE;
978
                else
979
                  init_next_state <= INIT_IDLE;
980
                end if;
981
              when "0110" =>
982
                if (count6 = "00000000") then
983
                  init_next_state <= INIT_AUTO_REFRESH;
984
                else
985
                  init_next_state <= INIT_IDLE;
986
                end if;
987
              when "0111" =>
988
                if (count6 = "00000000") then
989
                  init_next_state <= INIT_AUTO_REFRESH;
990
                else
991
                  init_next_state <= INIT_IDLE;
992
                end if;
993
              when "1000" =>
994
                -- to deactivate the rst DLL bit in the LMR
995
                if (count6 = "00000000") then
996
                  init_next_state <= INIT_LOAD_MODE_REG;
997
                else
998
                  init_next_state <= INIT_IDLE;
999
                end if;
1000
              when "1001" =>
1001
                -- to set OCD to default in EMR
1002
                if (count6 = "00000000") then
1003
                  init_next_state <= INIT_LOAD_MODE_REG;
1004
                else
1005
                  init_next_state <= INIT_IDLE;
1006
                end if;
1007
              when "1010" =>
1008
                if (count6 = "00000000") then
1009
                  init_next_state <= INIT_LOAD_MODE_REG;  --  OCD exit in EMR
1010
                else
1011
                  init_next_state <= INIT_IDLE;
1012
                end if;
1013
              when "1011" =>
1014
                if (count6 = "00000000") then
1015
                  init_next_state <= INIT_IDLE;
1016
                else
1017
                  init_next_state <= init_current_state;
1018
                end if;
1019
              when others =>
1020
                init_next_state   <= INIT_IDLE;
1021
            end case;
1022
          else
1023
            init_next_state <= INIT_IDLE;
1024
          end if;
1025
        when INIT_PRECHARGE =>
1026
          init_next_state <= INIT_IDLE;
1027
        when INIT_LOAD_MODE_REG =>
1028
          init_next_state <= INIT_IDLE;
1029
        when INIT_AUTO_REFRESH =>
1030
          init_next_state <= INIT_IDLE;
1031
        when others =>
1032
          init_next_state <= INIT_IDLE;
1033
      end case;
1034
    end if;
1035
  end process;
1036
 
1037
--******************************************************************************
1038
-- MAIN state machine
1039
--******************************************************************************
1040
 
1041
  process(clk)
1042
  begin
1043
    if clk'event and clk = '0' then
1044
      if rst180_r = '1' then
1045
        current_state <= IDLE;
1046
      else
1047
        current_state <= next_state;
1048
      end if;
1049
    end if;
1050
  end process;
1051
 
1052
  process (rst180_r, cas_count, wr_count,
1053
           go_to_active, write_cmd1, read_cmd3, current_state,
1054
           wrburst_end, wrburst_end_cnt,
1055
           rdburst_end, init_memory,rcd_count, ras_count,
1056
           auto_ref, rfc_count_reg, rp_count)
1057
  begin
1058
    if rst180_r = '1' then
1059
      next_state         <= IDLE;
1060
    else
1061
      case current_state is
1062
 
1063
        when IDLE =>
1064
          if (init_memory = '0') then
1065
            if(auto_ref = '1' and rfc_count_reg = '1' and rp_count = "000") then
1066
              next_state <= AUTO_REFRESH;  -- normal Refresh in the IDLE state
1067
            elsif go_to_active = '1' then
1068
              next_state <= ACTIVE;
1069
            else
1070
              next_state <= IDLE;
1071
            end if;
1072
          else
1073
            next_state   <= IDLE;
1074
          end if;
1075
 
1076
        when PRECHARGE =>
1077
          next_state <= IDLE;
1078
 
1079
        when AUTO_REFRESH =>
1080
          next_state <= IDLE;
1081
 
1082
        when ACTIVE =>
1083
          next_state <= ACTIVE_WAIT;
1084
 
1085
        when ACTIVE_WAIT =>
1086
          if (rcd_count = "000" and write_cmd1 = '1') then
1087
            next_state <= FIRST_WRITE;
1088
          elsif (rcd_count = "000" and read_cmd3 = '1') then
1089
            next_state <= BURST_READ;
1090
          else
1091
            next_state <= ACTIVE_WAIT;
1092
          end if;
1093
 
1094
        when FIRST_WRITE =>
1095
          next_state <= WRITE_WAIT;
1096
 
1097
        when WRITE_WAIT =>
1098
          case wrburst_end is
1099
            when '1' =>
1100
              next_state <= PRECHARGE_AFTER_WRITE;
1101
            when '0' =>
1102
              if wrburst_end_cnt = "010" then
1103
                next_state <= BURST_WRITE;
1104
              else
1105
                next_state <= WRITE_WAIT;
1106
              end if;
1107
            when others =>
1108
              next_state   <= WRITE_WAIT;
1109
          end case;
1110
 
1111
        when BURST_WRITE =>
1112
          next_state <= WRITE_WAIT;
1113
 
1114
        when PRECHARGE_AFTER_WRITE =>
1115
          next_state <= PRECHARGE_AFTER_WRITE_2;
1116
 
1117
        when PRECHARGE_AFTER_WRITE_2 =>
1118
          if(wr_count = "00" and ras_count = "00000") then
1119
            next_state <= PRECHARGE;
1120
          else
1121
            next_state <= PRECHARGE_AFTER_WRITE_2;
1122
          end if;
1123
 
1124
        when READ_WAIT  =>
1125
          case rdburst_end is
1126
            when '1'    =>
1127
              next_state   <= PRECHARGE_AFTER_WRITE;
1128
            when '0'    =>
1129
              if cas_count = "001" then
1130
                next_state <= BURST_READ;
1131
              else
1132
                next_state <= READ_WAIT;
1133
              end if;
1134
            when others =>
1135
              next_state   <= READ_WAIT;
1136
          end case;
1137
 
1138
        when BURST_READ =>
1139
          next_state <= READ_WAIT;
1140
 
1141
        when others =>
1142
          next_state <= IDLE;
1143
      end case;
1144
    end if;
1145
  end process;
1146
 
1147
  process(clk)
1148
  begin
1149
    if clk'event and clk = '0' then
1150
      if rst180_r = '1' then
1151
        ddr_address1 <= (others => '0');
1152
      elsif (init_mem = '1') then
1153
        case (init_count) is
1154
          when "0000" | "0101" =>
1155
            ddr_address1 <= addr_const1((ROW_ADDRESS - 1) downto 0);
1156
          when "0001"               =>
1157
            ddr_address1 <= (others => '0');
1158
          when "0010"               =>
1159
            ddr_address1 <= (others => '0');
1160
          when "0011"               =>
1161
            ddr_address1 <= emr;
1162
          when "0100"               =>
1163
            ddr_address1 <= lmr_dll_rst;
1164
          when "1000"               =>
1165
            ddr_address1 <= lmr_dll_set;
1166
          when "1001"               =>
1167
            ddr_address1 <= emr or addr_const2((ROW_ADDRESS - 1) downto 0);
1168
          when "1010"               =>
1169
            ddr_address1 <= emr and addr_const3((ROW_ADDRESS - 1) downto 0);
1170
          when others               =>
1171
            ddr_address1 <= (others => '0');
1172
        end case;
1173
      elsif (current_state = PRECHARGE) then
1174
        ddr_address1 <= addr_const1((ROW_ADDRESS - 1) downto 0);
1175
      elsif (current_state = ACTIVE) then
1176
        ddr_address1 <= row_address_reg;
1177
      elsif (current_state = BURST_WRITE or current_state = FIRST_WRITE or
1178
             current_state = BURST_READ) then
1179
        ddr_address1 <= column_address_reg((ROW_ADDRESS - 1) downto 0);
1180
      else
1181
        ddr_address1 <= (others => '0');
1182
      end if;
1183
    end if;
1184
  end process;
1185
 
1186
  process(clk)
1187
  begin
1188
    if clk'event and clk = '0' then
1189
      if rst180_r = '1' then
1190
        ddr_ba1     <= (others => '0');
1191
      elsif (init_mem = '1') then
1192
        case (init_count) is
1193
          when "0001" =>
1194
            ddr_ba1 <= ba_const1((BANK_ADDRESS -1) downto 0);
1195
          when "0010" =>
1196
            ddr_ba1 <= ba_const2((BANK_ADDRESS -1) downto 0);
1197
          when "0011" | "1001" | "1010" =>
1198
            ddr_ba1 <= ba_const3((BANK_ADDRESS -1) downto 0);
1199
          when others =>
1200
            ddr_ba1 <= (others => '0');
1201
        end case;
1202
      elsif (current_state = ACTIVE or current_state = FIRST_WRITE or
1203
             current_state = BURST_WRITE or current_state = BURST_READ) then
1204
        ddr_ba1     <= ba_address_reg2;
1205
      else
1206
        ddr_ba1     <= (others => '0');
1207
      end if;
1208
    end if;
1209
  end process;
1210
 
1211
  process(clk)
1212
  begin
1213
    if clk'event and clk = '0' then
1214
      if rst180_r = '1' then
1215
        odt_deassert <= '0';
1216
      elsif(wrburst_end_3 = '1') then
1217
        odt_deassert <= '1';
1218
      elsif(write_cmd3 = '0') then
1219
        odt_deassert <= '0';
1220
      else
1221
        odt_deassert <= odt_deassert;
1222
      end if;
1223
    end if;
1224
  end process;
1225
 
1226
  ddr_odt1 <= '1' when (write_cmd3 = '1' and (emr(6) = '1' or emr(2) = '1') and
1227
                        odt_deassert = '0') else '0';
1228
 
1229
--******************************************************************************
1230
-- Register CONTROL SIGNALS outputs
1231
--******************************************************************************
1232
 
1233
  process(clk)
1234
  begin
1235
    if clk'event and clk = '0' then
1236
      if rst180_r = '1' then
1237
        ddr_odt2  <= '0';
1238
        ddr_rasb2 <= '1';
1239
        ddr_casb2 <= '1';
1240
        ddr_web2  <= '1';
1241
      else
1242
        ddr_odt2  <= ddr_odt1;
1243
        ddr_rasb2 <= ddr_rasb1;
1244
        ddr_casb2 <= ddr_casb1;
1245
        ddr_web2  <= ddr_web1;
1246
      end if;
1247
    end if;
1248
  end process;
1249
 
1250
  process(clk)
1251
  begin
1252
    if clk'event and clk = '0' then
1253
      if rst180_r = '1' then
1254
        ddr_odt_cntrl <= '0';
1255
      else
1256
        ddr_odt_cntrl <= ddr_odt2;
1257
      end if;
1258
    end if;
1259
  end process;
1260
 
1261
--******************************************************************************
1262
-- control signals to the Memory
1263
--******************************************************************************
1264
 
1265
  ddr_rasb1 <= '0' when (current_state = ACTIVE or current_state = PRECHARGE or
1266
                         current_state = AUTO_REFRESH or
1267
                         init_current_state = INIT_PRECHARGE or
1268
                         init_current_state = INIT_AUTO_REFRESH or
1269
                         init_current_state = INIT_LOAD_MODE_REG) else '1';
1270
 
1271
  ddr_casb1 <= '0' when (current_state = BURST_READ or
1272
                         current_state = BURST_WRITE or
1273
                         current_state = FIRST_WRITE or
1274
                         current_state = AUTO_REFRESH or
1275
                         init_current_state = INIT_AUTO_REFRESH or
1276
                         init_current_state = INIT_LOAD_MODE_REG) else '1';
1277
 
1278
  ddr_web1 <= '0' when (current_state = BURST_WRITE or
1279
                        current_state = FIRST_WRITE or
1280
                        current_state = PRECHARGE or
1281
                        init_current_state = INIT_PRECHARGE or
1282
                        init_current_state = INIT_LOAD_MODE_REG) else '1';
1283
 
1284
-------------------------------------------------------------------------------
1285
 
1286
  process(clk)
1287
  begin
1288
    if(clk'event and clk = '0') then
1289
      if rst180_r = '1' then
1290
        dqs_div_cascount     <= "000";
1291
      else
1292
        if(ddr_rasb2 = '1' and ddr_casb2 = '0' and ddr_web2 = '1') then
1293
          dqs_div_cascount   <= burst_cnt_max;
1294
        else
1295
          if dqs_div_cascount /= "000" then
1296
            dqs_div_cascount <= dqs_div_cascount - "001";
1297
          else
1298
            dqs_div_cascount <= dqs_div_cascount;
1299
          end if;
1300
        end if;
1301
      end if;
1302
    end if;
1303
  end process;
1304
 
1305
  process(clk)
1306
  begin
1307
    if(clk'event and clk = '0') then
1308
      if rst180_r = '1' then
1309
        dqs_div_rdburstcount     <= "000";
1310
      else
1311
        if (dqs_div_cascount = "001" and burst_length = "010") then
1312
          dqs_div_rdburstcount   <= "010";
1313
        elsif (dqs_div_cascount = "011" and burst_length = "011") then
1314
          dqs_div_rdburstcount   <= "100";
1315
        else
1316
          if dqs_div_rdburstcount /= "000" then
1317
            dqs_div_rdburstcount <= dqs_div_rdburstcount - "001";
1318
          else
1319
            dqs_div_rdburstcount <= dqs_div_rdburstcount;
1320
          end if;
1321
        end if;
1322
      end if;
1323
    end if;
1324
  end process;
1325
 
1326
  process(clk)
1327
  begin
1328
    if(clk'event and clk = '0') then
1329
      if rst180_r = '1' then
1330
        rst_dqs_div_r     <= '0';
1331
      else
1332
        if (dqs_div_cascount = "001" and burst_length = "010")then
1333
          rst_dqs_div_r   <= '1';
1334
        elsif (dqs_div_cascount = "011" and burst_length = "011")then
1335
          rst_dqs_div_r   <= '1';
1336
        else
1337
          if (dqs_div_rdburstcount = "001" and dqs_div_cascount = "000") then
1338
            rst_dqs_div_r <= '0';
1339
          else
1340
            rst_dqs_div_r <= rst_dqs_div_r;
1341
          end if;
1342
        end if;
1343
      end if;
1344
    end if;
1345
  end process;
1346
 
1347
  process(clk)                          -- For Reg dimm
1348
  begin
1349
    if(clk'event and clk = '0') then
1350
      rst_dqs_div_r1 <= rst_dqs_div_r;
1351
    end if;
1352
  end process;
1353
 
1354
  process (clk)
1355
  begin
1356
    if (clk'event and clk = '0') then
1357
      if (dqs_div_cascount /= "000" or dqs_div_rdburstcount /= "000") then
1358
        rst_calib <= '1';
1359
      else
1360
        rst_calib <= '0';
1361
      end if;
1362
    end if;
1363
  end process;
1364
 
1365
  rst_iob_out : FD
1366
    port map (
1367
      Q => rst_dqs_div_int1,
1368
            D => rst_dqs_div_r,
1369
      C => clk
1370
      );
1371
 
1372
--Read fifo read enable logic, this signal is same as rst_dqs_div_int signal for RDIMM 
1373
--and one clock ahead of rst_dqs_div_int for component or UDIMM OR SODIMM. 
1374
  process(clk)
1375
  begin
1376
    if clk'event and clk = '0' then
1377
      read_fifo_rden <= rst_dqs_div_r1;
1378
    end if;
1379
  end process;
1380
end arc;

powered by: WebSVN 2.1.0

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