📄 fifo.vhd
字号:
--*******************************************************************--
-- Copyright (c) 2007-... www.soctop.com --
--*******************************************************************--
-- Please review the terms of the license agreement before using --
-- this file. If you are not an authorized user, please destroy this --
-- source code file and notify Evatronix SA immediately that you --
-- inadvertently received an unauthorized copy. --
--*******************************************************************--
-----------------------------------------------------------------------
-- Project name : Fifo
-- Project description : Fifo controller Unit
--
-- File name : FIFO.VHD
-- File contents :
--
-- Purpose :
--
-- Destination library :
-- Dependencies : IEEE.STD_LOGIC_1164
--
-- Design Engineer : Distance
-- Quality Engineer :
-- Version :
-- Last modification : 2007-06-29
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity fifo is
port(
CE : in std_logic;
CLR : in std_logic;
CLRptr : in std_logic;
RDinc : in std_logic;
WRinc : in std_logic;
CLK : in std_logic;
RD : in std_logic;
WR : in std_logic;
DATA : in std_logic_vector (7 downto 0);
EMPTY : out std_logic;
FULL : out std_logic;
AE : out std_logic;
AF : out std_logic;
Q : out std_logic_vector (7 downto 0)
);
end entity;
architecture fifo_arch of fifo is
type fifo_array_type is array (15 downto 0) of std_logic_vector (7 downto 0);
signal fifo_array : fifo_array_type; --定义fifo_array,表示FIFO的阵列.
signal WR_PTR : INTEGER range 0 to 15; --定义写指针,类型为整型.
signal RD_PTR : INTEGER range 0 to 15; --定义读指针
begin
process (CLK)
begin
if rising_edge(CLK) then -- rising_edge(CLK)表示时钟的上升沿
if CE = '1' then --时钟使能信号有效
if CLR = '1' then --清零信号
for INDEX in 15 downto 0 loop
fifo_array(INDEX) <= (others => '0'); --对队列清零
end loop;
elsif WR = '1' then --写使能信号
fifo_array(WR_PTR) <= DATA; --把端口数据写入队列
end if;
end if;
end if;
end process;
process (CLK)
variable PTR : INTEGER range 0 to 16;
begin
if rising_edge(CLK) then -- rising_edge(CLK)表示时钟的上升沿
if CE = '1' then --时钟使能信号有效
if CLR = '1' or CLRptr = '1' then --清零信号有效或者读写指针信号无效
WR_PTR <= 0; --以下执行指针和标志位清零操作
RD_PTR <= 0;
EMPTY <= '1';
FULL <= '0';
AE <= '0';
AF <= '0';
PTR := 0;
elsif WRinc = '1' and PTR < 16 then --判断写指针增量,同时判断PTR
if WR_PTR < 15 then --判断写指针(如果小于15)
WR_PTR <= WR_PTR + 1; --对写指针累加
elsif WR_PTR = 15 then --判断写指针(如果等于15)
WR_PTR <= 0; --写指针清零
end if;
PTR := PTR + 1;
elsif RDinc = '1' and PTR > 0 then --判断读指针增量,同时判断PTR
if RD_PTR<15 then --判断读指针(如果小于15)
RD_PTR <= RD_PTR + 1; --对读指针累加
elsif RD_PTR = 15 then --判断读指针(如果等于15)
RD_PTR <= 0; --读指针清零
end if;
PTR := PTR - 1;
end if;
if PTR = 0 then --判断PTR(如果为0)
EMPTY <= '1'; --标志位EMPTY置1,FIFO状态为空
else
EMPTY <= '0'; --否则标志位EMPTY置0
end if;
if PTR = 16 then --判断PTR(如果为16)
FULL<= '1'; --标志位FULL置1,FIFO状态为满
else
FULL <= '0'; --否则标志位FULL置0
end if;
if PTR > 0 and PTR <= 2 then --判断PTR(如果大于0,而小于2)
AE <= '1'; --标志位置1,表示FIFO基本为空
else
AE <= '0'; --标志位置0,表示FIFO状态大于2
end if;
if PTR < 16 and PTR >= 14 then --判断PTR(如果大于等于14,而小于16)
AF <= '1'; --标志位置1,表示FIFO基本为满
else
AF <= '0'; --标志位为0,表示FIFO的状态小于14
end if;
end if;
end if;
end process;
Q <= fifo_array(RD_PTR) when RD = '1' else (others => 'Z');--读使能(RD)有效,把队列的数据送到数据输出端,否则置为高阻,表示不占用数据总线.这个语法是非常有用的语法,在操作数据总线的时候,经常会用到,前面讲双向电路也曾用到.
end architecture;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -