OpenCores
URL https://opencores.org/ocsvn/mlite/mlite/trunk

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [ram.vhd] - Diff between revs 344 and 350

Only display areas with differences | Details | Blame | View Log

Rev 344 Rev 350
---------------------------------------------------------------------
---------------------------------------------------------------------
-- TITLE: Random Access Memory
-- TITLE: Random Access Memory
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
-- DATE CREATED: 4/21/01
-- DATE CREATED: 4/21/01
-- FILENAME: ram.vhd
-- FILENAME: ram.vhd
-- PROJECT: Plasma CPU core
-- PROJECT: Plasma CPU core
-- COPYRIGHT: Software placed into the public domain by the author.
-- COPYRIGHT: Software placed into the public domain by the author.
--    Software 'as is' without warranty.  Author liable for nothing.
--    Software 'as is' without warranty.  Author liable for nothing.
-- DESCRIPTION:
-- DESCRIPTION:
--    Implements the RAM, reads the executable from either "code.txt",
--    Implements the RAM, reads the executable from either "code.txt",
--    or for Altera "code[0-3].hex".
--    or for Altera "code[0-3].hex".
--    Modified from "The Designer's Guide to VHDL" by Peter J. Ashenden
--    Modified from "The Designer's Guide to VHDL" by Peter J. Ashenden
---------------------------------------------------------------------
---------------------------------------------------------------------
library ieee;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
use ieee.std_logic_misc.all;
use ieee.std_logic_misc.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_textio.all;
use ieee.std_logic_textio.all;
use std.textio.all;
use std.textio.all;
use work.mlite_pack.all;
use work.mlite_pack.all;
 
 
entity ram is
entity ram is
   generic(memory_type : string := "DEFAULT");
   generic(memory_type : string := "DEFAULT");
   port(clk               : in std_logic;
   port(clk               : in std_logic;
        enable            : in std_logic;
        enable            : in std_logic;
        write_byte_enable : in std_logic_vector(3 downto 0);
        write_byte_enable : in std_logic_vector(3 downto 0);
        address           : in std_logic_vector(31 downto 2);
        address           : in std_logic_vector(31 downto 2);
        data_write        : in std_logic_vector(31 downto 0);
        data_write        : in std_logic_vector(31 downto 0);
        data_read         : out std_logic_vector(31 downto 0));
        data_read         : out std_logic_vector(31 downto 0));
end; --entity ram
end; --entity ram
 
 
architecture logic of ram is
architecture logic of ram is
   constant ADDRESS_WIDTH   : natural := 13;
   constant ADDRESS_WIDTH   : natural := 13;
begin
begin
 
 
   generic_ram:
   generic_ram:
   if memory_type /= "ALTERA_LPM" generate
   if memory_type /= "ALTERA_LPM" generate
   begin
   begin
   --Simulate a synchronous RAM
   --Simulate a synchronous RAM
   ram_proc: process(clk, enable, write_byte_enable,
   ram_proc: process(clk, enable, write_byte_enable,
         address, data_write) --mem_write, mem_sel
         address, data_write) --mem_write, mem_sel
      variable mem_size : natural := 2 ** ADDRESS_WIDTH;
      variable mem_size : natural := 2 ** ADDRESS_WIDTH;
      variable data : std_logic_vector(31 downto 0);
      variable data : std_logic_vector(31 downto 0);
      subtype word is std_logic_vector(data_write'length-1 downto 0);
      subtype word is std_logic_vector(data_write'length-1 downto 0);
      type storage_array is
      type storage_array is
         array(natural range 0 to mem_size/4 - 1) of word;
         array(natural range 0 to mem_size/4 - 1) of word;
      variable storage : storage_array;
      variable storage : storage_array;
      variable index : natural := 0;
      variable index : natural := 0;
      file load_file : text open read_mode is "code.txt";
      file load_file : text open read_mode is "code.txt";
      variable hex_file_line : line;
      variable hex_file_line : line;
   begin
   begin
 
 
      --Load in the ram executable image
      --Load in the ram executable image
      if index = 0 then
      if index = 0 then
         while not endfile(load_file) loop
         while not endfile(load_file) loop
--The following two lines had to be commented out for synthesis
--The following two lines had to be commented out for synthesis
            readline(load_file, hex_file_line);
            readline(load_file, hex_file_line);
            hread(hex_file_line, data);
            hread(hex_file_line, data);
            storage(index) := data;
            storage(index) := data;
            index := index + 1;
            index := index + 1;
         end loop;
         end loop;
      end if;
      end if;
 
 
      if rising_edge(clk) then
      if rising_edge(clk) then
         index := conv_integer(address(ADDRESS_WIDTH-1 downto 2));
         index := conv_integer(address(ADDRESS_WIDTH-1 downto 2));
         data := storage(index);
         data := storage(index);
 
 
         if enable = '1' then
         if enable = '1' then
            if write_byte_enable(0) = '1' then
            if write_byte_enable(0) = '1' then
               data(7 downto 0) := data_write(7 downto 0);
               data(7 downto 0) := data_write(7 downto 0);
            end if;
            end if;
            if write_byte_enable(1) = '1' then
            if write_byte_enable(1) = '1' then
               data(15 downto 8) := data_write(15 downto 8);
               data(15 downto 8) := data_write(15 downto 8);
            end if;
            end if;
            if write_byte_enable(2) = '1' then
            if write_byte_enable(2) = '1' then
               data(23 downto 16) := data_write(23 downto 16);
               data(23 downto 16) := data_write(23 downto 16);
            end if;
            end if;
            if write_byte_enable(3) = '1' then
            if write_byte_enable(3) = '1' then
               data(31 downto 24) := data_write(31 downto 24);
               data(31 downto 24) := data_write(31 downto 24);
            end if;
            end if;
         end if;
         end if;
 
 
         if write_byte_enable /= "0000" then
         if write_byte_enable /= "0000" then
            storage(index) := data;
            storage(index) := data;
         end if;
         end if;
      end if;
      end if;
 
 
      data_read <= data;
      data_read <= data;
   end process;
   end process;
   end generate; --generic_ram
   end generate; --generic_ram
 
 
 
 
   altera_ram:
   altera_ram:
   if memory_type = "ALTERA_LPM" generate
   if memory_type = "ALTERA_LPM" generate
      signal byte_we : std_logic_vector(3 downto 0);
      signal byte_we : std_logic_vector(3 downto 0);
   begin
   begin
      byte_we <= write_byte_enable when enable = '1' else "0000";
      byte_we <= write_byte_enable when enable = '1' else "0000";
      lpm_ram_io_component0 : lpm_ram_dq
      lpm_ram_io_component0 : lpm_ram_dq
         GENERIC MAP (
         GENERIC MAP (
            intended_device_family => "UNUSED",
            intended_device_family => "UNUSED",
            lpm_width => 8,
            lpm_width => 8,
            lpm_widthad => ADDRESS_WIDTH-2,
            lpm_widthad => ADDRESS_WIDTH-2,
            lpm_indata => "REGISTERED",
            lpm_indata => "REGISTERED",
            lpm_address_control => "REGISTERED",
            lpm_address_control => "REGISTERED",
            lpm_outdata => "UNREGISTERED",
            lpm_outdata => "UNREGISTERED",
            lpm_file => "code0.hex",
            lpm_file => "code0.hex",
            use_eab => "ON",
            use_eab => "ON",
            lpm_type => "LPM_RAM_DQ")
            lpm_type => "LPM_RAM_DQ")
         PORT MAP (
         PORT MAP (
            data    => data_write(31 downto 24),
            data    => data_write(31 downto 24),
            address => address(ADDRESS_WIDTH-1 downto 2),
            address => address(ADDRESS_WIDTH-1 downto 2),
            inclock => clk,
            inclock => clk,
            we      => byte_we(3),
            we      => byte_we(3),
            q       => data_read(31 downto 24));
            q       => data_read(31 downto 24));
 
 
      lpm_ram_io_component1 : lpm_ram_dq
      lpm_ram_io_component1 : lpm_ram_dq
         GENERIC MAP (
         GENERIC MAP (
            intended_device_family => "UNUSED",
            intended_device_family => "UNUSED",
            lpm_width => 8,
            lpm_width => 8,
            lpm_widthad => ADDRESS_WIDTH-2,
            lpm_widthad => ADDRESS_WIDTH-2,
            lpm_indata => "REGISTERED",
            lpm_indata => "REGISTERED",
            lpm_address_control => "REGISTERED",
            lpm_address_control => "REGISTERED",
            lpm_outdata => "UNREGISTERED",
            lpm_outdata => "UNREGISTERED",
            lpm_file => "code1.hex",
            lpm_file => "code1.hex",
            use_eab => "ON",
            use_eab => "ON",
            lpm_type => "LPM_RAM_DQ")
            lpm_type => "LPM_RAM_DQ")
         PORT MAP (
         PORT MAP (
            data    => data_write(23 downto 16),
            data    => data_write(23 downto 16),
            address => address(ADDRESS_WIDTH-1 downto 2),
            address => address(ADDRESS_WIDTH-1 downto 2),
            inclock => clk,
            inclock => clk,
            we      => byte_we(2),
            we      => byte_we(2),
            q       => data_read(23 downto 16));
            q       => data_read(23 downto 16));
 
 
      lpm_ram_io_component2 : lpm_ram_dq
      lpm_ram_io_component2 : lpm_ram_dq
         GENERIC MAP (
         GENERIC MAP (
            intended_device_family => "UNUSED",
            intended_device_family => "UNUSED",
            lpm_width => 8,
            lpm_width => 8,
            lpm_widthad => ADDRESS_WIDTH-2,
            lpm_widthad => ADDRESS_WIDTH-2,
            lpm_indata => "REGISTERED",
            lpm_indata => "REGISTERED",
            lpm_address_control => "REGISTERED",
            lpm_address_control => "REGISTERED",
            lpm_outdata => "UNREGISTERED",
            lpm_outdata => "UNREGISTERED",
            lpm_file => "code2.hex",
            lpm_file => "code2.hex",
            use_eab => "ON",
            use_eab => "ON",
            lpm_type => "LPM_RAM_DQ")
            lpm_type => "LPM_RAM_DQ")
         PORT MAP (
         PORT MAP (
            data    => data_write(15 downto 8),
            data    => data_write(15 downto 8),
            address => address(ADDRESS_WIDTH-1 downto 2),
            address => address(ADDRESS_WIDTH-1 downto 2),
            inclock => clk,
            inclock => clk,
            we      => byte_we(1),
            we      => byte_we(1),
            q       => data_read(15 downto 8));
            q       => data_read(15 downto 8));
 
 
      lpm_ram_io_component3 : lpm_ram_dq
      lpm_ram_io_component3 : lpm_ram_dq
         GENERIC MAP (
         GENERIC MAP (
            intended_device_family => "UNUSED",
            intended_device_family => "UNUSED",
            lpm_width => 8,
            lpm_width => 8,
            lpm_widthad => ADDRESS_WIDTH-2,
            lpm_widthad => ADDRESS_WIDTH-2,
            lpm_indata => "REGISTERED",
            lpm_indata => "REGISTERED",
            lpm_address_control => "REGISTERED",
            lpm_address_control => "REGISTERED",
            lpm_outdata => "UNREGISTERED",
            lpm_outdata => "UNREGISTERED",
            lpm_file => "code3.hex",
            lpm_file => "code3.hex",
            use_eab => "ON",
            use_eab => "ON",
            lpm_type => "LPM_RAM_DQ")
            lpm_type => "LPM_RAM_DQ")
         PORT MAP (
         PORT MAP (
            data    => data_write(7 downto 0),
            data    => data_write(7 downto 0),
            address => address(ADDRESS_WIDTH-1 downto 2),
            address => address(ADDRESS_WIDTH-1 downto 2),
            inclock => clk,
            inclock => clk,
            we      => byte_we(0),
            we      => byte_we(0),
            q       => data_read(7 downto 0));
            q       => data_read(7 downto 0));
 
 
   end generate; --altera_ram
   end generate; --altera_ram
 
 
 
 
   --For XILINX see ram_xilinx.vhd
   --For XILINX see ram_xilinx.vhd
 
 
end; --architecture logic
end; --architecture logic
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.