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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [vhdl/] [ram.vhd] - Blame information for rev 48

Go to most recent revision | 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
use ieee.std_logic_textio.all;
19
use std.textio.all;
20
 
21
use ieee.std_logic_unsigned.all;
22 39 rhoads
use work.mlite_pack.all;
23 2 rhoads
 
24
entity ram is
25 48 rhoads
   generic(memory_type : string := "GENERIC");
26 2 rhoads
   port(clk          : in std_logic;
27
        mem_byte_sel : in std_logic_vector(3 downto 0);
28
        mem_write    : in std_logic;
29 48 rhoads
        mem_address  : in std_logic_vector(31 downto 0);
30
        mem_data     : inout std_logic_vector(31 downto 0));
31 2 rhoads
end; --entity ram
32
 
33
architecture logic of ram is
34 48 rhoads
   signal mem_sel        : std_logic;
35
   signal read_enable    : std_logic;
36
   signal write_byte_enable : std_logic_vector(3 downto 0);
37 2 rhoads
begin
38
 
39 48 rhoads
   mem_sel <= '1' when mem_address(30 downto 16) = ZERO(30 downto 16) else
40
              '0';
41
   read_enable <= mem_sel and not mem_write;
42
   write_byte_enable <= mem_byte_sel when mem_sel = '1' else
43
                        "0000";
44 2 rhoads
 
45 48 rhoads
   generic_ram:
46
   if memory_type = "GENERIC" generate
47
   ram_proc: process(clk, mem_byte_sel, mem_write,
48
         mem_address, mem_data, mem_sel)
49
      variable data : std_logic_vector(31 downto 0);
50
      subtype word is std_logic_vector(mem_data'length-1 downto 0);
51
      type storage_array is
52
         array(natural range 0 to 8191) of word;
53
      variable storage : storage_array;
54
      variable index : natural := 0;
55
      file load_file : text is in "code.txt";
56
      variable hex_file_line : line;
57
   begin
58
      --load in the ram executable image
59
      if index = 0 then
60
         while not endfile(load_file) loop
61
            readline(load_file, hex_file_line);
62
            hread(hex_file_line, data);
63
            storage(index) := data;
64
            index := index + 1;
65
         end loop;
66
         --assert false report "done reading code" severity note;
67 2 rhoads
      end if;
68
 
69
      index := conv_integer(mem_address(mem_address'length-1 downto 2));
70
      data := storage(index);
71
 
72 48 rhoads
      if mem_sel = '1' then
73
         if mem_write = '0' then
74
            mem_data <= data;
75
         end if;
76
         if mem_byte_sel(0) = '1' then
77
            data(7 downto 0) := mem_data(7 downto 0);
78
         end if;
79
         if mem_byte_sel(1) = '1' then
80
            data(15 downto 8) := mem_data(15 downto 8);
81
         end if;
82
         if mem_byte_sel(2) = '1' then
83
            data(23 downto 16) := mem_data(23 downto 16);
84
         end if;
85
         if mem_byte_sel(3) = '1' then
86
            data(31 downto 24) := mem_data(31 downto 24);
87
         end if;
88 2 rhoads
      end if;
89
 
90
      if rising_edge(clk) then
91
         if mem_write = '1' then
92
            storage(index) := data;
93
         end if;
94
      end if;
95 48 rhoads
   end process;
96
   end generate; --generic_ram
97 2 rhoads
 
98 48 rhoads
 
99
   altera_ram:
100
   if memory_type = "ALTERA" generate
101
      lpm_ram_io_component0 : lpm_ram_io
102
         GENERIC MAP (
103
            intended_device_family => "UNUSED",
104
            lpm_width => 8,
105
            lpm_widthad => 11,
106
            lpm_indata => "REGISTERED",
107
            lpm_address_control => "UNREGISTERED",
108
            lpm_outdata => "UNREGISTERED",
109
            lpm_file => "code0.hex",
110
            use_eab => "ON",
111
            lpm_type => "LPM_RAM_DQ")
112
         PORT MAP (
113
            outenab => read_enable,
114
            address => mem_address(12 downto 2),
115
            inclock => clk,
116
            we      => write_byte_enable(3),
117
            dio     => mem_data(31 downto 24));
118
 
119
      lpm_ram_io_component1 : lpm_ram_io
120
         GENERIC MAP (
121
            intended_device_family => "UNUSED",
122
            lpm_width => 8,
123
            lpm_widthad => 11,
124
            lpm_indata => "REGISTERED",
125
            lpm_address_control => "UNREGISTERED",
126
            lpm_outdata => "UNREGISTERED",
127
            lpm_file => "code1.hex",
128
            use_eab => "ON",
129
            lpm_type => "LPM_RAM_DQ")
130
         PORT MAP (
131
            outenab => read_enable,
132
            address => mem_address(12 downto 2),
133
            inclock => clk,
134
            we      => write_byte_enable(2),
135
            dio     => mem_data(23 downto 16));
136
 
137
      lpm_ram_io_component2 : lpm_ram_io
138
         GENERIC MAP (
139
            intended_device_family => "UNUSED",
140
            lpm_width => 8,
141
            lpm_widthad => 11,
142
            lpm_indata => "REGISTERED",
143
            lpm_address_control => "UNREGISTERED",
144
            lpm_outdata => "UNREGISTERED",
145
            lpm_file => "code2.hex",
146
            use_eab => "ON",
147
            lpm_type => "LPM_RAM_DQ")
148
         PORT MAP (
149
            outenab => read_enable,
150
            address => mem_address(12 downto 2),
151
            inclock => clk,
152
            we      => write_byte_enable(1),
153
            dio     => mem_data(15 downto 8));
154
 
155
      lpm_ram_io_component3 : lpm_ram_io
156
         GENERIC MAP (
157
            intended_device_family => "UNUSED",
158
            lpm_width => 8,
159
            lpm_widthad => 11,
160
            lpm_indata => "REGISTERED",
161
            lpm_address_control => "UNREGISTERED",
162
            lpm_outdata => "UNREGISTERED",
163
            lpm_file => "code3.hex",
164
            use_eab => "ON",
165
            lpm_type => "LPM_RAM_DQ")
166
         PORT MAP (
167
            outenab => read_enable,
168
            address => mem_address(12 downto 2),
169
            inclock => clk,
170
            we      => write_byte_enable(0),
171
            dio     => mem_data(7 downto 0));
172
   end generate; --altera_ram
173
 
174 2 rhoads
end; --architecture logic
175
 

powered by: WebSVN 2.1.0

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