1 |
4 |
arniml |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- The Data Memory control unit.
|
4 |
|
|
-- All accesses to the Data Memory are managed here.
|
5 |
|
|
--
|
6 |
222 |
arniml |
-- $Id: dmem_ctrl.vhd,v 1.5 2006-06-20 01:07:16 arniml Exp $
|
7 |
4 |
arniml |
--
|
8 |
|
|
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
|
9 |
|
|
--
|
10 |
|
|
-- All rights reserved
|
11 |
|
|
--
|
12 |
|
|
-- Redistribution and use in source and synthezised forms, with or without
|
13 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
14 |
|
|
--
|
15 |
|
|
-- Redistributions of source code must retain the above copyright notice,
|
16 |
|
|
-- this list of conditions and the following disclaimer.
|
17 |
|
|
--
|
18 |
|
|
-- Redistributions in synthesized form must reproduce the above copyright
|
19 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
20 |
|
|
-- documentation and/or other materials provided with the distribution.
|
21 |
|
|
--
|
22 |
|
|
-- Neither the name of the author nor the names of other contributors may
|
23 |
|
|
-- be used to endorse or promote products derived from this software without
|
24 |
|
|
-- specific prior written permission.
|
25 |
|
|
--
|
26 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
27 |
|
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
28 |
|
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
29 |
|
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
30 |
|
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
31 |
|
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
32 |
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
33 |
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
34 |
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
35 |
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
36 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
37 |
|
|
--
|
38 |
|
|
-- Please report bugs to the author, but before you do so, please
|
39 |
|
|
-- make sure that this is not a derivative work and that
|
40 |
|
|
-- you have the latest version of this file.
|
41 |
|
|
--
|
42 |
|
|
-- The latest version of this file can be found at:
|
43 |
|
|
-- http://www.opencores.org/cvsweb.shtml/t48/
|
44 |
|
|
--
|
45 |
|
|
-------------------------------------------------------------------------------
|
46 |
|
|
|
47 |
|
|
library ieee;
|
48 |
|
|
use ieee.std_logic_1164.all;
|
49 |
|
|
|
50 |
|
|
use work.t48_pack.dmem_addr_t;
|
51 |
|
|
use work.t48_pack.word_t;
|
52 |
179 |
arniml |
use work.t48_dmem_ctrl_pack.dmem_addr_ident_t;
|
53 |
4 |
arniml |
|
54 |
179 |
arniml |
entity t48_dmem_ctrl is
|
55 |
4 |
arniml |
|
56 |
|
|
port (
|
57 |
|
|
-- Global Interface -------------------------------------------------------
|
58 |
|
|
clk_i : in std_logic;
|
59 |
|
|
res_i : in std_logic;
|
60 |
|
|
en_clk_i : in boolean;
|
61 |
|
|
-- Control Interface ------------------------------------------------------
|
62 |
|
|
data_i : in word_t;
|
63 |
|
|
write_dmem_addr_i : in boolean;
|
64 |
|
|
write_dmem_i : in boolean;
|
65 |
|
|
read_dmem_i : in boolean;
|
66 |
|
|
addr_type_i : in dmem_addr_ident_t;
|
67 |
|
|
bank_select_i : in std_logic;
|
68 |
|
|
data_o : out word_t;
|
69 |
|
|
-- Data Memory Interface --------------------------------------------------
|
70 |
|
|
dmem_data_i : in word_t;
|
71 |
|
|
dmem_addr_o : out dmem_addr_t;
|
72 |
|
|
dmem_we_o : out std_logic;
|
73 |
|
|
dmem_data_o : out word_t
|
74 |
|
|
);
|
75 |
|
|
|
76 |
179 |
arniml |
end t48_dmem_ctrl;
|
77 |
4 |
arniml |
|
78 |
|
|
|
79 |
|
|
library ieee;
|
80 |
77 |
arniml |
use ieee.numeric_std.all;
|
81 |
4 |
arniml |
|
82 |
|
|
use work.t48_pack.clk_active_c;
|
83 |
|
|
use work.t48_pack.res_active_c;
|
84 |
|
|
use work.t48_pack.bus_idle_level_c;
|
85 |
|
|
use work.t48_pack.to_stdLogic;
|
86 |
|
|
|
87 |
179 |
arniml |
use work.t48_dmem_ctrl_pack.all;
|
88 |
4 |
arniml |
|
89 |
179 |
arniml |
architecture rtl of t48_dmem_ctrl is
|
90 |
4 |
arniml |
|
91 |
|
|
signal dmem_addr_s,
|
92 |
|
|
dmem_addr_q : dmem_addr_t;
|
93 |
|
|
begin
|
94 |
|
|
|
95 |
|
|
-----------------------------------------------------------------------------
|
96 |
|
|
-- Process addr_decode
|
97 |
|
|
--
|
98 |
|
|
-- Purpose:
|
99 |
|
|
-- Decode/multiplex the address information for the Data Memory.
|
100 |
|
|
--
|
101 |
|
|
addr_decode: process (data_i,
|
102 |
|
|
addr_type_i,
|
103 |
|
|
bank_select_i,
|
104 |
65 |
arniml |
dmem_addr_q)
|
105 |
4 |
arniml |
variable stack_addr_v : unsigned(5 downto 0);
|
106 |
|
|
begin
|
107 |
|
|
-- default assignment
|
108 |
77 |
arniml |
dmem_addr_s <= dmem_addr_q;
|
109 |
|
|
stack_addr_v := (others => '0');
|
110 |
4 |
arniml |
|
111 |
|
|
case addr_type_i is
|
112 |
|
|
when DM_PLAIN =>
|
113 |
|
|
dmem_addr_s <= data_i;
|
114 |
|
|
|
115 |
|
|
when DM_REG =>
|
116 |
|
|
dmem_addr_s <= (others => '0');
|
117 |
|
|
dmem_addr_s(2 downto 0) <= data_i(2 downto 0);
|
118 |
|
|
-- implement bank switching
|
119 |
|
|
if bank_select_i = '1' then
|
120 |
|
|
-- dmem address 24 - 31: access proper set
|
121 |
|
|
dmem_addr_s(4 downto 3) <= "11";
|
122 |
|
|
end if;
|
123 |
|
|
|
124 |
|
|
when DM_STACK =>
|
125 |
|
|
-- build address from stack pointer
|
126 |
|
|
stack_addr_v(3 downto 1) := unsigned(data_i(2 downto 0));
|
127 |
|
|
-- dmem address 8 - 23
|
128 |
|
|
stack_addr_v := stack_addr_v + 8;
|
129 |
|
|
|
130 |
|
|
dmem_addr_s <= (others => '0');
|
131 |
77 |
arniml |
dmem_addr_s(5 downto 0) <= std_logic_vector(stack_addr_v);
|
132 |
4 |
arniml |
|
133 |
|
|
when DM_STACK_HIGH =>
|
134 |
|
|
dmem_addr_s(0) <= '1';
|
135 |
|
|
|
136 |
|
|
when others =>
|
137 |
|
|
-- do nothing
|
138 |
|
|
|
139 |
|
|
-- pragma translate_off
|
140 |
|
|
assert false
|
141 |
|
|
report "Unknown address type identification for Data Memory controller!"
|
142 |
|
|
severity error;
|
143 |
|
|
-- pragma translate_on
|
144 |
|
|
|
145 |
|
|
end case;
|
146 |
|
|
|
147 |
|
|
end process addr_decode;
|
148 |
|
|
--
|
149 |
|
|
-----------------------------------------------------------------------------
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
-----------------------------------------------------------------------------
|
153 |
|
|
-- Process dmem_addr_reg
|
154 |
|
|
--
|
155 |
|
|
-- Purpose:
|
156 |
|
|
-- Implements the Data Memory Address Register.
|
157 |
222 |
arniml |
-- This register is required to hold the address during a write operation
|
158 |
4 |
arniml |
-- as we cannot hold the address in the input register of the
|
159 |
|
|
-- synchronous RAM (no clock suppression/gating).
|
160 |
|
|
--
|
161 |
222 |
arniml |
-- NOTE: May be obsoleted by clock enable feature of generic RTL RAM.
|
162 |
|
|
--
|
163 |
4 |
arniml |
dmem_addr_reg: process (res_i, clk_i)
|
164 |
|
|
begin
|
165 |
|
|
if res_i = res_active_c then
|
166 |
|
|
dmem_addr_q <= (others => '0');
|
167 |
|
|
|
168 |
|
|
elsif clk_i'event and clk_i = clk_active_c then
|
169 |
|
|
if en_clk_i then
|
170 |
|
|
|
171 |
|
|
if write_dmem_addr_i then
|
172 |
|
|
dmem_addr_q <= dmem_addr_s;
|
173 |
|
|
end if;
|
174 |
|
|
|
175 |
|
|
end if;
|
176 |
|
|
|
177 |
|
|
end if;
|
178 |
|
|
|
179 |
|
|
end process dmem_addr_reg;
|
180 |
|
|
--
|
181 |
|
|
-----------------------------------------------------------------------------
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
-----------------------------------------------------------------------------
|
185 |
|
|
-- Output mapping.
|
186 |
|
|
-----------------------------------------------------------------------------
|
187 |
|
|
dmem_addr_o <= dmem_addr_s
|
188 |
|
|
when write_dmem_addr_i and en_clk_i else
|
189 |
|
|
dmem_addr_q;
|
190 |
|
|
|
191 |
|
|
-- data from bus is fed through
|
192 |
|
|
dmem_data_o <= data_i;
|
193 |
|
|
|
194 |
|
|
-- data to bus is enabled upon read request
|
195 |
|
|
data_o <= dmem_data_i
|
196 |
|
|
when read_dmem_i else
|
197 |
|
|
(others => bus_idle_level_c);
|
198 |
|
|
|
199 |
|
|
-- write enable to Data Memory is fed through
|
200 |
|
|
dmem_we_o <= to_stdLogic(write_dmem_i);
|
201 |
|
|
|
202 |
|
|
end rtl;
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
-------------------------------------------------------------------------------
|
206 |
|
|
-- File History:
|
207 |
|
|
--
|
208 |
|
|
-- $Log: not supported by cvs2svn $
|
209 |
222 |
arniml |
-- Revision 1.4 2005/06/11 10:08:43 arniml
|
210 |
|
|
-- introduce prefix 't48_' for all packages, entities and configurations
|
211 |
|
|
--
|
212 |
179 |
arniml |
-- Revision 1.3 2004/04/24 23:44:25 arniml
|
213 |
|
|
-- move from std_logic_arith to numeric_std
|
214 |
|
|
--
|
215 |
77 |
arniml |
-- Revision 1.2 2004/04/18 18:58:29 arniml
|
216 |
|
|
-- clean up sensitivity list
|
217 |
|
|
--
|
218 |
65 |
arniml |
-- Revision 1.1 2004/03/23 21:31:52 arniml
|
219 |
|
|
-- initial check-in
|
220 |
4 |
arniml |
--
|
221 |
|
|
-------------------------------------------------------------------------------
|