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

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [src/] [components/] [BRAM/] [ram_parts.vhdl] - Blame information for rev 16

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 lcdsgmtr
-- Copyright 2015, Jürgen Defurne
2
--
3
-- This file is part of the Experimental Unstable CPU System.
4
--
5
-- The Experimental Unstable CPU System Is free software: you can redistribute
6
-- it and/or modify it under the terms of the GNU Lesser General Public License
7
-- as published by the Free Software Foundation, either version 3 of the
8
-- License, or (at your option) any later version.
9
--
10
-- The Experimental Unstable CPU System is distributed in the hope that it will
11
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
13
-- General Public License for more details.
14
--
15
-- You should have received a copy of the GNU Lesser General Public License
16
-- along with Experimental Unstable CPU System. If not, see
17
-- http://www.gnu.org/licenses/lgpl.txt.
18
 
19
 
20
LIBRARY ieee;
21
USE ieee.std_logic_1164.ALL;
22
USE ieee.numeric_std.ALL;
23
 
24
PACKAGE ram_parts IS
25
 
26
  COMPONENT RAM_GENERIC IS
27
    GENERIC (
28
      filename : STRING                := "";
29
      w_data   : NATURAL RANGE 1 TO 32 := 16;
30
      w_addr   : NATURAL RANGE 8 TO 14 := 10);
31
    PORT (
32
      clk : IN  STD_LOGIC;
33
      we  : IN  STD_LOGIC;
34
      a1  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Data port address
35
      a2  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Instruction port address
36
      d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port input
37
      q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port output
38
      q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
39
 
40
  END COMPONENT RAM_GENERIC;
41
 
42
  COMPONENT RAM32K IS
43
 
44
    GENERIC (
45
      filename : STRING                := "";
46
      w_data   : NATURAL RANGE 1 TO 32 := 16);
47
    PORT (
48
      clk : IN  STD_LOGIC;
49
      we  : IN  STD_LOGIC;
50
      a1  : IN  STD_LOGIC_VECTOR(14 DOWNTO 0);  -- Data port address
51
      a2  : IN  STD_LOGIC_VECTOR(14 DOWNTO 0);  -- Instruction port address
52
      d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);   -- Data port input
53
      q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);   -- Data port output
54
      q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
55
 
56
  END COMPONENT RAM32K;
57
 
58 16 lcdsgmtr
  COMPONENT RAM8K IS
59
    GENERIC (
60
      initial : cstr_array_type(0 TO 8191);
61
      w_data  : NATURAL RANGE 1 TO 32 := 16);
62
    PORT (
63
      clk : IN  STD_LOGIC;
64
      we  : IN  STD_LOGIC;
65
      a1  : IN  STD_LOGIC_VECTOR(12 DOWNTO 0);
66
      a2  : IN  STD_LOGIC_VECTOR(12 DOWNTO 0);
67
      d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
68
      q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
69
      q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));
70
  END COMPONENT RAM8K;
71
 
72 15 lcdsgmtr
END PACKAGE ram_parts;
73
 
74
LIBRARY ieee;
75
USE ieee.std_logic_1164.ALL;
76
USE ieee.numeric_std.ALL;
77
USE std.textio.ALL;
78
USE ieee.std_logic_textio.ALL;
79 16 lcdsgmtr
USE work.hexio.ALL;
80 15 lcdsgmtr
 
81
ENTITY RAM_GENERIC IS
82
 
83
  -- Memory component based upon Xilinx Spartan-6 block RAM
84
  -- Maximum capacity is 16k words
85
  -- This component can be initialised by passing a file name as a generic
86
  -- parameter.
87
 
88
  GENERIC (
89
    filename : STRING                := "";
90
    w_data   : NATURAL RANGE 1 TO 32 := 16;
91
    w_addr   : NATURAL RANGE 8 TO 14 := 10);
92
  PORT (
93
    clk : IN  STD_LOGIC;
94
    we  : IN  STD_LOGIC;
95
    a1  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Data port address
96
    a2  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Instruction port address
97
    d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port input
98
    q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port output
99
    q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
100
 
101
END RAM_GENERIC;
102
 
103
ARCHITECTURE Behavioral OF RAM_GENERIC IS
104
 
105
  SIGNAL mem : cstr_array_type(0 TO (2**w_addr) - 1) := init_cstr(2**w_addr, filename);
106
 
107
  SIGNAL address_reg_1 : STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);
108
  SIGNAL address_reg_2 : STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);
109
 
110
BEGIN  -- Behavioral
111
 
112
  -- purpose: Try to describe a proper block ram without needing to instantiate a BRAM
113
  -- type   : sequential
114
  -- inputs : clk, we, a1, a2, d1
115
  -- outputs: q1, q2
116
  MP1 : PROCESS (clk, address_reg_1, address_reg_2, mem)
117
  BEGIN  -- PROCESS MP1
118
 
119
    -- Reading
120
    q1 <= STD_LOGIC_VECTOR(to_unsigned(mem(to_integer(UNSIGNED(address_reg_1))), w_data));
121
    q2 <= STD_LOGIC_VECTOR(to_unsigned(mem(to_integer(UNSIGNED(address_reg_2))), w_data));
122
 
123
    IF rising_edge(clk) THEN            -- rising clock edge
124
 
125
      -- These work like the block RAM registers
126
      address_reg_1 <= a1;
127
      address_reg_2 <= a2;
128
 
129
      -- Writing
130
      IF we = '1' THEN
131
        mem(to_integer(UNSIGNED(a1))) <= to_integer(UNSIGNED(d1));
132
      END IF;
133
 
134
    END IF;
135
 
136
  END PROCESS MP1;
137
 
138
END Behavioral;
139
 
140
LIBRARY ieee;
141
USE ieee.std_logic_1164.ALL;
142
USE ieee.numeric_std.ALL;
143 16 lcdsgmtr
USE work.hexio.ALL;
144
 
145
LIBRARY ieee;
146
USE ieee.std_logic_1164.ALL;
147
USE ieee.numeric_std.ALL;
148 15 lcdsgmtr
USE work.mux_parts.ALL;
149 16 lcdsgmtr
USE work.hexio.ALL;
150 15 lcdsgmtr
 
151
ENTITY RAM32K IS
152
 
153
  -- This component is based upon the above defined memory
154
  -- It is constructed using a 4-to-1 multiplexer and 4 8k word
155
  -- memories.
156
 
157
  GENERIC (
158
    w_data   : NATURAL RANGE 1 TO 32 := 16;
159
    filename : STRING                := "");
160
  PORT (
161
    clk : IN  STD_LOGIC;
162
    we  : IN  STD_LOGIC;
163
    a1  : IN  STD_LOGIC_VECTOR(14 DOWNTO 0);  -- Data port address
164
    a2  : IN  STD_LOGIC_VECTOR(14 DOWNTO 0);  -- Instruction port address
165
    d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);   -- Data port input
166
    q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);   -- Data port output
167
    q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
168
 
169
END RAM32K;
170
 
171
ARCHITECTURE Structural OF RAM32K IS
172
 
173
  SIGNAL data_address  : STD_LOGIC_VECTOR(12 DOWNTO 0);
174
  SIGNAL data_select   : STD_LOGIC_VECTOR(1 DOWNTO 0);
175
  SIGNAL instr_address : STD_LOGIC_VECTOR(12 DOWNTO 0);
176
  SIGNAL instr_select  : STD_LOGIC_VECTOR(1 DOWNTO 0);
177
 
178
  SIGNAL wr_sel : STD_LOGIC_VECTOR(3 DOWNTO 0);
179
 
180
  TYPE bus_array_t IS ARRAY(0 TO 3) OF STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
181
 
182
  SIGNAL data : bus_array_t;
183
  SIGNAL inst : bus_array_t;
184
 
185
  TYPE file_array IS ARRAY(INTEGER RANGE <>) OF STRING(1 TO 100);
186
 
187
  CONSTANT i_file : file_array(0 TO 3) := (file_1, file_2, file_3, file_4);
188
 
189
BEGIN  -- Structural
190
 
191
  data_address <= a1(12 DOWNTO 0);
192
  data_select  <= a1(14 DOWNTO 13);
193
 
194
  instr_address <= a2(12 DOWNTO 0);
195
  instr_select  <= a2(14 DOWNTO 13);
196
 
197
  wr_sel <= "0001" WHEN data_select = "00" AND we = '1' ELSE
198
            "0010" WHEN data_select = "01" AND we = '1' ELSE
199
            "0100" WHEN data_select = "10" AND we = '1' ELSE
200
            "1000" WHEN data_select = "11" AND we = '1' ELSE
201
            "0000";
202
 
203
  M1 : mux4to1
204
    PORT MAP (
205
      SEL => data_select,
206
      S0  => data(0),
207
      S1  => data(1),
208
      S2  => data(2),
209
      S3  => data(3),
210
      Y   => q1);
211
 
212
  M2 : mux4to1
213
    PORT MAP (
214
      SEL => instr_select,
215
      S0  => inst(0),
216
      S1  => inst(1),
217
      S2  => inst(2),
218
      S3  => inst(3),
219
      Y   => q2);
220
 
221
  RAM : FOR i IN 0 TO 3 GENERATE
222
 
223 16 lcdsgmtr
    R0 : RAM8K
224 15 lcdsgmtr
      GENERIC MAP (
225
        filename => i_file(i),
226 16 lcdsgmtr
        w_data   => w_data)
227 15 lcdsgmtr
      PORT MAP (
228
        clk => clk,
229
        we  => wr_sel(i),
230
        a1  => data_address,
231
        a2  => instr_address,
232
        d1  => d1,
233
        q1  => data(i),
234
        q2  => inst(i));
235
 
236
  END GENERATE RAM;
237
 
238
END Structural;
239
 

powered by: WebSVN 2.1.0

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