Committed on the Free edition of March Hare Software CVSNT Server. Upgrade to CVS Suite for more features and support: http://march-hare.com/cvsnt/ git-svn-id: http://moon:8086/svn/vhdl/trunk@944 cc03376c-175c-47c8-b038-4cd826a8556b
207 lines
4.4 KiB
VHDL
207 lines
4.4 KiB
VHDL
-------------------------------------------------------------------------
|
|
-- Project: FIFO, generic FIFOs written in VHDL
|
|
-- Release 1
|
|
--
|
|
-- Copyright (C) 2007 J. Ahrensfeld
|
|
--
|
|
-- This library is free software; you can redistribute it and/or
|
|
-- modify it under the terms of the GNU Lesser General Public
|
|
-- License as published by the Free Software Foundation; either
|
|
-- version 2.1 of the License, or (at your option) any later version.
|
|
--
|
|
-- This library is distributed in the hope that it will be useful,
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
-- Lesser General Public License for more details.
|
|
--
|
|
-- You should have received a copy of the GNU Lesser General Public
|
|
-- License along with this library; if not, write to the Free Software
|
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
--
|
|
-- For questions and ideas, please contact the author at jens@jayfield.org
|
|
--
|
|
-----------------------------------------------------------------------
|
|
|
|
LIBRARY IEEE;
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
|
USE IEEE.MATH_REAL.ALL;
|
|
USE IEEE.NUMERIC_STD.ALL;
|
|
USE STD.TEXTIO.ALL;
|
|
|
|
-- LIBRARY WORK;
|
|
-- USE.YOURLIB.WHATELSE
|
|
|
|
ENTITY tb_fifo_sync IS
|
|
END tb_fifo_sync;
|
|
|
|
ARCHITECTURE behavior OF tb_fifo_sync IS
|
|
|
|
--Constants
|
|
constant PERIOD : time := 10 ns;
|
|
constant ADDR_WIDTH : integer := 3;
|
|
constant DATA_WIDTH : integer := 8;
|
|
|
|
--Inputs
|
|
signal rst : STD_LOGIC := '1';
|
|
signal clk : STD_LOGIC := '0';
|
|
signal we : STD_LOGIC := '0';
|
|
signal re : STD_LOGIC := '0';
|
|
signal din : unsigned (7 downto 0);
|
|
--Outputs
|
|
|
|
signal dout : unsigned (7 downto 0);
|
|
signal fifo_full : STD_LOGIC;
|
|
signal fifo_empty : STD_LOGIC;
|
|
signal fifo_almost_full : STD_LOGIC;
|
|
signal fifo_almost_empty : STD_LOGIC;
|
|
|
|
signal write_en : STD_LOGIC := '0';
|
|
signal read_en : STD_LOGIC := '0';
|
|
|
|
signal ref_r : unsigned (7 downto 0) := (others => '0');
|
|
|
|
BEGIN
|
|
|
|
-- Instantiate the Unit Under Test (UUT)
|
|
uut: entity work.fifo_sync
|
|
GENERIC MAP
|
|
(
|
|
data_width => DATA_WIDTH,
|
|
addr_width => ADDR_WIDTH,
|
|
almost_full_thresh => 6,
|
|
almost_empty_thresh => 2,
|
|
do_last_read_update => false
|
|
)
|
|
PORT MAP
|
|
(
|
|
rst => rst,
|
|
clk => clk,
|
|
we => we,
|
|
re => re,
|
|
data_w => din,
|
|
data_r => dout,
|
|
fifo_full => fifo_full,
|
|
fifo_empty => fifo_empty,
|
|
fifo_afull => fifo_almost_full,
|
|
fifo_aempty => fifo_almost_empty
|
|
|
|
);
|
|
|
|
tb_clk : PROCESS
|
|
BEGIN
|
|
clk <= not clk;
|
|
wait for PERIOD/2;
|
|
END PROCESS;
|
|
|
|
tb_write : PROCESS
|
|
BEGIN
|
|
|
|
-- Wait 100 ns for global reset to finish
|
|
wait for 5*PERIOD;
|
|
rst <= '0';
|
|
wait for 7*PERIOD;
|
|
write_en <= '1';
|
|
wait for 25*PERIOD;
|
|
write_en <= '0';
|
|
wait for 7*PERIOD;
|
|
write_en <= '1';
|
|
wait for 25*PERIOD;
|
|
write_en <= '0';
|
|
wait for 7*PERIOD;
|
|
write_en <= '1';
|
|
wait for 1*PERIOD;
|
|
write_en <= '0';
|
|
wait for 1*PERIOD;
|
|
write_en <= '1';
|
|
wait for 1*PERIOD;
|
|
write_en <= '0';
|
|
wait for 3*PERIOD;
|
|
write_en <= '1';
|
|
wait for 4*PERIOD;
|
|
write_en <= '0';
|
|
wait for 17*PERIOD;
|
|
write_en <= '1';
|
|
wait for 25*PERIOD;
|
|
write_en <= '0';
|
|
|
|
wait;
|
|
|
|
END PROCESS;
|
|
|
|
tb_read : PROCESS
|
|
BEGIN
|
|
|
|
-- Wait 100 ns for global reset to finish
|
|
wait for 25*PERIOD;
|
|
read_en <= '1';
|
|
wait for 25*PERIOD;
|
|
read_en <= '0';
|
|
wait for 25*PERIOD;
|
|
read_en <= '1';
|
|
wait for 1*PERIOD;
|
|
read_en <= '0';
|
|
wait for 5*PERIOD;
|
|
read_en <= '1';
|
|
wait for 1*PERIOD;
|
|
read_en <= '0';
|
|
wait for 5*PERIOD;
|
|
read_en <= '1';
|
|
wait for 1*PERIOD;
|
|
read_en <= '0';
|
|
wait for 5*PERIOD;
|
|
read_en <= '1';
|
|
wait for 1*PERIOD;
|
|
read_en <= '0';
|
|
wait for 5*PERIOD;
|
|
read_en <= '1';
|
|
wait for 1*PERIOD;
|
|
read_en <= '0';
|
|
wait for 5*PERIOD;
|
|
read_en <= '1';
|
|
wait for 1*PERIOD;
|
|
read_en <= '0';
|
|
wait for 5*PERIOD;
|
|
read_en <= '1';
|
|
wait for 1*PERIOD;
|
|
read_en <= '0';
|
|
wait for 7*PERIOD;
|
|
read_en <= '1';
|
|
wait for 20*PERIOD;
|
|
read_en <= '0';
|
|
|
|
wait;
|
|
|
|
END PROCESS;
|
|
|
|
we <= write_en and not fifo_full;
|
|
|
|
tb_w : PROCESS(rst, clk)
|
|
BEGIN
|
|
|
|
if rst = '1' then
|
|
din <= (others => '0');
|
|
elsif rising_edge(clk) then
|
|
if we = '1' then
|
|
din <= din + 1;
|
|
end if;
|
|
end if;
|
|
|
|
END PROCESS;
|
|
|
|
re <= read_en and not fifo_empty;
|
|
|
|
tb_r : PROCESS(rst, clk)
|
|
BEGIN
|
|
|
|
if rst = '1' then
|
|
ref_r <= (others => '0');
|
|
elsif rising_edge(clk) then
|
|
if re = '1' then
|
|
assert ref_r = dout report "FIFO read error!" severity failure;
|
|
ref_r <= ref_r + 1;
|
|
end if;
|
|
end if;
|
|
|
|
END PROCESS;
|
|
|
|
END behavior; |