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

Subversion Repositories xucpu

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

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 17 lcdsgmtr
USE work.hexio.ALL;
24 15 lcdsgmtr
 
25
PACKAGE ram_parts IS
26
 
27
  COMPONENT RAM_GENERIC IS
28
    GENERIC (
29
      filename : STRING                := "";
30
      w_data   : NATURAL RANGE 1 TO 32 := 16;
31
      w_addr   : NATURAL RANGE 8 TO 14 := 10);
32
    PORT (
33
      clk : IN  STD_LOGIC;
34
      we  : IN  STD_LOGIC;
35
      a1  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Data port address
36
      a2  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Instruction port address
37
      d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port input
38
      q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port output
39
      q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
40
 
41
  END COMPONENT RAM_GENERIC;
42
 
43
  COMPONENT RAM32K IS
44
 
45
    GENERIC (
46
      filename : STRING                := "";
47
      w_data   : NATURAL RANGE 1 TO 32 := 16);
48
    PORT (
49
      clk : IN  STD_LOGIC;
50
      we  : IN  STD_LOGIC;
51
      a1  : IN  STD_LOGIC_VECTOR(14 DOWNTO 0);  -- Data port address
52
      a2  : IN  STD_LOGIC_VECTOR(14 DOWNTO 0);  -- Instruction port address
53
      d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);   -- Data port input
54
      q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);   -- Data port output
55
      q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
56
 
57
  END COMPONENT RAM32K;
58
 
59
END PACKAGE ram_parts;
60
 
61
LIBRARY ieee;
62
USE ieee.std_logic_1164.ALL;
63
USE ieee.numeric_std.ALL;
64 16 lcdsgmtr
USE work.hexio.ALL;
65 15 lcdsgmtr
 
66
ENTITY RAM_GENERIC IS
67
 
68
  -- Memory component based upon Xilinx Spartan-6 block RAM
69
  -- Maximum capacity is 16k words
70
  -- This component can be initialised by passing a file name as a generic
71
  -- parameter.
72
 
73
  GENERIC (
74
    filename : STRING                := "";
75
    w_data   : NATURAL RANGE 1 TO 32 := 16;
76
    w_addr   : NATURAL RANGE 8 TO 14 := 10);
77
  PORT (
78
    clk : IN  STD_LOGIC;
79
    we  : IN  STD_LOGIC;
80
    a1  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Data port address
81
    a2  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Instruction port address
82
    d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port input
83
    q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port output
84
    q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
85
 
86
END RAM_GENERIC;
87
 
88
ARCHITECTURE Behavioral OF RAM_GENERIC IS
89
 
90
  SIGNAL mem : cstr_array_type(0 TO (2**w_addr) - 1) := init_cstr(2**w_addr, filename);
91
 
92
  SIGNAL address_reg_1 : STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);
93
  SIGNAL address_reg_2 : STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);
94
 
95
BEGIN  -- Behavioral
96
 
97
  -- purpose: Try to describe a proper block ram without needing to instantiate a BRAM
98
  -- type   : sequential
99
  -- inputs : clk, we, a1, a2, d1
100
  -- outputs: q1, q2
101
  MP1 : PROCESS (clk, address_reg_1, address_reg_2, mem)
102
  BEGIN  -- PROCESS MP1
103
 
104
    -- Reading
105
    q1 <= STD_LOGIC_VECTOR(to_unsigned(mem(to_integer(UNSIGNED(address_reg_1))), w_data));
106
    q2 <= STD_LOGIC_VECTOR(to_unsigned(mem(to_integer(UNSIGNED(address_reg_2))), w_data));
107
 
108
    IF rising_edge(clk) THEN            -- rising clock edge
109
 
110
      -- These work like the block RAM registers
111
      address_reg_1 <= a1;
112
      address_reg_2 <= a2;
113
 
114
      -- Writing
115
      IF we = '1' THEN
116
        mem(to_integer(UNSIGNED(a1))) <= to_integer(UNSIGNED(d1));
117
      END IF;
118
 
119
    END IF;
120
 
121
  END PROCESS MP1;
122
 
123
END Behavioral;
124
 
125
LIBRARY ieee;
126
USE ieee.std_logic_1164.ALL;
127
USE ieee.numeric_std.ALL;
128
USE work.mux_parts.ALL;
129 16 lcdsgmtr
USE work.hexio.ALL;
130 15 lcdsgmtr
 
131
ENTITY RAM32K IS
132
 
133
  -- This component is based upon the above defined memory
134
  -- It is constructed using a 4-to-1 multiplexer and 4 8k word
135
  -- memories.
136
 
137
  GENERIC (
138
    w_data   : NATURAL RANGE 1 TO 32 := 16;
139
    filename : STRING                := "");
140
  PORT (
141
    clk : IN  STD_LOGIC;
142
    we  : IN  STD_LOGIC;
143
    a1  : IN  STD_LOGIC_VECTOR(14 DOWNTO 0);  -- Data port address
144
    a2  : IN  STD_LOGIC_VECTOR(14 DOWNTO 0);  -- Instruction port address
145
    d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);   -- Data port input
146
    q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);   -- Data port output
147
    q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
148
 
149
END RAM32K;
150
 
151
ARCHITECTURE Structural OF RAM32K IS
152
 
153 17 lcdsgmtr
  COMPONENT generic_memory_block IS
154
 
155
    GENERIC (
156
      init_data : cstr_array_type;
157
      w_data    : NATURAL RANGE 1 TO 32 := 16;
158
      w_addr    : NATURAL RANGE 8 TO 14 := 10);
159
    PORT (
160
      clk : IN  STD_LOGIC;
161
      we  : IN  STD_LOGIC;
162
      a1  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Data port address
163
      a2  : IN  STD_LOGIC_VECTOR(w_addr - 1 DOWNTO 0);  -- Instruction port address
164
      d1  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port input
165
      q1  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);  -- Data port output
166
      q2  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));  -- Instruction port output
167
 
168
  END COMPONENT generic_memory_block;
169
 
170
  SIGNAL memory_array : B32K_array_type;
171
 
172 15 lcdsgmtr
  SIGNAL data_address  : STD_LOGIC_VECTOR(12 DOWNTO 0);
173
  SIGNAL data_select   : STD_LOGIC_VECTOR(1 DOWNTO 0);
174
  SIGNAL instr_address : STD_LOGIC_VECTOR(12 DOWNTO 0);
175
  SIGNAL instr_select  : STD_LOGIC_VECTOR(1 DOWNTO 0);
176
 
177
  SIGNAL wr_sel : STD_LOGIC_VECTOR(3 DOWNTO 0);
178
 
179
  TYPE bus_array_t IS ARRAY(0 TO 3) OF STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
180
 
181
  SIGNAL data : bus_array_t;
182
  SIGNAL inst : bus_array_t;
183
 
184
  TYPE file_array IS ARRAY(INTEGER RANGE <>) OF STRING(1 TO 100);
185
 
186
BEGIN  -- Structural
187
 
188
  data_address <= a1(12 DOWNTO 0);
189
  data_select  <= a1(14 DOWNTO 13);
190
 
191
  instr_address <= a2(12 DOWNTO 0);
192
  instr_select  <= a2(14 DOWNTO 13);
193
 
194
  wr_sel <= "0001" WHEN data_select = "00" AND we = '1' ELSE
195
            "0010" WHEN data_select = "01" AND we = '1' ELSE
196
            "0100" WHEN data_select = "10" AND we = '1' ELSE
197
            "1000" WHEN data_select = "11" AND we = '1' ELSE
198
            "0000";
199
 
200
  M1 : mux4to1
201
    PORT MAP (
202
      SEL => data_select,
203
      S0  => data(0),
204
      S1  => data(1),
205
      S2  => data(2),
206
      S3  => data(3),
207
      Y   => q1);
208
 
209
  M2 : mux4to1
210
    PORT MAP (
211
      SEL => instr_select,
212
      S0  => inst(0),
213
      S1  => inst(1),
214
      S2  => inst(2),
215
      S3  => inst(3),
216
      Y   => q2);
217
 
218
  RAM : FOR i IN 0 TO 3 GENERATE
219
 
220 17 lcdsgmtr
    R0 : generic_memory_block
221 15 lcdsgmtr
      GENERIC MAP (
222 17 lcdsgmtr
        init_data => memory_array(i),
223
        w_data   => w_data,
224
        w_addr   => 13)
225 15 lcdsgmtr
      PORT MAP (
226
        clk => clk,
227
        we  => wr_sel(i),
228
        a1  => data_address,
229
        a2  => instr_address,
230
        d1  => d1,
231
        q1  => data(i),
232
        q2  => inst(i));
233
 
234
  END GENERATE RAM;
235
 
236
END Structural;

powered by: WebSVN 2.1.0

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