?? arbitrate.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 + -