1 |
5 |
jesus |
--
|
2 |
|
|
-- 90S1200 compatible microcontroller core
|
3 |
|
|
--
|
4 |
25 |
jesus |
-- Version : 0224
|
5 |
5 |
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 |
25 |
jesus |
-- http://www.opencores.org/cvsweb.shtml/ax8/
|
42 |
5 |
jesus |
--
|
43 |
|
|
-- Limitations :
|
44 |
|
|
--
|
45 |
|
|
-- File history :
|
46 |
|
|
--
|
47 |
13 |
jesus |
-- 0146 : First release
|
48 |
|
|
-- 0220 : Changed to synchronous ROM
|
49 |
|
|
-- 0220b : Changed reset
|
50 |
24 |
jesus |
-- 0221 : Changed to configurable buses
|
51 |
25 |
jesus |
-- 0224 : Fixed timer interrupt enable
|
52 |
5 |
jesus |
|
53 |
|
|
--Registers: Comments:
|
54 |
|
|
--$3F SREG Status Register Implemented in the AX8 core
|
55 |
|
|
--$3B GIMSK General Interrupt Mask register
|
56 |
|
|
--$39 TIMSK Timer/Counter Interrupt Mask register
|
57 |
|
|
--$38 TIFR Timer/Counter Interrupt Flag register
|
58 |
|
|
--$35 MCUCR MCU general Control Register No power down
|
59 |
|
|
--$33 TCCR0 Timer/Counter 0 Control Register
|
60 |
|
|
--$32 TCNT0 Timer/Counter 0 (8-bit)
|
61 |
|
|
--$21 WDTCR Watchdog Timer Control Register Not implemented
|
62 |
|
|
--$1E EEAR EEPROM Address Register Not implemented
|
63 |
|
|
--$1D EEDR EEPROM Data Register Not implemented
|
64 |
|
|
--$1C EECR EEPROM Control Register Not implemented
|
65 |
|
|
--$18 PORTB Data Register, Port B No pullup
|
66 |
|
|
--$17 DDRB Data Direction Register, Port B
|
67 |
|
|
--$16 PINB Input Pins, Port B
|
68 |
|
|
--$12 PORTD Data Register, Port D No pullup
|
69 |
|
|
--$11 DDRD Data Direction Register, Port D
|
70 |
|
|
--$10 PIND Input Pins, Port D
|
71 |
|
|
--$08 ACSR Analog Comparator Control and Status Register Not implemented
|
72 |
|
|
|
73 |
|
|
library IEEE;
|
74 |
|
|
use IEEE.std_logic_1164.all;
|
75 |
|
|
use work.AX_Pack.all;
|
76 |
|
|
|
77 |
|
|
entity A90S1200 is
|
78 |
|
|
generic(
|
79 |
24 |
jesus |
SyncReset : boolean := true;
|
80 |
|
|
TriState : boolean := false
|
81 |
5 |
jesus |
);
|
82 |
|
|
port(
|
83 |
|
|
Clk : in std_logic;
|
84 |
|
|
Reset_n : in std_logic;
|
85 |
|
|
INT0 : in std_logic;
|
86 |
|
|
T0 : in std_logic;
|
87 |
|
|
Port_B : inout std_logic_vector(7 downto 0);
|
88 |
|
|
Port_D : inout std_logic_vector(7 downto 0)
|
89 |
|
|
);
|
90 |
|
|
end A90S1200;
|
91 |
|
|
|
92 |
|
|
architecture rtl of A90S1200 is
|
93 |
|
|
|
94 |
|
|
constant ROMAddressWidth : integer := 9;
|
95 |
|
|
constant RAMAddressWidth : integer := 0;
|
96 |
|
|
constant BigISet : boolean := false;
|
97 |
|
|
|
98 |
|
|
component ROM1200
|
99 |
|
|
port(
|
100 |
|
|
Clk : in std_logic;
|
101 |
|
|
A : in std_logic_vector(ROMAddressWidth - 1 downto 0);
|
102 |
|
|
D : out std_logic_vector(15 downto 0)
|
103 |
|
|
);
|
104 |
|
|
end component;
|
105 |
|
|
|
106 |
|
|
signal Reset_s_n : std_logic;
|
107 |
|
|
signal ROM_Addr : std_logic_vector(ROMAddressWidth - 1 downto 0);
|
108 |
|
|
signal ROM_Data : std_logic_vector(15 downto 0);
|
109 |
24 |
jesus |
signal SREG : std_logic_vector(7 downto 0);
|
110 |
5 |
jesus |
signal IO_Rd : std_logic;
|
111 |
|
|
signal IO_Wr : std_logic;
|
112 |
|
|
signal IO_Addr : std_logic_vector(5 downto 0);
|
113 |
|
|
signal IO_WData : std_logic_vector(7 downto 0);
|
114 |
|
|
signal IO_RData : std_logic_vector(7 downto 0);
|
115 |
|
|
signal TCCR_Sel : std_logic;
|
116 |
|
|
signal TCNT_Sel : std_logic;
|
117 |
|
|
signal PORTB_Sel : std_logic;
|
118 |
|
|
signal DDRB_Sel : std_logic;
|
119 |
|
|
signal PINB_Sel : std_logic;
|
120 |
|
|
signal PORTD_Sel : std_logic;
|
121 |
|
|
signal DDRD_Sel : std_logic;
|
122 |
|
|
signal PIND_Sel : std_logic;
|
123 |
|
|
signal Sleep_En : std_logic;
|
124 |
|
|
signal ISC0 : std_logic_vector(1 downto 0);
|
125 |
|
|
signal Int0_ET : std_logic;
|
126 |
|
|
signal Int0_En : std_logic;
|
127 |
|
|
signal Int0_r : std_logic_vector(1 downto 0);
|
128 |
|
|
signal TC_Trig : std_logic;
|
129 |
|
|
signal TOIE0 : std_logic;
|
130 |
|
|
signal TOV0 : std_logic;
|
131 |
|
|
signal Int_Trig : std_logic_vector(15 downto 1);
|
132 |
|
|
signal Int_Acc : std_logic_vector(15 downto 1);
|
133 |
24 |
jesus |
signal TCCR : std_logic_vector(2 downto 0);
|
134 |
|
|
signal TCNT : std_logic_vector(7 downto 0);
|
135 |
|
|
signal DirB : std_logic_vector(7 downto 0);
|
136 |
|
|
signal Port_InB : std_logic_vector(7 downto 0);
|
137 |
|
|
signal Port_OutB : std_logic_vector(7 downto 0);
|
138 |
|
|
signal DirD : std_logic_vector(7 downto 0);
|
139 |
|
|
signal Port_InD : std_logic_vector(7 downto 0);
|
140 |
|
|
signal Port_OutD : std_logic_vector(7 downto 0);
|
141 |
5 |
jesus |
|
142 |
|
|
begin
|
143 |
|
|
|
144 |
|
|
-- Synchronise reset
|
145 |
|
|
process (Reset_n, Clk)
|
146 |
|
|
variable Reset_v : std_logic;
|
147 |
|
|
begin
|
148 |
|
|
if Reset_n = '0' then
|
149 |
|
|
if SyncReset then
|
150 |
|
|
Reset_s_n <= '0';
|
151 |
|
|
Reset_v := '0';
|
152 |
|
|
end if;
|
153 |
|
|
elsif Clk'event and Clk = '1' then
|
154 |
|
|
if SyncReset then
|
155 |
|
|
Reset_s_n <= Reset_v;
|
156 |
|
|
Reset_v := '1';
|
157 |
|
|
end if;
|
158 |
|
|
end if;
|
159 |
|
|
end process;
|
160 |
|
|
|
161 |
|
|
g_reset : if not SyncReset generate
|
162 |
|
|
Reset_s_n <= Reset_n;
|
163 |
|
|
end generate;
|
164 |
|
|
|
165 |
|
|
-- Registers/Interrupts
|
166 |
|
|
process (Reset_s_n, Clk)
|
167 |
|
|
begin
|
168 |
|
|
if Reset_s_n = '0' then
|
169 |
|
|
Sleep_En <= '0';
|
170 |
|
|
ISC0 <= "00";
|
171 |
|
|
Int0_ET <= '0';
|
172 |
|
|
Int0_En <= '0';
|
173 |
|
|
Int0_r <= "11";
|
174 |
|
|
TOIE0 <= '0';
|
175 |
|
|
TOV0 <= '0';
|
176 |
|
|
elsif Clk'event and Clk = '1' then
|
177 |
|
|
Int0_r(0) <= INT0;
|
178 |
|
|
Int0_r(1) <= Int0_r(0);
|
179 |
|
|
if IO_Wr = '1' and IO_Addr = "110101" then -- $35 MCUCR
|
180 |
|
|
Sleep_En <= IO_WData(5);
|
181 |
|
|
ISC0 <= IO_WData(1 downto 0);
|
182 |
|
|
end if;
|
183 |
|
|
if IO_Wr = '1' and IO_Addr = "111011" then -- $3B GIMSK
|
184 |
|
|
Int0_En <= IO_WData(6);
|
185 |
|
|
end if;
|
186 |
|
|
if IO_Wr = '1' and IO_Addr = "111001" then -- $39 TIMSK
|
187 |
|
|
TOIE0 <= IO_WData(1);
|
188 |
|
|
end if;
|
189 |
|
|
if IO_Wr = '1' and IO_Addr = "111000" then -- $38 TIFR
|
190 |
|
|
if IO_WData(1) = '1' then
|
191 |
|
|
TOV0 <= '0';
|
192 |
|
|
end if;
|
193 |
|
|
end if;
|
194 |
|
|
if Int_Acc(2) = '1' then
|
195 |
|
|
TOV0 <= '0';
|
196 |
|
|
end if;
|
197 |
|
|
if TC_Trig = '1' then
|
198 |
|
|
TOV0 <= '1';
|
199 |
|
|
end if;
|
200 |
|
|
if Int_Acc(1) = '1' then
|
201 |
|
|
Int0_ET <= '0';
|
202 |
|
|
end if;
|
203 |
|
|
if (ISC0 = "10" and Int0_r = "10") or (ISC0 = "11" and Int0_r = "01") then
|
204 |
|
|
Int0_ET <= '1';
|
205 |
|
|
end if;
|
206 |
|
|
end if;
|
207 |
|
|
end process;
|
208 |
|
|
|
209 |
|
|
Int_Trig(1) <= '0' when Int0_En = '0' else not Int0_r(1) when ISC0 = "00" else Int0_ET;
|
210 |
25 |
jesus |
Int_Trig(2) <= '1' when TOIE0 = '1' and TOV0 = '1' else '0';
|
211 |
5 |
jesus |
Int_Trig(15 downto 3) <= (others => '0');
|
212 |
|
|
|
213 |
|
|
rom : ROM1200 port map (
|
214 |
|
|
Clk => Clk,
|
215 |
|
|
A => ROM_Addr,
|
216 |
|
|
D => ROM_Data);
|
217 |
|
|
|
218 |
|
|
ax : AX8
|
219 |
|
|
generic map(
|
220 |
|
|
ROMAddressWidth => ROMAddressWidth,
|
221 |
|
|
RAMAddressWidth => RAMAddressWidth,
|
222 |
|
|
BigIset => BigIset)
|
223 |
|
|
port map (
|
224 |
|
|
Clk => Clk,
|
225 |
|
|
Reset_n => Reset_s_n,
|
226 |
|
|
ROM_Addr => ROM_Addr,
|
227 |
|
|
ROM_Data => ROM_Data,
|
228 |
|
|
Sleep_En => Sleep_En,
|
229 |
|
|
Int_Trig => Int_Trig,
|
230 |
|
|
Int_Acc => Int_Acc,
|
231 |
24 |
jesus |
SREG => SREG,
|
232 |
5 |
jesus |
IO_Rd => IO_Rd,
|
233 |
|
|
IO_Wr => IO_Wr,
|
234 |
|
|
IO_Addr => IO_Addr,
|
235 |
24 |
jesus |
IO_RData => IO_RData,
|
236 |
|
|
IO_WData => IO_WData);
|
237 |
5 |
jesus |
|
238 |
|
|
TCCR_Sel <= '1' when IO_Addr = "110011" else '0'; -- $33 TCCR0
|
239 |
|
|
TCNT_Sel <= '1' when IO_Addr = "110010" else '0'; -- $32 TCNT0
|
240 |
|
|
tc : AX_TC8 port map(
|
241 |
|
|
Clk => Clk,
|
242 |
|
|
Reset_n => Reset_s_n,
|
243 |
|
|
T => T0,
|
244 |
|
|
TCCR_Sel => TCCR_Sel,
|
245 |
|
|
TCNT_Sel => TCNT_Sel,
|
246 |
|
|
Wr => IO_Wr,
|
247 |
|
|
Data_In => IO_WData,
|
248 |
24 |
jesus |
TCCR => TCCR,
|
249 |
|
|
TCNT => TCNT,
|
250 |
5 |
jesus |
Int => TC_Trig);
|
251 |
|
|
|
252 |
|
|
PINB_Sel <= '1' when IO_Addr = "010101" else '0';
|
253 |
|
|
DDRB_Sel <= '1' when IO_Addr = "010111" else '0';
|
254 |
|
|
PORTB_Sel <= '1' when IO_Addr = "011000" else '0';
|
255 |
|
|
PIND_Sel <= '1' when IO_Addr = "010000" else '0';
|
256 |
|
|
DDRD_Sel <= '1' when IO_Addr = "010001" else '0';
|
257 |
|
|
PORTD_Sel <= '1' when IO_Addr = "010010" else '0';
|
258 |
24 |
jesus |
portb : AX_Port port map(
|
259 |
5 |
jesus |
Clk => Clk,
|
260 |
|
|
Reset_n => Reset_s_n,
|
261 |
|
|
PORT_Sel => PORTB_Sel,
|
262 |
|
|
DDR_Sel => DDRB_Sel,
|
263 |
|
|
PIN_Sel => PINB_Sel,
|
264 |
|
|
Wr => IO_Wr,
|
265 |
|
|
Data_In => IO_WData,
|
266 |
24 |
jesus |
Dir => DirB,
|
267 |
|
|
Port_Input => Port_InB,
|
268 |
|
|
Port_Output => Port_OutB,
|
269 |
5 |
jesus |
IOPort => Port_B);
|
270 |
24 |
jesus |
portd : AX_Port port map(
|
271 |
5 |
jesus |
Clk => Clk,
|
272 |
|
|
Reset_n => Reset_s_n,
|
273 |
|
|
PORT_Sel => PORTD_Sel,
|
274 |
|
|
DDR_Sel => DDRD_Sel,
|
275 |
|
|
PIN_Sel => PIND_Sel,
|
276 |
|
|
Wr => IO_Wr,
|
277 |
|
|
Data_In => IO_WData,
|
278 |
24 |
jesus |
Dir => DirD,
|
279 |
|
|
Port_Input => Port_InD,
|
280 |
|
|
Port_Output => Port_OutD,
|
281 |
5 |
jesus |
IOPort => Port_D);
|
282 |
|
|
|
283 |
24 |
jesus |
gNoTri : if not TriState generate
|
284 |
|
|
with IO_Addr select
|
285 |
|
|
IO_RData <= SREG when "111111",
|
286 |
|
|
"00" & Sleep_En & "000" & ISC0 when "110101",
|
287 |
|
|
"0" & Int0_En & "000000" when "111011",
|
288 |
|
|
"000000" & TOIE0 & "0" when "111001",
|
289 |
|
|
"000000" & TOV0 & "0" when "111000",
|
290 |
|
|
"00000" & TCCR when "110011",
|
291 |
|
|
TCNT when "110010",
|
292 |
|
|
Port_InB when "010101",
|
293 |
|
|
DirB when "010111",
|
294 |
|
|
Port_OutB when "011000",
|
295 |
|
|
Port_InD when "010000",
|
296 |
|
|
DirD when "010001",
|
297 |
|
|
Port_OutD when "010010",
|
298 |
|
|
"--------" when others;
|
299 |
|
|
end generate;
|
300 |
|
|
gTri : if TriState generate
|
301 |
|
|
IO_RData <= SREG when IO_Addr = "111111" else "ZZZZZZZZ";
|
302 |
|
|
|
303 |
|
|
IO_RData <= "00" & Sleep_En & "000" & ISC0 when IO_Addr = "110101" else "ZZZZZZZZ";
|
304 |
|
|
IO_RData <= "0" & Int0_En & "000000" when IO_Addr = "111011" else "ZZZZZZZZ";
|
305 |
|
|
IO_RData <= "000000" & TOIE0 & "0" when IO_Addr = "111001" else "ZZZZZZZZ";
|
306 |
|
|
IO_RData <= "000000" & TOV0 & "0" when IO_Addr = "111000" else "ZZZZZZZZ";
|
307 |
|
|
|
308 |
|
|
IO_RData <= "00000" & TCCR when TCCR_Sel = '1' else "ZZZZZZZZ";
|
309 |
|
|
IO_RData <= TCNT when TCNT_Sel = '1' else "ZZZZZZZZ";
|
310 |
|
|
|
311 |
|
|
IO_RData <= Port_InB when PINB_Sel = '1' else "ZZZZZZZZ";
|
312 |
|
|
IO_RData <= DirB when DDRB_Sel = '1' else "ZZZZZZZZ";
|
313 |
|
|
IO_RData <= Port_OutB when PORTB_Sel = '1' else "ZZZZZZZZ";
|
314 |
|
|
|
315 |
|
|
IO_RData <= Port_InD when PIND_Sel = '1' else "ZZZZZZZZ";
|
316 |
|
|
IO_RData <= DirD when DDRD_Sel = '1' else "ZZZZZZZZ";
|
317 |
|
|
IO_RData <= Port_OutD when PORTD_Sel = '1' else "ZZZZZZZZ";
|
318 |
|
|
end generate;
|
319 |
|
|
|
320 |
5 |
jesus |
end;
|