A
ALuPin
Guest
Hi everybody,
I have written some little code for a FIFO and I want
to know whether the signals "l_fifo_full" / "l_fifo_empty" are
correct generated.
I would appreciate your opinion.
Thanx in advance.
Here is the code
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity frame_fifo is
port( Reset : in std_logic;
Clk : in std_logic;
Data_in : in std_logic_vector(7 downto 0);
Data_in_valid : in std_logic;
Take_data_out : in std_logic;
Erase : in std_logic;
Fifo_full : out std_logic;
Fifo_empty : out std_logic;
Data_out : out std_logic_vector(7 downto 0);
Data_out_valid : out std_logic
);
end frame_fifo;
architecture rtl of frame_fifo is
signal l_fifo_full, next_l_fifo_full : std_logic;
signal l_fifo_empty, next_l_fifo_empty : std_logic;
signal l_data_out : std_logic_vector(7 downto 0);
signal l_data_out_valid : std_logic;
constant ROWS : integer := 16;
constant COLS : integer := 8;
type matrix_buffer is array(0 to ROWS-1, 0 to COLS-1) of std_logic;
signal l_write_array : matrix_buffer;
signal l_read_pointer : integer range 0 to ROWS-1;
signal l_rp_reg : integer range 0 to ROWS-1;
signal l_write_pointer : integer range 0 to ROWS-1;
signal l_wp_turn_around : std_logic;
begin
Fifo_full <= l_fifo_full;
Fifo_empty <= l_fifo_empty;
Data_out <= l_data_out;
Data_out_valid <= l_data_out_valid;
----------------------------------------------------------------------
----------------------------------------------------------------------
-- write FIFO
process(Reset, Clk)
begin
if Reset='1' then
l_write_array <= (others => (others => '0'));
l_write_pointer <= 0;
elsif rising_edge(Clk) then
l_write_array <= l_write_array;
l_write_pointer <= l_write_pointer;
if ((Data_in_valid='1') and (next_l_fifo_full='0')) then
l_write_array(l_write_pointer, 7) <= Data_in(7);
l_write_array(l_write_pointer, 6) <= Data_in(6);
l_write_array(l_write_pointer, 5) <= Data_in(5);
l_write_array(l_write_pointer, 4) <= Data_in(4);
l_write_array(l_write_pointer, 3) <= Data_in(3);
l_write_array(l_write_pointer, 2) <= Data_in(2);
l_write_array(l_write_pointer, 1) <= Data_in(1);
l_write_array(l_write_pointer, 0) <= Data_in(0);
end if;
if (l_fifo_full='1')) then
l_write_pointer <= 0;
end if;
end if;
end process;
----------------------------------------------------------------------
----------------------------------------------------------------------
-- read FIFO
process(Reset, Clk)
begin
if Reset='1' then
l_data_out <= (others => '0');
l_data_out_valid <= '0';
l_read_pointer <= 0;
l_rp_reg <= 0;
elsif rising_edge(Clk) then
l_data_out <= l_data_out;
l_data_out_valid <= '0';
l_read_pointer <= l_read_pointer;
l_rp_reg <= l_read_pointer;
if Take_data_out='1' then
l_data_out(7) <= l_write_array(l_read_pointer, 7);
l_data_out(6) <= l_write_array(l_read_pointer, 6);
l_data_out(5) <= l_write_array(l_read_pointer, 5);
l_data_out(4) <= l_write_array(l_read_pointer, 4);
l_data_out(3) <= l_write_array(l_read_pointer, 3);
l_data_out(2) <= l_write_array(l_read_pointer, 2);
l_data_out(1) <= l_write_array(l_read_pointer, 1);
l_data_out(0) <= l_write_array(l_read_pointer, 0);
l_data_out_valid <= '1';
end if;
if (l_fifo_full='1')) then
l_read_pointer <= 0;
end if;
end if;
end process;
----------------------------------------------------------------------
----------------------------------------------------------------------
-- FIFO full/empty
-- clk transitions
process(Reset, Clk)
begin
if Reset='1' then
l_fifo_full <= '0';
l_fifo_empty <= '0';
elsif rising_edge(Clk) then
l_fifo_full <= next_l_fifo_full;
l_fifo_empty <= next_l_fifo_empty;
end if;
end process;
----------------------------------------------------------------------
-- FIFO full/empty
process(l_fifo_full, l_fifo_empty, l_wp_turn_around, l_write_pointer,
l_read_pointer, l_rp_reg)
begin
next_l_fifo_full <= '0';
next_l_fifo_empty <= '0';
if ((l_wp_turn_around='1') and (l_write_pointer=l_read_pointer) and
(l_read_pointer=l_rp_reg)) then
next_l_fifo_full <= '1';
end if;
if ((l_read_pointer=l_write_pointer) and (l_read_pointer>0)) then
next_l_fifo_empty <= '1';
end if;
end process;
----------------------------------------------------------------------
----------------------------------------------------------------------
-- This signal indicates whether the write pointer has arrived at
-- the maximum value (ROWS-1) and turned back to zero
process(Reset, Clk)
begin
if Reset='1' then
l_wp_turn_around <= '0';
elsif rising_edge(Clk) then
l_wp_turn_around <= l_wp_turn_around;
if (l_write_pointer=ROWS-1) then
l_wp_turn_around <= '1';
elsif (Erase='1') then
l_wp_turn_around <= '0';
end if;
end if;
end process;
----------------------------------------------------------------------
----------------------------------------------------------------------
end rtl;
I have written some little code for a FIFO and I want
to know whether the signals "l_fifo_full" / "l_fifo_empty" are
correct generated.
I would appreciate your opinion.
Thanx in advance.
Here is the code
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity frame_fifo is
port( Reset : in std_logic;
Clk : in std_logic;
Data_in : in std_logic_vector(7 downto 0);
Data_in_valid : in std_logic;
Take_data_out : in std_logic;
Erase : in std_logic;
Fifo_full : out std_logic;
Fifo_empty : out std_logic;
Data_out : out std_logic_vector(7 downto 0);
Data_out_valid : out std_logic
);
end frame_fifo;
architecture rtl of frame_fifo is
signal l_fifo_full, next_l_fifo_full : std_logic;
signal l_fifo_empty, next_l_fifo_empty : std_logic;
signal l_data_out : std_logic_vector(7 downto 0);
signal l_data_out_valid : std_logic;
constant ROWS : integer := 16;
constant COLS : integer := 8;
type matrix_buffer is array(0 to ROWS-1, 0 to COLS-1) of std_logic;
signal l_write_array : matrix_buffer;
signal l_read_pointer : integer range 0 to ROWS-1;
signal l_rp_reg : integer range 0 to ROWS-1;
signal l_write_pointer : integer range 0 to ROWS-1;
signal l_wp_turn_around : std_logic;
begin
Fifo_full <= l_fifo_full;
Fifo_empty <= l_fifo_empty;
Data_out <= l_data_out;
Data_out_valid <= l_data_out_valid;
----------------------------------------------------------------------
----------------------------------------------------------------------
-- write FIFO
process(Reset, Clk)
begin
if Reset='1' then
l_write_array <= (others => (others => '0'));
l_write_pointer <= 0;
elsif rising_edge(Clk) then
l_write_array <= l_write_array;
l_write_pointer <= l_write_pointer;
if ((Data_in_valid='1') and (next_l_fifo_full='0')) then
l_write_array(l_write_pointer, 7) <= Data_in(7);
l_write_array(l_write_pointer, 6) <= Data_in(6);
l_write_array(l_write_pointer, 5) <= Data_in(5);
l_write_array(l_write_pointer, 4) <= Data_in(4);
l_write_array(l_write_pointer, 3) <= Data_in(3);
l_write_array(l_write_pointer, 2) <= Data_in(2);
l_write_array(l_write_pointer, 1) <= Data_in(1);
l_write_array(l_write_pointer, 0) <= Data_in(0);
end if;
if (l_fifo_full='1')) then
l_write_pointer <= 0;
end if;
end if;
end process;
----------------------------------------------------------------------
----------------------------------------------------------------------
-- read FIFO
process(Reset, Clk)
begin
if Reset='1' then
l_data_out <= (others => '0');
l_data_out_valid <= '0';
l_read_pointer <= 0;
l_rp_reg <= 0;
elsif rising_edge(Clk) then
l_data_out <= l_data_out;
l_data_out_valid <= '0';
l_read_pointer <= l_read_pointer;
l_rp_reg <= l_read_pointer;
if Take_data_out='1' then
l_data_out(7) <= l_write_array(l_read_pointer, 7);
l_data_out(6) <= l_write_array(l_read_pointer, 6);
l_data_out(5) <= l_write_array(l_read_pointer, 5);
l_data_out(4) <= l_write_array(l_read_pointer, 4);
l_data_out(3) <= l_write_array(l_read_pointer, 3);
l_data_out(2) <= l_write_array(l_read_pointer, 2);
l_data_out(1) <= l_write_array(l_read_pointer, 1);
l_data_out(0) <= l_write_array(l_read_pointer, 0);
l_data_out_valid <= '1';
end if;
if (l_fifo_full='1')) then
l_read_pointer <= 0;
end if;
end if;
end process;
----------------------------------------------------------------------
----------------------------------------------------------------------
-- FIFO full/empty
-- clk transitions
process(Reset, Clk)
begin
if Reset='1' then
l_fifo_full <= '0';
l_fifo_empty <= '0';
elsif rising_edge(Clk) then
l_fifo_full <= next_l_fifo_full;
l_fifo_empty <= next_l_fifo_empty;
end if;
end process;
----------------------------------------------------------------------
-- FIFO full/empty
process(l_fifo_full, l_fifo_empty, l_wp_turn_around, l_write_pointer,
l_read_pointer, l_rp_reg)
begin
next_l_fifo_full <= '0';
next_l_fifo_empty <= '0';
if ((l_wp_turn_around='1') and (l_write_pointer=l_read_pointer) and
(l_read_pointer=l_rp_reg)) then
next_l_fifo_full <= '1';
end if;
if ((l_read_pointer=l_write_pointer) and (l_read_pointer>0)) then
next_l_fifo_empty <= '1';
end if;
end process;
----------------------------------------------------------------------
----------------------------------------------------------------------
-- This signal indicates whether the write pointer has arrived at
-- the maximum value (ROWS-1) and turned back to zero
process(Reset, Clk)
begin
if Reset='1' then
l_wp_turn_around <= '0';
elsif rising_edge(Clk) then
l_wp_turn_around <= l_wp_turn_around;
if (l_write_pointer=ROWS-1) then
l_wp_turn_around <= '1';
elsif (Erase='1') then
l_wp_turn_around <= '0';
end if;
end if;
end process;
----------------------------------------------------------------------
----------------------------------------------------------------------
end rtl;