Advertisement
Guest User

Untitled

a guest
May 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.59 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 (4**addr_width-1 downto 0) of std_logic_vector(data_width-1 downto 0);
  47.     signal mem : mem_t := (others => X"42");
  48.    
  49.     signal current, prefetch : std_logic_vector(data_width - 1 downto 0);
  50.    
  51.     signal waddr : unsigned(addr_width-1 downto 0);
  52.     signal raddr : unsigned(addr_width-1 downto 0);
  53.     signal raddr_next : unsigned(addr_width-1 downto 0);
  54.     signal size : unsigned(addr_width-1 downto 0);
  55.  
  56. --  constant high_water : Integer := 2**addr_width-32;
  57.     constant high_water : Integer := 2**addr_width-2;
  58.  
  59.     signal empty_reg : std_logic;
  60.  
  61. begin
  62.  
  63.     empty <= empty_reg;
  64.     fifo : process(clock, reset)
  65.     begin
  66.  
  67.         if rising_edge(clock) then
  68.  
  69.             -- read
  70.             if rden = '1' then
  71.                 dout <= mem(to_integer(raddr));
  72.                 raddr <= raddr + 1;
  73.             end if;
  74.  
  75.             -- write
  76.             if wren = '1' then
  77.                 mem(to_integer(waddr)) <= din;
  78.                 if empty_reg = '1' then
  79.                     current <= din;
  80.                 end if;
  81.                 waddr <= waddr + 1;
  82.             end if;
  83.            
  84.             -- size calculation
  85.             if wren = '1' and rden = '0' then
  86.                 size <= size + 1;
  87.                 empty_reg <= '0';
  88.             elsif wren = '0' and rden = '1' then
  89.                 size <= size - 1;
  90.                 if size = 1 then
  91.                     empty_reg <= '1';
  92.                 end if;
  93.             end if;
  94.  
  95.             if size >= high_water then
  96.                 almost_full <= '1';
  97.             else
  98.                 almost_full <= '0';
  99.             end if;
  100.  
  101.         end if;
  102.  
  103.         if reset = '1' then
  104.             waddr <= (others => '0');
  105.             raddr <= (others => '0');
  106.             size <= (others => '0');
  107.             empty_reg <= '1';
  108.         end if;
  109.     end process;
  110.  
  111. end architecture Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement