1 |
6 |
jesus |
--
|
2 |
|
|
-- AT90Sxxxx compatible microcontroller core
|
3 |
|
|
--
|
4 |
24 |
jesus |
-- Version : 0221b
|
5 |
6 |
jesus |
--
|
6 |
|
|
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
|
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/t51/
|
42 |
|
|
--
|
43 |
|
|
-- Limitations :
|
44 |
|
|
--
|
45 |
|
|
-- File history :
|
46 |
|
|
--
|
47 |
|
|
|
48 |
|
|
library IEEE;
|
49 |
|
|
use IEEE.std_logic_1164.all;
|
50 |
|
|
use IEEE.numeric_std.all;
|
51 |
|
|
|
52 |
|
|
package AX_Pack is
|
53 |
|
|
|
54 |
|
|
component AX_ALU
|
55 |
22 |
jesus |
port(
|
56 |
6 |
jesus |
Clk : in std_logic;
|
57 |
|
|
ROM_Data : in std_logic_vector(15 downto 0);
|
58 |
|
|
A : in std_logic_vector(7 downto 0);
|
59 |
|
|
B : in std_logic_vector(7 downto 0);
|
60 |
22 |
jesus |
Q : out std_logic_vector(7 downto 0);
|
61 |
6 |
jesus |
SREG : in std_logic_vector(7 downto 0);
|
62 |
|
|
PassB : in std_logic;
|
63 |
|
|
Skip : in std_logic;
|
64 |
|
|
Do_Other : out std_logic;
|
65 |
|
|
Z_Skip : out std_logic;
|
66 |
22 |
jesus |
Status_D : out std_logic_vector(6 downto 0);
|
67 |
6 |
jesus |
Status_Wr : out std_logic_vector(6 downto 0) -- T,H,S,V,N,Z,C
|
68 |
|
|
);
|
69 |
|
|
end component;
|
70 |
|
|
|
71 |
|
|
component AX_PCS
|
72 |
|
|
generic(
|
73 |
|
|
HW_Stack : boolean
|
74 |
|
|
);
|
75 |
|
|
port(
|
76 |
|
|
Clk : in std_logic;
|
77 |
|
|
Reset_n : in std_logic;
|
78 |
|
|
Offs_In : in std_logic_vector(11 downto 0);
|
79 |
|
|
Z : in unsigned(15 downto 0);
|
80 |
|
|
Data_In : in std_logic_vector(7 downto 0);
|
81 |
|
|
Pause : in std_logic;
|
82 |
|
|
Push : in std_logic;
|
83 |
|
|
Pop : in std_logic;
|
84 |
|
|
HRet : in std_logic;
|
85 |
|
|
LRet : in std_logic;
|
86 |
|
|
ZJmp : in std_logic;
|
87 |
|
|
RJmp : in std_logic;
|
88 |
|
|
CInt : in std_logic_vector(3 downto 0);
|
89 |
|
|
IPending : in std_logic;
|
90 |
|
|
IPush : out std_logic;
|
91 |
|
|
NPC : out std_logic_vector(15 downto 0);
|
92 |
|
|
PC : out std_logic_vector(15 downto 0)
|
93 |
|
|
);
|
94 |
|
|
end component;
|
95 |
|
|
|
96 |
22 |
jesus |
component AX_DPRAM
|
97 |
|
|
port(
|
98 |
|
|
Clk : in std_logic;
|
99 |
|
|
Rst_n : in std_logic;
|
100 |
|
|
Wr : in std_logic;
|
101 |
|
|
Rd_Addr : in std_logic_vector(4 downto 0);
|
102 |
|
|
Wr_Addr : in std_logic_vector(4 downto 0);
|
103 |
|
|
Data_In : in std_logic_vector(7 downto 0);
|
104 |
|
|
Data_Out : out std_logic_vector(7 downto 0)
|
105 |
|
|
);
|
106 |
|
|
end component;
|
107 |
|
|
|
108 |
6 |
jesus |
component AX_Reg
|
109 |
|
|
generic(
|
110 |
|
|
BigISet : boolean
|
111 |
|
|
);
|
112 |
22 |
jesus |
port(
|
113 |
6 |
jesus |
Clk : in std_logic;
|
114 |
|
|
Reset_n : in std_logic;
|
115 |
|
|
Wr : in std_logic;
|
116 |
|
|
Rd_Addr : in std_logic_vector(4 downto 0);
|
117 |
|
|
Rr_Addr : in std_logic_vector(4 downto 0);
|
118 |
|
|
Data_In : in std_logic_vector(7 downto 0);
|
119 |
|
|
Rd_Data : out std_logic_vector(7 downto 0);
|
120 |
|
|
Rr_Data : out std_logic_vector(7 downto 0);
|
121 |
|
|
Add : in std_logic;
|
122 |
|
|
Sub : in std_logic;
|
123 |
|
|
AS_Offset : in std_logic_vector(5 downto 0);
|
124 |
|
|
AS_Reg : in std_logic_vector(1 downto 0);
|
125 |
|
|
Dec_X : in std_logic;
|
126 |
|
|
Dec_Y : in std_logic;
|
127 |
|
|
Dec_Z : in std_logic;
|
128 |
|
|
Inc_X : in std_logic;
|
129 |
|
|
Inc_Y : in std_logic;
|
130 |
|
|
Inc_Z : in std_logic;
|
131 |
|
|
X : out unsigned(15 downto 0);
|
132 |
|
|
Y : out unsigned(15 downto 0);
|
133 |
|
|
Z : out unsigned(15 downto 0);
|
134 |
|
|
Status_D : out std_logic_vector(4 downto 0) -- S,V,N,Z,C
|
135 |
|
|
);
|
136 |
|
|
end component;
|
137 |
|
|
|
138 |
|
|
component AX_RAM
|
139 |
|
|
generic(
|
140 |
|
|
RAMAddressWidth : integer
|
141 |
|
|
);
|
142 |
22 |
jesus |
port(
|
143 |
6 |
jesus |
Clk : in std_logic;
|
144 |
|
|
Rd_Addr : in std_logic_vector(RAMAddressWidth downto 0);
|
145 |
|
|
Wr_Addr : in std_logic_vector(RAMAddressWidth downto 0);
|
146 |
|
|
Wr : in std_logic;
|
147 |
|
|
Data_In : in std_logic_vector(7 downto 0);
|
148 |
|
|
Data_Out : out std_logic_vector(7 downto 0)
|
149 |
|
|
);
|
150 |
|
|
end component;
|
151 |
|
|
|
152 |
|
|
component AX8
|
153 |
|
|
generic(
|
154 |
|
|
ROMAddressWidth : integer;
|
155 |
|
|
RAMAddressWidth : integer;
|
156 |
|
|
BigISet : boolean
|
157 |
|
|
);
|
158 |
|
|
port(
|
159 |
|
|
Clk : in std_logic;
|
160 |
|
|
Reset_n : in std_logic;
|
161 |
|
|
ROM_Addr : out std_logic_vector(ROMAddressWidth - 1 downto 0);
|
162 |
|
|
ROM_Data : in std_logic_vector(15 downto 0);
|
163 |
|
|
Sleep_En : in std_logic;
|
164 |
|
|
Int_Trig : in std_logic_vector(15 downto 1);
|
165 |
|
|
Int_Acc : out std_logic_vector(15 downto 1);
|
166 |
24 |
jesus |
SREG : out std_logic_vector(7 downto 0);
|
167 |
|
|
SP : out std_logic_vector(15 downto 0);
|
168 |
6 |
jesus |
IO_Rd : out std_logic;
|
169 |
|
|
IO_Wr : out std_logic;
|
170 |
|
|
IO_Addr : out std_logic_vector(5 downto 0);
|
171 |
24 |
jesus |
IO_RData : in std_logic_vector(7 downto 0);
|
172 |
6 |
jesus |
IO_WData : out std_logic_vector(7 downto 0);
|
173 |
|
|
WDR : out std_logic
|
174 |
|
|
);
|
175 |
|
|
end component;
|
176 |
|
|
|
177 |
|
|
component AX_Port
|
178 |
|
|
port(
|
179 |
|
|
Clk : in std_logic;
|
180 |
|
|
Reset_n : in std_logic;
|
181 |
24 |
jesus |
PORT_Sel : in std_logic;
|
182 |
|
|
DDR_Sel : in std_logic;
|
183 |
|
|
PIN_Sel : in std_logic;
|
184 |
6 |
jesus |
Wr : in std_logic;
|
185 |
|
|
Data_In : in std_logic_vector(7 downto 0);
|
186 |
24 |
jesus |
Dir : out std_logic_vector(7 downto 0);
|
187 |
|
|
Port_Input : out std_logic_vector(7 downto 0);
|
188 |
|
|
Port_Output : out std_logic_vector(7 downto 0);
|
189 |
6 |
jesus |
IOPort : inout std_logic_vector(7 downto 0)
|
190 |
|
|
);
|
191 |
|
|
end component;
|
192 |
|
|
|
193 |
|
|
component AX_UART
|
194 |
7 |
jesus |
port(
|
195 |
6 |
jesus |
Clk : in std_logic;
|
196 |
|
|
Reset_n : in std_logic;
|
197 |
|
|
UDR_Sel : in std_logic;
|
198 |
|
|
USR_Sel : in std_logic;
|
199 |
|
|
UCR_Sel : in std_logic;
|
200 |
|
|
UBRR_Sel : in std_logic;
|
201 |
|
|
Rd : in std_logic;
|
202 |
|
|
Wr : in std_logic;
|
203 |
|
|
TXC_Clr : in std_logic;
|
204 |
|
|
Data_In : in std_logic_vector(7 downto 0);
|
205 |
24 |
jesus |
UDR : out std_logic_vector(7 downto 0);
|
206 |
|
|
USR : out std_logic_vector(7 downto 3);
|
207 |
|
|
UCR : out std_logic_vector(7 downto 0);
|
208 |
|
|
UBRR : out std_logic_vector(7 downto 0);
|
209 |
6 |
jesus |
RXD : in std_logic;
|
210 |
|
|
TXD : out std_logic;
|
211 |
|
|
Int_RX : out std_logic;
|
212 |
|
|
Int_TR : out std_logic;
|
213 |
|
|
Int_TC : out std_logic
|
214 |
|
|
);
|
215 |
|
|
end component;
|
216 |
|
|
|
217 |
|
|
component AX_TC8
|
218 |
|
|
port(
|
219 |
|
|
Clk : in std_logic;
|
220 |
|
|
Reset_n : in std_logic;
|
221 |
|
|
T : in std_logic;
|
222 |
|
|
TCCR_Sel : in std_logic;
|
223 |
|
|
TCNT_Sel : in std_logic;
|
224 |
|
|
Wr : in std_logic;
|
225 |
|
|
Data_In : in std_logic_vector(7 downto 0);
|
226 |
24 |
jesus |
TCCR : out std_logic_vector(2 downto 0);
|
227 |
|
|
TCNT : out std_logic_vector(7 downto 0);
|
228 |
6 |
jesus |
Int : out std_logic
|
229 |
|
|
);
|
230 |
|
|
end component;
|
231 |
|
|
|
232 |
|
|
component AX_TC16
|
233 |
|
|
port(
|
234 |
|
|
Clk : in std_logic;
|
235 |
|
|
Reset_n : in std_logic;
|
236 |
|
|
T : in std_logic;
|
237 |
|
|
ICP : in std_logic;
|
238 |
|
|
TCCR_Sel : in std_logic;
|
239 |
|
|
TCNT_Sel : in std_logic;
|
240 |
|
|
OCR_Sel : in std_logic;
|
241 |
|
|
ICR_Sel : in std_logic;
|
242 |
|
|
A0 : in std_logic;
|
243 |
|
|
Rd : in std_logic;
|
244 |
|
|
Wr : in std_logic;
|
245 |
|
|
Data_In : in std_logic_vector(7 downto 0);
|
246 |
24 |
jesus |
COM : out std_logic_vector(1 downto 0);
|
247 |
|
|
PWM : out std_logic_vector(1 downto 0);
|
248 |
|
|
CRBH : out std_logic_vector(1 downto 0);
|
249 |
|
|
CRBL : out std_logic_vector(3 downto 0);
|
250 |
|
|
TCNT : out std_logic_vector(15 downto 0);
|
251 |
|
|
IC : out std_logic_vector(15 downto 0);
|
252 |
|
|
OCR : out std_logic_vector(15 downto 0);
|
253 |
|
|
Tmp : out std_logic_vector(15 downto 0);
|
254 |
6 |
jesus |
OC : out std_logic;
|
255 |
|
|
Int_TO : out std_logic;
|
256 |
|
|
Int_OC : out std_logic;
|
257 |
|
|
Int_IC : out std_logic
|
258 |
|
|
);
|
259 |
|
|
end component;
|
260 |
|
|
|
261 |
|
|
procedure AddSub(A : std_logic_vector;
|
262 |
|
|
B : std_logic_vector;
|
263 |
|
|
Sub : std_logic;
|
264 |
|
|
Carry_In : std_logic;
|
265 |
|
|
signal Res : out std_logic_vector;
|
266 |
|
|
signal Carry : out std_logic);
|
267 |
|
|
|
268 |
|
|
end AX_Pack;
|
269 |
|
|
|
270 |
|
|
package body AX_Pack is
|
271 |
|
|
|
272 |
|
|
procedure AddSub(A : std_logic_vector;
|
273 |
|
|
B : std_logic_vector;
|
274 |
|
|
Sub : std_logic;
|
275 |
|
|
Carry_In : std_logic;
|
276 |
|
|
signal Res : out std_logic_vector;
|
277 |
|
|
signal Carry : out std_logic) is
|
278 |
|
|
variable B_i : unsigned(A'length downto 0);
|
279 |
|
|
variable Full_Carry : unsigned(A'length downto 0);
|
280 |
|
|
variable Res_i : unsigned(A'length downto 0);
|
281 |
|
|
begin
|
282 |
|
|
if Sub = '1' then
|
283 |
|
|
B_i := "0" & unsigned(not B);
|
284 |
|
|
else
|
285 |
|
|
B_i := "0" & unsigned(B);
|
286 |
|
|
end if;
|
287 |
|
|
if (Sub = '1' and Carry_In = '1') or (Sub = '0' and Carry_In = '1') then
|
288 |
|
|
Full_Carry := (others => '0');
|
289 |
|
|
Full_Carry(0) := '1';
|
290 |
|
|
else
|
291 |
|
|
Full_Carry := (others => '0');
|
292 |
|
|
end if;
|
293 |
|
|
Res_i := unsigned("0" & A) + B_i + Full_Carry;
|
294 |
|
|
Carry <= Res_i(A'length);
|
295 |
|
|
Res <= std_logic_vector(Res_i(A'length - 1 downto 0));
|
296 |
|
|
end;
|
297 |
|
|
|
298 |
|
|
end;
|