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

📄 arbitrate.vhd

📁 sdram控制器
💻 VHD
字号:
--本程序是Sdram控制器中的裁决部分,完成外部的6个随机请求按时间顺序排列,并保证信号的完整性
--从而控制后续的状态机发出特定的Sdram命令序列
--输入:
--	SdramClk	Sdram时钟,100MHz
--	ResetGlb	全局复位
--	FIFO1AlmostF	前端Fifo几乎满信号,高电平有效
--	FIFO2AlmostE		后端FIFO几乎空信号,低电平有效
--	HostWr		主机写信号,低电平有效
--	HostRd		主机读信号,低电平有效
--	TransferMode	操作请求,高电平:页操作;底电平:随机操作
--	OperationAck	Sdram操作结束应答
--
--输出:
--	HostReady	随机操作准备好信号,高电平:准备好,低电平:忙
--	OperationReq	操作请求:
--				000	空闲
--				001	页写
--				010	页读
--				011	随机写
--				100	随机读
--				101	页模式配置
--				110	随机模式配置
--				111	空闲 补充页操作的刷新

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity Arbitrate is

	generic(
		--请求种类
		constant	IdleReq:		std_logic_vector(2 downto 0):= "000";
		constant	PageWrReq:		std_logic_vector(2 downto 0):= "001";
		constant	PageRdReq:		std_logic_vector(2 downto 0):= "010";
		constant	HostWrReq:		std_logic_vector(2 downto 0):= "011";
		constant	HostRdReq:		std_logic_vector(2 downto 0):= "100";
		constant	ConfigPageReq:		std_logic_vector(2 downto 0):= "101";
		constant	ConfigHostReq:		std_logic_vector(2 downto 0):= "110";
---------------------------------------------------------------------------------------------------
		constant	refresh:		std_logic_vector(2 downto 0):= "111"
	);
	
	port(
		--Test
--		testflagPageWr:		out	std_logic;
--		testflagPageRd:		out	std_logic;
--		testflagHostWr:		out	std_logic;
--		testflagHostRd:		out	std_logic;
--		testflagPageConfig:	out	std_logic;
--		testflagHostConfig:	out	std_logic;
--		testOperationState:	out	std_logic_vector(2 downto 0);
		--End
		
		--RealPort
--		ResetGlb:	in	std_logic;
		SdramClk:	in	std_logic;
		ResetGlb:	in	std_logic;
		FIFO1AlmostF:	in	std_logic;
		FIFO2AlmostE:	in	std_logic;
		HostWr:		in	std_logic;
		HostRd:		in	std_logic;
		TransferMode:	in	std_logic;

		OperationAck:	in	std_logic:='0';

--		HostReady:	out	std_logic;
		OperationReq:	out	std_logic_vector(2 downto 0)
	);
		
end;

architecture SecondLevel of Arbitrate is
--signal	ResetGlb:	std_logic:='0';
signal	flagPageWr:	std_logic:='0';
signal	flagPageRd:	std_logic:='0';
signal	flagHostWr:	std_logic:='0';
signal	flagHostRd:	std_logic:='0';
signal	flagPageConfig:	std_logic:='0';
signal	flagHostConfig:	std_logic:='0';
--signal	OptionClr:	std_logic:='0';
signal	PageEn:		std_logic:='0';
--signal	HostClk:	std_logic:='1';
signal	OperationState:	std_logic_vector(2 downto 0):="000";
signal	refcounter:	std_logic_vector(15 downto 0):="0000000000000000";
signal	RefEn:	std_logic;
signal	RefEnd:	std_logic;
signal	refreshreq:	std_logic;
--signal	RstCnt:		std_logic_vector(3 downto 0):="0000";
--signal	RstConfigReq:	std_logic;

begin
	--test
--	testflagPageWr <= flagPageWr;
--	testflagPageRd <= flagPageRd;
--	testflagHostWr <= flagHostWr;
--	testflagHostRd <= flagHostRd;
--	testflagPageConfig <= flagPageConfig;
--	testflagHostConfig <= flagHostConfig;
--	testOperationState <= OperationState;
	--End
-------刷新操作模块--------------------------------------------
	process(ResetGlb,SdramClk,OperationAck)
	begin
	if(ResetGlb = '0') then
		refcounter <= X"0003";
		RefEn<='0';
		RefEnd<='0';
		refreshreq <='0';
	elsif rising_edge(SdramClk) then
		
		if RefEnd='1' then
			refcounter<=X"03e8";
		elsif RefEn='1' then
		      	refcounter<= refcounter-1;
		end if;
	
		if refcounter=X"0000" then
			RefEnd<='1';
		else
			RefEnd<='0';
		end if;

		if OperationAck='1' then
			RefEn<='1';
		end if;
		if refcounter=X"0000" then	
			refreshreq <='1';
		elsif OperationState="111" and OperationAck='1' then
			refreshreq <='0';
		end if;
	end if;
	end process;
-------------------------------------------------------------------
	--页写请求
	process(FIFO1AlmostF,OperationAck,OperationState,ResetGlb)
	begin
		if (OperationAck='1' and OperationState=PageWrReq) or ResetGlb='0' then
			flagPageWr<='0';						--异步清0
--		elsif FIFO1AlmostF = '1' then
		elsif rising_edge(FIFO1AlmostF) then
			flagPageWr<='1';						--页写标记异步置位
		end if;
	end process;

	--页读请求
	process(FIFO2AlmostE,OperationAck,OperationState,ResetGlb)
	begin
		if (OperationAck='1' and OperationState=PageRdReq) or ResetGlb='0' then
			flagPageRd<='0';						--异步清0
--		elsif FIFO2AlmostE='0' then						
		elsif falling_edge(FIFO2AlmostE) then
			flagPageRd<='1';						--页读标记异步置位
		end if;
	end process;
	
	--随机写请求
--	process(HostWr,OperationAck,OperationState,ResetGlb)
--	begin
--		if (OperationAck='1' and OperationState=HostWrReq) or ResetGlb='0' then
--			flagHostWr<='0';						--异步清0
--		elsif falling_edge(HostWr) then
--			flagHostWr<='1';						--随机写标记异步置位
--		end if;
--	end process;
	process(SdramClk) 
		begin
		if rising_edge(SdramClk) then
			flagHostWr<= not HostWr;						--随机写标记异步置位
			flagHostRd<= not HostRd;
		end if;
	end process;
	--随机读请求
--	process(HostRd,OperationAck,OperationState,ResetGlb)
--	begin
--		if (OperationAck='1' and OperationState=HostRdReq) or ResetGlb='0' then
--			flagHostRd<='0';						--异步清0
--		elsif falling_edge(HostRd) then
--			flagHostRd<='1';						--随机读标记异步置位
--		end if;
--	end process;


	
--	flagHostRd<= not HostRd;						--随机读标记异步置位

	--页配置请求
	process(TransferMode,OperationAck,OperationState,ResetGlb)
	begin
		if (OperationAck='1' and OperationState=ConfigPageReq) or ResetGlb='0' then
			flagPageConfig<='0';						--异步清0
		elsif falling_edge(TransferMode) then
			flagPageConfig<='1';						--由随机模式转为页模时,配置页标记异步置位
		end if;
	end process;

--	HostClk<='0' when TransferMode='0' or RstConfigReq='0' else '1';

	--随机配置请求
	process(TransferMode,OperationAck,OperationState,ResetGlb)
	begin
		if (OperationAck='1' and OperationState=ConfigHostReq) or ResetGlb='0' then
			flagHostConfig<='0';						--异步清0
		elsif rising_edge(TransferMode) then
			flagHostConfig<='1';						--由页模式转为随机模时,配置页标记异步置位
		end if;
	end process;

	--请求寄存器清除脉冲
--	process(SdramClk,OptionAck)
--	begin
--		if rising_edge(SdramClk) then
--			OptionClr<=OptionAck;
--		end if;
--	end process;

	--页操作和随机操作允许标志,0:随机,1:页
	process(SdramClk,OperationState,ResetGlb)
	begin

		if ResetGlb='0' then
			PageEn<='0';
		elsif rising_edge(SdramClk) then
			if OperationState=ConfigPageReq then				--当进行完配置页操作时,页操作使能
				PageEn<='1';
			elsif OperationState=ConfigHostReq then
				PageEn<='0';						--当进行完配置随机操作时,随机操作使能
			end if;
		end if;
	end process;
	

	--主机等待信号
--	HostReady<=((not HostWrReq) and (not HostRdReq)) or PageReq;

	--操作码裁决
	process(ResetGlb,SdramClk,PageEn,flagPageWr,flagPageRd,OperationAck,OperationState)
	begin
		if ResetGlb='0' then
			OperationState<="000";		--异步复位
		elsif rising_edge(SdramClk) then
			if refreshreq ='1' and OperationState=IdleReq  and OperationAck='0' then 
  				OperationState <= refresh;

			elsif flagHostConfig='1' and OperationState=IdleReq and refreshreq ='0' and OperationAck='0' then
				OperationState <= ConfigHostReq;
			elsif flagPageConfig='1' and OperationState=IdleReq and refreshreq ='0' and OperationAck='0' then
				OperationState <= ConfigPageReq;
			elsif flagPageConfig='0' and flagHostConfig='0' and OperationAck='0' and OperationState=IdleReq and refreshreq ='0' and PageEn='1' and flagPageRd='1' then
				OperationState <= PageRdReq;
			elsif flagPageConfig='0' and flagHostConfig='0' and OperationAck='0' and OperationState=IdleReq and refreshreq ='0' and PageEn='1' and flagPageRd='0' and flagPageWr='1' then
				OperationState <= PageWrReq;
			elsif flagPageConfig='0' and flagHostConfig='0' and OperationAck='0' and OperationState=IdleReq and refreshreq ='0' and PageEn='0' and flagHostRd='1' then
				OperationState <= HostRdReq;
			elsif flagPageConfig='0' and flagHostConfig='0' and OperationAck='0' and OperationState=IdleReq and refreshreq ='0' and PageEn='0' and flagHostWr='1' then
				OperationState <= HostWrReq;
			elsif OperationAck='1' and PageEn='1' then
				OperationState <= IdleReq;
			elsif OperationAck='1' and OperationState=ConfigHostReq then			--页模式状态下的请求清0操作,是靠OperationAck来完成的
				OperationState <= IdleReq;
			elsif OperationState=HostWrReq and PageEn='0' and flagHostWr='0' then		--随机写操作一直维持到主机写操作结束
				OperationState <= IdleReq;
			elsif OperationState=HostRdReq and PageEn='0' and flagHostRd='0' then
				OperationState <= IdleReq;
			---------------刷新的回零状态--------------------------------
			elsif  OperationAck='1' and OperationState = refresh  then
				OperationState <= IdleReq;
			
			end if;
		end if;
	end process;

	process(SdramClk)
	begin
		if rising_edge(SdramClk) then
			OperationReq<=OperationState	after 1 ns;
		end if;
	end process;
	--复位时间计数器
--	process(ResetGlb,SdramClk,RstCnt)
--	begin
--		if ResetGlb='0' then
--			RstCnt<="0000";
--		elsif rising_edge(SdramClk) then
--			if RstCnt<="1100" then
--				RstCnt<=RstCnt+1;
--			else
--				RstCnt<="1110";
--			end if;
--		end if;
--	end process;
	
	--复位后的配置申请
--	RstConfigReq<='0' when RstCnt<="1100" else '1';
	
end SecondLevel;

⌨️ 快捷键说明

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