Advertisement
Guest User

Untitled

a guest
Sep 12th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.13 KB | None | 0 0
  1. library IEEE;
  2.  
  3. use IEEE.std_logic_1164.all;
  4. use IEEE.numeric_std.all;
  5.  
  6. entity Ram is
  7.    generic (
  8.         g_ADDR_BITS : natural := 16;
  9.         g_DATA_BITS : natural := 8 
  10.     );
  11.     port (
  12.         CLOCK            : in  std_logic;
  13.         WRITE_SIGNAL : in  std_logic;
  14.         WRITE_ADDR   : in  std_logic_vector (g_ADDR_BITS-1 downto 0);
  15.         WRITE_DATA   : in  std_logic_vector (g_DATA_BITS-1 downto 0);
  16.        
  17.         READ_ADDR    : in  std_logic_vector (g_ADDR_BITS-1 downto 0);
  18.         READ_DATA    : out std_logic_vector (g_DATA_BITS-1 downto 0)
  19.     );
  20. end entity Ram;
  21.  
  22. architecture RTL of Ram is
  23.  
  24.     subtype t_Word is std_logic_vector (g_DATA_BITS-1 downto 0);
  25.     type t_BlockMem is array(0 to 2**g_ADDR_BITS-1) of t_Word;
  26.    
  27.     signal r_Ram : t_BlockMem := (others => (others => '0'));
  28.  
  29. begin
  30.  
  31.     p_WriteData : process (CLOCK) is begin
  32.         if rising_edge(CLOCK) then
  33.             if WRITE_SIGNAL = '1' then
  34.                 r_Ram(to_integer(unsigned(WRITE_ADDR))) <= WRITE_DATA;
  35.             end if;
  36.         end if;
  37.     end process p_WriteData;
  38.    
  39.     p_ReadData : process (CLOCK) is begin
  40.         if rising_edge(CLOCK) then
  41.             READ_DATA <= r_Ram(to_integer(unsigned(READ_ADDR)));
  42.         end if;
  43.     end process p_ReadData;
  44.    
  45. end architecture RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement