Advertisement
Guest User

Single Port Ram with combined R/W

a guest
May 30th, 2018
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.06 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_arith.all;
  4.  
  5. entity single_port_ram_rwc is
  6. generic(
  7.     address_length: natural := 8;
  8.     data_length: natural := 8
  9. );
  10. port(
  11.     clock: in std_logic;
  12.     rw_enable: in std_logic;
  13.     mem_enable: in std_logic;
  14.     address: in std_logic_vector((address_length - 1) downto 0);
  15.     data_input: in std_logic_vector ((data_length - 1) downto 0);
  16.     data_output: out std_logic_vector ((data_length - 1) downto 0)
  17. );
  18. end single_port_ram_rwc;
  19.  
  20. architecture arch of single_port_ram_rwc is
  21.     type ram_type is array (0 to (2**(address_length) -1)) of std_logic_vector((data_length - 1) downto 0);
  22.     signal ram: ram_type;
  23.     signal temp_address: std_logic_vector((address_length - 1) downto 0);
  24. begin
  25.  
  26. process(clock) is
  27. begin
  28.     if rising_edge(clock)and mem_enable = '1' then
  29.         if(rw_enable = '0') then
  30.             temp_address <= address;
  31.         elsif (rw_enable = '1') then
  32.             ram(conv_integer(unsigned(address))) <= data_input;
  33.         end if;
  34.         data_output <= ram(conv_integer(unsigned(temp_address)));
  35.     end if;
  36.    
  37. end process;
  38.  
  39. end arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement