1
|
-- Simple generic RAM Model
|
2
|
--
|
3
|
-- +-----------------------------+
|
4
|
-- | Copyright 2008 DOULOS |
|
5
|
-- | designer : JK |
|
6
|
-- +-----------------------------+
|
7
|
|
8
|
library ieee;
|
9
|
use ieee.std_logic_1164.all;
|
10
|
use ieee.numeric_std.all;
|
11
|
|
12
|
entity sync_ram is
|
13
|
port (
|
14
|
clock : in std_logic;
|
15
|
we : in std_logic;
|
16
|
address : in std_logic_vector;
|
17
|
datain : in std_logic_vector;
|
18
|
dataout : out std_logic_vector
|
19
|
);
|
20
|
end entity sync_ram;
|
21
|
|
22
|
architecture rtl of sync_ram is
|
23
|
|
24
|
type ram_type is array (0 to (2**address'length)-1) of std_logic_vector(datain'range);
|
25
|
signal ram : ram_type;
|
26
|
signal read_address : std_logic_vector(address'range);
|
27
|
|
28
|
begin
|
29
|
|
30
|
ramproc: process(clock) is
|
31
|
begin
|
32
|
if rising_edge(clock) then
|
33
|
if we = '1' then
|
34
|
ram(to_integer(unsigned(address))) <= datain;
|
35
|
end if;
|
36
|
read_address <= address;
|
37
|
end if;
|
38
|
end process ramproc;
|
39
|
|
40
|
dataout <= ram(to_integer(unsigned(read_address)));
|
41
|
|
42
|
end architecture rtl;
|