altera/MainController/RAM.vhd

70 lines
2.0 KiB
VHDL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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