2024-03-04 17:16:43 +03:00
|
|
|
|
library ieee;
|
|
|
|
|
use ieee.std_logic_1164.all;
|
|
|
|
|
use ieee.std_logic_unsigned.all;
|
2024-03-04 18:16:35 +03:00
|
|
|
|
|
|
|
|
|
-- Блок памяти способен асинхронно принимать данные с двух устройств одновременно
|
2024-03-04 17:16:43 +03:00
|
|
|
|
|
|
|
|
|
entity RAM is
|
|
|
|
|
port(
|
|
|
|
|
clk : in std_logic;
|
2024-03-04 18:16:35 +03:00
|
|
|
|
|
2024-03-12 16:30:45 +03:00
|
|
|
|
data0 : inout std_logic_vector(7 downto 0);
|
2024-03-04 18:16:35 +03:00
|
|
|
|
address0 : in std_logic_vector(7 downto 0);
|
|
|
|
|
wr0 : in std_logic;
|
|
|
|
|
clk0 : in std_logic;
|
|
|
|
|
|
2024-03-12 16:30:45 +03:00
|
|
|
|
data1 : inout std_logic_vector(7 downto 0);
|
2024-03-04 18:16:35 +03:00
|
|
|
|
address1 : in std_logic_vector(7 downto 0);
|
|
|
|
|
wr1 : in std_logic;
|
|
|
|
|
clk1 : in std_logic
|
2024-03-04 17:16:43 +03:00
|
|
|
|
);
|
|
|
|
|
end entity;
|
|
|
|
|
|
|
|
|
|
architecture behavorial of RAM is
|
|
|
|
|
|
2024-03-12 16:30:45 +03:00
|
|
|
|
type mem is array (255 downto 0) of std_logic_vector(7 downto 0);
|
2024-03-04 17:16:43 +03:00
|
|
|
|
signal memory : mem;
|
|
|
|
|
|
2024-03-04 18:16:35 +03:00
|
|
|
|
signal clk0Prev : std_logic := '0';
|
|
|
|
|
signal clk1Prev : std_logic := '0';
|
2024-03-04 17:16:43 +03:00
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
process(clk)
|
2024-03-04 18:16:35 +03:00
|
|
|
|
variable addr0 : integer range 0 to 255;
|
|
|
|
|
variable addr1 : integer range 0 to 255;
|
2024-03-04 17:16:43 +03:00
|
|
|
|
begin
|
|
|
|
|
if rising_edge(clk) then
|
2024-03-04 18:16:35 +03:00
|
|
|
|
|
|
|
|
|
if clk1 = '1' and clk1Prev = '0' then
|
|
|
|
|
addr1 := conv_integer(address1); -- переменной addr1 присваивается новое значение сразу. Удобно для преобразования типов.
|
|
|
|
|
if (wr1 = '0') then
|
|
|
|
|
memory(addr1) <= data1; -- тут уже новое значение переменной addr1
|
2024-03-04 17:16:43 +03:00
|
|
|
|
else
|
2024-03-04 18:16:35 +03:00
|
|
|
|
data1 <= memory(addr1);
|
2024-03-04 17:16:43 +03:00
|
|
|
|
end if;
|
|
|
|
|
end if;
|
2024-03-04 18:16:35 +03:00
|
|
|
|
if clk1 = '0' and clk1Prev = '1' then
|
|
|
|
|
data1 <= (others => 'Z');
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
clk1Prev <= clk1;
|
|
|
|
|
|
|
|
|
|
if clk0 = '1' and clk0Prev = '0' then
|
|
|
|
|
addr0 := conv_integer(address0); -- переменной addr0 присваивается новое значение сразу. Удобно для преобразования типов.
|
|
|
|
|
if (wr0 = '0') then
|
|
|
|
|
memory(addr0) <= data0; -- тут уже новое значение переменной addr0
|
|
|
|
|
else
|
|
|
|
|
data0 <= memory(addr0);
|
|
|
|
|
end if;
|
|
|
|
|
end if;
|
|
|
|
|
if clk0 = '0' and clk0Prev = '1' then
|
|
|
|
|
data0 <= (others => 'Z');
|
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
clk0Prev <= clk0;
|
|
|
|
|
|
2024-03-04 17:16:43 +03:00
|
|
|
|
end if;
|
|
|
|
|
end process;
|
|
|
|
|
|
|
|
|
|
end behavorial;
|