Professional Documents
Culture Documents
--
-- Design Name : ram_sp_sr_sw
-- File Name : ram_sp_sr_sw.vhd
-- Function : Synchronous read write RAM
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ram_sp_ar_sw is
generic (
DATA_WIDTH :integer := 8;
ADDR_WIDTH :integer := 8
);
port (
clk :in std_logic; -- Clock
Input
address :in std_logic_vector (ADDR_WIDTH-1 downto 0); --
address Input
data :inout std_logic_vector (DATA_WIDTH-1 downto 0); -- data
bi-directional
cs :in std_logic; -- Chip
Select
we :in std_logic; -- Write
Enable/Read Enable
oe :in std_logic -- Output
Enable
);
end entity;
architecture rtl of ram_sp_ar_sw is
----------------Internal variables----------------
constant RAM_DEPTH :integer := 2**ADDR_WIDTH;
end architecture;
-----------------------------------------------------
--
-- Design Name : ram_sp_ar_sw
-- File Name : ram_sp_ar_sw.vhd
-- Function : Asynchronous read write RAM
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ram_sp_ar_sw is
generic (
DATA_WIDTH :integer := 8;
ADDR_WIDTH :integer := 8
);
port (
clk :in std_logic; -- Clock
Input
address :in std_logic_vector (ADDR_WIDTH-1 downto 0); --
address Input
data :inout std_logic_vector (DATA_WIDTH-1 downto 0); -- data
bi-directional
cs :in std_logic; -- Chip
Select
we :in std_logic; -- Write
Enable/Read Enable
oe :in std_logic -- Output
Enable
);
end entity;
architecture rtl of ram_sp_ar_sw is
----------------Internal variables----------------
constant RAM_DEPTH :integer := 2**ADDR_WIDTH;
signal data_out :std_logic_vector (DATA_WIDTH-1 downto 0);
end architecture;
-----------------------------------------------------
--
-- Design Name : ram_sp_ar_aw
-- File Name : ram_sp_ar_aw.vhd
-- Function : Asynchronous read write RAM
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ram_sp_ar_aw is
generic (
DATA_WIDTH :integer := 8;
ADDR_WIDTH :integer := 8
);
port (
address :in std_logic_vector (ADDR_WIDTH-1 downto 0); --
address Input
data :inout std_logic_vector (DATA_WIDTH-1 downto 0); -- data
bi-directional
cs :in std_logic; -- Chip
Select
we :in std_logic; -- Write
Enable/Read Enable
oe :in std_logic -- Output
Enable
);
end entity;
architecture rtl of ram_sp_ar_aw is
----------------Internal variables----------------
constant RAM_DEPTH :integer := 2**ADDR_WIDTH;
end architecture;
-----------------------------------------------------
--
-- Design Name : ram_dp_sr_sw
-- File Name : ram_dp_sr_sw.vhd
-- Function : Synchronous read write RAM
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ram_dp_sr_sw is
generic (
DATA_WIDTH :integer := 8;
ADDR_WIDTH :integer := 8
);
port (
clk :in std_logic; --
Clock Input
address_0 :in std_logic_vector (ADDR_WIDTH-1 downto 0); --
address_0 Input
data_0 :inout std_logic_vector (DATA_WIDTH-1 downto 0); --
data_0 bi-directional
cs_0 :in std_logic; -- Chip
Select
we_0 :in std_logic; --
Write Enable/Read Enable
oe_0 :in std_logic; --
Output Enable
address_1 :in std_logic_vector (ADDR_WIDTH-1 downto 0); --
address_1 Input
data_1 :inout std_logic_vector (DATA_WIDTH-1 downto 0); --
data_1 bi-directional
cs_1 :in std_logic; -- Chip
Select
we_1 :in std_logic; --
Write Enable/Read Enable
oe_1 :in std_logic --
Output Enable
);
end entity;
architecture rtl of ram_dp_sr_sw is
----------------Internal variables----------------
constant RAM_DEPTH :integer := 2**ADDR_WIDTH;
begin
----------------Code Starts Here------------------
-- Memory Write Block
-- Write Operation : When we_0 = 1, cs_0 = 1
MEM_WRITE:
process (clk) begin
if (rising_edge(clk)) then
if ( cs_0 = '1' and we_0 = '1') then
mem(conv_integer(address_0)) <= data_0;
elsif (cs_1 = '1' and we_1 = '1') then
mem(conv_integer(address_1)) <= data_1;
end if;
end if;
end process;
end architecture;
-----------------------------------------------------
--
-- Design Name : ram_dp_ar_aw
-- File Name : ram_dp_ar_aw.vhd
-- Function : Asynchronous read write RAM
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ram_dp_ar_aw is
generic (
DATA_WIDTH :integer := 8;
ADDR_WIDTH :integer := 8
);
port (
address_0 :in std_logic_vector (ADDR_WIDTH-1 downto 0); --
address_0 Input
data_0 :inout std_logic_vector (DATA_WIDTH-1 downto 0); --
data_0 bi-directional
cs_0 :in std_logic; -- Chip
Select
we_0 :in std_logic; --
Write Enable/Read Enable
oe_0 :in std_logic; --
Output Enable
address_1 :in std_logic_vector (ADDR_WIDTH-1 downto 0); --
address_1 Input
data_1 :inout std_logic_vector (DATA_WIDTH-1 downto 0); --
data_1 bi-directional
cs_1 :in std_logic; -- Chip
Select
we_1 :in std_logic; --
Write Enable/Read Enable
oe_1 :in std_logic --
Output Enable
);
end entity;
architecture rtl of ram_dp_ar_aw is
----------------Internal variables----------------
end architecture;
-----------------------------------------------------
--
-- Design Name : cam
-- File Name : cam.vhd
-- Function : CAM
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity cam is
generic (
ADDR_WIDTH :integer := 8
);
port (
clk :in std_logic; -- Cam clock
cam_enable :in std_logic; -- Cam enable
cam_data_in :in std_logic_vector (2**ADDR_WIDTH-1 downto 0); --
Cam data to match
cam_hit_out :out std_logic; -- Cam match has happened
cam_addr_out:out std_logic_vector (ADDR_WIDTH-1 downto 0) -- Cam
output address
);
end entity;
architecture rtl of cam is
----------------Internal variables----------------
constant DEPTH :integer := 2**ADDR_WIDTH;
end architecture;
-----------------------------------------------------
--
-- Design Name : syn_fifo
-- File Name : syn_fifo.vhd
-- Function : Synchronous (single clock) FIFO
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity syn_fifo is
generic (
DATA_WIDTH :integer := 8;
ADDR_WIDTH :integer := 8
);
port (
clk :in std_logic; -- Clock input
rst :in std_logic; -- Active high reset
wr_cs :in std_logic; -- Write chip select
rd_cs :in std_logic; -- Read chipe select
data_in :in std_logic_vector (DATA_WIDTH-1 downto 0); -- Data
input
rd_en :in std_logic; -- Read enable
wr_en :in std_logic; -- Write Enable
data_out :out std_logic_vector (DATA_WIDTH-1 downto 0); -- Data
Output
empty :out std_logic; -- FIFO empty
full :out std_logic -- FIFO full
);
end entity;
architecture rtl of syn_fifo is
-------------Internal variables-------------------
constant RAM_DEPTH :integer := 2**ADDR_WIDTH;
component ram_dp_ar_aw is
generic (
DATA_WIDTH :integer := 8;
ADDR_WIDTH :integer := 8
);
port (
address_0 :in std_logic_vector (ADDR_WIDTH-1 downto 0); --
address_0 Input
data_0 :inout std_logic_vector (DATA_WIDTH-1 downto 0); --
data_0 bi-directional
cs_0 :in std_logic; -- Chip
Select
we_0 :in std_logic; --
Write Enable/Read Enable
oe_0 :in std_logic; --
Output Enable
address_1 :in std_logic_vector (ADDR_WIDTH-1 downto 0); --
address_1 Input
data_1 :inout std_logic_vector (DATA_WIDTH-1 downto 0); --
data_1 bi-directional
cs_1 :in std_logic; -- Chip
Select
we_1 :in std_logic; --
Write Enable/Read Enable
oe_1 :in std_logic --
Output Enable
);
end component;
begin
-------------Code Start---------------------------
full <= '1' when (status_cnt = (RAM_DEPTH-1)) else '0';
empty <= '1' when (status_cnt = 0) else '0';
WRITE_POINTER:
process (clk, rst) begin
if (rst = '1') then
wr_pointer <= (others=>'0');
elsif (rising_edge(clk)) then
if (wr_cs = '1' and wr_en = '1') then
wr_pointer <= wr_pointer + 1;
end if;
end if;
end process;
READ_POINTER:
process (clk, rst) begin
if (rst = '1') then
rd_pointer <= (others=>'0');
elsif (rising_edge(clk)) then
if (rd_cs = '1' and rd_en = '1') then
rd_pointer <= rd_pointer + 1;
end if;
end if;
end process;
READ_DATA:
process (clk, rst) begin
if (rst = '1') then
data_out <= (others=>'0');
elsif (rising_edge(clk)) then
if (rd_cs = '1' and rd_en = '1') then
data_out <= data_ram_out;
end if;
end if;
end process;
STATUS_COUNTER:
process (clk, rst) begin
if (rst = '1') then
status_cnt <= (others=>'0');
-- Read but no write.
elsif (rising_edge(clk)) then
if ((rd_cs = '1' and rd_en = '1') and not(wr_cs = '1' and wr_en
= '1') and (status_cnt /= 0)) then
status_cnt <= status_cnt - 1;
-- Write but no read.
elsif ((wr_cs = '1' and wr_en = '1') and not (rd_cs = '1' and
rd_en = '1') and (status_cnt /= RAM_DEPTH)) then
status_cnt <= status_cnt + 1;
end if;
end if;
end process;
DP_RAM : ram_dp_ar_aw
generic map (
DATA_WIDTH => DATA_WIDTH,
ADDR_WIDTH => ADDR_WIDTH
)
port map (
address_0 => wr_pointer, -- address_0 input
data_0 => data_ram_in, -- data_0 bi-directional
cs_0 => wr_cs, -- chip select
we_0 => wr_en, -- write enable
oe_0 => '0', -- output enable
address_1 => rd_pointer, -- address_q input
data_1 => data_ram_out, -- data_1 bi-directional
cs_1 => rd_cs, -- chip select
we_1 => '0', -- Read enable
oe_1 => rd_en -- output enable
);
end architecture;
-----------------------------------------------------
--
-- Design Name : rom_using_file
-- File Name : rom_using_file.vhd
-- Function : ROM using readmemh
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_textio.all;
use std.textio.all;
entity rom_using_file is
port (
ce :in std_logic; -- Chip Enable
read_en :in std_logic; -- Read Enable
address :in std_logic_vector (7 downto 0); -- Address input
data :out std_logic_vector (7 downto 0) -- Data output
);
end entity;
architecture behavior of rom_using_file is
begin
-- Procedural Call --
Load_ROM(mem);
end architecture;
-----------------------------------------------------
--
-- Design Name : rom_using_case
-- File Name : rom_using_case.vhd
-- Function : ROM using case
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity rom_using_case is
port (
ce :in std_logic; -- Chip Enable
read_en :in std_logic; -- Read Enable
address :in std_logic_vector (3 downto 0); -- Address input
data :out std_logic_vector (7 downto 0) -- Data output
);
end entity;
architecture behavior of rom_using_case is
begin
end architecture;
-----------------------------------------------------
--
-- Design Name : rom_using_constant
-- File Name : rom_using_constant.vhd
-- Function : ROM using constant
-- Coder : Deepak Kumar Tala (Verilog)
-- Translator : Alexander H Pham (VHDL)
-----------------------------------------------------
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity rom_using_constant is
port (
read_en :in std_logic; -- Read Enable
address :in std_logic_vector (3 downto 0); -- Address input
data :out std_logic_vector (7 downto 0) -- Data output
);
end entity;
architecture behavior of rom_using_constant is
subtype ROM_Word is std_logic_vector (7 downto 0);
subtype ROM_Addr is integer range 0 to 15;
begin
end architecture;