📄 mem_interface_top_ddr_controller_0.vhd
字号:
end case;
end process;
--Main control state machine
process (ACT_r, LMR_PRE_REF_ACT_cmd_r, LMR_r, RD
, RD_r, REF_r, WR, WR_r, auto_ref
, conflict_detect, conflict_detect_r
, conflict_resolved_r, idle_cnt, mrd_count, ras_count, rcd_count
, rd_to_wr_count, read_burst_cnt, rfc_count, rp_count
, rtp_count, state, wr_to_rd_count, wrburst_cnt
, wtp_count,burst_cnt, init_done, af_empty_r)
begin
next_state <= state;
case state is
when IDLE =>
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
next_state <= PRECHARGE;
elsif ((WR_r= '1' or RD_r= '1') and (ras_count = "0000")) then
next_state <= ACTIVE;
end if;
when LOAD_MODE_REG_ST => next_state <= MODE_REGISTER_WAIT;
when MODE_REGISTER_WAIT =>
if (mrd_count = '0') then
next_state <= IDLE;
else
next_state <= MODE_REGISTER_WAIT;
end if;
when PRECHARGE => next_state <= PRECHARGE_WAIT;
when PRECHARGE_WAIT =>
if (rp_count = "000") then
if ((auto_ref or REF_r) = '1') then
next_state <= AUTO_REFRESH;
elsif (LMR_r = '1') then
next_state <= LOAD_MODE_REG_ST;
elsif ((conflict_detect_r or ACT_r) = '1') then
next_state <= ACTIVE;
else
next_state <= IDLE;
end if;
else
next_state <= PRECHARGE_WAIT;
end if;
when AUTO_REFRESH => next_state <= AUTO_REFRESH_WAIT;
when AUTO_REFRESH_WAIT =>
if ( (rfc_count = "00001") and (conflict_detect_r = '1') ) then
next_state <= ACTIVE;
elsif (rfc_count = "00001") then
next_state <= IDLE;
else
next_state <= AUTO_REFRESH_WAIT;
end if;
when ACTIVE => next_state <= ACTIVE_WAIT;
when ACTIVE_WAIT =>
if (rcd_count = "000") then
if(WR = '1') then
next_state <= FIRST_WRITE;
elsif (RD = '1') then
next_state <= FIRST_READ;
else
next_state <= IDLE;
end if;
else
next_state <= ACTIVE_WAIT;
end if;
when FIRST_WRITE =>
if((((conflict_detect = '1') and (conflict_resolved_r ='0')) or (auto_ref = '1')) or RD = '1') then
next_state <= WRITE_WAIT;
elsif((burst_cnt = "001") and (WR = '1')) then
next_state <= BURST_WRITE;
else
next_state <= WRITE_WAIT;
end if;
when BURST_WRITE =>
if((((conflict_detect = '1') and (conflict_resolved_r = '0')) or (auto_ref = '1')) or (RD = '1')) then
next_state <= WRITE_WAIT;
elsif((burst_cnt = "001") and (WR = '1')) then
next_state <= BURST_WRITE;
else
next_state <= WRITE_WAIT;
end if;
when WRITE_WAIT =>
if (((conflict_detect = '1') and (conflict_resolved_r = '0')) or (auto_ref = '1')) then
if ((wtp_count = "0000") and (ras_count = "0000")) then
next_state <= PRECHARGE;
else
next_state <= WRITE_WAIT;
end if;
elsif (RD = '1') then
next_state <= WRITE_READ;
elsif ((WR ='1') and (wrburst_cnt = "010")) then
next_state <= BURST_WRITE;
elsif((WR = '1') and (wrburst_cnt = "000")) then --added to improve the efficiency (June 21, 2006)
next_state <= FIRST_WRITE;
elsif (idle_cnt = "0000") then
next_state <= PRECHARGE;
else
next_state <= WRITE_WAIT;
end if;
when WRITE_READ =>
if (wr_to_rd_count = "0000") then
next_state <= FIRST_READ;
else
next_state <= WRITE_READ;
end if;
when FIRST_READ =>
if((((conflict_detect = '1') and (conflict_resolved_r = '0')) or (auto_ref = '1')) or (WR = '1')) then
next_state <= READ_WAIT;
elsif((burst_cnt = "001") and (RD = '1')) then
next_state <= BURST_READ;
else
next_state <= READ_WAIT;
end if;
when BURST_READ =>
if((((conflict_detect = '1') and (conflict_resolved_r = '0'))or (auto_ref = '1')) or (WR = '1')) then
next_state <= READ_WAIT;
elsif((burst_cnt = "001") and (RD = '1')) then
next_state <= BURST_READ;
else
next_state <= READ_WAIT;
end if;
when READ_WAIT =>
if (((conflict_detect = '1') and (conflict_resolved_r = '0')) or (auto_ref = '1')) then
if(rtp_count = "0000" and ras_count = "0000") then
next_state <= PRECHARGE;
else
next_state <= READ_WAIT;
end if;
elsif (WR = '1') then
next_state <= READ_WRITE;
elsif ((RD = '1') and (read_burst_cnt <= "010")) then
if(af_empty_r = '1') then
next_state <= FIRST_READ;
else
next_state <= BURST_READ;
end if;
elsif (idle_cnt = "0000") then
next_state <= PRECHARGE;
else
next_state <= READ_WAIT;
end if;
when READ_WRITE =>
if (rd_to_wr_count = "0000") then
next_state <= FIRST_WRITE;
else
next_state <= READ_WRITE;
end if;
when others => next_state <= IDLE;
end case;
end process;
--register command outputs
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
state_r2 <= "00000";
state_r3 <= "00000";
else
state_r2 <= state;
state_r3 <= state_r2;
end if;
end if;
end process;
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
init_state_r2 <= "00000";
init_state_r3 <= "00000";
else
init_state_r2 <= init_state;
init_state_r3 <= init_state_r2;
end if;
end if;
end process;
-- commands to the memory
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_ras_r <= '1';
elsif ((state = LOAD_MODE_REG_ST) or (state = PRECHARGE) or (state = ACTIVE) or (state = AUTO_REFRESH)
or (init_state = INIT_LOAD_MODE_REG_ST) or (init_state = INIT_PRECHARGE) or (init_state = INIT_AUTO_REFRESH)
or (init_state = INIT_DUMMY_ACTIVE)) then
ddr_ras_r <= '0';
else ddr_ras_r <= '1';
end if;
end if;
end process;
-- commands to the memory
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_cas_r <= '1';
elsif ((state = LOAD_MODE_REG_ST) or (init_state = INIT_LOAD_MODE_REG_ST) or (read_write_state = '1') or
(init_state = INIT_DUMMY_FIRST_READ) or (init_state = INIT_DUMMY_WRITE) or (state = AUTO_REFRESH)
or (init_state = INIT_AUTO_REFRESH) or (init_state= INIT_DUMMY_READ) or (init_state = INIT_PATTERN_READ)) then
ddr_cas_r <= '0';
elsif ((state = ACTIVE_WAIT) or (init_state = INIT_DUMMY_ACTIVE_WAIT)) then
ddr_cas_r <= '1';
else
ddr_cas_r <= '1';
end if;
end if;
end process;
-- commands to the memory
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_we_r <= '1';
elsif ((state = LOAD_MODE_REG_ST) or (state = PRECHARGE) or (init_state = INIT_LOAD_MODE_REG_ST)
or (init_state = INIT_PRECHARGE) or (write_state = '1') or (dummy_write_state = '1')) then
ddr_we_r <= '0';
else ddr_we_r <= '1';
end if;
end if;
end process;
--register commands to the memory
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_ras_r2 <= '1';
ddr_cas_r2 <= '1';
ddr_we_r2 <= '1';
else
ddr_ras_r2 <= ddr_ras_r;
ddr_cas_r2 <= ddr_cas_r;
ddr_we_r2 <= ddr_we_r;
end if;
end if;
end process;
--register commands to the memory
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if (rst = '1') then
ddr_ras_r3 <= '1';
ddr_cas_r3 <= '1';
ddr_we_r3 <= '1';
else
ddr_ras_r3 <= ddr_ras_r2;
ddr_cas_r3 <= ddr_cas_r2;
ddr_we_r3 <= ddr_we_r2;
end if;
end if;
end process;
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
row_addr_r(row_address-1 downto 0) <= (others => '0');
else
row_addr_r(row_address-1 downto 0) <= af_addr((row_address + col_ap_width)-1 downto col_ap_width);
end if;
end if;
end process;
-- address during init
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_address_init_r <= (others => '0');
elsif (init_memory = '1') then
if (init_state_r2 = INIT_PRECHARGE) then
ddr_address_init_r <= add_const1((row_address-1) downto 0);--X"0400"; --A10 = 1 for precharge all
elsif (( init_state_r2 = INIT_LOAD_MODE_REG_ST) and (init_count_cp = "0011")) then
ddr_address_init_r <= ext_mode_reg; -- A0 = 0 for DLL enable
elsif (( init_state_r2 = INIT_LOAD_MODE_REG_ST) and (init_count_cp = "0100")) then
ddr_address_init_r <= add_const2((row_address-1) downto 0) or load_mode_reg; -- A8 = 1 for DLL reset
elsif (( init_state_r2 = INIT_LOAD_MODE_REG_ST) and (init_count_cp = "1001")) then
ddr_address_init_r <= add_const5((row_address-1) downto 0) and load_mode_reg; -- A8 = 0 to deactivate DLL reset
else
ddr_address_init_r <= add_const3((row_address-1) downto 0);
end if;
end if;
end if;
end process;
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_address_r1 <= (others => '0');
elsif ((state_r2 = ACTIVE)) then
ddr_address_r1 <= row_addr_r;
elsif (read_write_state_r2 = '1') then
ddr_address_r1 <= af_addr_r(row_address-1 downto 0) and add_const4((row_address-1) downto 0); -- Auto Precharge option is disabled
elsif ((state_r2 = PRECHARGE) or (init_state_r2 = INIT_PRECHARGE)) then
if(PRE_r = '1') then
ddr_address_r1 <= af_addr_r(row_address-1 downto 0);
else
ddr_address_r1 <= add_const1((row_address-1) downto 0);--X"0400";
end if;
elsif ((state_r2 = LOAD_MODE_REG_ST) or (init_state_r2 = INIT_LOAD_MODE_REG_ST))then
ddr_address_r1 <= af_addr_r(row_address-1 downto 0);
else
ddr_address_r1 <= add_const3((row_address-1) downto 0);--X"0000";
end if;
end if;
end process;
process(clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_address_r2 <= (others =>'0');
elsif(init_memory = '1') then
ddr_address_r2 <= ddr_address_init_r;
else
ddr_address_r2 <= ddr_address_r1;
end if;
end if;
end process;
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_ba_r1(bank_address-1 downto 0) <= (others => '0');
elsif (init_memory = '1' and (state_r2 = LOAD_MODE_REG_ST or init_state_r2 = INIT_LOAD_MODE_REG_ST) ) then
if (init_count_cp = "0011") then
ddr_ba_r1(bank_address-1 downto 0) <= "01";--X"1";
else
ddr_ba_r1(bank_address-1 downto 0) <= "00";--X"0";
end if;
elsif ((state_r2 = ACTIVE) or (init_state_r2 = INIT_DUMMY_ACTIVE) or (state_r2 = LOAD_MODE_REG_ST) or
(init_state_r2 = INIT_LOAD_MODE_REG_ST) or (((state_r2 = PRECHARGE) or (init_state_r2 = INIT_PRECHARGE)) and PRE_r = '1')) then
ddr_ba_r1(bank_address-1 downto 0) <= af_addr((bank_address+row_address + col_ap_width)-1 downto (col_ap_width + row_address));
else ddr_ba_r1(bank_address-1 downto 0) <= ddr_ba_r1(bank_address-1 downto 0);
end if;
end if;
end process;
process(clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_ba_r2 <= (others => '0');
else
ddr_ba_r2 <= ddr_ba_r1;
end if;
end if;
end process;
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
conflict_resolved_r <= '0';
else
if (((state = PRECHARGE_WAIT) or (init_state = INIT_PRECHARGE_WAIT)) and (conflict_detect_r= '1')) then
conflict_resolved_r <= '1';
elsif(af_rden = '1') then
conflict_resolved_r <= '0';
end if;
end if;
end if;
end process;
process (clk_0)
begin
if(clk_0'event and clk_0 = '1') then
if(rst = '1') then
ddr_cke_r<= '0';
else
if(done_200us = '1') then
ddr_cke_r<= '1';
end if;
end if;
end if;
end process;
ctrl_ddr_address(row_address-1 downto 0) <= ddr_address_r2(row_address-1 downto 0);
ctrl_ddr_ba (bank_address-1 downto 0) <= ddr_ba_r2(bank_address-1 downto 0);
ctrl_ddr_ras_L <= ddr_ras_r3;
ctrl_ddr_cas_L <= ddr_cas_r3;
ctrl_ddr_we_L <= ddr_we_r3;
ctrl_ddr_cs_L <= '0';
ctrl_ddr_cke <= ddr_cke_r;
end arch;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -