Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.73 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity ram is
  6.     generic(
  7.         M : integer := 4;
  8.         N : integer := 3;
  9.         X : integer := 10
  10.     );
  11.     port(
  12.         rd_in   : in    std_logic;
  13.         wr_in   : in    std_logic;
  14.         clk     : in    std_logic;
  15.         rst     : in    std_logic;
  16.         addr_in : in    std_logic_vector(M - 1 downto 0);
  17.         finish  : out   std_logic;
  18.         data    : inout std_logic_vector(N - 1 downto 0)
  19.     );
  20. end entity ram;
  21.  
  22. architecture RTL of ram is
  23.     type mem_type is array (0 to 2 ** M - 1) of std_logic_vector(N - 1 downto 0);
  24.     signal count : integer := X;
  25.     signal mem     : mem_type;
  26.  
  27. begin
  28.     process(clk, rst) is
  29.        
  30.  
  31.     begin
  32.         if rst = '1' then
  33.             count <= X;
  34.         elsif rising_edge(clk) then
  35.             if (rd_in = '1' or wr_in = '1') then
  36.                 count <= count - 1;
  37.                 if (count = 0) then
  38.                     count <= X;
  39.                 end if;    
  40.             end if;
  41.         end if;
  42.        
  43.     end process;
  44.    
  45.     process (clk) is
  46.     begin
  47.         if(count = 0) then
  48.             if(wr_in = '1') then
  49.                 mem(to_integer(unsigned(addr_in))) <= data;
  50.        
  51.             end if;
  52.         end if;
  53.     end process;
  54.  
  55.    
  56.     process (rd_in, count, wr_in) is
  57.     begin
  58.         if(count = 0) then
  59.             if(rd_in = '1') then
  60.                 data <= mem(to_integer(unsigned(addr_in)));
  61.             elsif(wr_in = '1') then
  62.                 data <= (others => 'Z');
  63.             end if;
  64.        else
  65.             data <= (others => 'Z');
  66.    
  67.         end if;
  68.     end process;
  69.     finish <= '1' when count = 0 else '0';
  70.    
  71.  
  72. end architecture RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement