⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdram.vhd

📁 vhdl 编写的sdram controler, 双通道
💻 VHD
📖 第 1 页 / 共 2 页
字号:
				Pcmd_WRITE_TIME	<= (others=>'1');
				Pcmd_READ_TIME	<= "00000011";		-- 3
				Pcmd_BST_TIME	<= Ir_cmd(7 downto 0)+3;
				Pcmd_PRE_TIME	<= Ir_cmd(7 downto 0)+4;
				Pcmd_REF_TIME	<= (others=>'1');
				Pcmd_MRS_TIME	<= (others=>'1');
				Pcmd_END_TIME	<= Ir_cmd(7 downto 0)+4;
				Iw_rdcmden		<= '0';
				IIw_rdcmden		<= '0';
				Ir_rdcmden		<= '1';
				IIr_rdcmden		<= '0';
				clr_need_init0	<= '0';
				clr_need_init1	<= '0';
				clr_need_refresh<= '0';
			elsif IIr_cmdfull='1' then
				Pcmdfull		<= '1';
				Pcmdtype		<= "01";
				Pwhich_channel	<= '1';
				Pcmd			<= IIr_cmd;
				Pcmd_ACT_TIME	<= "00000000";		-- 0
				Pcmd_WRITE_TIME	<= (others=>'1');
				Pcmd_READ_TIME	<= "00000011";		-- 3
				Pcmd_BST_TIME	<= IIr_cmd(7 downto 0)+3;
				Pcmd_PRE_TIME	<= IIr_cmd(7 downto 0)+4;
				Pcmd_REF_TIME	<= (others=>'1');
				Pcmd_MRS_TIME	<= (others=>'1');
				Pcmd_END_TIME	<= IIr_cmd(7 downto 0)+4;
				Iw_rdcmden		<= '0';
				IIw_rdcmden		<= '0';
				Ir_rdcmden		<= '0';
				IIr_rdcmden		<= '1';
				clr_need_init0	<= '0';
				clr_need_init1	<= '0';
				clr_need_refresh<= '0';
			elsif Iw_cmdfull='1' then
				Pcmdfull		<= '1';
				Pcmdtype		<= "10";
				Pwhich_channel	<= '0';
				Pcmd			<= Iw_cmd;
				Pcmd_ACT_TIME	<= "00000000";		-- 0
				Pcmd_WRITE_TIME	<= "00000011";		-- 3
				Pcmd_READ_TIME	<= (others=>'1');
				Pcmd_BST_TIME	<= Iw_cmd(7 downto 0)+3;
				if Iw_cmd(7 downto 0)=1 then
					Pcmd_PRE_TIME	<= "00000110";			-- 6
				else
					Pcmd_PRE_TIME	<= Iw_cmd(7 downto 0)+4;
				end if;
				Pcmd_REF_TIME	<= (others=>'1');
				Pcmd_MRS_TIME	<= (others=>'1');
				if Iw_cmd(7 downto 0)=1 then
					Pcmd_END_TIME	<= "00000110";			-- 6
				else
					Pcmd_END_TIME	<= Iw_cmd(7 downto 0)+4;
				end if;
				Iw_rdcmden		<= '1';
				IIw_rdcmden		<= '0';
				Ir_rdcmden		<= '0';
				IIr_rdcmden		<= '0';
				clr_need_init0	<= '0';
				clr_need_init1	<= '0';
				clr_need_refresh<= '0';
			elsif IIw_cmdfull='1' then
				Pcmdfull		<= '1';
				Pcmdtype		<= "10";
				Pwhich_channel	<= '1';
				Pcmd			<= IIw_cmd;
				Pcmd_ACT_TIME	<= "00000000";		-- 0
				Pcmd_WRITE_TIME	<= "00000011";		-- 3
				Pcmd_READ_TIME	<= (others=>'1');
				Pcmd_BST_TIME	<= IIw_cmd(7 downto 0)+3;
				if IIw_cmd(7 downto 0)=1 then
					Pcmd_PRE_TIME	<= "00000110";
				else
					Pcmd_PRE_TIME	<= IIw_cmd(7 downto 0)+4;
				end if;
				Pcmd_REF_TIME	<= (others=>'1');
				Pcmd_MRS_TIME	<= (others=>'1');
				if IIw_cmd(7 downto 0)=1 then
					Pcmd_END_TIME	<= "00000110";
				else
					Pcmd_END_TIME	<= IIw_cmd(7 downto 0)+4;
				end if;
				Iw_rdcmden		<= '0';
				IIw_rdcmden		<= '1';
				Ir_rdcmden		<= '0';
				IIr_rdcmden		<= '0';
				clr_need_init0	<= '0';
				clr_need_init1	<= '0';
				clr_need_refresh<= '0';
			else
				Pcmdfull		<= Pcmdfull;
				Pcmdtype		<= Pcmdtype;
				Pwhich_channel	<= Pwhich_channel;
				Pcmd			<= Pcmd;
				Pcmd_ACT_TIME	<= Pcmd_ACT_TIME;
				Pcmd_WRITE_TIME	<= Pcmd_WRITE_TIME;
				Pcmd_READ_TIME	<= Pcmd_READ_TIME;
				Pcmd_BST_TIME	<= Pcmd_BST_TIME;
				Pcmd_PRE_TIME	<= Pcmd_PRE_TIME;
				Pcmd_REF_TIME	<= Pcmd_REF_TIME;
				Pcmd_MRS_TIME	<= Pcmd_MRS_TIME;
				Pcmd_END_TIME	<= Pcmd_END_TIME;
				Iw_rdcmden		<= '0';
				IIw_rdcmden		<= '0';
				Ir_rdcmden		<= '0';
				IIr_rdcmden		<= '0';
				clr_need_init0	<= '0';
				clr_need_init1	<= '0';
				clr_need_refresh<= '0';
			end if;
		end if;
	end if;
end process;

--sdram的命令读
process(sysclk) begin
	if rising_edge(sysclk) then
		if rrst='1' then
			sbusy <= '0';
			clr_Pcmdfull <= '0';
			Scmdtype		<= "00";
			Swhich_channel	<= '0';
			Scmd			<= (others=>'0');
			Scmd_ACT_TIME	<= (others=>'1');
			Scmd_WRITE_TIME	<= (others=>'1');
			Scmd_READ_TIME	<= (others=>'1');
			Scmd_BST_TIME	<= (others=>'1');
			Scmd_PRE_TIME	<= (others=>'1');
			Scmd_REF_TIME	<= (others=>'1');
			Scmd_MRS_TIME	<= (others=>'1');
			Scmd_END_TIME	<= (others=>'1');
		elsif sbusy='0' and pcmdfull='1' then
			sbusy <= '1';
			clr_Pcmdfull <= '1';
			Scmdtype		<= Pcmdtype;
			Swhich_channel	<= Pwhich_channel;
			Scmd			<= Pcmd;
			Scmd_ACT_TIME	<= Pcmd_ACT_TIME;
			Scmd_WRITE_TIME	<= Pcmd_WRITE_TIME;
			Scmd_READ_TIME	<= Pcmd_READ_TIME;
			Scmd_BST_TIME	<= Pcmd_BST_TIME;
			Scmd_PRE_TIME	<= Pcmd_PRE_TIME;
			Scmd_REF_TIME	<= Pcmd_REF_TIME;
			Scmd_MRS_TIME	<= Pcmd_MRS_TIME;
			Scmd_END_TIME	<= Pcmd_END_TIME;
		else
			if clr_sbusy='1' then
				sbusy <= '0';
			else
				sbusy <= sbusy;
			end if;
			clr_Pcmdfull <= '0';
			Scmdtype		<= Scmdtype;
			Swhich_channel	<= Swhich_channel;
			Scmd			<= Scmd;
			Scmd_ACT_TIME	<= Scmd_ACT_TIME;
			Scmd_WRITE_TIME	<= Scmd_WRITE_TIME;
			Scmd_READ_TIME	<= Scmd_READ_TIME;
			Scmd_BST_TIME	<= Scmd_BST_TIME;
			Scmd_PRE_TIME	<= Scmd_PRE_TIME;
			Scmd_REF_TIME	<= Scmd_REF_TIME;
			Scmd_MRS_TIME	<= Scmd_MRS_TIME;
			Scmd_END_TIME	<= Scmd_END_TIME;
		end if;
	end if;
end process;

--确定每个时间干什么
process(sysclk) begin
	if rising_edge(sysclk) then
		if sbusy='1' then
			s_cnt <= s_cnt+1;
		else
			s_cnt <= (others=>'0');
		end if;

		if sbusy='1' and s_cnt=Scmd_ACT_TIME then
			do_act <= '1';
		else
			do_act <= '0';
		end if;
		
		if sbusy='1' and s_cnt=Scmd_WRITE_TIME then
			do_write <= '1';
		else
			do_write <= '0';
		end if;

		if sbusy='1' and s_cnt=Scmd_READ_TIME then
			do_read <= '1';
		else
			do_read <= '0';
		end if;

		if sbusy='1' and s_cnt=Scmd_BST_TIME then
			do_bst <= '1';
		else
			do_bst <= '0';
		end if;

		if sbusy='1' and s_cnt=Scmd_PRE_TIME then
			do_pre <= '1';
		else
			do_pre <= '0';
		end if;

		if sbusy='1' and s_cnt=Scmd_REF_TIME then
			do_ref <= '1';
		else
			do_ref <= '0';
		end if;

		if sbusy='1' and s_cnt=Scmd_MRS_TIME then
			do_mrs <= '1';
		else
			do_mrs <= '0';
		end if;

		if sbusy='1' and s_cnt=Scmd_END_TIME then
			clr_sbusy <= '1';
		else
			clr_sbusy <= '0';
		end if;

	end if;
end process;

--生成CS RAS CAS WE信号
process(sysclk) begin
	if rising_edge(sysclk) then
		if (do_bst or do_read or do_write or do_act or do_pre or do_ref or do_mrs)='1' then
			sdram_cs_p <= '0';
		else
			sdram_cs_p <= '1';
		end if;
		
		if (do_bst or do_write or do_pre or do_mrs)='1' then
			sdram_we_p <= '0';
		else
			sdram_we_p <= '1';
		end if;		
				
		if (do_act or do_pre or do_ref or do_mrs)='1' then
			sdram_ras_p <= '0';
		else
			sdram_ras_p <= '1';
		end if;		
		
		if (do_read or do_write or do_ref or do_mrs)='1' then
			sdram_cas_p <= '0';
		else
			sdram_cas_p <= '1';
		end if;		
		
		sdram_cs <= sdram_cs_p;
		sdram_ras <= sdram_ras_p;
		sdram_cas <= sdram_cas_p;
		sdram_we <= sdram_we_p;
	end if;
end process;

--生成sdram_addr
--do_bst 		(others=>'0');
--do_read		(page(11) & "000" & addr)
--do_write		(page(11) & "000" & addr)
--do_act		page
--do_pre		"0100 0000 0000"
--do_ref		(others=>'0');
--do_mrs		"0000 0011 0111"
process(sysclk) begin
	if rising_edge(sysclk) then
		sdram_addr_p(11) <= (do_act or do_read or do_write) and scmd(27);		--page(11)
		sdram_addr_p(10) <= do_pre or (do_act and scmd(26));
		sdram_addr_p(9)  <= 		   do_act and scmd(25) ; 
		sdram_addr_p(8)  <=            do_act and scmd(24) ;
		sdram_addr_p(7)  <=           (do_act and scmd(23)) or ((do_read or do_write) and scmd(15));
		sdram_addr_p(6)  <=           (do_act and scmd(22)) or ((do_read or do_write) and scmd(14));
		sdram_addr_p(5)  <= do_mrs or (do_act and scmd(21)) or ((do_read or do_write) and scmd(13));
		sdram_addr_p(4)  <= do_mrs or (do_act and scmd(20)) or ((do_read or do_write) and scmd(12));
		sdram_addr_p(3)  <=           (do_act and scmd(19)) or ((do_read or do_write) and scmd(11));
		sdram_addr_p(2)  <= do_mrs or (do_act and scmd(18)) or ((do_read or do_write) and scmd(10));
		sdram_addr_p(1)  <= do_mrs or (do_act and scmd(17)) or ((do_read or do_write) and scmd( 9));
		sdram_addr_p(0)  <= do_mrs or (do_act and scmd(16)) or ((do_read or do_write) and scmd( 8));
						
		sdram_addr <= sdram_addr_p;
	end if;
end process;

--生成写的相关信号
process(sysclk) begin
	if rising_edge(sysclk) then
		if sbusy='0' then
			rddataen <= '0';
		elsif Scmdtype="10" and s_cnt="00000000" then
			rddataen <= '1';
		elsif Scmdtype="10" and s_cnt=Scmd(7 downto 0) then
			rddataen <= '0';	
		else
			rddataen <= rddataen;
		end if;

		if sbusy='0' then
			do_dataoe <= '0';
		elsif Scmdtype="10" and s_cnt="00000010" then
			do_dataoe <= '1';
		elsif Scmdtype="10" and s_cnt=Scmd_BST_TIME then
			do_dataoe <= '0';	
		else
			do_dataoe <= do_dataoe;
		end if;
		
		do_dataoe_d <= do_dataoe;
		dataoe <= do_dataoe_d;
		
		if Swhich_channel='0' then
			w_datain <= Iw_datain;
		else
			w_datain <= IIw_datain;
		end if;	
		
		Iw_rddataen <= rddataen and not Swhich_channel;
		IIw_rddataen <= rddataen and Swhich_channel;
		sdram_dataout <= w_datain;
	end if;
end process;
sdram_data <= sdram_dataout when dataoe='1' else (others=>'Z');

--生成读的相关信号
process(sysclk) begin
	if rising_edge(sysclk) then
		if sbusy='0' then
			datav_p <= '0';
		elsif Scmdtype="01" and s_cnt="00000011" then
			datav_p <= '1';
		elsif Scmdtype="01" and s_cnt=Scmd_BST_TIME then
			datav_p <= '0';
		else
			datav_p <= datav_p;
		end if;

		if Scmdtype="01" and s_cnt="00000110" then
			qqr_ch <= Swhich_channel;
		else
			qqr_ch <= qqr_ch;
		end if;	 	
		
		qqr_ch4 <= qqr_ch;
		qqr_ch5 <= qqr_ch4;
		datav_p1 <= datav_p;
		datav_p2 <= datav_p1;
		datav_p3 <= datav_p2;
		datav_p4 <= datav_p3;
		datav_p5 <= datav_p4;
			
		IIr_datav <= qqr_ch5 and datav_p5;
		Ir_datav <= not qqr_ch5 and datav_p5;
		
--		r_dataout <= sdram_datain;
		r_dataout <= sdram_data;
	end if;
end process;

--处理order, order在rddataen时全程有效,在data_v开始有效
process(sysclk) begin
	if rising_edge(sysclk) then
		if rrst='1' then
			order_i <= (others=>'0');
		elsif sbusy='1' and Scmdtype="10" and s_cnt="00000000" then		--write
			order_i <= Scmd(32 downto 28);
		elsif sbusy='1' and Scmdtype="01" and s_cnt="00000110" then		--read
			order_i <= Scmd(32 downto 28);
		else
			order_i <= order_i;
		end if;		
	end if;
end process;
order <= order_i;

----------------------------------------------------------------------------------
end a;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -