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

Subversion Repositories plasma

[/] [plasma/] [tags/] [V3_0/] [vhdl/] [ram.vhd] - Blame information for rev 352

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rhoads
---------------------------------------------------------------------
2
-- TITLE: Random Access Memory
3
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 4/21/01
5
-- FILENAME: ram.vhd
6 43 rhoads
-- PROJECT: Plasma CPU core
7 2 rhoads
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- DESCRIPTION:
10 48 rhoads
--    Implements the RAM, reads the executable from either "code.txt",
11
--    or for Altera "code[0-3].hex".
12 2 rhoads
--    Modified from "The Designer's Guide to VHDL" by Peter J. Ashenden
13
---------------------------------------------------------------------
14
library ieee;
15
use ieee.std_logic_1164.all;
16
use ieee.std_logic_misc.all;
17
use ieee.std_logic_arith.all;
18 85 rhoads
use ieee.std_logic_unsigned.all;
19 2 rhoads
use ieee.std_logic_textio.all;
20
use std.textio.all;
21 39 rhoads
use work.mlite_pack.all;
22 139 rhoads
--Uncomment following two lines for Xilinx RAM16X1D
23
library UNISIM;              --Xilinx
24
use UNISIM.vcomponents.all;  --Xilinx
25 2 rhoads
 
26
entity ram is
27 132 rhoads
   generic(memory_type : string := "DEFAULT");
28 139 rhoads
   port(clk               : in std_logic;
29
        enable            : in std_logic;
30
        write_byte_enable : in std_logic_vector(3 downto 0);
31
        address           : in std_logic_vector(31 downto 2);
32
        data_write        : in std_logic_vector(31 downto 0);
33
        data_read         : out std_logic_vector(31 downto 0));
34 2 rhoads
end; --entity ram
35
 
36
architecture logic of ram is
37 55 rhoads
   constant ADDRESS_WIDTH   : natural := 13;
38 2 rhoads
begin
39
 
40 48 rhoads
   generic_ram:
41 139 rhoads
   if memory_type /= "ALTERA_LPM" generate
42
   --Simulate a synchronous RAM
43
   ram_proc: process(clk, enable, write_byte_enable,
44
         address, data_write) --mem_write, mem_sel
45 98 rhoads
      variable mem_size : natural := 2 ** ADDRESS_WIDTH;
46 48 rhoads
      variable data : std_logic_vector(31 downto 0);
47 139 rhoads
      subtype word is std_logic_vector(data_write'length-1 downto 0);
48 48 rhoads
      type storage_array is
49 98 rhoads
         array(natural range 0 to mem_size/4 - 1) of word;
50 48 rhoads
      variable storage : storage_array;
51
      variable index : natural := 0;
52 139 rhoads
      file load_file : text open read_mode is "code.txt";
53 48 rhoads
      variable hex_file_line : line;
54
   begin
55 128 rhoads
 
56 139 rhoads
      --Load in the ram executable image
57 48 rhoads
      if index = 0 then
58
         while not endfile(load_file) loop
59 55 rhoads
--The following two lines had to be commented out for synthesis
60 48 rhoads
            readline(load_file, hex_file_line);
61
            hread(hex_file_line, data);
62
            storage(index) := data;
63
            index := index + 1;
64
         end loop;
65 2 rhoads
      end if;
66
 
67 139 rhoads
      if rising_edge(clk) then
68
         index := conv_integer(address(ADDRESS_WIDTH-1 downto 2));
69
         data := storage(index);
70 2 rhoads
 
71 139 rhoads
         if enable = '1' then
72
            if write_byte_enable(0) = '1' then
73
               data(7 downto 0) := data_write(7 downto 0);
74
            end if;
75
            if write_byte_enable(1) = '1' then
76
               data(15 downto 8) := data_write(15 downto 8);
77
            end if;
78
            if write_byte_enable(2) = '1' then
79
               data(23 downto 16) := data_write(23 downto 16);
80
            end if;
81
            if write_byte_enable(3) = '1' then
82
               data(31 downto 24) := data_write(31 downto 24);
83
            end if;
84 48 rhoads
         end if;
85 2 rhoads
 
86 139 rhoads
         if write_byte_enable /= "0000" then
87 2 rhoads
            storage(index) := data;
88
         end if;
89
      end if;
90 139 rhoads
 
91
      data_read <= data;
92 48 rhoads
   end process;
93
   end generate; --generic_ram
94 2 rhoads
 
95 48 rhoads
 
96
   altera_ram:
97 139 rhoads
   if memory_type = "ALTERA_LPM" generate
98 55 rhoads
      lpm_ram_io_component0 : lpm_ram_dq
99 48 rhoads
         GENERIC MAP (
100
            intended_device_family => "UNUSED",
101
            lpm_width => 8,
102 55 rhoads
            lpm_widthad => ADDRESS_WIDTH-2,
103 48 rhoads
            lpm_indata => "REGISTERED",
104 55 rhoads
            lpm_address_control => "REGISTERED",
105 48 rhoads
            lpm_outdata => "UNREGISTERED",
106
            lpm_file => "code0.hex",
107
            use_eab => "ON",
108
            lpm_type => "LPM_RAM_DQ")
109
         PORT MAP (
110 139 rhoads
            data    => data_write(31 downto 24),
111
            address => address(ADDRESS_WIDTH-1 downto 2),
112
            inclock => clk,
113 48 rhoads
            we      => write_byte_enable(3),
114 139 rhoads
            q       => data_read(31 downto 24));
115 48 rhoads
 
116 55 rhoads
      lpm_ram_io_component1 : lpm_ram_dq
117 48 rhoads
         GENERIC MAP (
118
            intended_device_family => "UNUSED",
119
            lpm_width => 8,
120 55 rhoads
            lpm_widthad => ADDRESS_WIDTH-2,
121 48 rhoads
            lpm_indata => "REGISTERED",
122 55 rhoads
            lpm_address_control => "REGISTERED",
123 48 rhoads
            lpm_outdata => "UNREGISTERED",
124
            lpm_file => "code1.hex",
125
            use_eab => "ON",
126
            lpm_type => "LPM_RAM_DQ")
127
         PORT MAP (
128 139 rhoads
            data    => data_write(23 downto 16),
129
            address => address(ADDRESS_WIDTH-1 downto 2),
130
            inclock => clk,
131 48 rhoads
            we      => write_byte_enable(2),
132 139 rhoads
            q       => data_read(23 downto 16));
133 48 rhoads
 
134 55 rhoads
      lpm_ram_io_component2 : lpm_ram_dq
135 48 rhoads
         GENERIC MAP (
136
            intended_device_family => "UNUSED",
137
            lpm_width => 8,
138 55 rhoads
            lpm_widthad => ADDRESS_WIDTH-2,
139 48 rhoads
            lpm_indata => "REGISTERED",
140 55 rhoads
            lpm_address_control => "REGISTERED",
141 48 rhoads
            lpm_outdata => "UNREGISTERED",
142
            lpm_file => "code2.hex",
143
            use_eab => "ON",
144
            lpm_type => "LPM_RAM_DQ")
145
         PORT MAP (
146 139 rhoads
            data    => data_write(15 downto 8),
147
            address => address(ADDRESS_WIDTH-1 downto 2),
148
            inclock => clk,
149 48 rhoads
            we      => write_byte_enable(1),
150 139 rhoads
            q       => data_read(15 downto 8));
151 48 rhoads
 
152 55 rhoads
      lpm_ram_io_component3 : lpm_ram_dq
153 48 rhoads
         GENERIC MAP (
154
            intended_device_family => "UNUSED",
155
            lpm_width => 8,
156 55 rhoads
            lpm_widthad => ADDRESS_WIDTH-2,
157 48 rhoads
            lpm_indata => "REGISTERED",
158 55 rhoads
            lpm_address_control => "REGISTERED",
159 48 rhoads
            lpm_outdata => "UNREGISTERED",
160
            lpm_file => "code3.hex",
161
            use_eab => "ON",
162
            lpm_type => "LPM_RAM_DQ")
163
         PORT MAP (
164 139 rhoads
            data    => data_write(7 downto 0),
165
            address => address(ADDRESS_WIDTH-1 downto 2),
166
            inclock => clk,
167 48 rhoads
            we      => write_byte_enable(0),
168 139 rhoads
            q       => data_read(7 downto 0));
169 55 rhoads
 
170 48 rhoads
   end generate; --altera_ram
171
 
172 139 rhoads
 
173
   --For XILINX see ram_xilinx.vhd
174
 
175 2 rhoads
end; --architecture logic

powered by: WebSVN 2.1.0

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