Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------------
- -- Company:
- -- Engineer: Nabil Sayegh
- --
- -- Create Date: 12:11:03 08/07/2009
- -- Design Name:
- -- Module Name: fifo - Behavioral
- -- Project Name:
- -- Target Devices:
- -- Tool versions:
- -- Description:
- --
- -- Dependencies:
- --
- -- Revision:
- -- Revision 0.01 - File Created
- -- Additional Comments:
- --
- ----------------------------------------------------------------------------------
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.numeric_std.all;
- entity fifo_simple is
- generic
- (
- addr_width : Integer := 8;
- data_width : Integer := 8
- );
- port
- (
- clock : IN std_logic;
- reset : IN std_logic;
- wren : IN std_logic;
- rden : IN std_logic;
- din : IN std_logic_vector(data_width-1 downto 0);
- dout : OUT std_logic_vector(data_width-1 downto 0);
- empty : OUT std_logic;
- almost_full : OUT std_logic
- );
- end entity fifo_simple;
- architecture Behavioral of fifo_simple is
- type mem_t is array (2**addr_width-1 downto 0) of std_logic_vector(data_width-1 downto 0);
- signal mem : mem_t;
- signal waddr : unsigned(addr_width-1 downto 0);
- signal raddr : unsigned(addr_width-1 downto 0);
- signal raddr_next : unsigned(addr_width-1 downto 0);
- signal size : unsigned(addr_width-1 downto 0);
- constant high_water : Integer := 2**addr_width-32;
- begin
- raddr_next <= raddr + unsigned'(0 => rden);
- fifo : process(clock, reset)
- begin
- if rising_edge(clock) then
- -- write
- if wren = '1' then
- mem(to_integer(waddr)) <= din;
- waddr <= waddr + 1;
- end if;
- -- read (read before write, because we read the old value)
- dout <= mem(to_integer(raddr_next));
- raddr <= raddr_next;
- -- size calculation
- if wren = '1' and rden = '0' then
- size <= size + 1;
- empty <= '0';
- elsif wren = '0' and rden = '1' then
- size <= size - 1;
- if size = 1 then
- empty <= '1';
- end if;
- end if;
- if size >= high_water then
- almost_full <= '1';
- else
- almost_full <= '0';
- end if;
- end if;
- if reset = '1' then
- waddr <= (others => '0');
- raddr <= (others => '0');
- size <= (others => '0');
- else
- end if;
- end process;
- end architecture Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement