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

Subversion Repositories plasma

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

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