--
|
--
|
-- fifo.vhd
|
-- fifo.vhd
|
--
|
--
|
-- simple fifo
|
-- simple fifo
|
--
|
--
|
-- uses FF and every rd or wr has to 'bubble' through the hole fifo.
|
-- uses FF and every rd or wr has to 'bubble' through the hole fifo.
|
--
|
--
|
-- Author: Martin Schoeberl martin.schoeberl@chello.at
|
-- Author: Martin Schoeberl martin.schoeberl@chello.at
|
--
|
--
|
--
|
--
|
-- resources on ACEX1K
|
-- resources on ACEX1K
|
--
|
--
|
-- (width+2)*depth-1 LCs
|
-- (width+2)*depth-1 LCs
|
--
|
--
|
--
|
--
|
-- 2002-01-06 first working version
|
-- 2002-01-06 first working version
|
-- 2002-11-03 a signal for reaching threshold
|
-- 2002-11-03 a signal for reaching threshold
|
-- 2005-02-20 change entity order for modelsim vcom
|
-- 2005-02-20 change entity order for modelsim vcom
|
--
|
--
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
|
|
use work.marca_pkg.all;
|
use work.marca_pkg.all;
|
|
|
entity fifo_elem is
|
entity fifo_elem is
|
|
|
generic (width : integer);
|
generic (width : integer);
|
port (
|
port (
|
clk : in std_logic;
|
clk : in std_logic;
|
reset : in std_logic;
|
reset : in std_logic;
|
|
|
din : in std_logic_vector(width-1 downto 0);
|
din : in std_logic_vector(width-1 downto 0);
|
dout : out std_logic_vector(width-1 downto 0);
|
dout : out std_logic_vector(width-1 downto 0);
|
|
|
rd : in std_logic;
|
rd : in std_logic;
|
wr : in std_logic;
|
wr : in std_logic;
|
|
|
rd_prev : out std_logic;
|
rd_prev : out std_logic;
|
full : out std_logic
|
full : out std_logic
|
);
|
);
|
end fifo_elem;
|
end fifo_elem;
|
|
|
architecture rtl of fifo_elem is
|
architecture rtl of fifo_elem is
|
|
|
signal buf : std_logic_vector(width-1 downto 0);
|
signal buf : std_logic_vector(width-1 downto 0);
|
signal f : std_logic;
|
signal f : std_logic;
|
|
|
begin
|
begin
|
|
|
dout <= buf;
|
dout <= buf;
|
|
|
process(clk, reset, f)
|
process(clk, reset, f)
|
|
|
begin
|
begin
|
|
|
full <= f;
|
full <= f;
|
|
|
if reset = RESET_ACTIVE then
|
if reset = RESET_ACTIVE then
|
|
|
buf <= (others => '0');
|
buf <= (others => '0');
|
f <= '0';
|
f <= '0';
|
rd_prev <= '0';
|
rd_prev <= '0';
|
|
|
elsif rising_edge(clk) then
|
elsif rising_edge(clk) then
|
|
|
rd_prev <= '0';
|
rd_prev <= '0';
|
if f='0' then
|
if f='0' then
|
if wr='1' then
|
if wr='1' then
|
rd_prev <= '1';
|
rd_prev <= '1';
|
buf <= din;
|
buf <= din;
|
f <= '1';
|
f <= '1';
|
end if;
|
end if;
|
else
|
else
|
if rd='1' then
|
if rd='1' then
|
f <= '0';
|
f <= '0';
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
end if;
|
end if;
|
|
|
end process;
|
end process;
|
|
|
end rtl;
|
end rtl;
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
|
|
entity fifo is
|
entity fifo is
|
|
|
generic (width : integer := 8; depth : integer := 4; thres : integer := 2);
|
generic (width : integer := 8; depth : integer := 4; thres : integer := 2);
|
port (
|
port (
|
clk : in std_logic;
|
clk : in std_logic;
|
reset : in std_logic;
|
reset : in std_logic;
|
|
|
din : in std_logic_vector(width-1 downto 0);
|
din : in std_logic_vector(width-1 downto 0);
|
dout : out std_logic_vector(width-1 downto 0);
|
dout : out std_logic_vector(width-1 downto 0);
|
|
|
rd : in std_logic;
|
rd : in std_logic;
|
wr : in std_logic;
|
wr : in std_logic;
|
|
|
empty : out std_logic;
|
empty : out std_logic;
|
full : out std_logic;
|
full : out std_logic;
|
half : out std_logic
|
half : out std_logic
|
);
|
);
|
end fifo ;
|
end fifo ;
|
|
|
architecture rtl of fifo is
|
architecture rtl of fifo is
|
|
|
component fifo_elem is
|
component fifo_elem is
|
generic (width : integer);
|
generic (width : integer);
|
port (
|
port (
|
clk : in std_logic;
|
clk : in std_logic;
|
reset : in std_logic;
|
reset : in std_logic;
|
|
|
din : in std_logic_vector(width-1 downto 0);
|
din : in std_logic_vector(width-1 downto 0);
|
dout : out std_logic_vector(width-1 downto 0);
|
dout : out std_logic_vector(width-1 downto 0);
|
|
|
rd : in std_logic;
|
rd : in std_logic;
|
wr : in std_logic;
|
wr : in std_logic;
|
|
|
rd_prev : out std_logic;
|
rd_prev : out std_logic;
|
full : out std_logic);
|
full : out std_logic);
|
end component;
|
end component;
|
|
|
signal r, w, rp, f : std_logic_vector(depth-1 downto 0);
|
signal r, w, rp, f : std_logic_vector(depth-1 downto 0);
|
type d_array is array (0 to depth-1) of std_logic_vector(width-1 downto 0);
|
type d_array is array (0 to depth-1) of std_logic_vector(width-1 downto 0);
|
signal di, do : d_array;
|
signal di, do : d_array;
|
|
|
begin
|
begin
|
|
|
g1: for i in 0 to depth-1 generate
|
g1: for i in 0 to depth-1 generate
|
|
|
f1: fifo_elem generic map (width)
|
f1: fifo_elem generic map (width)
|
port map (clk, reset, di(i), do(i), r(i), w(i), rp(i), f(i));
|
port map (clk, reset, di(i), do(i), r(i), w(i), rp(i), f(i));
|
|
|
x: if i<depth-1 generate
|
x: if i<depth-1 generate
|
r(i) <= rp(i+1);
|
r(i) <= rp(i+1);
|
w(i+1) <= f(i);
|
w(i+1) <= f(i);
|
di(i+1) <= do(i);
|
di(i+1) <= do(i);
|
end generate;
|
end generate;
|
|
|
end generate;
|
end generate;
|
|
|
di(0) <= din;
|
di(0) <= din;
|
dout <= do(depth-1);
|
dout <= do(depth-1);
|
w(0) <= wr;
|
w(0) <= wr;
|
r(depth-1) <= rd;
|
r(depth-1) <= rd;
|
|
|
full <= f(0);
|
full <= f(0);
|
half <= f(depth-thres);
|
half <= f(depth-thres);
|
empty <= not f(depth-1);
|
empty <= not f(depth-1);
|
|
|
end rtl;
|
end rtl;
|
|
|
|
|