repo2/common/components/generic_ram_infer.vhdl @ 1475
1 | markw | ---------------------------------------------------------------------------
|
|
-- (c) 2013 mark watson
|
|||
-- I am happy for anyone to use this for non-commercial use.
|
|||
-- If my vhdl files are used commercially or otherwise sold,
|
|||
-- please contact me for explicit permission at scrameta (gmail).
|
|||
-- This applies for source and binary form and derived works.
|
|||
---------------------------------------------------------------------------
|
|||
LIBRARY ieee;
|
|||
USE ieee.std_logic_1164.ALL;
|
|||
use ieee.numeric_std.all;
|
|||
ENTITY generic_ram_infer IS
|
|||
generic
|
|||
(
|
|||
ADDRESS_WIDTH : natural := 9;
|
|||
SPACE : natural := 512;
|
|||
DATA_WIDTH : natural := 8
|
|||
);
|
|||
PORT
|
|||
(
|
|||
clock: IN std_logic;
|
|||
803 | markw | reset_n: IN std_logic :='1';
|
|
1 | markw | data: IN std_logic_vector (data_width-1 DOWNTO 0);
|
|
address: IN std_logic_vector(address_width-1 downto 0);
|
|||
we: IN std_logic;
|
|||
q: OUT std_logic_vector (data_width-1 DOWNTO 0)
|
|||
);
|
|||
END generic_ram_infer;
|
|||
ARCHITECTURE rtl OF generic_ram_infer IS
|
|||
3 | markw | TYPE mem IS ARRAY(0 TO space-1) OF std_logic_vector(data_width-1 DOWNTO 0);
|
|
10 | markw | SIGNAL ram_block : mem;
|
|
SIGNAL q_ram : std_logic_vector(data_width-1 downto 0);
|
|||
SIGNAL we_ram : std_logic;
|
|||
40 | markw | ||
signal address2 : std_logic_vector(address_width-1 downto 0);
|
|||
1 | markw | BEGIN
|
|
10 | markw | ||
803 | markw | -- PROCESS (clock,reset_n)
|
|
1 | markw | PROCESS (clock)
|
|
BEGIN
|
|||
803 | markw | -- IF (RESET_N = '0') then
|
|
-- ram_block <= (others=>(others=>'1'));
|
|||
-- ELSIF (clock'event AND clock = '1') THEN
|
|||
10 | markw | IF (clock'event AND clock = '1') THEN
|
|
IF (we_ram = '1') THEN
|
|||
40 | markw | ram_block(to_integer(to_01(unsigned(address2), '0'))) <= data;
|
|
10 | markw | q_ram <= data;
|
|
ELSE
|
|||
40 | markw | q_ram <= ram_block(to_integer(to_01(unsigned(address2), '0')));
|
|
10 | markw | END IF;
|
|
END IF;
|
|||
1 | markw | END PROCESS;
|
|
10 | markw | ||
40 | markw | PROCESS(address, we, q_ram)
|
|
10 | markw | begin
|
|
q <= (others=>'1');
|
|||
we_ram <= '0';
|
|||
40 | markw | address2 <= (others=>'0');
|
|
10 | markw | IF (to_integer(to_01(unsigned(address))) < space) THEN
|
|
q <= q_ram;
|
|||
we_ram <= we;
|
|||
40 | markw | address2 <= address;
|
|
10 | markw | end if;
|
|
end process;
|
|||
3 | markw | END rtl;
|