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

Subversion Repositories plasma

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

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 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 2 rhoads
 
23
entity ram is
24 132 rhoads
   generic(memory_type : string := "DEFAULT");
25 139 rhoads
   port(clk               : in std_logic;
26
        enable            : in std_logic;
27
        write_byte_enable : in std_logic_vector(3 downto 0);
28
        address           : in std_logic_vector(31 downto 2);
29
        data_write        : in std_logic_vector(31 downto 0);
30
        data_read         : out std_logic_vector(31 downto 0));
31 2 rhoads
end; --entity ram
32
 
33
architecture logic of ram is
34 55 rhoads
   constant ADDRESS_WIDTH   : natural := 13;
35 2 rhoads
begin
36
 
37 48 rhoads
   generic_ram:
38 344 rhoads
   if memory_type /= "ALTERA_LPM" generate
39
   begin
40 139 rhoads
   --Simulate a synchronous RAM
41
   ram_proc: process(clk, enable, write_byte_enable,
42
         address, data_write) --mem_write, mem_sel
43 98 rhoads
      variable mem_size : natural := 2 ** ADDRESS_WIDTH;
44 48 rhoads
      variable data : std_logic_vector(31 downto 0);
45 139 rhoads
      subtype word is std_logic_vector(data_write'length-1 downto 0);
46 48 rhoads
      type storage_array is
47 98 rhoads
         array(natural range 0 to mem_size/4 - 1) of word;
48 48 rhoads
      variable storage : storage_array;
49
      variable index : natural := 0;
50 139 rhoads
      file load_file : text open read_mode is "code.txt";
51 48 rhoads
      variable hex_file_line : line;
52
   begin
53 128 rhoads
 
54 139 rhoads
      --Load in the ram executable image
55 48 rhoads
      if index = 0 then
56
         while not endfile(load_file) loop
57 55 rhoads
--The following two lines had to be commented out for synthesis
58 48 rhoads
            readline(load_file, hex_file_line);
59
            hread(hex_file_line, data);
60
            storage(index) := data;
61
            index := index + 1;
62
         end loop;
63 2 rhoads
      end if;
64
 
65 139 rhoads
      if rising_edge(clk) then
66
         index := conv_integer(address(ADDRESS_WIDTH-1 downto 2));
67
         data := storage(index);
68 2 rhoads
 
69 139 rhoads
         if enable = '1' then
70
            if write_byte_enable(0) = '1' then
71
               data(7 downto 0) := data_write(7 downto 0);
72
            end if;
73
            if write_byte_enable(1) = '1' then
74
               data(15 downto 8) := data_write(15 downto 8);
75
            end if;
76
            if write_byte_enable(2) = '1' then
77
               data(23 downto 16) := data_write(23 downto 16);
78
            end if;
79
            if write_byte_enable(3) = '1' then
80
               data(31 downto 24) := data_write(31 downto 24);
81
            end if;
82 48 rhoads
         end if;
83 2 rhoads
 
84 139 rhoads
         if write_byte_enable /= "0000" then
85 2 rhoads
            storage(index) := data;
86
         end if;
87
      end if;
88 139 rhoads
 
89
      data_read <= data;
90 48 rhoads
   end process;
91
   end generate; --generic_ram
92 2 rhoads
 
93 48 rhoads
 
94
   altera_ram:
95 139 rhoads
   if memory_type = "ALTERA_LPM" generate
96 335 rhoads
      signal byte_we : std_logic_vector(3 downto 0);
97 344 rhoads
   begin
98 335 rhoads
      byte_we <= write_byte_enable when enable = '1' else "0000";
99 55 rhoads
      lpm_ram_io_component0 : lpm_ram_dq
100 48 rhoads
         GENERIC MAP (
101
            intended_device_family => "UNUSED",
102
            lpm_width => 8,
103 55 rhoads
            lpm_widthad => ADDRESS_WIDTH-2,
104 48 rhoads
            lpm_indata => "REGISTERED",
105 55 rhoads
            lpm_address_control => "REGISTERED",
106 48 rhoads
            lpm_outdata => "UNREGISTERED",
107
            lpm_file => "code0.hex",
108
            use_eab => "ON",
109
            lpm_type => "LPM_RAM_DQ")
110
         PORT MAP (
111 139 rhoads
            data    => data_write(31 downto 24),
112
            address => address(ADDRESS_WIDTH-1 downto 2),
113
            inclock => clk,
114 335 rhoads
            we      => byte_we(3),
115 139 rhoads
            q       => data_read(31 downto 24));
116 48 rhoads
 
117 55 rhoads
      lpm_ram_io_component1 : lpm_ram_dq
118 48 rhoads
         GENERIC MAP (
119
            intended_device_family => "UNUSED",
120
            lpm_width => 8,
121 55 rhoads
            lpm_widthad => ADDRESS_WIDTH-2,
122 48 rhoads
            lpm_indata => "REGISTERED",
123 55 rhoads
            lpm_address_control => "REGISTERED",
124 48 rhoads
            lpm_outdata => "UNREGISTERED",
125
            lpm_file => "code1.hex",
126
            use_eab => "ON",
127
            lpm_type => "LPM_RAM_DQ")
128
         PORT MAP (
129 139 rhoads
            data    => data_write(23 downto 16),
130
            address => address(ADDRESS_WIDTH-1 downto 2),
131
            inclock => clk,
132 335 rhoads
            we      => byte_we(2),
133 139 rhoads
            q       => data_read(23 downto 16));
134 48 rhoads
 
135 55 rhoads
      lpm_ram_io_component2 : lpm_ram_dq
136 48 rhoads
         GENERIC MAP (
137
            intended_device_family => "UNUSED",
138
            lpm_width => 8,
139 55 rhoads
            lpm_widthad => ADDRESS_WIDTH-2,
140 48 rhoads
            lpm_indata => "REGISTERED",
141 55 rhoads
            lpm_address_control => "REGISTERED",
142 48 rhoads
            lpm_outdata => "UNREGISTERED",
143
            lpm_file => "code2.hex",
144
            use_eab => "ON",
145
            lpm_type => "LPM_RAM_DQ")
146
         PORT MAP (
147 139 rhoads
            data    => data_write(15 downto 8),
148
            address => address(ADDRESS_WIDTH-1 downto 2),
149
            inclock => clk,
150 335 rhoads
            we      => byte_we(1),
151 139 rhoads
            q       => data_read(15 downto 8));
152 48 rhoads
 
153 55 rhoads
      lpm_ram_io_component3 : lpm_ram_dq
154 48 rhoads
         GENERIC MAP (
155
            intended_device_family => "UNUSED",
156
            lpm_width => 8,
157 55 rhoads
            lpm_widthad => ADDRESS_WIDTH-2,
158 48 rhoads
            lpm_indata => "REGISTERED",
159 55 rhoads
            lpm_address_control => "REGISTERED",
160 48 rhoads
            lpm_outdata => "UNREGISTERED",
161
            lpm_file => "code3.hex",
162
            use_eab => "ON",
163
            lpm_type => "LPM_RAM_DQ")
164
         PORT MAP (
165 139 rhoads
            data    => data_write(7 downto 0),
166
            address => address(ADDRESS_WIDTH-1 downto 2),
167
            inclock => clk,
168 335 rhoads
            we      => byte_we(0),
169 139 rhoads
            q       => data_read(7 downto 0));
170 55 rhoads
 
171 48 rhoads
   end generate; --altera_ram
172
 
173 139 rhoads
 
174
   --For XILINX see ram_xilinx.vhd
175
 
176 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.