00001 --**************************************************************
00002 --* *
00003 --* The source code for the ATLAS BCM "AAA" FPGA is made *
00004 --* available via the GNU General Public License (GPL) *
00005 --* unless otherwise stated below. *
00006 --* *
00007 --* In case of problems/questions/bug reports etc. please *
00008 --* contact michael.niegl@cern.ch *
00009 --* *
00010 --**************************************************************
00011
00012 --**************************************************************
00013 --* *
00014 --* $Source: /local/reps/bcmfpga/bcm_aaa/bcm_aaa/ddr2/ddr2_mem_ddr2_controller.vhd,v $
00015 --* $Revision: 1.4.2.5 $ *
00016 --* $Name: $ *
00017 --* $Author: mniegl $ *
00018 --* $Date: 2008/11/03 23:46:50 $ *
00019
00020
00021 --* *
00022 --**************************************************************
00023 -------------------------------------------------------------------------------
00024 -- Copyright (c) 2005 Xilinx, Inc.
00025 -- This design is confidential and proprietary of Xilinx, All Rights Reserved.
00026 -------------------------------------------------------------------------------
00027 -- ____ ____
00028 -- / /\/ /
00029 -- /___/ \ / Vendor: Xilinx
00030 -- \ \ \/ Version: 1.6
00031 -- \ \ Application : MIG
00032 -- / / Filename: ddr2_mem_ddr2_controller_0.vhd
00033 -- /___/ /\ Date Last Modified: Wed Jun 1 2005
00034 -- \ \ / \Date Created: Mon May 2 2005
00035 -- \___\/\___\
00036 --
00037 -- Device: Virtex-4
00038 -- Design Name: DDR2_V4
00039 -------------------------------------------------------------------------------
00040
00041
00042 library ieee;
00043
00044 use ieee.std_logic_1164.all;
00045
00046 use ieee.std_logic_unsigned.all;
00047
00048 use ieee.numeric_std.all;
00049 library work;
00050 use work.ddr2_mem_parameters_0.all;
00051
00052 library unisim;
00053
00054 use unisim.vcomponents.all;
00055
00056
00057
00058
00059
00060 entity ddr2_mem_ddr2_controller_0 is
00061 port(
00062 clk0 : in ;
00063 refresh_clk : in ;
00064 rst : in ;
00065 af_addr : in (35 downto 0);
00066 af_empty : in ;
00067 phy_Dly_Slct_Done : in ;
00068 COMP_DONE : in ;
00069 ctrl_dummy_wr_sel : out ;
00070 ctrl_Dummyread_Start : out ;
00071 burst_length : out (2 downto 0);
00072 ctrl_af_RdEn : out ;
00073 ctrl_Wdf_RdEn : out ;
00074 ctrl_Dqs_Rst : out ;
00075 ctrl_Dqs_En : out ;
00076 ctrl_WrEn : out ;
00077 ctrl_RdEn : out ;
00078 ctrl_ddr2_address : out ((row_address-1) downto 0);
00079 ctrl_ddr2_ba : out ((bank_address-1) downto 0);
00080 ctrl_ddr2_ras_L : out ;
00081 ctrl_ddr2_cas_L : out ;
00082 ctrl_ddr2_we_L : out ;
00083 ctrl_ddr2_cs_L : out ;
00084 ctrl_ddr2_cke : out ;
00085 ctrl_ddr2_odt : out ;
00086 dummy_write_flag : out
00087 );
00088 end entity;
00089
00090
00091
00092
00093
00094 architecture arc_controller of ddr2_mem_ddr2_controller_0 is
00095
00096 -- INTERNAL SIGNALS--
00097 signal init_count : (3 downto 0);
00098 signal init_count_cp : (3 downto 0);
00099 signal init_memory : ;
00100 signal count_200_cycle : (7 downto 0);
00101 signal ref_flag : ;
00102 signal ref_flag_266 : ;
00103 signal ref_flag_266_r : ;
00104 signal auto_ref : ;
00105 signal next_state : (4 downto 0);
00106 signal state : (4 downto 0);
00107 signal state_r2 : (4 downto 0);
00108 signal state_r3 : (4 downto 0);
00109 signal init_next_state : (4 downto 0);
00110 signal init_state : (4 downto 0);
00111 signal init_state_r2 : (4 downto 0);
00112 signal row_addr_r : ((row_address -1) downto 0);
00113 signal ddr2_address_init_r : ((row_address -1) downto 0);
00114 signal ddr2_address_r1 : ((row_address -1) downto 0);
00115 signal ddr2_address_r2 : ((row_address -1) downto 0);
00116 signal ddr2_ba_r1 : ((bank_address -1) downto 0);
00117 signal ddr2_ba_r2 : ((bank_address -1) downto 0);
00118 -- counters for ddr controller
00119 signal mrd_count : ;
00120 signal rp_count : (2 downto 0);
00121 signal rfc_count : (5 downto 0);
00122 signal rcd_count : (2 downto 0);
00123 signal ras_count : (3 downto 0);
00124 signal wr_to_rd_count : (3 downto 0);
00125 signal rd_to_wr_count : (3 downto 0);
00126 signal rtp_count : (3 downto 0);
00127 signal wtp_count : (3 downto 0);
00128 signal refi_count : (7 downto 0);
00129 signal cas_count : (2 downto 0);
00130 signal cas_check_count : (3 downto 0);
00131 signal wrburst_cnt : (2 downto 0);
00132 signal read_burst_cnt : (2 downto 0);
00133 signal ctrl_WrEn_cnt : (2 downto 0);
00134 signal rdburst_cnt : (3 downto 0);
00135 signal af_addr_r : (35 downto 0);
00136 signal af_addr_r1 : (35 downto 0);
00137 signal wdf_rden_r : ;
00138 signal wdf_rden_r2 : ;
00139 signal wdf_rden_r3 : ;
00140 signal wdf_rden_r4 : ;
00141 signal ctrl_Wdf_RdEn_int : ;
00142 signal af_rden : ;
00143 signal ddr2_ras_r2 : ;
00144 signal ddr2_cas_r2 : ;
00145 signal ddr2_we_r2 : ;
00146 signal ddr2_ras_r : ;
00147 signal ddr2_cas_r : ;
00148 signal ddr2_we_r : ;
00149 signal ddr2_ras_r3 : ;
00150 signal ddr2_cas_r3 : ;
00151 signal ddr2_we_r3 : ;
00152 signal idle_cnt : (3 downto 0);
00153 signal ctrl_Dummyread_Start_r1 : := '0';
00154 signal ctrl_Dummyread_Start_r2 : := '0';
00155 signal ctrl_Dummyread_Start_r3 : := '0';
00156 signal ctrl_Dummyread_Start_r4 : := '0';
00157 signal conflict_resolved_r : ;
00158 signal dqs_reset : ;
00159 signal dqs_reset_r1 : ;
00160 signal dqs_reset_r2 : ;
00161 signal dqs_reset_r3 : ;
00162 signal dqs_reset_r4 : ;
00163 signal dqs_reset_r5 : ;
00164 signal dqs_reset_r6 : ;
00165 signal dqs_en : ;
00166 signal dqs_en_r1 : ;
00167 signal dqs_en_r2 : ;
00168 signal dqs_en_r3 : ;
00169 signal dqs_en_r4 : ;
00170 signal dqs_en_r5 : ;
00171 signal dqs_en_r6 : ;
00172 signal ctrl_wdf_read_en : ;
00173 signal ctrl_wdf_read_en_r1 : ;
00174 signal ctrl_wdf_read_en_r2 : ;
00175 signal ctrl_wdf_read_en_r3 : ;
00176 signal ctrl_wdf_read_en_r4 : ;
00177 signal ctrl_wdf_read_en_r5 : ;
00178 signal ctrl_wdf_read_en_r6 : ;
00179 signal ddr2_cs_r1 : ;
00180 signal ddr2_cs_r : ;
00181 signal ddr2_cke_r : ;
00182 signal chip_cnt : (1 downto 0);
00183 signal auto_cnt : (2 downto 0);
00184 -- Precharge fix for deep memory
00185 signal pre_cnt : (2 downto 0);
00186 -- FIFO read enable signals
00187 -- Rst and Enable signals for DQS logic
00188 -- Read and Write Enable signals to the phy interface
00189 signal dummy_read_en : ;
00190 signal ctrl_init_done : ;
00191 signal count_200cycle_done_r : ;
00192 signal init_done : ;
00193 signal burst_cnt : (2 downto 0);
00194 signal ctrl_write_en : ;
00195 signal ctrl_write_en_r1 : ;
00196 signal ctrl_write_en_r2 : ;
00197 signal ctrl_write_en_r3 : ;
00198 signal ctrl_write_en_r4 : ;
00199 signal ctrl_write_en_r5 : ;
00200 signal ctrl_write_en_r6 : ;
00201 signal ctrl_read_en : ;
00202 signal ctrl_read_en_r : ;
00203 signal ctrl_read_en_r1 : ;
00204 signal ctrl_read_en_r2 : ;
00205 signal ctrl_read_en_r3 : ;
00206 signal odt_cnt : (3 downto 0);
00207 signal odt_en_cnt : (3 downto 0);
00208 signal odt_en : ;
00209 signal conflict_detect : ;
00210 signal conflict_detect_r : ;
00211 signal load_mode_reg : ((row_address-1) downto 0);
00212 signal ext_mode_reg : ((row_address-1) downto 0);
00213 signal CAS_LATENCY_VALUE : (2 downto 0);
00214 signal BURST_LENGTH_VALUE : (2 downto 0);
00215 signal ADDITIVE_LATENCY_VALUE : (2 downto 0);
00216 signal ODT_ENABLE : ;
00217 signal REGISTERED_VALUE : ;
00218 signal ECC_VALUE : ;
00219 signal WR : ;
00220 signal RD : ;
00221 signal LMR : ;
00222 signal PRE : ;
00223 signal REF : ;
00224 signal ACT : ;
00225 signal WR_r : ;
00226 signal RD_r : ;
00227 signal LMR_r : ;
00228 signal PRE_r : ;
00229 signal REF_r : ;
00230 signal ACT_r : ;
00231 signal af_empty_r : ;
00232 signal LMR_PRE_REF_ACT_cmd_r : ;
00233 signal cke_200us_cnt : (4 downto 0);
00234 signal done_200us : ;
00235 signal dummy_write_state_r : ;
00236 signal dummy_write_state : ;
00237 signal ctrl_dummy_write : ;
00238 signal dummy_write_flag_r : ;
00239 signal command_address : (2 downto 0);
00240 signal ctrl_odt : ;
00241 signal cs_width0 : (1 downto 0);
00242 signal cs_width1 : (2 downto 0);
00243 signal s1_h, s2_h, s3_h , s5_h : (3 downto 0);
00244 signal s4_h : (2 downto 0);
00245 signal COMP_DONE_r : ;
00246 signal ctrl_Dqs_Rst_r1 : ;
00247 signal ctrl_Dqs_En_r1 : ;
00248 signal ctrl_WrEn_r1 : ;
00249 signal ctrl_RdEn_r1 : ;
00250 signal ddr2_cs_r_out : ;
00251 signal ddr2_cs_r_odt : ;
00252 signal count6 : (5 downto 0);
00253
00254 constant INIT_IDLE : (4 downto 0) := "00000"; -- 5'h00//0_0000
00255 constant INIT_LOAD_MODE : (4 downto 0) := "00001"; -- 5'h01//0_0001
00256 constant INIT_MODE_REGISTER_WAIT : (4 downto 0) := "00010"; -- 5'h02//0_0010
00257 constant INIT_PRECHARGE : (4 downto 0) := "00011"; -- 5'h03//0_0011
00258 constant INIT_PRECHARGE_WAIT : (4 downto 0) := "00100"; -- 5'h04//0_0100
00259 constant INIT_AUTO_REFRESH : (4 downto 0) := "00101"; -- 5'h05//0_0101
00260 constant INIT_AUTO_REFRESH_WAIT : (4 downto 0) := "00110"; -- 5'h06//0_0110
00261 constant INIT_COUNT_200 : (4 downto 0) := "00111"; -- 5'h07//0_0111
00262 constant INIT_COUNT_200_WAIT : (4 downto 0) := "01000"; -- 5'h08//0_1000
00263 constant INIT_DUMMY_READ_CYCLES : (4 downto 0) := "01001"; -- 5'h09//0_1001
00264 constant INIT_DUMMY_ACTIVE : (4 downto 0) := "01010"; -- 5'h0A//0_1010
00265 constant INIT_DUMMY_ACTIVE_WAIT : (4 downto 0) := "01011"; -- 5'h0B//0_1011
00266 constant INIT_DUMMY_READ : (4 downto 0) := "01100"; -- 5'h0C//0_1100
00267 constant INIT_DUMMY_READ_WAIT : (4 downto 0) := "01101"; -- 5'h0D//0_1101
00268 constant INIT_DUMMY_FIRST_READ : (4 downto 0) := "01110"; -- 5'h0E//0_1110
00269 constant INIT_DEEP_MEMORY_ST : (4 downto 0) := "01111"; -- 5'h0F//0_1111
00270 constant INIT_ACTIVE : (4 downto 0) := "10000"; -- 5'h10//1_0000
00271 constant INIT_ACTIVE_WAIT : (4 downto 0) := "10001"; -- 5'h11//1_0001
00272 constant INIT_PATTERN_WRITE : (4 downto 0) := "10010"; -- 5'h12//1_0010
00273 constant INIT_PATTERN_WRITE_READ : (4 downto 0) := "10011"; -- 5'h13//1_0011
00274 constant INIT_PATTERN_READ : (4 downto 0) := "10100"; -- 5'h14//1_0100
00275 constant INIT_PATTERN_READ_WAIT : (4 downto 0) := "10101"; -- 5'h15//1_0101
00276 constant IDLE : (4 downto 0) := "00000"; -- 5'h00//0_0000
00277 constant LOAD_MODE : (4 downto 0) := "00001"; -- 5'h01//0_0001
00278 constant MODE_REGISTER_WAIT : (4 downto 0) := "00010"; -- 5'h02//0_0010
00279 constant PRECHARGE : (4 downto 0) := "00011"; -- 5'h03//0_0011
00280 constant PRECHARGE_WAIT : (4 downto 0) := "00100"; -- 5'h04//0_0100
00281 constant AUTO_REFRESH : (4 downto 0) := "00101"; -- 5'h05//0_0101
00282 constant AUTO_REFRESH_WAIT : (4 downto 0) := "00110"; -- 5'h06//0_0110
00283 constant ACTIVE : (4 downto 0) := "00111"; -- 5'h07//0_0111
00284 constant ACTIVE_WAIT : (4 downto 0) := "01000"; -- 5'h08//0_1000
00285 constant FIRST_READ : (4 downto 0) := "01001"; -- 5'h09//0_1001
00286 constant BURST_READ : (4 downto 0) := "01010"; -- 5'h0A//0_1010
00287 constant READ_WAIT : (4 downto 0) := "01011"; -- 5'h0B//0_1011
00288 constant FIRST_WRITE : (4 downto 0) := "01100"; -- 5'h0C//0_1100
00289 constant BURST_WRITE : (4 downto 0) := "01101"; -- 5'h0D//0_1101
00290 constant WRITE_WAIT : (4 downto 0) := "01110"; -- 5'h0E//0_1110
00291 constant WRITE_READ : (4 downto 0) := "01111"; -- 5'h0F//0_1111
00292 constant READ_WRITE : (4 downto 0) := "10000"; -- 5'h10//1_0000
00293 constant cntnext : (5 downto 0) := "101000";
00294
00295 attribute equivalent_register_removal : ;
00296 attribute equivalent_register_removal of ddr2_cs_r_odt : signal is "no";
00297
00298 begin
00299
00300 REGISTERED_VALUE <= '1';
00301 CAS_LATENCY_VALUE <= load_mode_reg(6 downto 4);
00302 BURST_LENGTH_VALUE <= load_mode_reg(2 downto 0);
00303 ADDITIVE_LATENCY_VALUE <= ext_mode_reg(5 downto 3);
00304 ODT_ENABLE <= ext_mode_reg(2) or ext_mode_reg(6);
00305 burst_length <= burst_cnt;
00306 command_address <= af_addr(34 downto 32);
00307 ECC_VALUE <= '0';
00308 dummy_write_flag <= dummy_write_flag_r;
00309 ctrl_af_RdEn <= af_rden; -- fifo control signals
00310 conflict_detect <= af_addr(35) and ctrl_init_done and (not af_empty);
00311 cs_width1 <= (('0' & cs_width0) + "001");
00312
00313 process(clk0)
00314 begin
00315 if (clk0 = '1' and clk0'event) then
00316 if (rst = '1') then
00317 ctrl_dummy_write <= '1';
00318 elsif(init_state = INIT_PATTERN_READ) then
00319 ctrl_dummy_write <= '0';
00320 end if;
00321 end if;
00322 end process;
00323
00324 process(clk0)
00325 begin
00326 if (clk0 = '1' and clk0'event) then
00327 if (rst = '1') then
00328 COMP_DONE_r <= '0';
00329 else
00330 COMP_DONE_r <= COMP_DONE;
00331 end if;
00332 end if;
00333 end process;
00334
00335 ctrl_Wdf_RdEn <= ctrl_Wdf_RdEn_int when (ctrl_dummy_write = '0') else '0';
00336
00337
00338 process(command_address, ctrl_init_done, af_empty)
00339 begin
00340 WR <= '0';
00341 RD <= '0';
00342 LMR <= '0';
00343 PRE <= '0';
00344 REF <= '0';
00345 ACT <= '0';
00346 if (ctrl_init_done = '1' and af_empty = '0') then
00347 case command_address is
00348 when "000" => LMR <= '1';
00349 when "001" => REF <= '1';
00350 when "010" => PRE <= '1';
00351 when "011" => ACT <= '1';
00352 when "100" => WR <= '1';
00353 when "101" => RD <= '1';
00354 when others => null;
00355 end case;
00356 end if;
00357 end process;
00358
00359
00360 process(clk0)
00361 begin
00362 if (clk0 = '1' and clk0'event) then
00363 if (rst = '1') then
00364 WR_r <= '0';
00365 RD_r <= '0';
00366 LMR_r <= '0';
00367 PRE_r <= '0';
00368 REF_r <= '0';
00369 ACT_r <= '0';
00370 af_empty_r <= '0';
00371 LMR_PRE_REF_ACT_cmd_r <= '0';
00372 else
00373 WR_r <= WR;
00374 RD_r <= RD;
00375 LMR_r <= LMR;
00376 PRE_r <= PRE;
00377 REF_r <= REF;
00378 ACT_r <= ACT;
00379 af_empty_r <= af_empty;
00380 LMR_PRE_REF_ACT_cmd_r <= LMR or PRE or REF or ACT;
00381 end if;
00382 end if;
00383 end process;
00384
00385
00386 process(clk0)
00387 begin
00388 if (clk0 = '1' and clk0'event) then
00389 if (rst = '1') then
00390 af_addr_r <= (others => '0');
00391 af_addr_r1 <= (others => '0');
00392 conflict_detect_r <= '0';
00393 else
00394 af_addr_r <= af_addr;
00395 af_addr_r1 <= af_addr_r;
00396 conflict_detect_r <= conflict_detect;
00397 end if;
00398 end if;
00399 end process;
00400
00401 process(clk0)
00402 begin
00403 if (clk0 = '1' and clk0'event) then
00404 if (rst = '1') then
00405 load_mode_reg <= load_mode_register;
00406 elsif((state = LOAD_MODE) and (LMR_r = '1') and (af_addr_r(((bank_address + row_address + col_ap_width)-1) downto (col_ap_width + row_address)) = "00")) then
00407 load_mode_reg <= af_addr((row_address-1) downto 0);
00408 end if;
00409 end if;
00410 end process;
00411
00412 process(clk0)
00413 begin
00414 if (clk0 = '1' and clk0'event) then
00415 if (rst = '1') then
00416 ext_mode_reg <= ext_load_mode_register;
00417 elsif((state = LOAD_MODE) and (LMR_r = '1') and (af_addr_r(((bank_address + row_address + col_ap_width)-1) downto (col_ap_width + row_address)) = "01")) then
00418 ext_mode_reg <= af_addr((row_address-1) downto 0);
00419 end if;
00420 end if;
00421 end process;
00422
00423
00424 process(clk0)
00425 begin
00426 if (clk0 = '1' and clk0'event) then
00427 if ((rst = '1') or (init_state = INIT_DEEP_MEMORY_ST)) then
00428 init_memory <= '1';
00429 elsif (init_count_cp = "1111") then
00430 init_memory <= '0';
00431 else
00432 init_memory <= init_memory;
00433 end if;
00434 end if;
00435 end process;
00436
00437
00438 process(clk0)
00439 begin
00440 if (clk0 = '1' and clk0'event) then
00441 if (rst = '1') then
00442 mrd_count <= '0';
00443 elsif (state = LOAD_MODE) then
00444 mrd_count <= mrd_count_value;
00445 elsif (mrd_count /= '0') then
00446 mrd_count <= '0';
00447 else
00448 mrd_count <= '0';
00449 end if;
00450 end if;
00451 end process;
00452
00453
00454 process(clk0)
00455 begin
00456 if (clk0 = '1' and clk0'event) then
00457 if (rst = '1') then
00458 rp_count(2 downto 0) <= "000";
00459 elsif (state = PRECHARGE) then
00460 rp_count(2 downto 0) <= rp_count_value;
00461 elsif (rp_count(2 downto 0) /= "000") then
00462 rp_count(2 downto 0) <= rp_count(2 downto 0) - "001";
00463 else
00464 rp_count(2 downto 0) <= "000";
00465 end if;
00466 end if;
00467 end process;
00468
00469
00470 process(clk0)
00471 begin
00472 if (clk0 = '1' and clk0'event) then
00473 if (rst = '1') then
00474 rfc_count(5 downto 0) <= (others => '0');
00475 elsif (state = AUTO_REFRESH) then
00476 rfc_count(5 downto 0) <= rfc_count_value;
00477 elsif (rfc_count(5 downto 0) /= "000000") then
00478 rfc_count(5 downto 0) <= rfc_count(5 downto 0) - "000001";
00479 else
00480 rfc_count(5 downto 0) <= "000000";
00481 end if;
00482 end if;
00483 end process;
00484
00485
00486 process(clk0)
00487 begin
00488 if (clk0 = '1' and clk0'event) then
00489 if (rst = '1') then
00490 rcd_count(2 downto 0) <= "000";
00491 elsif (state = ACTIVE) then
00492 rcd_count(2 downto 0) <= rcd_count_value - ADDITIVE_LATENCY_VALUE - "001";
00493 elsif (rcd_count(2 downto 0) /= "000") then
00494 rcd_count(2 downto 0) <= rcd_count(2 downto 0) - "001";
00495 else
00496 rcd_count(2 downto 0) <= "000";
00497 end if;
00498 end if;
00499 end process;
00500
00501
00502 process(clk0)
00503 begin
00504 if (clk0 = '1' and clk0'event) then
00505 if (rst = '1') then
00506 ras_count(3 downto 0) <= "0000";
00507 elsif (state = ACTIVE) then
00508 ras_count(3 downto 0) <= ras_count_value;
00509 elsif (ras_count(3 downto 1) = "000") then
00510 if (ras_count(0) /= '0') then
00511 ras_count(0) <= '0';
00512 end if;
00513 else
00514 ras_count(3 downto 0) <= ras_count(3 downto 0) - "0001";
00515 end if;
00516 end if;
00517 end process;
00518
00519
00520
00521 process(clk0)
00522 begin
00523 if (clk0 = '1' and clk0'event) then
00524 if (rst = '1') then
00525 rtp_count(3 downto 0) <= "0000";
00526 elsif ((state = FIRST_READ) or (state = BURST_READ)) then
00527 rtp_count(3 downto 0) <= (('0' & trtp_count_value) + ('0' & burst_cnt) + ('0' & ADDITIVE_LATENCY_VALUE) -"0011") ;
00528 elsif (rtp_count(3 downto 1) = "000") then
00529 if (rtp_count(0) /= '0') then
00530 rtp_count(0) <= '0';
00531 end if;
00532 else
00533 rtp_count(3 downto 0) <= rtp_count(3 downto 0) - "0001";
00534 end if;
00535 end if;
00536 end process;
00537
00538
00539
00540 process(clk0)
00541 begin
00542 if (clk0 = '1' and clk0'event) then
00543 if (rst = '1') then
00544 wtp_count(3 downto 0) <= "0000";
00545 elsif ((state = FIRST_WRITE) or (state = BURST_WRITE)) then
00546 wtp_count(3 downto 0) <= (('0' & twr_count_value) + ('0' & burst_cnt) + ('0' & CAS_LATENCY_VALUE) + ('0' & ADDITIVE_LATENCY_VALUE) -"0011") ;
00547 elsif (wtp_count(3 downto 1) = "000") then
00548 if (wtp_count(0) /= '0') then
00549 wtp_count(0) <= '0';
00550 end if;
00551 else
00552 wtp_count(3 downto 0) <= wtp_count(3 downto 0) - "0001";
00553 end if;
00554 end if;
00555 end process;
00556
00557
00558
00559 process(clk0)
00560 begin
00561 if (clk0 = '1' and clk0'event) then
00562 if (rst = '1') then
00563 wr_to_rd_count(3 downto 0) <= "0000";
00564 elsif ((state = FIRST_WRITE) or (state = BURST_WRITE)) then
00565 wr_to_rd_count(3 downto 0) <= (('0' & twtr_count_value) + ('0' & burst_cnt) + ('0' & ADDITIVE_LATENCY_VALUE) + ('0' & CAS_LATENCY_VALUE) - "0010");
00566 elsif (wr_to_rd_count(3 downto 0) /= "0000") then
00567 wr_to_rd_count(3 downto 0) <= wr_to_rd_count(3 downto 0) - "0001";
00568 else
00569 wr_to_rd_count(3 downto 0) <= "0000";
00570 end if;
00571 end if;
00572 end process;
00573
00574
00575 process(clk0)
00576 begin
00577 if (clk0 = '1' and clk0'event) then
00578 if (rst = '1') then
00579 rd_to_wr_count(3 downto 0) <= "0000";
00580 elsif ((state = FIRST_READ) or (state = BURST_READ)) then
00581 rd_to_wr_count(3 downto 0) <= (('0' & ADDITIVE_LATENCY_VALUE) + ("000" & REGISTERED_VALUE) + ('0' & burst_cnt));
00582 elsif (rd_to_wr_count(3 downto 0) /= "0000") then
00583 rd_to_wr_count(3 downto 0) <= rd_to_wr_count(3 downto 0) - "0001";
00584 else
00585 rd_to_wr_count(3 downto 0) <= "0000";
00586 end if;
00587 end if;
00588 end process;
00589
00590
00591 process(refresh_clk)
00592 begin
00593 if (refresh_clk = '1' and refresh_clk'event) then
00594 if (rst = '1') then
00595 refi_count <= "00000000";
00596 elsif (refi_count = max_ref_cnt) then
00597 refi_count <= "00000000";
00598 else
00599 refi_count <= refi_count + "00000001";
00600 end if;
00601 end if;
00602 end process;
00603
00604
00605 process(refi_count, done_200us)
00606 begin
00607 if ((refi_count = max_ref_cnt) and (done_200us = '1')) then
00608 ref_flag <= '1';
00609 else
00610 ref_flag <= '0';
00611 end if;
00612 end process;
00613
00614 -- 200us counter for cke
00615 process(refresh_clk)
00616 begin
00617 if (refresh_clk = '1' and refresh_clk'event) then
00618 if (rst = '1') then
00619 cke_200us_cnt <= "11011";
00620 -- cke_200us_cnt <= "00001";
00621 elsif (refi_count((max_ref_width-1) downto 0) = max_ref_cnt) then
00622 cke_200us_cnt <= cke_200us_cnt - "00001";
00623 else
00624 cke_200us_cnt <= cke_200us_cnt;
00625 end if;
00626 end if;
00627 end process;
00628
00629
00630 process(clk0)
00631 begin
00632 if (clk0 = '1' and clk0'event) then
00633 if (rst = '1') then
00634 ref_flag_266 <= '0';
00635 ref_flag_266_r <= '0';
00636 done_200us <= '0';
00637 else
00638 ref_flag_266 <= ref_flag;
00639 ref_flag_266_r <= ref_flag_266;
00640 if (done_200us = '0') then
00641 if (cke_200us_cnt = "00000") then
00642 done_200us <= '1';
00643 end if;
00644 end if;
00645 end if;
00646 end if;
00647 end process;
00648
00649
00650
00651
00652 process(clk0)
00653 begin
00654 if (clk0 = '1' and clk0'event) then
00655 if (rst = '1') then
00656 auto_ref <= '0';
00657 elsif (ref_flag_266 = '1' and ref_flag_266_r = '0') then
00658 auto_ref <= '1';
00659 elsif (state = AUTO_REFRESH) then
00660 auto_ref <= '0';
00661 else
00662 auto_ref <= auto_ref;
00663 end if;
00664 end if;
00665 end process;
00666
00667
00668
00669 process(clk0)
00670 begin
00671 if (clk0 = '1' and clk0'event) then
00672 if (rst = '1') then
00673 count_200_cycle(7 downto 0) <= "00000000";
00674 elsif (init_state = INIT_COUNT_200) then
00675 count_200_cycle(7 downto 0) <= X"C8";
00676 elsif (count_200_cycle(7 downto 0) /= "00000000") then
00677 count_200_cycle(7 downto 0) <= count_200_cycle(7 downto 0) - "00000001";
00678 else
00679 count_200_cycle(7 downto 0) <= "00000000";
00680 end if;
00681 end if;
00682 end process;
00683
00684
00685 process(clk0)
00686 begin
00687 if (clk0 = '1' and clk0'event) then
00688 if (rst = '1') then
00689 count_200cycle_done_r <= '0';
00690 elsif ((init_memory = '1') and (count_200_cycle = "00000000")) then
00691 count_200cycle_done_r <= '1';
00692 else
00693 count_200cycle_done_r <= '0';
00694 end if;
00695 end if;
00696 end process;
00697
00698
00699 process(clk0)
00700 begin
00701 if (clk0 = '1' and clk0'event) then
00702 if (rst = '1') then
00703 init_done <= '0';
00704 elsif ((init_count_cp = "1101") and (count_200cycle_done_r = '1') and (Phy_Mode = '0'))then
00705 init_done <= '1';
00706 elsif ((Phy_Mode = '1') and (COMP_DONE_r = '1') and (count6 = "010100")) then -- Precharge fix after pattern read
00707 init_done <= '1';
00708 else
00709 init_done <= init_done;
00710 end if;
00711 end if;
00712 end process;
00713
00714 ctrl_init_done <= init_done;
00715
00716
00717 process(BURST_LENGTH_VALUE)
00718 begin
00719 if (BURST_LENGTH_VALUE = "010") then
00720 burst_cnt <= "010";
00721 elsif (BURST_LENGTH_VALUE = "011") then
00722 burst_cnt <= "100";
00723 else
00724 burst_cnt <= "000";
00725 end if;
00726 end process;
00727
00728
00729 process(clk0)
00730 begin
00731 if (clk0 = '1' and clk0'event) then
00732 if ((rst = '1') or (init_state = INIT_DEEP_MEMORY_ST))then
00733 init_count(3 downto 0) <= "0000";
00734 elsif (init_memory = '1') then
00735 if (init_state = INIT_LOAD_MODE or init_state = INIT_PRECHARGE or init_state = INIT_AUTO_REFRESH or
00736 init_state = INIT_DUMMY_READ_CYCLES or init_state = INIT_COUNT_200 or init_state = INIT_DEEP_MEMORY_ST
00737 or init_state = INIT_PATTERN_WRITE) then
00738 init_count(3 downto 0) <= init_count(3 downto 0) + "0001";
00739 elsif(init_count = "1111") then
00740 init_count(3 downto 0) <= "0000";
00741 else
00742 init_count(3 downto 0) <= init_count(3 downto 0);
00743 end if;
00744 end if;
00745 end if;
00746 end process;
00747
00748
00749 process(clk0)
00750 begin
00751 if (clk0 = '1' and clk0'event) then
00752 if ((rst = '1') or (init_state = INIT_DEEP_MEMORY_ST)) then
00753 init_count_cp(3 downto 0) <= "0000";
00754 elsif (init_memory = '1') then
00755 if (init_state = INIT_LOAD_MODE or init_state = INIT_PRECHARGE or init_state = INIT_AUTO_REFRESH or
00756 init_state = INIT_DUMMY_READ_CYCLES or init_state = INIT_COUNT_200 or init_state = INIT_DEEP_MEMORY_ST
00757 or init_state = INIT_PATTERN_WRITE) then
00758 init_count_cp(3 downto 0) <= init_count_cp(3 downto 0) + "0001";
00759 elsif(init_count_cp = "1111") then
00760 init_count_cp(3 downto 0) <= "0000";
00761 else
00762 init_count_cp(3 downto 0) <= init_count_cp(3 downto 0);
00763 end if;
00764 end if;
00765 end if;
00766 end process;
00767
00768
00769 process(clk0)
00770 begin
00771 if (clk0 = '1' and clk0'event) then
00772 if (rst = '1') then
00773 chip_cnt <= "00";
00774 elsif (init_state = INIT_DEEP_MEMORY_ST) then
00775 chip_cnt <= chip_cnt + "01";
00776 else
00777 chip_cnt <= chip_cnt;
00778 end if;
00779 end if;
00780 end process;
00781
00782
00783 process(clk0)
00784 begin
00785 if (clk0 = '1' and clk0'event) then
00786 if (rst = '1' or state = PRECHARGE) then
00787 auto_cnt <= "000";
00788 elsif (state = AUTO_REFRESH and init_memory = '0') then
00789 auto_cnt <= auto_cnt + "001";
00790 else
00791 auto_cnt <= auto_cnt;
00792 end if;
00793 end if;
00794 end process;
00795
00796
00797 process(clk0)
00798 begin
00799 if (clk0 = '1' and clk0'event) then
00800 if (rst = '1' or state = auto_refresh) then
00801 pre_cnt <= "000";
00802 elsif (state = PRECHARGE and init_memory = '0' and auto_ref = '1') then
00803 pre_cnt <= pre_cnt + "001";
00804 else
00805 pre_cnt <= pre_cnt;
00806 end if;
00807 end if;
00808 end process;
00809
00810
00811 process(clk0)
00812 begin
00813 if (clk0 = '1' and clk0'event) then
00814 if (rst = '1') then
00815 wrburst_cnt(2 downto 0) <= "000";
00816 elsif (state = FIRST_WRITE or state = BURST_WRITE or init_state = INIT_PATTERN_WRITE) then
00817 wrburst_cnt(2 downto 0) <= burst_cnt(2 downto 0);
00818 elsif (wrburst_cnt(2 downto 0) /= "000") then
00819 wrburst_cnt(2 downto 0) <= wrburst_cnt(2 downto 0) - "001";
00820 else
00821 wrburst_cnt(2 downto 0) <= "000";
00822 end if;
00823 end if;
00824 end process;
00825
00826
00827 process(clk0)
00828 begin
00829 if (clk0 = '1' and clk0'event) then
00830 if (rst = '1') then
00831 read_burst_cnt(2 downto 0) <= "000";
00832 elsif (state = FIRST_READ or state = BURST_READ) then
00833 read_burst_cnt(2 downto 0) <= burst_cnt(2 downto 0);
00834 elsif (read_burst_cnt(2 downto 0) /= "000") then
00835 read_burst_cnt(2 downto 0) <= read_burst_cnt(2 downto 0) - "001";
00836 else
00837 read_burst_cnt(2 downto 0) <= "000";
00838 end if;
00839 end if;
00840 end process;
00841
00842
00843 process(clk0)
00844 begin
00845 if (clk0 = '1' and clk0'event) then
00846 if (rst = '1') then
00847 ctrl_WrEn_cnt(2 downto 0) <= "000";
00848 elsif (wdf_rden_r = '1' or dummy_write_state_r = '1') then
00849 ctrl_WrEn_cnt(2 downto 0) <= burst_cnt(2 downto 0);
00850 elsif (ctrl_WrEn_cnt(2 downto 0) /= "000") then
00851 ctrl_WrEn_cnt(2 downto 0) <= ctrl_WrEn_cnt(2 downto 0)- "001";
00852 else
00853 ctrl_WrEn_cnt(2 downto 0) <= "000";
00854 end if;
00855 end if;
00856 end process;
00857
00858
00859 process(ctrl_WrEn_cnt)
00860 begin
00861 if (ctrl_WrEn_cnt(2 downto 0) /= "000") then
00862 ctrl_write_en <= '1';
00863 else
00864 ctrl_write_en <= '0';
00865 end if;
00866 end process;
00867
00868 s1_h <= (('0' & ADDITIVE_LATENCY_VALUE) + ('0' & CAS_LATENCY_VALUE) + ("000" & REGISTERED_VALUE) + ("000" & ECC_VALUE)); -- internal signal to calculate the value of expression used in CASE
00869
00870 process(clk0)
00871 begin
00872
00873 if (clk0 = '1' and clk0'event) then
00874 if (rst = '1') then
00875 ctrl_WrEn_r1 <= '0';
00876 ctrl_write_en_r1 <= '0';
00877 ctrl_write_en_r2 <= '0';
00878 ctrl_write_en_r3 <= '0';
00879 ctrl_write_en_r4 <= '0';
00880 ctrl_write_en_r5 <= '0';
00881 ctrl_write_en_r6 <= '0';
00882 else
00883 ctrl_write_en_r1 <= ctrl_write_en;
00884 ctrl_write_en_r2 <= ctrl_write_en_r1;
00885 ctrl_write_en_r3 <= ctrl_write_en_r2;
00886 ctrl_write_en_r4 <= ctrl_write_en_r3;
00887 ctrl_write_en_r5 <= ctrl_write_en_r4;
00888 ctrl_write_en_r6 <= ctrl_write_en_r5;
00889
00890 case s1_h is
00891 when "0011" => ctrl_WrEn_r1 <= ctrl_write_en;
00892 when "0100" => ctrl_WrEn_r1 <= ctrl_write_en_r1;
00893 when "0101" => ctrl_WrEn_r1 <= ctrl_write_en_r2;
00894 when "0110" => ctrl_WrEn_r1 <= ctrl_write_en_r3;
00895 when "0111" => ctrl_WrEn_r1 <= ctrl_write_en_r4;
00896 when "1000" => ctrl_WrEn_r1 <= ctrl_write_en_r5;
00897 when "1001" => ctrl_WrEn_r1 <= ctrl_write_en_r6;
00898 when others => ctrl_WrEn_r1 <= '0';
00899 end case; -- case(ADDITIVE_LATENCY_VALUE + CAS_LATENCY_VALUE )
00900
00901 end if;
00902 end if;
00903 end process;
00904
00905
00906 process(state, init_state)
00907 begin
00908 if (state = FIRST_WRITE or init_state = INIT_PATTERN_WRITE) then
00909 dqs_reset <= '1';
00910 else
00911 dqs_reset <= '0';
00912 end if;
00913 end process;
00914
00915 s2_h <= (('0' & ADDITIVE_LATENCY_VALUE) + ('0' & CAS_LATENCY_VALUE)+("000" & REGISTERED_VALUE)+("000" & ECC_VALUE));
00916
00917
00918 process(clk0)
00919 begin
00920
00921 if (clk0 = '1' and clk0'event) then
00922 if (rst = '1') then
00923 ctrl_Dqs_Rst_r1 <= '0';
00924 dqs_reset_r1 <= '0';
00925 dqs_reset_r2 <= '0';
00926 dqs_reset_r3 <= '0';
00927 dqs_reset_r4 <= '0';
00928 dqs_reset_r5 <= '0';
00929 dqs_reset_r6 <= '0';
00930
00931 else
00932 dqs_reset_r1 <= dqs_reset;
00933 dqs_reset_r2 <= dqs_reset_r1;
00934 dqs_reset_r3 <= dqs_reset_r2;
00935 dqs_reset_r4 <= dqs_reset_r3;
00936 dqs_reset_r5 <= dqs_reset_r4;
00937 dqs_reset_r6 <= dqs_reset_r5;
00938
00939 case s2_h is
00940 when "0011" => ctrl_Dqs_Rst_r1 <= dqs_reset;
00941 when "0100" => ctrl_Dqs_Rst_r1 <= dqs_reset_r1;
00942 when "0101" => ctrl_Dqs_Rst_r1 <= dqs_reset_r2;
00943 when "0110" => ctrl_Dqs_Rst_r1 <= dqs_reset_r3;
00944 when "0111" => ctrl_Dqs_Rst_r1 <= dqs_reset_r4;
00945 when "1000" => ctrl_Dqs_Rst_r1 <= dqs_reset_r5;
00946 when "1001" => ctrl_Dqs_Rst_r1 <= dqs_reset_r6;
00947 when others => ctrl_Dqs_Rst_r1 <= '0';
00948 end case; -- case(ADDITIVE_LATENCY_VALUE + CAS_LATENCY_VALUE )
00949 end if;
00950 end if;
00951 end process;
00952
00953
00954 process(state , init_state, wrburst_cnt)
00955 begin
00956 if ((state = FIRST_WRITE) or (state = BURST_WRITE) or (init_state = INIT_PATTERN_WRITE) or (wrburst_cnt /= "000")) then
00957 dqs_en <= '1';
00958 else
00959 dqs_en <= '0';
00960 end if;
00961 end process;
00962
00963 s3_h <= (('0' & ADDITIVE_LATENCY_VALUE)+('0' & CAS_LATENCY_VALUE)+("000" & REGISTERED_VALUE)+("000" & ECC_VALUE));
00964
00965
00966 process(clk0)
00967 begin
00968
00969 if (clk0 = '1' and clk0'event) then
00970 if (rst = '1') then
00971 ctrl_Dqs_En_r1 <= '0';
00972 dqs_en_r1 <= '0';
00973 dqs_en_r2 <= '0';
00974 dqs_en_r3 <= '0';
00975 dqs_en_r4 <= '0';
00976 dqs_en_r5 <= '0';
00977 dqs_en_r6 <= '0';
00978
00979 else
00980 dqs_en_r1 <= dqs_en;
00981 dqs_en_r2 <= dqs_en_r1;
00982 dqs_en_r3 <= dqs_en_r2;
00983 dqs_en_r4 <= dqs_en_r3;
00984 dqs_en_r5 <= dqs_en_r4;
00985 dqs_en_r6 <= dqs_en_r5;
00986
00987 case s3_h is
00988 when "0011" => ctrl_Dqs_En_r1 <= dqs_en;
00989 when "0100" => ctrl_Dqs_En_r1 <= dqs_en_r1;
00990 when "0101" => ctrl_Dqs_En_r1 <= dqs_en_r2;
00991 when "0110" => ctrl_Dqs_En_r1 <= dqs_en_r3;
00992 when "0111" => ctrl_Dqs_En_r1 <= dqs_en_r4;
00993 when "1000" => ctrl_Dqs_En_r1 <= dqs_en_r5;
00994 when "1001" => ctrl_Dqs_En_r1 <= dqs_en_r6;
00995 when others => ctrl_Dqs_En_r1 <= '0';
00996 end case;
00997 end if;
00998 end if;
00999 end process;
01000
01001
01002
01003 process(clk0)
01004 begin
01005 if (clk0 = '1' and clk0'event) then
01006 if (rst = '1') then
01007 cas_count(2 downto 0) <= "000";
01008 elsif (init_state = INIT_DUMMY_FIRST_READ) then
01009 cas_count(2 downto 0) <= CAS_LATENCY_VALUE + ("00" & REGISTERED_VALUE);
01010 elsif (cas_count(2 downto 0) /= "000") then
01011 cas_count(2 downto 0) <= cas_count(2 downto 0) - "001";
01012 else
01013 cas_count(2 downto 0) <= "000";
01014 end if;
01015 end if;
01016 end process;
01017
01018
01019 process(clk0)
01020 begin
01021 if (clk0 = '1' and clk0'event) then
01022 if (rst = '1') then
01023 dummy_read_en <= '0';
01024 elsif (init_state = INIT_DUMMY_READ) then
01025 dummy_read_en <= '1';
01026 elsif (phy_Dly_Slct_Done = '1') then
01027 dummy_read_en <= '0';
01028 else
01029 dummy_read_en <= dummy_read_en;
01030 end if;
01031 end if;
01032 end process;
01033
01034
01035 process(clk0)
01036 begin
01037 if (clk0 = '1' and clk0'event) then
01038 if ((dummy_read_en = '1') and (cas_count = "000")) then
01039 ctrl_Dummyread_Start_r1 <= '1';
01040 elsif (phy_Dly_Slct_Done = '1') then
01041 ctrl_Dummyread_Start_r1 <= '0';
01042 else
01043 ctrl_Dummyread_Start_r1 <= ctrl_Dummyread_Start_r1;
01044 end if;
01045 end if;
01046 end process;
01047
01048
01049 process(clk0)
01050 begin
01051 if (clk0 = '1' and clk0'event) then
01052 ctrl_Dummyread_Start_r2 <= ctrl_Dummyread_Start_r1;
01053 ctrl_Dummyread_Start_r3 <= ctrl_Dummyread_Start_r2;
01054 ctrl_Dummyread_Start_r4 <= ctrl_Dummyread_Start_r3;
01055 ctrl_Dummyread_Start <= ctrl_Dummyread_Start_r4;
01056 end if;
01057 end process;
01058
01059
01060
01061
01062
01063 process(clk0)
01064 begin
01065 if (clk0 = '1' and clk0'event) then
01066 if (rst = '1') then
01067 idle_cnt(3 downto 0) <= "0000";
01068 elsif (state = FIRST_READ or state = FIRST_WRITE or state = BURST_READ or state = BURST_WRITE) then
01069 idle_cnt(3 downto 0) <= "1111";
01070 elsif (idle_cnt(3 downto 0) /= "0000") then
01071 idle_cnt(3 downto 0) <= idle_cnt(3 downto 0) - "0001";
01072 else
01073 idle_cnt(3 downto 0) <= "0000";
01074 end if;
01075 end if;
01076 end process;
01077
01078
01079 process(clk0)
01080 begin
01081 if (clk0 = '1' and clk0'event) then
01082 if (rst = '1') then
01083 cas_check_count(3 downto 0) <= "0000";
01084 elsif ((state_r2 = FIRST_READ) or (init_state_r2 = INIT_PATTERN_READ)) then
01085 cas_check_count(3 downto 0) <= (('0' & CAS_LATENCY_VALUE) - "0001");
01086 elsif (cas_check_count(3 downto 0) /= "0000") then
01087 cas_check_count(3 downto 0) <= cas_check_count(3 downto 0) - "0001";
01088 else
01089 cas_check_count(3 downto 0) <= "0000";
01090 end if;
01091 end if;
01092 end process;
01093
01094
01095 process(clk0)
01096 begin
01097 if (clk0 = '1' and clk0'event) then
01098 if (rst = '1') then
01099 rdburst_cnt(3 downto 0) <= "0000";
01100 elsif (cas_check_count = "0010") then
01101 rdburst_cnt(3 downto 0) <= ('0' & burst_cnt(2 downto 0));
01102 elsif(state_r3 = BURST_READ) then
01103 if(burst_cnt(2) = '1') then
01104 rdburst_cnt(3 downto 0) <= ((burst_cnt(2 downto 0) & '0') -("0111" - ('0' & CAS_LATENCY_VALUE)));
01105 else
01106 rdburst_cnt(3 downto 0) <= ((burst_cnt(2 downto 0) & '0') -("0101" - ('0' & CAS_LATENCY_VALUE)));
01107 end if;
01108 elsif (rdburst_cnt(3 downto 0) /= "0000") then
01109 rdburst_cnt(3 downto 0) <= rdburst_cnt(3 downto 0) - "0001";
01110 else
01111 rdburst_cnt(3 downto 0) <= "0000";
01112 end if;
01113 end if;
01114 end process;
01115
01116
01117 process(rdburst_cnt)
01118 begin
01119 if (rdburst_cnt = "0000") then
01120 ctrl_read_en <= '0';
01121 else
01122 ctrl_read_en <= '1';
01123 end if;
01124 end process;
01125
01126
01127 process(clk0)
01128 begin
01129 if (clk0 = '1' and clk0'event) then
01130 if (rst = '1') then
01131 ctrl_read_en_r <= '0';
01132 ctrl_read_en_r1 <= '0';
01133 ctrl_read_en_r2 <= '0';
01134 ctrl_read_en_r3 <= '0';
01135 else
01136 ctrl_read_en_r <= ctrl_read_en;
01137 ctrl_read_en_r1 <= ctrl_read_en_r;
01138 ctrl_read_en_r2 <= ctrl_read_en_r1;
01139 ctrl_read_en_r3 <= ctrl_read_en_r2;
01140 end if;
01141 end if;
01142 end process;
01143
01144 s4_h <= (ADDITIVE_LATENCY_VALUE + ("00" & ECC_VALUE) + ("00" & REGISTERED_VALUE));
01145
01146
01147 process(clk0)
01148 begin
01149
01150 if (clk0 = '1' and clk0'event) then
01151 if (rst = '1') then
01152 ctrl_RdEn_r1 <= '0';
01153 else
01154 case s4_h is
01155 when "000" => ctrl_RdEn_r1 <= ctrl_read_en;
01156 when "001" => ctrl_RdEn_r1 <= ctrl_read_en_r;
01157 when "010" => ctrl_RdEn_r1 <= ctrl_read_en_r1;
01158 when "011" => ctrl_RdEn_r1 <= ctrl_read_en_r2;
01159 when "100" => ctrl_RdEn_r1 <= ctrl_read_en_r3;
01160 when others => ctrl_RdEn_r1 <= '0';
01161 end case; -- case(ADDITIVE_LATENCY_VALUE)
01162 end if; -- else: !if(rst)
01163 end if;
01164 end process;
01165
01166 --**********************************************************************************************************************************************************//
01167 -- Code Changed
01168 --**********************************************************************************************************************************************************//
01169
01170 af_rden <= '1' when ((state = FIRST_WRITE) or (state = FIRST_READ) or (state = BURST_WRITE) or (state = BURST_READ) or
01171 ((state = MODE_REGISTER_WAIT) and (LMR_r = '1') and (mrd_count = '0')) or ((state = PRECHARGE)and (PRE_r = '1')) or
01172 ((state = AUTO_REFRESH) and (REF_r = '1')) or ((state = ACTIVE) and (ACT_r = '1'))) else '0';
01173
01174
01175 process(clk0)
01176 begin
01177 if (clk0 = '1' and clk0'event) then
01178 if (rst = '1') then
01179 wdf_rden_r <= '0';
01180 elsif ((state = FIRST_WRITE) or (state = BURST_WRITE) or (init_state = INIT_PATTERN_WRITE)) then -- place holder for BURST_WRITE
01181 wdf_rden_r <= '1';
01182 else
01183 wdf_rden_r <= '0';
01184 end if;
01185 end if;
01186 end process;
01187
01188
01189 process(clk0)
01190 begin
01191 if (clk0 = '1' and clk0'event) then
01192 if (rst = '1') then
01193 wdf_rden_r2 <= '0';
01194 wdf_rden_r3 <= '0';
01195 wdf_rden_r4 <= '0';
01196 else
01197 wdf_rden_r2 <= wdf_rden_r;
01198 wdf_rden_r3 <= wdf_rden_r2;
01199 wdf_rden_r4 <= wdf_rden_r3;
01200 end if; --else: !if(rst)
01201 end if;
01202 end process;
01203
01204
01205 process(burst_cnt, wdf_rden_r, wdf_rden_r2, wdf_rden_r3, wdf_rden_r4)
01206 begin
01207 if (burst_cnt = "010") then
01208 ctrl_wdf_read_en <= (wdf_rden_r or wdf_rden_r2);
01209 elsif (burst_cnt = "100") then
01210 ctrl_wdf_read_en <= (wdf_rden_r or wdf_rden_r2 or wdf_rden_r3 or wdf_rden_r4);
01211 else
01212 ctrl_wdf_read_en <= '0';
01213 end if;
01214 end process;
01215
01216 s5_h <= (('0' & ADDITIVE_LATENCY_VALUE)+('0' & CAS_LATENCY_VALUE)+("000" & REGISTERED_VALUE));
01217
01218
01219 process(clk0)
01220 begin
01221 if (clk0 = '1' and clk0'event) then
01222 if (rst = '1') then
01223 ctrl_Wdf_RdEn_int <= '0';
01224 ctrl_wdf_read_en_r1 <= '0';
01225 ctrl_wdf_read_en_r2 <= '0';
01226 ctrl_wdf_read_en_r3 <= '0';
01227 ctrl_wdf_read_en_r4 <= '0';
01228 ctrl_wdf_read_en_r5 <= '0';
01229 ctrl_wdf_read_en_r6 <= '0';
01230 else
01231 ctrl_wdf_read_en_r1 <= ctrl_wdf_read_en;
01232 ctrl_wdf_read_en_r2 <= ctrl_wdf_read_en_r1;
01233 ctrl_wdf_read_en_r3 <= ctrl_wdf_read_en_r2;
01234 ctrl_wdf_read_en_r4 <= ctrl_wdf_read_en_r3;
01235 ctrl_wdf_read_en_r5 <= ctrl_wdf_read_en_r4;
01236 ctrl_wdf_read_en_r6 <= ctrl_wdf_read_en_r5;
01237 case s5_h is
01238 when "0011" => ctrl_Wdf_RdEn_int <= ctrl_wdf_read_en;
01239 when "0100" => ctrl_Wdf_RdEn_int <= ctrl_wdf_read_en_r1;
01240 when "0101" => ctrl_Wdf_RdEn_int <= ctrl_wdf_read_en_r2;
01241 when "0110" => ctrl_Wdf_RdEn_int <= ctrl_wdf_read_en_r3;
01242 when "0111" => ctrl_Wdf_RdEn_int <= ctrl_wdf_read_en_r4;
01243 when "1000" => ctrl_Wdf_RdEn_int <= ctrl_wdf_read_en_r5;
01244 when "1001" => ctrl_Wdf_RdEn_int <= ctrl_wdf_read_en_r6;
01245 when others => ctrl_Wdf_RdEn_int <= '0';
01246 end case;
01247 end if; -- else: !if(rst)
01248 end if;
01249 end process;
01250
01251
01252 process(clk0)
01253 begin
01254 if (clk0 = '1' and clk0'event) then
01255 if (rst = '1') then
01256 count6 <= "000000";
01257 else
01258 case init_state is
01259
01260 when INIT_PRECHARGE_WAIT | INIT_MODE_REGISTER_WAIT | INIT_AUTO_REFRESH_WAIT |
01261 INIT_ACTIVE_WAIT | INIT_PATTERN_WRITE_READ | INIT_PATTERN_READ_WAIT |
01262 INIT_DUMMY_READ_WAIT | INIT_DUMMY_ACTIVE_WAIT =>
01263 count6 <= count6 + "000001";
01264
01265 when others => count6 <= "000000";
01266 end case;
01267 end if;
01268 end if;
01269 end process;
01270
01271
01272 process(clk0)
01273 begin
01274 if (clk0 = '1' and clk0'event) then
01275 if (rst = '1') then
01276 init_state <= INIT_IDLE;
01277 else
01278 init_state <= init_next_state;
01279 end if;
01280 end if;
01281 end process;
01282
01283
01284 process(clk0)
01285 begin
01286 if (clk0 = '1' and clk0'event) then
01287 if (rst = '1') then
01288 state <= IDLE;
01289 else
01290 state <= next_state;
01291 end if;
01292 end if;
01293 end process;
01294
01295
01296 process(clk0)
01297 begin
01298 if (clk0 = '1' and clk0'event) then
01299 if (rst = '1') then
01300 dummy_write_flag_r <= '0';
01301 elsif(phy_Dly_Slct_Done = '1' and COMP_DONE_r = '0') then
01302 dummy_write_flag_r <= '1';
01303 elsif(COMP_DONE_r = '1') then
01304 dummy_write_flag_r <= '0';
01305 end if;
01306 end if;
01307 end process;
01308
01309 dummy_write_state <= '1' when (init_state = INIT_PATTERN_WRITE) else '0';
01310
01311
01312 process(clk0)
01313 begin
01314 if (clk0 = '1' and clk0'event) then
01315 if (rst = '1') then
01316 dummy_write_state_r <= '0';
01317 else
01318 dummy_write_state_r <= dummy_write_state;
01319 end if;
01320 end if;
01321 end process;
01322
01323 cs_width0 <= "00" when cs_width = 1 else
01324 "01" when cs_width = 2 else
01325 "10" when cs_width = 3 else
01326 "11" when cs_width = 4;
01327
01328
01329 process(RD, RD_r, WR, WR_r, LMR_r, PRE_r, ACT_r, REF_r,
01330 auto_ref, chip_cnt, auto_cnt, conflict_detect, conflict_detect_r,
01331 conflict_resolved_r, count_200cycle_done_r, idle_cnt,
01332 init_count, init_memory, mrd_count, LMR_PRE_REF_ACT_cmd_r,
01333 phy_Dly_Slct_Done, ras_count, rcd_count, rd_to_wr_count,
01334 read_burst_cnt, rfc_count, rp_count, rtp_count,
01335 init_state, wr_to_rd_count, wrburst_cnt, wtp_count, done_200us,
01336 cs_width0, dummy_write_flag_r, COMP_DONE_r, count6)
01337 begin
01338 init_next_state <= init_state;
01339 case init_state is
01340 when INIT_IDLE =>
01341 if (init_memory = '1' and done_200us = '1') then
01342 case init_count is -- synthesis parallel_case full_case
01343 when "0000" =>
01344 init_next_state <= INIT_COUNT_200;
01345
01346 when "0001" =>
01347 if (count_200cycle_done_r = '1') then
01348 init_next_state <= INIT_PRECHARGE;
01349 else
01350 init_next_state <= INIT_IDLE;
01351 end if;
01352
01353 when "0010" =>
01354 init_next_state <= INIT_LOAD_MODE; -- emr(2)
01355
01356 when "0011" =>
01357 init_next_state <= INIT_LOAD_MODE; -- emr(3)
01358
01359 when "0100" =>
01360 init_next_state <= INIT_LOAD_MODE; -- emr
01361
01362 when "0101" =>
01363 init_next_state <= INIT_LOAD_MODE; --lmr
01364
01365 when "0110" =>
01366 init_next_state <= INIT_PRECHARGE;
01367
01368 when "0111" =>
01369 init_next_state <= INIT_AUTO_REFRESH;
01370
01371 when "1000" =>
01372 init_next_state <= INIT_AUTO_REFRESH;
01373
01374 when "1001" =>
01375 init_next_state <= INIT_LOAD_MODE;
01376
01377 when "1010" => -- EMR OCD DEFAULT
01378 init_next_state <= INIT_LOAD_MODE;
01379
01380 when "1011" => -- EMR OCD EXIT
01381 init_next_state <= INIT_LOAD_MODE;
01382
01383 when "1100" =>
01384 init_next_state <= INIT_COUNT_200;
01385
01386 when "1101" =>
01387 if (chip_cnt < cs_width0) then
01388 -- if (chip_cnt < (cs_width- 1)) then
01389 init_next_state <= INIT_DEEP_MEMORY_ST;
01390 elsif (Phy_Mode = '1' and count_200cycle_done_r = '1') then
01391 init_next_state <= INIT_DUMMY_READ_CYCLES;
01392 else
01393 init_next_state <= INIT_IDLE;
01394 end if;
01395
01396 when "1110" =>
01397 if (phy_Dly_Slct_Done = '1') then
01398 init_next_state <= INIT_PRECHARGE;
01399 else
01400 init_next_state <= INIT_IDLE;
01401 end if;
01402
01403 when "1111" =>
01404 if (COMP_DONE_r = '1') then
01405 init_next_state <= INIT_IDLE;
01406 end if;
01407
01408 when others => init_next_state <= INIT_IDLE;
01409
01410 end case; -- case(init_count)
01411
01412 end if; -- case: INIT_IDLE
01413
01414 when INIT_DEEP_MEMORY_ST =>
01415 init_next_state <= INIT_IDLE;
01416
01417 when INIT_COUNT_200 =>
01418 init_next_state <= INIT_COUNT_200_WAIT;
01419
01420 when INIT_COUNT_200_WAIT =>
01421 if (count_200cycle_done_r = '1') then
01422 init_next_state <= INIT_IDLE;
01423 else
01424 init_next_state <= INIT_COUNT_200_WAIT;
01425 end if;
01426
01427 when INIT_DUMMY_READ_CYCLES =>
01428 init_next_state <= INIT_DUMMY_ACTIVE;
01429
01430 when INIT_DUMMY_ACTIVE =>
01431 init_next_state <= INIT_DUMMY_ACTIVE_WAIT;
01432
01433 when INIT_DUMMY_ACTIVE_WAIT =>
01434 if (count6 = cntnext) then
01435 init_next_state <= INIT_DUMMY_FIRST_READ;
01436 else
01437 init_next_state <= INIT_DUMMY_ACTIVE_WAIT;
01438 end if;
01439
01440 when INIT_DUMMY_FIRST_READ =>
01441 init_next_state <= INIT_DUMMY_READ_WAIT;
01442
01443 when INIT_DUMMY_READ =>
01444 init_next_state <= INIT_DUMMY_READ_WAIT;
01445
01446 when INIT_DUMMY_READ_WAIT =>
01447 if (phy_Dly_Slct_Done = '1') then
01448 if(count6 = cntnext) then
01449 init_next_state <= INIT_PATTERN_WRITE;
01450 else
01451 init_next_state <= INIT_DUMMY_READ_WAIT;
01452 end if;
01453 else
01454 init_next_state <= INIT_DUMMY_READ;
01455 end if;
01456
01457 -- pattern write
01458 when INIT_PRECHARGE =>
01459 init_next_state <= INIT_PRECHARGE_WAIT;
01460
01461 when INIT_PRECHARGE_WAIT =>
01462 if (count6 = cntnext) then
01463 init_next_state <= INIT_IDLE;
01464 else
01465 init_next_state <= INIT_PRECHARGE_WAIT;
01466 end if;
01467
01468 when INIT_LOAD_MODE =>
01469 init_next_state <= INIT_MODE_REGISTER_WAIT;
01470
01471 when INIT_MODE_REGISTER_WAIT =>
01472 if (count6 = cntnext) then
01473 init_next_state <= INIT_IDLE;
01474 else
01475 init_next_state <= INIT_MODE_REGISTER_WAIT;
01476 end if;
01477
01478 when INIT_AUTO_REFRESH =>
01479 init_next_state <= INIT_AUTO_REFRESH_WAIT;
01480
01481 when INIT_AUTO_REFRESH_WAIT =>
01482 if (count6 = cntnext) then
01483 init_next_state <= INIT_IDLE;
01484 else
01485 init_next_state <= INIT_AUTO_REFRESH_WAIT;
01486 end if;
01487
01488 when INIT_ACTIVE =>
01489 init_next_state <= INIT_ACTIVE_WAIT;
01490
01491 when INIT_ACTIVE_WAIT => -- first active or when a new row is opened
01492 if (count6 = cntnext) then
01493 init_next_state <= INIT_IDLE;
01494 else
01495 init_next_state <= INIT_ACTIVE_WAIT;
01496 end if;
01497
01498 when INIT_PATTERN_WRITE =>
01499 init_next_state <= INIT_PATTERN_WRITE_READ;
01500
01501 when INIT_PATTERN_WRITE_READ =>
01502 if (count6 = cntnext) then
01503 init_next_state <= INIT_PATTERN_READ;
01504 else
01505 init_next_state <= INIT_PATTERN_WRITE_READ;
01506 end if;
01507
01508 when INIT_PATTERN_READ =>
01509 init_next_state <= INIT_PATTERN_READ_WAIT;
01510
01511 when INIT_PATTERN_READ_WAIT =>
01512 if (COMP_DONE_r = '1') then
01513 init_next_state <= INIT_PRECHARGE; -- Precharge fix after pattern read
01514 else
01515 init_next_state <= INIT_PATTERN_READ_WAIT;
01516 end if;
01517
01518 when others => init_next_state <= INIT_IDLE;
01519
01520 end case;
01521 end process;
01522
01523
01524 process(RD, RD_r, WR, WR_r, LMR_r, PRE_r, ACT_r, REF_r,
01525 auto_ref, chip_cnt, auto_cnt, conflict_detect, conflict_detect_r,
01526 conflict_resolved_r, count_200cycle_done_r, idle_cnt,
01527 init_count, init_memory, mrd_count, LMR_PRE_REF_ACT_cmd_r,
01528 phy_Dly_Slct_Done, ras_count, rcd_count, rd_to_wr_count,
01529 read_burst_cnt, rfc_count, rp_count, rtp_count, pre_cnt, --- Precharge fix for deep memory
01530 state, wr_to_rd_count, wrburst_cnt, wtp_count, done_200us,
01531 cs_width1, dummy_write_flag_r, COMP_DONE_r, init_done, af_empty_r)
01532 begin
01533 next_state <= state;
01534 case state is
01535 when IDLE =>
01536 if ((conflict_detect_r = '1' or LMR_PRE_REF_ACT_cmd_r = '1' or auto_ref = '1') and ras_count = "0000" and init_done = '1') then
01537 next_state <= PRECHARGE;
01538 elsif ((WR_r = '1' or RD_r = '1') and (ras_count = "0000")) then
01539 next_state <= ACTIVE;
01540 end if;
01541
01542 when PRECHARGE =>
01543 next_state <= PRECHARGE_WAIT;
01544
01545 -- Precharge fix for deep memory
01546 when PRECHARGE_WAIT =>
01547 if (rp_count = "000") then
01548 if (auto_ref = '1' or REF_r = '1') then
01549 if ((pre_cnt < cs_width1) and init_memory = '0')then
01550 next_state <= PRECHARGE;
01551 else
01552 next_state <= AUTO_REFRESH;
01553 end if;
01554 elsif (LMR_r = '1') then
01555 next_state <= LOAD_MODE;
01556 elsif (conflict_detect_r = '1' or ACT_r = '1') then
01557 next_state <= ACTIVE;
01558 else
01559 next_state <= IDLE;
01560 end if;
01561 else
01562 next_state <= PRECHARGE_WAIT;
01563 end if;
01564
01565 when LOAD_MODE =>
01566 next_state <= MODE_REGISTER_WAIT;
01567
01568 when MODE_REGISTER_WAIT =>
01569 if (mrd_count = '0') then
01570 next_state <= IDLE;
01571 else
01572 next_state <= MODE_REGISTER_WAIT;
01573 end if;
01574
01575 when AUTO_REFRESH =>
01576 next_state <= AUTO_REFRESH_WAIT;
01577
01578 when AUTO_REFRESH_WAIT =>
01579 if ((auto_cnt < cs_width1) and rfc_count = "000001" and init_memory = '0')then
01580 next_state <= AUTO_REFRESH;
01581 elsif ((rfc_count = "000001") and (conflict_detect_r = '1')) then
01582 next_state <= ACTIVE;
01583 elsif (rfc_count = "000001") then
01584 next_state <= IDLE;
01585 else
01586 next_state <= AUTO_REFRESH_WAIT;
01587 end if;
01588
01589 when ACTIVE =>
01590 next_state <= ACTIVE_WAIT;
01591
01592 when ACTIVE_WAIT =>
01593 if (rcd_count = "000") then -- first active or when a new row is opened
01594 if (WR = '1') then
01595 next_state <= FIRST_WRITE;
01596 elsif (RD = '1') then
01597 next_state <= FIRST_READ;
01598 else
01599 next_state <= IDLE;
01600 end if;
01601 else
01602 next_state <= ACTIVE_WAIT;
01603 end if;
01604
01605 when FIRST_WRITE =>
01606 next_state <= WRITE_WAIT;
01607
01608 when BURST_WRITE =>
01609 next_state <= WRITE_WAIT;
01610
01611 when WRITE_WAIT =>
01612 if (((conflict_detect = '1') and (conflict_resolved_r = '0')) or (auto_ref = '1')) then
01613 if ((wtp_count = "0000") and (ras_count = "0000")) then
01614 next_state <= PRECHARGE;
01615 else
01616 next_state <= WRITE_WAIT;
01617 end if;
01618 elsif (RD = '1') then
01619 next_state <= WRITE_READ;
01620 elsif ((WR = '1') and (wrburst_cnt = "010")) then
01621 next_state <= BURST_WRITE;
01622 elsif ((WR = '1') and (wrburst_cnt = "000")) then --added to improve the efficiency
01623 next_state <= FIRST_WRITE;
01624 elsif (idle_cnt = "0000") then
01625 next_state <= PRECHARGE;
01626 else
01627 next_state <= WRITE_WAIT;
01628 end if;
01629
01630 when WRITE_READ =>
01631 if (wr_to_rd_count = "0000") then
01632 next_state <= FIRST_READ;
01633 else
01634 next_state <= WRITE_READ;
01635 end if;
01636
01637 when FIRST_READ =>
01638 next_state <= READ_WAIT;
01639
01640 when BURST_READ =>
01641 next_state <= READ_WAIT;
01642
01643 when READ_WAIT =>
01644 if (((conflict_detect = '1') and (conflict_resolved_r = '0')) or (auto_ref = '1')) then
01645 if(rtp_count = "0000" and ras_count = "0000") then
01646 next_state <= PRECHARGE;
01647 else
01648 next_state <= READ_WAIT;
01649 end if;
01650 elsif (WR = '1')then
01651 next_state <= READ_WRITE;
01652 elsif ((RD = '1') and (read_burst_cnt <= "010")) then
01653 if(af_empty_r = '1') then
01654 next_state <= FIRST_READ;
01655 else
01656 next_state <= BURST_READ;
01657 end if;
01658 elsif (idle_cnt = "0000") then
01659 next_state <= PRECHARGE;
01660 else
01661 next_state <= READ_WAIT;
01662 end if;
01663
01664 when READ_WRITE =>
01665 if (rd_to_wr_count = "0000") then
01666 next_state <= FIRST_WRITE;
01667 else
01668 next_state <= READ_WRITE;
01669 end if;
01670
01671 when others => next_state <= IDLE;
01672
01673 end case;
01674 end process;
01675
01676
01677 process(clk0)
01678 begin
01679 if (clk0 = '1' and clk0'event) then
01680 if (rst = '1') then
01681 state_r2 <= idle;
01682 state_r3 <= idle;
01683 init_state_r2 <= "00000";
01684 else
01685 state_r2 <= state;
01686 state_r3 <= state_r2;
01687 init_state_r2 <= init_state;
01688 end if;
01689 end if;
01690 end process;
01691
01692
01693 process(clk0)
01694 begin
01695 if (clk0 = '1' and clk0'event) then
01696 if (rst = '1') then
01697 ddr2_ras_r <= '1';
01698 elsif (state = LOAD_MODE or state = PRECHARGE or state = ACTIVE or state = AUTO_REFRESH
01699 or init_state = INIT_LOAD_MODE or init_state = INIT_PRECHARGE or init_state = INIT_ACTIVE or init_state = INIT_AUTO_REFRESH
01700 or init_state = INIT_DUMMY_ACTIVE) then
01701 ddr2_ras_r <= '0';
01702 else
01703 ddr2_ras_r <= '1';
01704 end if;
01705 end if;
01706 end process;
01707
01708
01709 process(clk0)
01710 begin
01711 if (clk0 = '1' and clk0'event) then
01712 if (rst = '1') then
01713 ddr2_cas_r <= '1';
01714 elsif (state = LOAD_MODE or state = FIRST_WRITE or state = BURST_WRITE or
01715 state = FIRST_READ or state = BURST_READ or init_state = INIT_DUMMY_FIRST_READ or
01716 init_state = INIT_LOAD_MODE or init_state = INIT_AUTO_REFRESH or
01717 state = AUTO_REFRESH or init_state = INIT_DUMMY_READ or init_state = INIT_PATTERN_READ or init_state = INIT_PATTERN_WRITE) then
01718 ddr2_cas_r <= '0';
01719 else
01720 ddr2_cas_r <= '1';
01721 end if;
01722 end if;
01723 end process;
01724
01725
01726 process(clk0)
01727 begin
01728 if (clk0 = '1' and clk0'event) then
01729 if (rst = '1') then
01730 ddr2_we_r <= '1';
01731 elsif (state = LOAD_MODE or state = PRECHARGE or state = FIRST_WRITE or state = BURST_WRITE or init_state = INIT_PATTERN_WRITE
01732 or init_state = INIT_LOAD_MODE or init_state = INIT_PRECHARGE) then
01733 ddr2_we_r <= '0';
01734 else
01735 ddr2_we_r <= '1';
01736 end if;
01737 end if;
01738 end process;
01739
01740
01741 process(clk0)
01742 begin
01743 if (clk0 = '1' and clk0'event) then
01744 if (rst = '1') then
01745 ddr2_ras_r2 <= '1';
01746 ddr2_cas_r2 <= '1';
01747 ddr2_we_r2 <= '1';
01748 else
01749 ddr2_ras_r2 <= ddr2_ras_r;
01750 ddr2_cas_r2 <= ddr2_cas_r;
01751 ddr2_we_r2 <= ddr2_we_r;
01752 end if;
01753 end if;
01754 end process;
01755
01756
01757 process(clk0)
01758 begin
01759 if (clk0 = '1' and clk0'event) then
01760 if (rst = '1') then
01761 ddr2_ras_r3 <= '1';
01762 ddr2_cas_r3 <= '1';
01763 ddr2_we_r3 <= '1';
01764 else
01765 ddr2_ras_r3 <= ddr2_ras_r2;
01766 ddr2_cas_r3 <= ddr2_cas_r2;
01767 ddr2_we_r3 <= ddr2_we_r2;
01768 end if; -- else: !if(rst)
01769 end if;
01770 end process;
01771
01772
01773 process(clk0)
01774 begin
01775 if (clk0 = '1' and clk0'event) then
01776 if (rst = '1') then
01777 row_addr_r((row_address-1) downto 0) <= (others => '0');
01778 else
01779 row_addr_r((row_address-1) downto 0) <= af_addr(((row_address + col_ap_width)-1) downto col_ap_width);
01780 end if;
01781 end if;
01782 end process;
01783
01784
01785 process(clk0)
01786 begin
01787 if (clk0 = '1' and clk0'event) then
01788 if (rst = '1') then
01789 ddr2_cs_r <= '0';
01790 else
01791 if (af_addr_r((chip_address + bank_address +row_address + (col_ap_width-1)) downto (bank_address + row_address + col_ap_width)) =
01792 cs_h0((chip_address - 1) downto 0)) then
01793 ddr2_cs_r <= cs_hE(0);
01794 elsif (af_addr_r((chip_address + bank_address + row_address + (col_ap_width-1)) downto (bank_address +row_address + col_ap_width)) =
01795 cs_h1((chip_address - 1) downto 0)) then
01796 ddr2_cs_r <= cs_hD(0);
01797 elsif (af_addr_r((chip_address + bank_address +row_address + (col_ap_width-1)) downto (bank_address + row_address + col_ap_width)) =
01798 cs_h2((chip_address - 1) downto 0)) then
01799 ddr2_cs_r <= cs_hB(0);
01800 elsif (af_addr_r((chip_address + bank_address +row_address + (col_ap_width-1)) downto (bank_address + row_address + col_ap_width)) =
01801 cs_h3((chip_address - 1) downto 0)) then
01802 ddr2_cs_r <= cs_h7(0);
01803 else
01804 ddr2_cs_r <= cs_hF(0);
01805 end if;
01806 end if;
01807 end if;
01808 end process;
01809
01810
01811 process(clk0)
01812 begin
01813 if (clk0 = '1' and clk0'event) then
01814 if (rst = '1') then
01815 ddr2_address_init_r <= (others => '0');
01816 else
01817 if (init_state_r2 = INIT_PRECHARGE) then
01818 ddr2_address_init_r <= (10 => '1' , others => '0'); -- *A10 = 1 for precharge all *
01819 elsif (init_state_r2 = INIT_LOAD_MODE and init_count_cp = "0101") then
01820 ddr2_address_init_r <= ext_mode_reg; -- A0 == 0 for DLL enable
01821 elsif (init_state_r2 = INIT_LOAD_MODE and init_count_cp = "0110") then
01822 ddr2_address_init_r <= add_const1((row_address-1) downto 0) or load_mode_reg;
01823 elsif (init_state_r2 = INIT_LOAD_MODE and init_count_cp = "1010") then
01824 ddr2_address_init_r <= load_mode_reg; -- Write recovery = 4; cas_latency = 4; burst length = 4
01825 elsif (init_state_r2 = INIT_LOAD_MODE and init_count_cp = "1011") then
01826 ddr2_address_init_r <= (add_const2((row_address-1) downto 0) or ext_mode_reg); -- OCD DEFAULT
01827 elsif (init_state_r2 = INIT_LOAD_MODE and init_count_cp = "1100") then
01828 ddr2_address_init_r <= (add_const3((row_address-1) downto 0) or ext_mode_reg); -- OCD EXIT
01829 elsif(init_state_r2 = INIT_DUMMY_ACTIVE) then
01830 ddr2_address_init_r <= row_addr_r;
01831 else
01832 ddr2_address_init_r <= (others => '0');
01833 end if;
01834 end if;
01835 end if;
01836 end process;
01837
01838
01839 process(clk0)
01840 begin
01841 if (clk0 = '1' and clk0'event) then
01842 if (rst = '1') then
01843 ddr2_address_r1 <= (others => '0');
01844 elsif ((state_r2 = ACTIVE)) then
01845 ddr2_address_r1 <= row_addr_r;
01846 elsif (state_r2 = FIRST_WRITE or state_r2 = BURST_WRITE or
01847 state_r2 = FIRST_READ or state_r2 = BURST_READ) then
01848 ddr2_address_r1 <= af_addr_r1((row_address-1) downto 0) and add_const4((row_address-1) downto 0);
01849 elsif (state_r2 = PRECHARGE) then
01850 if(PRE_r = '1') then
01851 ddr2_address_r1 <= af_addr_r1((row_address-1) downto 0);
01852 else
01853 ddr2_address_r1 <= (10 => '1', others => '0');
01854 end if;
01855 elsif (state_r2 = LOAD_MODE) then
01856 ddr2_address_r1 <= af_addr_r1((row_address-1) downto 0);
01857 else
01858 ddr2_address_r1 <= (others => '0');
01859 end if;
01860 end if;
01861 end process;
01862
01863
01864 process(clk0)
01865 begin
01866 if (clk0 = '1' and clk0'event) then
01867 if (rst = '1') then
01868 ddr2_address_r2 <= (others => '0');
01869 elsif (init_memory = '1') then
01870 ddr2_address_r2 <= ddr2_address_init_r;
01871 else
01872 ddr2_address_r2 <= ddr2_address_r1;
01873 end if;
01874 end if;
01875 end process;
01876
01877
01878 process(clk0)
01879 begin
01880 if (clk0 = '1' and clk0'event) then
01881 if (rst = '1') then
01882 ddr2_ba_r1((bank_address-1) downto 0) <= (others => '0');
01883 elsif ((init_memory = '1') and (init_state_r2 = INIT_LOAD_MODE)) then
01884 if (init_count_cp = X"3") then
01885 ddr2_ba_r1((bank_address-1) downto 0) <= (1 => '1', others => '0'); -- emr2
01886 elsif (init_count_cp = X"4") then
01887 ddr2_ba_r1((bank_address-1) downto 0) <= (0 | 1 => '1', others => '0'); -- emr3
01888 elsif (init_count_cp = X"5" or init_count_cp = X"B" or init_count_cp = X"C") then
01889 ddr2_ba_r1((bank_address-1) downto 0) <= (0 => '1', others => '0'); -- emr
01890 else
01891 ddr2_ba_r1((bank_address-1) downto 0) <= (others => '0');
01892 end if;
01893 elsif ((state_r2 = ACTIVE) or (init_state_r2 = INIT_DUMMY_ACTIVE) or (state_r2 = LOAD_MODE) or ((state_r2 = PRECHARGE) and (PRE_r = '1'))
01894 or (init_state_r2 = INIT_ACTIVE) or (init_state_r2 = INIT_LOAD_MODE) or (init_state_r2 = INIT_PRECHARGE)) then
01895 ddr2_ba_r1((bank_address-1) downto 0) <= af_addr_r(((bank_address + row_address + col_ap_width)-1) downto (col_ap_width + row_address));
01896 else
01897 ddr2_ba_r1((bank_address-1) downto 0) <= ddr2_ba_r1((bank_address-1) downto 0);
01898 end if;
01899 end if;
01900 end process;
01901
01902
01903 process(clk0)
01904 begin
01905 if (clk0 = '1' and clk0'event) then
01906 if (rst = '1') then
01907 ddr2_ba_r2((bank_address-1) downto 0) <= (others => '0');
01908 else
01909 ddr2_ba_r2((bank_address-1) downto 0) <= ddr2_ba_r1;
01910 end if;
01911 end if;
01912 end process;
01913
01914
01915 process(clk0)
01916 begin
01917 if (clk0 = '1' and clk0'event) then
01918 if (rst = '1') then
01919 ddr2_cs_r1 <= '1';
01920 elsif (init_memory = '1') then
01921 if (chip_cnt = "00") then
01922 ddr2_cs_r1 <= cs_hE(0);
01923 elsif (chip_cnt = "01") then
01924 ddr2_cs_r1 <= cs_hD(0);
01925 elsif (chip_cnt = "10") then
01926 ddr2_cs_r1 <= cs_hB(0);
01927 elsif (chip_cnt = "11") then
01928 ddr2_cs_r1 <= cs_h7(0);
01929 else
01930 ddr2_cs_r1 <= cs_hF(0);
01931 end if;
01932 --- Precharge fix for deep memory
01933 elsif (state_r2 = PRECHARGE) then
01934 if (pre_cnt = "001") then
01935 ddr2_cs_r1 <= cs_hE(0);
01936 elsif (pre_cnt = "010") then
01937 ddr2_cs_r1 <= cs_hD(0);
01938 elsif (pre_cnt = "011") then
01939 ddr2_cs_r1 <= cs_hB(0);
01940 elsif (pre_cnt = "100") then
01941 ddr2_cs_r1 <= cs_h7(0);
01942 elsif (pre_cnt = "000") then
01943 ddr2_cs_r1 <= ddr2_cs_r1; --cs_hF
01944 else
01945 ddr2_cs_r1 <= cs_hF(0);
01946 end if;
01947 elsif (state_r2 = AUTO_REFRESH) then
01948 if (auto_cnt = "001") then
01949 ddr2_cs_r1 <= cs_hE(0);
01950 elsif (auto_cnt = "010") then
01951 ddr2_cs_r1 <= cs_hD(0);
01952 elsif (auto_cnt = "011") then
01953 ddr2_cs_r1 <= cs_hB(0);
01954 elsif (auto_cnt = "100") then
01955 ddr2_cs_r1 <= cs_h7(0);
01956 else
01957 ddr2_cs_r1 <= cs_hF(0);
01958 end if;
01959 elsif ((state_r2 = ACTIVE) or (init_state_r2 = INIT_DUMMY_ACTIVE) or (state_r2 = LOAD_MODE) or (state_r2 = PRECHARGE_WAIT)
01960 or (init_state_r2 = INIT_ACTIVE) or (init_state_r2 = INIT_LOAD_MODE) or (init_state_r2 = INIT_PRECHARGE_WAIT)) then
01961 ddr2_cs_r1 <= ddr2_cs_r;
01962 else
01963 ddr2_cs_r1 <= ddr2_cs_r1;
01964 end if;
01965 end if;
01966 end process;
01967
01968
01969 process(clk0)
01970 begin
01971 if (clk0 = '1' and clk0'event) then
01972 if (rst = '1') then
01973 ddr2_cs_r_out <= '1';
01974 ddr2_cs_r_odt <= '1';
01975 else
01976 ddr2_cs_r_out <= ddr2_cs_r1;
01977 ddr2_cs_r_odt <= ddr2_cs_r1;
01978 end if;
01979 end if;
01980 end process;
01981
01982
01983 process(clk0)
01984 begin
01985 if (clk0 = '1' and clk0'event) then
01986 if (rst = '1') then
01987 conflict_resolved_r <= '0';
01988 else
01989 if ((state = PRECHARGE_WAIT) and (conflict_detect_r = '1')) then
01990 conflict_resolved_r <= '1';
01991 elsif(af_rden = '1') then
01992 conflict_resolved_r <= '0';
01993 end if;
01994 end if;
01995 end if;
01996 end process;
01997
01998
01999 process(clk0)
02000 begin
02001 if (clk0 = '1' and clk0'event) then
02002 if (rst = '1') then
02003 ddr2_cke_r <= cs_h0(0);
02004 elsif (done_200us = '1') then
02005 ddr2_cke_r <= cs_hF(0);
02006 end if;
02007 end if;
02008 end process;
02009
02010
02011 process(clk0)
02012 begin
02013 if (clk0 = '1' and clk0'event) then
02014 if (rst = '1') then
02015 odt_en_cnt <= "0000";
02016 elsif((state = FIRST_WRITE) and (ODT_ENABLE = '1')) then
02017 odt_en_cnt <= (('0' & ADDITIVE_LATENCY_VALUE) + ('0' & CAS_LATENCY_VALUE) - "0010");
02018 elsif((state = FIRST_READ) and (ODT_ENABLE = '1')) then
02019 odt_en_cnt <= (('0' & ADDITIVE_LATENCY_VALUE) + ('0' & CAS_LATENCY_VALUE)- "0001");
02020 elsif(odt_en_cnt /= "0000") then
02021 odt_en_cnt <= odt_en_cnt - "0001";
02022 else
02023 odt_en_cnt <= "0000";
02024 end if;
02025 end if;
02026 end process;
02027
02028
02029 process(clk0)
02030 begin
02031 if (clk0 = '1' and clk0'event) then
02032 if (rst = '1') then
02033 odt_cnt <= "0000";
02034 elsif((state = FIRST_WRITE) or (state = BURST_WRITE)) then
02035 odt_cnt <= (('0' & ADDITIVE_LATENCY_VALUE) + ('0'& CAS_LATENCY_VALUE) + ('0' & burst_cnt));
02036 elsif((state = FIRST_READ) or (state = BURST_READ)) then
02037 odt_cnt <= (('0' & ADDITIVE_LATENCY_VALUE) + ('0' & CAS_LATENCY_VALUE) + ('0' & burst_cnt) + "0001");
02038 elsif(odt_cnt /= "0000") then
02039 odt_cnt <= odt_cnt - "0001";
02040 else
02041 odt_cnt <= "0000";
02042 end if;
02043 end if;
02044 end process;
02045
02046
02047 process(rst, odt_en_cnt, odt_cnt)
02048 begin
02049 if (rst = '1') then
02050 odt_en <= '0';
02051 elsif(odt_en_cnt = "0001") then
02052 odt_en <= cs_hF(0);
02053 elsif(odt_cnt > "0010" and odt_en_cnt <= "0001") then
02054 odt_en <= cs_hF(0);
02055 elsif (odt_cnt = "0010") then
02056 odt_en <= '0';
02057 else
02058 odt_en <= '0';
02059 end if;
02060 end process;
02061
02062
02063 process(clk0)
02064 begin
02065 if (clk0 = '1' and clk0'event) then
02066 if (rst = '1') then
02067 ctrl_odt <= '0';
02068 else
02069 case cs_width is
02070 when 1 =>
02071 if (ddr2_cs_r_odt = cs_h0(0)) then
02072 ctrl_odt <= (odt_en and cs_h1(0));
02073 else
02074 ctrl_odt <= '0';
02075 end if;
02076
02077 when 2 =>
02078 if (ddr2_cs_r_odt = cs_h2(0)) then
02079 ctrl_odt <= (odt_en and cs_hA(0));
02080 elsif (ddr2_cs_r_odt = cs_h1(0)) then
02081 ctrl_odt <= (odt_en and cs_h1(0));
02082 else
02083 ctrl_odt <= '0';
02084 end if;
02085
02086 when 3 =>
02087 if (ddr2_cs_r_odt = cs_h6(0)) then
02088 ctrl_odt <= (odt_en and cs_D100(0));
02089 elsif(ddr2_cs_r_odt = cs_h5(0)) then
02090 ctrl_odt <= (odt_en and cs_D100(0));
02091 elsif (ddr2_cs_r_odt = cs_h3(0)) then
02092 ctrl_odt <= (odt_en and cs_hA(0));
02093 else
02094 ctrl_odt <= '0';
02095 end if;
02096
02097 when 4 =>
02098 if (ddr2_cs_r_odt = cs_hE(0)) then
02099 ctrl_odt <= (odt_en and cs_D1000(0));
02100 elsif (ddr2_cs_r_odt = cs_hD(0)) then
02101 ctrl_odt <= (odt_en and cs_D1000(0));
02102 elsif (ddr2_cs_r_odt = cs_hB(0)) then
02103 ctrl_odt <= (odt_en and cs_D1000(0));
02104 elsif (ddr2_cs_r_odt = cs_h7(0)) then
02105 ctrl_odt <= (odt_en and cs_D100(0));
02106 else
02107 ctrl_odt <= '0';
02108 end if;
02109
02110 when others => ctrl_odt <= ctrl_odt;
02111
02112 end case;
02113 end if;
02114 end if;
02115 end process;
02116
02117 ctrl_ddr2_address((row_address-1) downto 0) <= ddr2_address_r2((row_address-1) downto 0);
02118 ctrl_ddr2_ba ((bank_address-1) downto 0) <= ddr2_ba_r2((bank_address-1) downto 0);
02119 ctrl_ddr2_ras_L <= ddr2_ras_r3;
02120 ctrl_ddr2_cas_L <= ddr2_cas_r3;
02121 ctrl_ddr2_we_L <= ddr2_we_r3;
02122 ctrl_ddr2_odt <= ctrl_odt;
02123 ctrl_ddr2_cs_L <= ddr2_cs_r_out;
02124 ctrl_Dqs_Rst <= ctrl_Dqs_Rst_r1;
02125 ctrl_Dqs_En <= ctrl_Dqs_En_r1;
02126 ctrl_WrEn <= ctrl_WrEn_r1;
02127 ctrl_RdEn <= ctrl_RdEn_r1;
02128 ctrl_ddr2_cke <= ddr2_cke_r;
02129 ctrl_dummy_wr_sel <= ctrl_Wdf_RdEn_int when (ctrl_dummy_write = '1') else '0';
02130
02131 end arc_controller;
02132
02133