Advertisement
Guest User

Untitled

a guest
May 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.36 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer: Nabil Sayegh
  4. --
  5. -- Create Date:    12:11:03 08/07/2009
  6. -- Design Name:
  7. -- Module Name:    fifo - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library ieee;
  21.   use ieee.std_logic_1164.all;
  22.   use ieee.numeric_std.all;
  23.  
  24. entity fifo_simple is
  25.     generic
  26.     (
  27.     addr_width : Integer := 8;
  28.     data_width : Integer := 8
  29.     );
  30.     port
  31.     (
  32.         clock              : IN  std_logic;
  33.         reset              : IN  std_logic;
  34.  
  35.         wren               : IN  std_logic;
  36.         rden               : IN  std_logic;
  37.         din                : IN  std_logic_vector(data_width-1 downto 0);
  38.         dout               : OUT std_logic_vector(data_width-1 downto 0);
  39.         empty              : OUT std_logic;
  40.         almost_full        : OUT std_logic
  41.     );
  42. end entity fifo_simple;
  43.  
  44. architecture Behavioral of fifo_simple is
  45.  
  46.     type mem_t is array (2**addr_width-1 downto 0) of std_logic_vector(data_width-1 downto 0);
  47.     signal mem : mem_t;
  48.     signal waddr : unsigned(addr_width-1 downto 0);
  49.     signal raddr : unsigned(addr_width-1 downto 0);
  50.     signal raddr_next : unsigned(addr_width-1 downto 0);
  51.     signal size : unsigned(addr_width-1 downto 0);
  52.  
  53.     constant high_water : Integer := 2**addr_width-32;
  54.  
  55. begin
  56.  
  57.     raddr_next <= raddr + unsigned'(0 => rden);
  58.     fifo : process(clock, reset)
  59.     begin
  60.         if rising_edge(clock) then
  61.             -- write
  62.             if wren = '1' then
  63.                 mem(to_integer(waddr)) <= din;
  64.                 waddr <= waddr + 1;                    
  65.             end if;
  66.  
  67.             -- read (read before write, because we read the old value)
  68.             dout <= mem(to_integer(raddr_next));
  69.             raddr <= raddr_next;
  70.  
  71.             -- size calculation
  72.             if wren = '1' and rden = '0' then
  73.                 size <= size + 1;
  74.                 empty <= '0';
  75.             elsif wren = '0' and rden = '1' then
  76.                 size <= size - 1;
  77.                 if size = 1 then
  78.                     empty <= '1';
  79.                 end if;
  80.             end if;
  81.  
  82.             if size >= high_water then
  83.                 almost_full <= '1';
  84.             else
  85.                 almost_full <= '0';
  86.             end if;
  87.  
  88.         end if;
  89.  
  90.         if reset = '1' then
  91.             waddr <= (others => '0');
  92.             raddr <= (others => '0');
  93.             size <= (others => '0');
  94.         else
  95.         end if;
  96.     end process;
  97.  
  98. end architecture Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement