uart_rx: ein prozessmodell. spart weitere 3 logic elements :P
[hwmod.git] / src / sp_ram.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use work.gen_pkg.all;
5
6 -- "synchronous single port RAM
7 entity sp_ram is
8         generic (
9                 ADDR_WIDTH : integer range 1 to integer'high
10         );
11         port (
12                 sys_clk : in std_logic;
13                 address : in std_logic_vector(ADDR_WIDTH - 1 downto 0);
14                 data_out : out hbyte;
15                 wr : in std_logic;
16                 data_in : in hbyte
17         );
18 end entity sp_ram;
19
20 architecture beh of sp_ram is
21         subtype RAM_ENTRY_TYPE is hbyte;
22         type RAM_TYPE is array (0 to (2 ** ADDR_WIDTH)-1) of RAM_ENTRY_TYPE;
23         signal ram : RAM_TYPE := (others => x"00");
24 begin
25         process(sys_clk)
26         begin
27                 if rising_edge(sys_clk) then
28                         data_out <= ram(to_integer(unsigned(address)));
29                         if wr = '1' then
30                                 ram(to_integer(unsigned(address))) <= data_in;
31                         end if;
32                 end if;
33         end process;
34 end architecture beh;