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

Subversion Repositories xucpu

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

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

powered by: WebSVN 2.1.0

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