1 |
2 |
arniml |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- The Data memory controller.
|
4 |
|
|
--
|
5 |
|
|
-- $Id: t400_dmem_ctrl.vhd,v 1.1.1.1 2006-05-06 01:56:44 arniml Exp $
|
6 |
|
|
--
|
7 |
|
|
-- Copyright (c) 2006 Arnim Laeuger (arniml@opencores.org)
|
8 |
|
|
--
|
9 |
|
|
-- All rights reserved
|
10 |
|
|
--
|
11 |
|
|
-- Redistribution and use in source and synthezised forms, with or without
|
12 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
13 |
|
|
--
|
14 |
|
|
-- Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
-- this list of conditions and the following disclaimer.
|
16 |
|
|
--
|
17 |
|
|
-- Redistributions in synthesized form must reproduce the above copyright
|
18 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
19 |
|
|
-- documentation and/or other materials provided with the distribution.
|
20 |
|
|
--
|
21 |
|
|
-- Neither the name of the author nor the names of other contributors may
|
22 |
|
|
-- be used to endorse or promote products derived from this software without
|
23 |
|
|
-- specific prior written permission.
|
24 |
|
|
--
|
25 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
26 |
|
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
27 |
|
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
28 |
|
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
29 |
|
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
30 |
|
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
31 |
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
32 |
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
33 |
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
34 |
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
36 |
|
|
--
|
37 |
|
|
-- Please report bugs to the author, but before you do so, please
|
38 |
|
|
-- make sure that this is not a derivative work and that
|
39 |
|
|
-- you have the latest version of this file.
|
40 |
|
|
--
|
41 |
|
|
-- The latest version of this file can be found at:
|
42 |
|
|
-- http://www.opencores.org/cvsweb.shtml/t400/
|
43 |
|
|
--
|
44 |
|
|
-------------------------------------------------------------------------------
|
45 |
|
|
|
46 |
|
|
library ieee;
|
47 |
|
|
use ieee.std_logic_1164.all;
|
48 |
|
|
|
49 |
|
|
use work.t400_opt_pack.all;
|
50 |
|
|
use work.t400_pack.all;
|
51 |
|
|
|
52 |
|
|
entity t400_dmem_ctrl is
|
53 |
|
|
|
54 |
|
|
generic (
|
55 |
|
|
opt_type_g : integer := t400_opt_type_420_c
|
56 |
|
|
);
|
57 |
|
|
port (
|
58 |
|
|
-- System Interface -------------------------------------------------------
|
59 |
|
|
ck_i : in std_logic;
|
60 |
|
|
ck_en_i : in boolean;
|
61 |
|
|
por_i : in boolean;
|
62 |
|
|
res_i : in boolean;
|
63 |
|
|
-- Control Interface ------------------------------------------------------
|
64 |
|
|
dmem_op_i : in dmem_op_t;
|
65 |
|
|
b_op_i : in b_op_t;
|
66 |
|
|
dec_data_i : in dec_data_t;
|
67 |
|
|
a_i : in dw_t;
|
68 |
|
|
q_high_i : in dw_t;
|
69 |
|
|
b_o : out b_t;
|
70 |
|
|
-- Data Memory Interface --------------------------------------------------
|
71 |
|
|
dm_addr_o : out dm_addr_t;
|
72 |
|
|
dm_data_i : in dw_t;
|
73 |
|
|
dm_data_o : out dw_t;
|
74 |
|
|
dm_we_o : out std_logic
|
75 |
|
|
);
|
76 |
|
|
|
77 |
|
|
end t400_dmem_ctrl;
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
library ieee;
|
81 |
|
|
use ieee.numeric_std.all;
|
82 |
|
|
|
83 |
|
|
architecture rtl of t400_dmem_ctrl is
|
84 |
|
|
|
85 |
|
|
signal br_q : unsigned(br_range_t);
|
86 |
|
|
signal bd_q : unsigned(bd_range_t);
|
87 |
|
|
|
88 |
|
|
begin
|
89 |
|
|
|
90 |
|
|
-----------------------------------------------------------------------------
|
91 |
|
|
-- Process b_reg
|
92 |
|
|
--
|
93 |
|
|
-- Purpose:
|
94 |
|
|
-- Implements the B register.
|
95 |
|
|
--
|
96 |
|
|
b_reg: process (ck_i, por_i)
|
97 |
|
|
begin
|
98 |
|
|
if por_i then
|
99 |
|
|
br_q <= (others => '0');
|
100 |
|
|
bd_q <= (others => '0');
|
101 |
|
|
|
102 |
|
|
elsif ck_i'event and ck_i = '1' then
|
103 |
|
|
if res_i then
|
104 |
|
|
-- synchronous reset upon external reset event
|
105 |
|
|
br_q <= (others => '0');
|
106 |
|
|
bd_q <= (others => '0');
|
107 |
|
|
|
108 |
|
|
elsif ck_en_i then
|
109 |
|
|
case b_op_i is
|
110 |
|
|
-- Set Bd from accumulator ------------------------------------------
|
111 |
|
|
when B_SET_BD =>
|
112 |
|
|
bd_q <= unsigned(a_i);
|
113 |
|
|
|
114 |
|
|
-- Set Br from accumulator ------------------------------------------
|
115 |
|
|
when B_SET_BR =>
|
116 |
|
|
br_q <= unsigned(a_i(1 downto 0));
|
117 |
|
|
|
118 |
|
|
-- Set Br and Bd from decoder data ----------------------------------
|
119 |
|
|
when B_SET_B =>
|
120 |
|
|
br_q <= unsigned(dec_data_i(br_range_t));
|
121 |
|
|
bd_q <= unsigned(dec_data_i(bd_range_t));
|
122 |
|
|
|
123 |
|
|
-- Set Br and Bd from decoder data, increment value for Bd ----------
|
124 |
|
|
when B_SET_B_INC =>
|
125 |
|
|
br_q <= unsigned(dec_data_i(br_range_t));
|
126 |
|
|
bd_q <= unsigned(dec_data_i(bd_range_t)) + 1;
|
127 |
|
|
|
128 |
|
|
-- XOR Br with decoder data -----------------------------------------
|
129 |
|
|
when B_XOR_BR =>
|
130 |
|
|
br_q <= br_q xor unsigned(dec_data_i(br_range_t));
|
131 |
|
|
|
132 |
|
|
-- Increment Bd -----------------------------------------------------
|
133 |
|
|
when B_INC_BD =>
|
134 |
|
|
bd_q <= bd_q + 1;
|
135 |
|
|
|
136 |
|
|
-- Increment Bd -----------------------------------------------------
|
137 |
|
|
when B_DEC_BD =>
|
138 |
|
|
bd_q <= bd_q - 1;
|
139 |
|
|
|
140 |
|
|
when others =>
|
141 |
|
|
null;
|
142 |
|
|
end case;
|
143 |
|
|
|
144 |
|
|
end if;
|
145 |
|
|
end if;
|
146 |
|
|
end process b_reg;
|
147 |
|
|
--
|
148 |
|
|
-----------------------------------------------------------------------------
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
-----------------------------------------------------------------------------
|
152 |
|
|
-- Process data_mux
|
153 |
|
|
--
|
154 |
|
|
-- Purpose:
|
155 |
|
|
-- Multiplexes the data for writing to the memory.
|
156 |
|
|
--
|
157 |
|
|
data_mux: process (dmem_op_i,
|
158 |
|
|
br_q, bd_q,
|
159 |
|
|
a_i,
|
160 |
|
|
q_high_i,
|
161 |
|
|
dec_data_i,
|
162 |
|
|
dm_data_i,
|
163 |
|
|
ck_en_i)
|
164 |
|
|
variable dm_addr_v : dm_addr_t;
|
165 |
|
|
variable dm_data_v : dw_t;
|
166 |
|
|
variable dm_we_v : std_logic;
|
167 |
|
|
variable bd_v : std_logic_vector(2 downto 0);
|
168 |
|
|
begin
|
169 |
|
|
-- default assignment
|
170 |
|
|
dm_addr_v(br_range_t) := std_logic_vector(br_q);
|
171 |
|
|
dm_addr_v(bd_range_t) := std_logic_vector(bd_q);
|
172 |
|
|
dm_data_v := (others => '0');
|
173 |
|
|
dm_we_v := '0';
|
174 |
|
|
|
175 |
|
|
case dmem_op_i is
|
176 |
|
|
-- Read data memory, indexed by B ---------------------------------------
|
177 |
|
|
when DMEM_RB =>
|
178 |
|
|
null;
|
179 |
|
|
|
180 |
|
|
-- Write data memory, indexed by B, source is Q -------------------------
|
181 |
|
|
when DMEM_WB_SRC_Q =>
|
182 |
|
|
dm_we_v := '1';
|
183 |
|
|
dm_data_v := q_high_i;
|
184 |
|
|
|
185 |
|
|
-- Write data memory, indexed by B, source is decoder data --------------
|
186 |
|
|
when DMEM_WB_SRC_DEC =>
|
187 |
|
|
dm_we_v := '1';
|
188 |
|
|
dm_data_v := dec_data_i(bd_range_t);
|
189 |
|
|
|
190 |
|
|
-- Write data memory, indexed by B, source is accumulator ---------------
|
191 |
|
|
when DMEM_WB_SRC_A =>
|
192 |
|
|
dm_we_v := '1';
|
193 |
|
|
dm_data_v := a_i;
|
194 |
|
|
|
195 |
|
|
-- Read data memory, indexed by decoder data ----------------------------
|
196 |
|
|
when DMEM_RDEC =>
|
197 |
|
|
dm_addr_v := dec_data_i(br_range_t'high downto 0);
|
198 |
|
|
|
199 |
|
|
-- Write data memory, indexed by decoder data, source is accumulator ----
|
200 |
|
|
when DMEM_WDEC_SRC_A =>
|
201 |
|
|
dm_we_v := '1';
|
202 |
|
|
dm_addr_v := dec_data_i(br_range_t'high downto 0);
|
203 |
|
|
dm_data_v := a_i;
|
204 |
|
|
|
205 |
|
|
-- Write data memory, indexed by B, set bit -----------------------------
|
206 |
|
|
when DMEM_WB_SET_BIT =>
|
207 |
|
|
dm_we_v := '1';
|
208 |
|
|
dm_data_v := dm_data_i or dec_data_i(dw_range_t);
|
209 |
|
|
|
210 |
|
|
-- Write data memory, indexed by B, reset bit ---------------------------
|
211 |
|
|
when DMEM_WB_RES_BIT =>
|
212 |
|
|
dm_we_v := '1';
|
213 |
|
|
dm_data_v := dm_data_i and not dec_data_i(dw_range_t);
|
214 |
|
|
|
215 |
|
|
when others =>
|
216 |
|
|
null;
|
217 |
|
|
end case;
|
218 |
|
|
|
219 |
|
|
-- adjust address vector for 41xL family members
|
220 |
|
|
if opt_type_g = t400_opt_type_410_c then
|
221 |
|
|
dm_addr_v := '0' & dm_addr_v(br_range_t) &
|
222 |
|
|
dm_addr_v(bd_range_t'high-1 downto 0);
|
223 |
|
|
end if;
|
224 |
|
|
|
225 |
|
|
dm_addr_o <= dm_addr_v;
|
226 |
|
|
|
227 |
|
|
if ck_en_i then
|
228 |
|
|
dm_we_o <= dm_we_v;
|
229 |
|
|
else
|
230 |
|
|
dm_we_o <= '0';
|
231 |
|
|
end if;
|
232 |
|
|
dm_data_o <= dm_data_v;
|
233 |
|
|
end process data_mux;
|
234 |
|
|
--
|
235 |
|
|
-----------------------------------------------------------------------------
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
-----------------------------------------------------------------------------
|
239 |
|
|
-- Output mapping
|
240 |
|
|
-----------------------------------------------------------------------------
|
241 |
|
|
b_o(br_range_t) <= std_logic_vector(br_q);
|
242 |
|
|
b_o(bd_range_t) <= std_logic_vector(bd_q);
|
243 |
|
|
|
244 |
|
|
end rtl;
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
-------------------------------------------------------------------------------
|
248 |
|
|
-- File History:
|
249 |
|
|
--
|
250 |
|
|
-- $Log: not supported by cvs2svn $
|
251 |
|
|
-------------------------------------------------------------------------------
|