📄 fifo1.vhd
字号:
---------------------------------------------------------------------------------------------------
--
-- Title : fifo1
-- Design : gateway
-- Author : zlm
-- Company : buaa
--
---------------------------------------------------------------------------------------------------
--
-- File : fifo1.vhd
-- Generated : Tue Dec 14 15:44:02 2004
-- From : interface description file
-- By : Itf2Vhdl ver. 1.20
--
---------------------------------------------------------------------------------------------------
--
-- Description :
--
---------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
entity fifo1 is
port(
clk_w : in STD_LOGIC;
clk_r : in STD_LOGIC;
reset : in STD_LOGIC;
wr : in STD_LOGIC;
rd : in STD_LOGIC;
din : in STD_LOGIC_VECTOR(3 downto 0);
full : out STD_LOGIC;
empty : out STD_LOGIC;
dout : out STD_LOGIC_VECTOR(3 downto 0)
);
end fifo1;
--}} End of automatically maintained section
architecture fifo1 of fifo1 is
constant w:integer:=256;
type memory is array(0 to w-1) of std_logic_vector(3 downto 0);
signal ram:memory;
signal wp,rp:integer range 0 to w-1;
signal in_full,in_empty:std_logic;
signal cnt:std_logic_vector(6 downto 0);
begin
full<=in_full;
empty<=in_empty;
dout<=ram(rp);
--write data--
process(clk_w)
begin
if (clk_w'event and clk_w='1')then
if (wr='0' and in_full='0')then
ram(wp)<=din;
end if;
end if;
end process;
--change wp--
process(clk_w,reset)
begin
if (reset='1')then
wp<=0;
elsif (clk_w'event and clk_w='1')then
if (wr='0' and in_full='0')then
if(wp=w-1)then
wp<=0;
else
wp<=wp+1;
end if;
end if;
end if;
end process;
--change rp--
process(clk_r,reset)
begin
if (reset='1')then
rp<=w-1;
elsif (clk_r'event and clk_r='1')then
if (rd='0' and in_empty='0')then
if(rp=w-1)then
rp<=0;
else
rp<=rp+1;
end if;
end if;
end if;
end process;
--generate empty--
process(clk_r,reset)
begin
if (reset='1')then
in_empty<='1';
elsif (clk_r'event and clk_r='1')then
if ((rp=wp-2 or (rp=w-1 and wp=1) or (rp=w-2 and wp=0)) and (rd='0'and wr='1')) then
in_empty<='1';
elsif (in_empty='1'and wr='0')then
in_empty<='0';
end if;
end if;
end process;
--generate full--
process(clk_w,reset)
begin
if (reset='1')then
in_full<='0';
cnt<=(others=>'0');
elsif (clk_w'event and clk_w='1')then
if cnt=0 then
if (rp=wp+1)then
in_full<='1';
cnt<=cnt+1;
elsif (in_full='1')then
in_full<='0';
end if;
elsif cnt=127 then
cnt<=(others=>'0');
else
cnt<=cnt+'1';
end if;
end if;
end process;
end fifo1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -