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

Subversion Repositories cpu_lecture

[/] [cpu_lecture/] [trunk/] [src/] [data_mem.vhd] - Blame information for rev 20

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

Line No. Rev Author Line
1 2 jsauermann
-------------------------------------------------------------------------------
2
-- 
3
-- Copyright (C) 2009, 2010 Dr. Juergen Sauermann
4
-- 
5
--  This code is free software: you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation, either version 3 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This code is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this code (see the file named COPYING).
17
--  If not, see http://www.gnu.org/licenses/.
18
--
19
-------------------------------------------------------------------------------
20
-------------------------------------------------------------------------------
21
--
22
-- Module Name:    data_mem - Behavioral 
23
-- Create Date:    14:09:04 10/30/2009 
24
-- Description:    the data mempry of a CPU.
25
--
26
-------------------------------------------------------------------------------
27
--
28
library IEEE;
29
use IEEE.STD_LOGIC_1164.ALL;
30
use IEEE.STD_LOGIC_ARITH.ALL;
31
use IEEE.STD_LOGIC_UNSIGNED.ALL;
32
 
33
entity data_mem is
34
    port (  I_CLK       : in  std_logic;
35
 
36
            I_ADR       : in  std_logic_vector(10 downto 0);
37
            I_DIN       : in  std_logic_vector(15 downto 0);
38
            I_WE        : in  std_logic_vector( 1 downto 0);
39
 
40
            Q_DOUT      : out std_logic_vector(15 downto 0));
41
end data_mem;
42
 
43
architecture Behavioral of data_mem is
44
 
45
constant zero_256 : bit_vector := X"00000000000000000000000000000000"
46
                                & X"00000000000000000000000000000000";
47
constant nine_256 : bit_vector := X"99999999999999999999999999999999"
48
                                & X"99999999999999999999999999999999";
49
 
50
component RAMB4_S4_S4
51
    generic(INIT_00 : bit_vector := zero_256;
52
            INIT_01 : bit_vector := zero_256;
53
            INIT_02 : bit_vector := zero_256;
54
            INIT_03 : bit_vector := zero_256;
55
            INIT_04 : bit_vector := zero_256;
56
            INIT_05 : bit_vector := zero_256;
57
            INIT_06 : bit_vector := zero_256;
58
            INIT_07 : bit_vector := zero_256;
59
            INIT_08 : bit_vector := zero_256;
60
            INIT_09 : bit_vector := zero_256;
61
            INIT_0A : bit_vector := zero_256;
62
            INIT_0B : bit_vector := zero_256;
63
            INIT_0C : bit_vector := zero_256;
64
            INIT_0D : bit_vector := zero_256;
65
            INIT_0E : bit_vector := zero_256;
66
            INIT_0F : bit_vector := zero_256);
67
 
68
    port(   DOA     : out std_logic_vector(3 downto 0);
69
            DOB     : out std_logic_vector(3 downto 0);
70
            ADDRA   : in  std_logic_vector(9 downto 0);
71
            ADDRB   : in  std_logic_vector(9 downto 0);
72
            CLKA    : in  std_ulogic;
73
            CLKB    : in  std_ulogic;
74
            DIA     : in  std_logic_vector(3 downto 0);
75
            DIB     : in  std_logic_vector(3 downto 0);
76
            ENA     : in  std_ulogic;
77
            ENB     : in  std_ulogic;
78
            RSTA    : in  std_ulogic;
79
            RSTB    : in  std_ulogic;
80
            WEA     : in  std_ulogic;
81
            WEB     : in  std_ulogic);
82
end component;
83
 
84
signal L_ADR_0      : std_logic;
85
signal L_ADR_E      : std_logic_vector(10 downto 1);
86
signal L_ADR_O      : std_logic_vector(10 downto 1);
87
signal L_DIN_E      : std_logic_vector( 7 downto 0);
88
signal L_DIN_O      : std_logic_vector( 7 downto 0);
89
signal L_DOUT_E     : std_logic_vector( 7 downto 0);
90
signal L_DOUT_O     : std_logic_vector( 7 downto 0);
91
signal L_WE_E       : std_logic;
92
signal L_WE_O       : std_logic;
93
 
94
begin
95
 
96
    sr_0 : RAMB4_S4_S4 ---------------------------------------------------------
97
    generic map(INIT_00 => nine_256, INIT_01 => nine_256, INIT_02 => nine_256,
98
                INIT_03 => nine_256, INIT_04 => nine_256, INIT_05 => nine_256,
99
                INIT_06 => nine_256, INIT_07 => nine_256, INIT_08 => nine_256,
100
                INIT_09 => nine_256, INIT_0A => nine_256, INIT_0B => nine_256,
101
                INIT_0C => nine_256, INIT_0D => nine_256, INIT_0E => nine_256,
102
                INIT_0F => nine_256)
103
 
104
    port map(   ADDRA => L_ADR_E,               ADDRB => "0000000000",
105
                CLKA  => I_CLK,                 CLKB  => I_CLK,
106
                DIA   => L_DIN_E(3 downto 0),   DIB   => "0000",
107
                ENA   => '1',                   ENB   => '0',
108
                RSTA  => '0',                   RSTB  => '0',
109
                WEA   => L_WE_E,                WEB   => '0',
110
                DOA   => L_DOUT_E(3 downto 0),  DOB   => open);
111
 
112
    sr_1 : RAMB4_S4_S4 ---------------------------------------------------------
113
    generic map(INIT_00 => nine_256, INIT_01 => nine_256, INIT_02 => nine_256,
114
                INIT_03 => nine_256, INIT_04 => nine_256, INIT_05 => nine_256,
115
                INIT_06 => nine_256, INIT_07 => nine_256, INIT_08 => nine_256,
116
                INIT_09 => nine_256, INIT_0A => nine_256, INIT_0B => nine_256,
117
                INIT_0C => nine_256, INIT_0D => nine_256, INIT_0E => nine_256,
118
                INIT_0F => nine_256)
119
 
120
    port map(   ADDRA => L_ADR_E,               ADDRB => "0000000000",
121
                CLKA  => I_CLK,                 CLKB  => I_CLK,
122
                DIA   => L_DIN_E(7 downto 4),   DIB   => "0000",
123
                ENA   => '1',                   ENB   => '0',
124
                RSTA  => '0',                   RSTB  => '0',
125
                WEA   => L_WE_E,                WEB   => '0',
126
                DOA   => L_DOUT_E(7 downto 4),  DOB   => open);
127
 
128
    sr_2 : RAMB4_S4_S4 ---------------------------------------------------------
129
    generic map(INIT_00 => nine_256, INIT_01 => nine_256, INIT_02 => nine_256,
130
                INIT_03 => nine_256, INIT_04 => nine_256, INIT_05 => nine_256,
131
                INIT_06 => nine_256, INIT_07 => nine_256, INIT_08 => nine_256,
132
                INIT_09 => nine_256, INIT_0A => nine_256, INIT_0B => nine_256,
133
                INIT_0C => nine_256, INIT_0D => nine_256, INIT_0E => nine_256,
134
                INIT_0F => nine_256)
135
 
136
    port map(   ADDRA => L_ADR_O,               ADDRB => "0000000000",
137
                CLKA  => I_CLK,                 CLKB  => I_CLK,
138
                DIA   => L_DIN_O(3 downto 0),   DIB   => "0000",
139
                ENA   => '1',                   ENB   => '0',
140
                RSTA  => '0',                   RSTB  => '0',
141
                WEA   => L_WE_O,                WEB   => '0',
142
                DOA   => L_DOUT_O(3 downto 0),  DOB   => open);
143
 
144
    sr_3 : RAMB4_S4_S4 ---------------------------------------------------------
145
    generic map(INIT_00 => nine_256, INIT_01 => nine_256, INIT_02 => nine_256,
146
                INIT_03 => nine_256, INIT_04 => nine_256, INIT_05 => nine_256,
147
                INIT_06 => nine_256, INIT_07 => nine_256, INIT_08 => nine_256,
148
                INIT_09 => nine_256, INIT_0A => nine_256, INIT_0B => nine_256,
149
                INIT_0C => nine_256, INIT_0D => nine_256, INIT_0E => nine_256,
150
                INIT_0F => nine_256)
151
 
152
    port map(   ADDRA => L_ADR_O,               ADDRB => "0000000000",
153
                CLKA  => I_CLK,                 CLKB  => I_CLK,
154
                DIA   => L_DIN_O(7 downto  4),  DIB   => "0000",
155
                ENA   => '1',                   ENB   => '0',
156
                RSTA  => '0',                   RSTB  => '0',
157
                WEA   => L_WE_O,                WEB   => '0',
158
                DOA   => L_DOUT_O(7 downto  4), DOB   => open);
159
 
160
 
161
    -- remember ADR(0)
162
    --
163
    adr0: process(I_CLK)
164
    begin
165
        if (rising_edge(I_CLK)) then
166
            L_ADR_0 <= I_ADR(0);
167
        end if;
168
    end process;
169
 
170
    -- we use two memory blocks _E and _O (even and odd).
171
    -- This gives us a memory with ADR and ADR + 1 at th same time.
172
    -- The second port is currently unused, but may be used later,
173
    -- e.g. for DMA.
174
    --
175
 
176
    L_ADR_O <= I_ADR(10 downto 1);
177
    L_ADR_E <= I_ADR(10 downto 1) + ("000000000" & I_ADR(0));
178
 
179
    L_DIN_E <= I_DIN( 7 downto 0) when (I_ADR(0) = '0') else I_DIN(15 downto 8);
180
    L_DIN_O <= I_DIN( 7 downto 0) when (I_ADR(0) = '1') else I_DIN(15 downto 8);
181
 
182
    L_WE_E <= I_WE(1) or (I_WE(0) and not I_ADR(0));
183
    L_WE_O <= I_WE(1) or (I_WE(0) and     I_ADR(0));
184
 
185
    Q_DOUT( 7 downto 0) <= L_DOUT_E when (L_ADR_0 = '0') else L_DOUT_O;
186
    Q_DOUT(15 downto 8) <= L_DOUT_E when (L_ADR_0 = '1') else L_DOUT_O;
187
 
188
end Behavioral;
189
 

powered by: WebSVN 2.1.0

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