1 |
4 |
arniml |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- The Program Memory control unit.
|
4 |
|
|
-- All operations related to the Program Memory are managed here.
|
5 |
|
|
--
|
6 |
|
|
-- $Id: pmem_ctrl.vhd,v 1.1 2004-03-23 21:31:53 arniml Exp $
|
7 |
|
|
--
|
8 |
|
|
-- All rights reserved
|
9 |
|
|
--
|
10 |
|
|
-- Redistribution and use in source and synthezised forms, with or without
|
11 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
12 |
|
|
--
|
13 |
|
|
-- Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
-- this list of conditions and the following disclaimer.
|
15 |
|
|
--
|
16 |
|
|
-- Redistributions in synthesized form must reproduce the above copyright
|
17 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
18 |
|
|
-- documentation and/or other materials provided with the distribution.
|
19 |
|
|
--
|
20 |
|
|
-- Neither the name of the author nor the names of other contributors may
|
21 |
|
|
-- be used to endorse or promote products derived from this software without
|
22 |
|
|
-- specific prior written permission.
|
23 |
|
|
--
|
24 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25 |
|
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
26 |
|
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
27 |
|
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
28 |
|
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
29 |
|
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
30 |
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31 |
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
32 |
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
33 |
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
34 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
35 |
|
|
--
|
36 |
|
|
-- Please report bugs to the author, but before you do so, please
|
37 |
|
|
-- make sure that this is not a derivative work and that
|
38 |
|
|
-- you have the latest version of this file.
|
39 |
|
|
--
|
40 |
|
|
-- The latest version of this file can be found at:
|
41 |
|
|
-- http://www.opencores.org/cvsweb.shtml/t48/
|
42 |
|
|
--
|
43 |
|
|
-------------------------------------------------------------------------------
|
44 |
|
|
|
45 |
|
|
library ieee;
|
46 |
|
|
use ieee.std_logic_1164.all;
|
47 |
|
|
|
48 |
|
|
use work.t48_pack.pmem_addr_t;
|
49 |
|
|
use work.t48_pack.word_t;
|
50 |
|
|
use work.pmem_ctrl_pack.pmem_addr_ident_t;
|
51 |
|
|
|
52 |
|
|
entity pmem_ctrl is
|
53 |
|
|
|
54 |
|
|
port (
|
55 |
|
|
-- Global Interface -------------------------------------------------------
|
56 |
|
|
clk_i : in std_logic;
|
57 |
|
|
res_i : in std_logic;
|
58 |
|
|
en_clk_i : in boolean;
|
59 |
|
|
-- T48 Bus Interface ------------------------------------------------------
|
60 |
|
|
data_i : in word_t;
|
61 |
|
|
data_o : out word_t;
|
62 |
|
|
write_pcl_i : in boolean;
|
63 |
|
|
read_pcl_i : in boolean;
|
64 |
|
|
write_pch_i : in boolean;
|
65 |
|
|
read_pch_i : in boolean;
|
66 |
|
|
inc_pc_i : in boolean;
|
67 |
|
|
write_pmem_addr_i : in boolean;
|
68 |
|
|
addr_type_i : in pmem_addr_ident_t;
|
69 |
|
|
read_pmem_i : in boolean;
|
70 |
|
|
-- Porgram Memroy Interface -----------------------------------------------
|
71 |
|
|
pmem_addr_o : out pmem_addr_t;
|
72 |
|
|
pmem_data_i : in word_t
|
73 |
|
|
);
|
74 |
|
|
|
75 |
|
|
end pmem_ctrl;
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
library ieee;
|
79 |
|
|
use ieee.std_logic_arith.all;
|
80 |
|
|
|
81 |
|
|
use work.pmem_ctrl_pack.all;
|
82 |
|
|
use work.t48_pack.res_active_c;
|
83 |
|
|
use work.t48_pack.clk_active_c;
|
84 |
|
|
use work.t48_pack.bus_idle_level_c;
|
85 |
|
|
use work.t48_pack.pmem_addr_width_c;
|
86 |
|
|
use work.t48_pack.dmem_addr_width_c;
|
87 |
|
|
use work.t48_pack.page_t;
|
88 |
|
|
|
89 |
|
|
architecture rtl of pmem_ctrl is
|
90 |
|
|
|
91 |
|
|
-- the Program Counter
|
92 |
|
|
signal program_counter_q : unsigned(pmem_addr_t'range);
|
93 |
|
|
|
94 |
|
|
-- the Program Memory address
|
95 |
|
|
signal pmem_addr_s,
|
96 |
|
|
pmem_addr_q : std_logic_vector(pmem_addr_t'range);
|
97 |
|
|
|
98 |
|
|
begin
|
99 |
|
|
|
100 |
|
|
-----------------------------------------------------------------------------
|
101 |
|
|
-- Process program_counter
|
102 |
|
|
--
|
103 |
|
|
-- Purpose:
|
104 |
|
|
-- Implements the Program Counter.
|
105 |
|
|
--
|
106 |
|
|
program_counter: process (res_i, clk_i)
|
107 |
|
|
begin
|
108 |
|
|
if res_i = res_active_c then
|
109 |
|
|
program_counter_q <= (others => '0');
|
110 |
|
|
pmem_addr_q <= (others => '0');
|
111 |
|
|
|
112 |
|
|
elsif clk_i'event and clk_i = clk_active_c then
|
113 |
|
|
if en_clk_i then
|
114 |
|
|
|
115 |
|
|
-- parallel load mode
|
116 |
|
|
if write_pcl_i then
|
117 |
|
|
program_counter_q(data_i'range) <= UNSIGNED(data_i);
|
118 |
|
|
elsif write_pch_i then
|
119 |
|
|
program_counter_q(pmem_addr_width_c-1 downto data_i'high+1) <=
|
120 |
|
|
UNSIGNED(data_i(pmem_addr_width_c - dmem_addr_width_c - 1 downto 0));
|
121 |
|
|
elsif inc_pc_i then
|
122 |
|
|
-- increment mode
|
123 |
|
|
program_counter_q <= program_counter_q + 1;
|
124 |
|
|
end if;
|
125 |
|
|
|
126 |
|
|
-- set pmem address
|
127 |
|
|
if write_pmem_addr_i then
|
128 |
|
|
pmem_addr_q <= pmem_addr_s;
|
129 |
|
|
end if;
|
130 |
|
|
|
131 |
|
|
end if;
|
132 |
|
|
|
133 |
|
|
end if;
|
134 |
|
|
|
135 |
|
|
end process program_counter;
|
136 |
|
|
--
|
137 |
|
|
-----------------------------------------------------------------------------
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
-----------------------------------------------------------------------------
|
141 |
|
|
-- Process pmem_addr
|
142 |
|
|
--
|
143 |
|
|
-- Purpose:
|
144 |
|
|
-- Multiplex the Program Memory address.
|
145 |
|
|
--
|
146 |
|
|
pmem_addr: process (program_counter_q,
|
147 |
|
|
addr_type_i,
|
148 |
|
|
pmem_addr_q,
|
149 |
|
|
data_i)
|
150 |
|
|
begin
|
151 |
|
|
-- default assignment
|
152 |
|
|
pmem_addr_s <= CONV_STD_LOGIC_VECTOR(program_counter_q,
|
153 |
|
|
pmem_addr_s'length);
|
154 |
|
|
|
155 |
|
|
case addr_type_i is
|
156 |
|
|
when PM_PC =>
|
157 |
|
|
-- default is ok
|
158 |
|
|
null;
|
159 |
|
|
|
160 |
|
|
when PM_PAGE =>
|
161 |
|
|
pmem_addr_s(word_t'range) <= data_i;
|
162 |
|
|
-- take page address from program counter
|
163 |
|
|
-- => important for JMPP, MOVP!
|
164 |
|
|
-- they must wrap to next page when at FF!
|
165 |
|
|
|
166 |
|
|
when PM_PAGE3 =>
|
167 |
|
|
pmem_addr_s(word_t'range) <= data_i;
|
168 |
|
|
-- page address is explicitely specified
|
169 |
|
|
pmem_addr_s(page_t'range) <= "0011";
|
170 |
|
|
|
171 |
|
|
when others =>
|
172 |
|
|
null;
|
173 |
|
|
|
174 |
|
|
end case;
|
175 |
|
|
|
176 |
|
|
end process pmem_addr;
|
177 |
|
|
--
|
178 |
|
|
-----------------------------------------------------------------------------
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
-----------------------------------------------------------------------------
|
182 |
|
|
-- Process data_output
|
183 |
|
|
--
|
184 |
|
|
-- Purpose:
|
185 |
|
|
-- Multiplex the data bus output.
|
186 |
|
|
--
|
187 |
|
|
data_output: process (read_pmem_i,
|
188 |
|
|
read_pcl_i,
|
189 |
|
|
read_pch_i,
|
190 |
|
|
pmem_data_i,
|
191 |
|
|
program_counter_q)
|
192 |
|
|
begin
|
193 |
|
|
data_o <= (others => bus_idle_level_c);
|
194 |
|
|
|
195 |
|
|
if read_pmem_i then
|
196 |
|
|
data_o <= pmem_data_i;
|
197 |
|
|
elsif read_pcl_i then
|
198 |
|
|
data_o <= CONV_STD_LOGIC_VECTOR(program_counter_q(data_o'range), data_o'length);
|
199 |
|
|
elsif read_pch_i then
|
200 |
|
|
data_o(3 downto 0) <= CONV_STD_LOGIC_VECTOR(program_counter_q(pmem_addr_width_c-1 downto data_o'high+1), 4);
|
201 |
|
|
end if;
|
202 |
|
|
|
203 |
|
|
end process data_output;
|
204 |
|
|
--
|
205 |
|
|
-----------------------------------------------------------------------------
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
-----------------------------------------------------------------------------
|
209 |
|
|
-- Output Mapping.
|
210 |
|
|
-----------------------------------------------------------------------------
|
211 |
|
|
pmem_addr_o <= pmem_addr_q;
|
212 |
|
|
|
213 |
|
|
end rtl;
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
-------------------------------------------------------------------------------
|
217 |
|
|
-- File History:
|
218 |
|
|
--
|
219 |
|
|
-- $Log: not supported by cvs2svn $
|
220 |
|
|
--
|
221 |
|
|
-------------------------------------------------------------------------------
|