2014-02-28 19:26:22 +00:00
|
|
|
library ieee;
|
|
|
|
use ieee.std_logic_1164.all;
|
|
|
|
use ieee.numeric_std.all;
|
|
|
|
|
|
|
|
entity dma_fifo is
|
|
|
|
generic (
|
|
|
|
RAM_ADDR_WIDTH : integer := 3;
|
|
|
|
FIFO_DWIDTH : integer := 32
|
|
|
|
);
|
|
|
|
port (
|
|
|
|
clk : in std_logic;
|
|
|
|
resetn : in std_logic;
|
|
|
|
fifo_reset : in std_logic;
|
|
|
|
|
|
|
|
-- Write port
|
|
|
|
in_stb : in std_logic;
|
|
|
|
in_ack : out std_logic;
|
|
|
|
in_data : in std_logic_vector(FIFO_DWIDTH-1 downto 0);
|
|
|
|
|
|
|
|
-- Read port
|
|
|
|
out_stb : out std_logic;
|
|
|
|
out_ack : in std_logic;
|
|
|
|
out_data : out std_logic_vector(FIFO_DWIDTH-1 downto 0)
|
|
|
|
);
|
|
|
|
end;
|
|
|
|
|
|
|
|
architecture imp of dma_fifo is
|
|
|
|
|
|
|
|
constant FIFO_MAX : natural := 2**RAM_ADDR_WIDTH -1;
|
|
|
|
type MEM is array (0 to FIFO_MAX) of std_logic_vector(FIFO_DWIDTH - 1 downto 0);
|
|
|
|
signal data_fifo : MEM;
|
|
|
|
signal wr_addr : natural range 0 to FIFO_MAX;
|
|
|
|
signal rd_addr : natural range 0 to FIFO_MAX;
|
2015-04-16 14:09:36 +00:00
|
|
|
signal not_full, not_empty : Boolean;
|
2014-02-28 19:26:22 +00:00
|
|
|
|
|
|
|
begin
|
2015-04-16 14:09:36 +00:00
|
|
|
in_ack <= '1' when not_full else '0';
|
2014-02-28 19:26:22 +00:00
|
|
|
|
2015-04-16 14:09:36 +00:00
|
|
|
out_stb <= '1' when not_empty else '0';
|
2014-02-28 19:26:22 +00:00
|
|
|
out_data <= data_fifo(rd_addr);
|
|
|
|
|
2015-04-16 14:09:36 +00:00
|
|
|
fifo_data: process (clk) is
|
|
|
|
begin
|
|
|
|
if rising_edge(clk) then
|
|
|
|
if not_full then
|
|
|
|
data_fifo(wr_addr) <= in_data;
|
|
|
|
end if;
|
|
|
|
end if;
|
|
|
|
end process;
|
|
|
|
|
|
|
|
fifo_ctrl: process (clk) is
|
2014-02-28 19:26:22 +00:00
|
|
|
variable free_cnt : integer range 0 to FIFO_MAX + 1;
|
|
|
|
begin
|
|
|
|
if rising_edge(clk) then
|
|
|
|
if (resetn = '0') or (fifo_reset = '1') then
|
|
|
|
wr_addr <= 0;
|
|
|
|
rd_addr <= 0;
|
|
|
|
free_cnt := FIFO_MAX + 1;
|
2015-04-16 14:09:36 +00:00
|
|
|
not_empty <= False;
|
|
|
|
not_full <= True;
|
2014-02-28 19:26:22 +00:00
|
|
|
else
|
2015-04-16 14:09:36 +00:00
|
|
|
if in_stb = '1' and not_full then
|
2014-02-28 19:26:22 +00:00
|
|
|
wr_addr <= (wr_addr + 1) mod (FIFO_MAX + 1);
|
|
|
|
free_cnt := free_cnt - 1;
|
|
|
|
end if;
|
|
|
|
|
2015-04-16 14:09:36 +00:00
|
|
|
if out_ack = '1' and not_empty then
|
2014-02-28 19:26:22 +00:00
|
|
|
rd_addr <= (rd_addr + 1) mod (FIFO_MAX + 1);
|
|
|
|
free_cnt := free_cnt + 1;
|
|
|
|
end if;
|
|
|
|
|
2015-04-16 14:09:36 +00:00
|
|
|
not_full <= not (free_cnt = 0);
|
|
|
|
not_empty <= not (free_cnt = FIFO_MAX + 1);
|
2014-02-28 19:26:22 +00:00
|
|
|
end if;
|
|
|
|
end if;
|
|
|
|
end process;
|
|
|
|
end;
|