Advertisement
Guest User

Untitled

a guest
Sep 12th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.33 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.     signal w_ReadOffset : std_logic_vector (g_ADDR_BITS-1 downto 0);
  30.     signal w_WriteOffset : std_logic_vector (g_ADDR_BITS-1 downto 0);
  31.  
  32. begin
  33.  
  34.     w_ReadOffset <= READ_ADDR;
  35.     w_WriteOffset <= WRITE_ADDR;
  36.  
  37.     p_WriteData : process (CLOCK) is begin
  38.         if rising_edge(CLOCK) then
  39.             if WRITE_SIGNAL = '1' then
  40.                 r_Ram(to_integer(unsigned(w_WriteOffset))) <= WRITE_DATA;
  41.             end if;
  42.         end if;
  43.     end process p_WriteData;
  44.    
  45.     p_ReadData : process (CLOCK) is begin
  46.         if rising_edge(CLOCK) then
  47.             READ_DATA <= r_Ram(to_integer(unsigned(w_ReadOffset)));
  48.         end if;
  49.     end process p_ReadData;
  50.  
  51. end architecture RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement