1 |
2 |
idiolatrie |
--------------------------------------------------------------------------------
|
2 |
|
|
-- layer[2] System-on-a-Chip --
|
3 |
|
|
--------------------------------------------------------------------------------
|
4 |
|
|
-- Copyright (C)2011 Mathias Hörtnagl <mathias.hoertnagl@gmail.comt> --
|
5 |
|
|
-- --
|
6 |
|
|
-- This program is free software: you can redistribute it and/or modify --
|
7 |
|
|
-- it under the terms of the GNU General Public License as published by --
|
8 |
|
|
-- the Free Software Foundation, either version 3 of the License, or --
|
9 |
|
|
-- (at your option) any later version. --
|
10 |
|
|
-- --
|
11 |
|
|
-- This program is distributed in the hope that it will be useful, --
|
12 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
|
13 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
|
14 |
|
|
-- GNU General Public License for more details. --
|
15 |
|
|
-- --
|
16 |
|
|
-- You should have received a copy of the GNU General Public License --
|
17 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
|
18 |
|
|
--------------------------------------------------------------------------------
|
19 |
|
|
library ieee;
|
20 |
|
|
use ieee.std_logic_1164.all;
|
21 |
|
|
use ieee.numeric_std.all;
|
22 |
|
|
|
23 |
|
|
library work;
|
24 |
|
|
use work.iwb.all;
|
25 |
|
|
use work.iwbm.all;
|
26 |
|
|
use work.icon.all;
|
27 |
|
|
use work.icpu.all;
|
28 |
|
|
use work.imem.all;
|
29 |
|
|
use work.iflash.all;
|
30 |
|
|
use work.iddr.all;
|
31 |
|
|
use work.ivga.all;
|
32 |
|
|
use work.ikeyb.all;
|
33 |
|
|
use work.ipit.all;
|
34 |
|
|
use work.iuart.all;
|
35 |
|
|
|
36 |
|
|
entity layer2 is
|
37 |
|
|
port(
|
38 |
|
|
CLK_I : in std_logic;
|
39 |
|
|
-- Flash
|
40 |
|
|
SF_OE : out std_logic;
|
41 |
|
|
SF_CE : out std_logic;
|
42 |
|
|
SF_WE : out std_logic;
|
43 |
|
|
SF_BYTE : out std_logic;
|
44 |
|
|
--SF_STS : in std_logic;
|
45 |
|
|
SF_A : out std_logic_vector(23 downto 0);
|
46 |
|
|
SF_D : inout std_logic_vector(7 downto 0);
|
47 |
|
|
PF_OE : out std_logic;
|
48 |
|
|
LCD_RW : out std_logic;
|
49 |
|
|
LCD_E : out std_logic;
|
50 |
|
|
SPI_ROM_CS : out std_logic;
|
51 |
|
|
SPI_ADC_CONV : out std_logic;
|
52 |
|
|
SPI_DAC_CS : out std_logic;
|
53 |
|
|
-- DDR2
|
54 |
|
|
SD_CK_N : out std_logic;
|
55 |
|
|
SD_CK_P : out std_logic;
|
56 |
|
|
SD_CKE : out std_logic;
|
57 |
|
|
SD_BA : out std_logic_vector(1 downto 0);
|
58 |
|
|
SD_A : out std_logic_vector(12 downto 0);
|
59 |
|
|
SD_CMD : out std_logic_vector(3 downto 0);
|
60 |
|
|
SD_DM : out std_logic_vector(1 downto 0);
|
61 |
|
|
SD_DQS : inout std_logic_vector(1 downto 0);
|
62 |
|
|
SD_DQ : inout std_logic_vector(15 downto 0);
|
63 |
|
|
-- VGA
|
64 |
|
|
VGA_HSYNC : out std_logic;
|
65 |
|
|
VGA_VSYNC : out std_logic;
|
66 |
|
|
VGA_RED : out std_logic;
|
67 |
|
|
VGA_GREEN : out std_logic;
|
68 |
|
|
VGA_BLUE : out std_logic;
|
69 |
|
|
-- Keyboard
|
70 |
|
|
PS2_CLK : in std_logic;
|
71 |
|
|
PS2_DATA : in std_logic;
|
72 |
|
|
-- RS-232 Serial Port
|
73 |
|
|
RS232_DCE_RXD : in std_logic;
|
74 |
|
|
RS232_DCE_TXD : out std_logic;
|
75 |
|
|
LED : out std_logic_vector(7 downto 0)
|
76 |
|
|
);
|
77 |
|
|
end layer2;
|
78 |
|
|
|
79 |
|
|
architecture rtl of layer2 is
|
80 |
|
|
|
81 |
|
|
-----------------------------------------------------------------------------
|
82 |
|
|
-- Clocks --
|
83 |
|
|
-----------------------------------------------------------------------------
|
84 |
|
|
component clook
|
85 |
|
|
port(
|
86 |
|
|
U1_CLKIN_IN : in std_logic;
|
87 |
|
|
U1_RST_IN : in std_logic;
|
88 |
|
|
U1_CLKDV_OUT : out std_logic;
|
89 |
|
|
U1_CLKIN_IBUFG_OUT : out std_logic;
|
90 |
|
|
U1_CLK0_OUT : out std_logic;
|
91 |
|
|
U2_CLK0_OUT : out std_logic;
|
92 |
|
|
U2_CLK90_OUT : out std_logic;
|
93 |
|
|
U2_LOCKED_OUT : out std_logic
|
94 |
|
|
);
|
95 |
|
|
end component;
|
96 |
|
|
|
97 |
|
|
signal clk50MHz : std_logic; -- 50 MHz clock of DCM 1.
|
98 |
|
|
signal clk50MHz_BUF : std_logic; -- 50 MHz clock for DCM reset operations.
|
99 |
|
|
signal clk25MHz0D : std_logic; -- 25 MHz phase 0 for DDR.
|
100 |
|
|
signal clk25MHz90D : std_logic; -- 25 MHz pahse 90 for DDR.
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
-----------------------------------------------------------------------------
|
104 |
|
|
-- Shared Bus --
|
105 |
|
|
-----------------------------------------------------------------------------
|
106 |
|
|
signal ci : cpu_in_t; -- CPU input signals.
|
107 |
|
|
signal co : cpu_out_t; -- CPU output signals.
|
108 |
|
|
signal mi : master_in_t; -- CPU WB Master input.
|
109 |
|
|
signal mo : master_out_t; -- CPU WB Master output.
|
110 |
|
|
|
111 |
|
|
signal irq : std_logic_vector(7 downto 0); -- Interrupt vector.
|
112 |
|
|
signal pit_intr : std_logic; -- PIT interrupt.
|
113 |
|
|
signal key_intr : std_logic; -- Keyboard interrupt.
|
114 |
|
|
|
115 |
|
|
signal brami, flasi, ddri, dispi, keybi, piti, uartri, uartti : slave_in_t;
|
116 |
|
|
signal bramo, flaso, ddro, dispo, keybo, pito, uartro, uartto : slave_out_t;
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
-----------------------------------------------------------------------------
|
120 |
|
|
-- Global Reset --
|
121 |
|
|
-----------------------------------------------------------------------------
|
122 |
|
|
type rst_state_t is (Setup, Done);
|
123 |
|
|
|
124 |
|
|
type rst_t is record
|
125 |
|
|
s : rst_state_t;
|
126 |
|
|
c : natural range 0 to 3;
|
127 |
|
|
end record;
|
128 |
|
|
|
129 |
|
|
signal r, rin : rst_t := rst_t'(Setup, 0);
|
130 |
|
|
signal rst : std_logic; -- Global reset signal.
|
131 |
|
|
begin
|
132 |
|
|
|
133 |
|
|
-----------------------------------------------------------------------------
|
134 |
|
|
-- Global Reset --
|
135 |
|
|
-----------------------------------------------------------------------------
|
136 |
|
|
-- Reset for 4 clock cycles at start-up. Something the DCM wishes for.
|
137 |
|
|
nsl : process(r)
|
138 |
|
|
begin
|
139 |
|
|
|
140 |
|
|
rin <= r;
|
141 |
|
|
|
142 |
|
|
case r.s is
|
143 |
|
|
when Setup =>
|
144 |
|
|
rst <= '1';
|
145 |
|
|
if r.c = 3 then
|
146 |
|
|
rin.c <= 0;
|
147 |
|
|
rin.s <= Done;
|
148 |
|
|
else
|
149 |
|
|
rin.c <= r.c + 1;
|
150 |
|
|
end if;
|
151 |
|
|
|
152 |
|
|
when Done =>
|
153 |
|
|
rst <= '0';
|
154 |
|
|
end case;
|
155 |
|
|
end process;
|
156 |
|
|
|
157 |
|
|
reg : process(clk50MHz_BUF)
|
158 |
|
|
begin
|
159 |
|
|
if rising_edge(clk50MHz_BUF) then r <= rin; end if;
|
160 |
|
|
end process;
|
161 |
|
|
|
162 |
|
|
-----------------------------------------------------------------------------
|
163 |
|
|
-- Clocks --
|
164 |
|
|
-----------------------------------------------------------------------------
|
165 |
|
|
mclk: clook port map(
|
166 |
|
|
U1_CLKIN_IN => CLK_I,
|
167 |
|
|
U1_RST_IN => rst,
|
168 |
|
|
U1_CLKDV_OUT => open,
|
169 |
|
|
U1_CLKIN_IBUFG_OUT => clk50MHz_BUF,
|
170 |
|
|
U1_CLK0_OUT => clk50MHz,
|
171 |
|
|
U2_CLK0_OUT => clk25MHz0D,
|
172 |
|
|
U2_CLK90_OUT => clk25MHz90D,
|
173 |
|
|
U2_LOCKED_OUT => open
|
174 |
|
|
);
|
175 |
|
|
|
176 |
|
|
-----------------------------------------------------------------------------
|
177 |
|
|
-- MIPS I Cpu --
|
178 |
|
|
-----------------------------------------------------------------------------
|
179 |
|
|
irq <= key_intr & "000000" & pit_intr;
|
180 |
|
|
LED <= irq;
|
181 |
|
|
|
182 |
|
|
mips : cpu port map(
|
183 |
|
|
ci => ci,
|
184 |
|
|
co => co
|
185 |
|
|
);
|
186 |
|
|
|
187 |
|
|
-----------------------------------------------------------------------------
|
188 |
|
|
-- Cpu's Wishbone Master --
|
189 |
|
|
-----------------------------------------------------------------------------
|
190 |
|
|
master : wbm port map(
|
191 |
|
|
mi => mi,
|
192 |
|
|
mo => mo,
|
193 |
|
|
-- Non Wishbone Signals
|
194 |
|
|
ci => ci,
|
195 |
|
|
co => co,
|
196 |
|
|
irq => irq
|
197 |
|
|
);
|
198 |
|
|
|
199 |
|
|
-----------------------------------------------------------------------------
|
200 |
|
|
-- Block Memory --
|
201 |
|
|
-----------------------------------------------------------------------------
|
202 |
|
|
-- NOTE: The starting point of execution.
|
203 |
|
|
ram : mem port map(
|
204 |
|
|
si => brami,
|
205 |
|
|
so => bramo
|
206 |
|
|
);
|
207 |
|
|
|
208 |
|
|
-----------------------------------------------------------------------------
|
209 |
|
|
-- Flash Memory --
|
210 |
|
|
-----------------------------------------------------------------------------
|
211 |
|
|
flas : flash port map(
|
212 |
|
|
si => flasi,
|
213 |
|
|
so => flaso,
|
214 |
|
|
-- Non Wishbone Signals
|
215 |
|
|
SF_OE => SF_OE,
|
216 |
|
|
SF_CE => SF_CE,
|
217 |
|
|
SF_WE => SF_WE,
|
218 |
|
|
SF_BYTE => SF_BYTE,
|
219 |
|
|
--SF_STS => SF_STS,
|
220 |
|
|
SF_A => SF_A,
|
221 |
|
|
SF_D => SF_D,
|
222 |
|
|
PF_OE => PF_OE,
|
223 |
|
|
LCD_RW => LCD_RW,
|
224 |
|
|
LCD_E => LCD_E,
|
225 |
|
|
SPI_ROM_CS => SPI_ROM_CS,
|
226 |
|
|
SPI_ADC_CONV => SPI_ADC_CONV,
|
227 |
|
|
SPI_DAC_CS => SPI_DAC_CS
|
228 |
|
|
);
|
229 |
|
|
|
230 |
|
|
-----------------------------------------------------------------------------
|
231 |
|
|
-- DDR2 Memory --
|
232 |
|
|
-----------------------------------------------------------------------------
|
233 |
|
|
ddr2 : ddr port map(
|
234 |
|
|
si => ddri,
|
235 |
|
|
so => ddro,
|
236 |
|
|
-- Non Wishbone Signals
|
237 |
|
|
clk0 => clk25MHz0D,
|
238 |
|
|
clk90 => clk25MHz90D,
|
239 |
|
|
SD_CK_N => SD_CK_N,
|
240 |
|
|
SD_CK_P => SD_CK_P,
|
241 |
|
|
SD_CKE => SD_CKE,
|
242 |
|
|
SD_BA => SD_BA,
|
243 |
|
|
SD_A => SD_A,
|
244 |
|
|
SD_CMD => SD_CMD,
|
245 |
|
|
SD_DM => SD_DM,
|
246 |
|
|
SD_DQS => SD_DQS,
|
247 |
|
|
SD_DQ => SD_DQ
|
248 |
|
|
);
|
249 |
|
|
|
250 |
|
|
-----------------------------------------------------------------------------
|
251 |
|
|
-- VGA 100x37 Text Display --
|
252 |
|
|
-----------------------------------------------------------------------------
|
253 |
|
|
disp : vga port map(
|
254 |
|
|
si => dispi,
|
255 |
|
|
so => dispo,
|
256 |
|
|
-- Non Wishbone Signals
|
257 |
|
|
VGA_HSYNC => VGA_HSYNC,
|
258 |
|
|
VGA_VSYNC => VGA_VSYNC,
|
259 |
|
|
VGA_RED => VGA_RED,
|
260 |
|
|
VGA_GREEN => VGA_GREEN,
|
261 |
|
|
VGA_BLUE => VGA_BLUE
|
262 |
|
|
);
|
263 |
|
|
|
264 |
|
|
-----------------------------------------------------------------------------
|
265 |
|
|
-- Keyboard --
|
266 |
|
|
-----------------------------------------------------------------------------
|
267 |
|
|
key : keyb port map(
|
268 |
|
|
si => keybi,
|
269 |
|
|
so => keybo,
|
270 |
|
|
-- Non-Wishbone Signals
|
271 |
|
|
PS2_CLK => PS2_CLK,
|
272 |
|
|
PS2_DATA => PS2_DATA,
|
273 |
|
|
intr => key_intr
|
274 |
|
|
);
|
275 |
|
|
|
276 |
|
|
-----------------------------------------------------------------------------
|
277 |
|
|
-- Programmable Intervall Timer --
|
278 |
|
|
-----------------------------------------------------------------------------
|
279 |
|
|
pit0 : pit port map(
|
280 |
|
|
si => piti,
|
281 |
|
|
so => pito,
|
282 |
|
|
-- Non-Wishbone Signals
|
283 |
|
|
intr => pit_intr
|
284 |
|
|
);
|
285 |
|
|
|
286 |
|
|
-----------------------------------------------------------------------------
|
287 |
|
|
-- RS-232 Receiver --
|
288 |
|
|
-----------------------------------------------------------------------------
|
289 |
|
|
recv : uartr port map(
|
290 |
|
|
si => uartri,
|
291 |
|
|
so => uartro,
|
292 |
|
|
-- Non-Wishbone Signals
|
293 |
|
|
RS232_DCE_RXD => RS232_DCE_RXD
|
294 |
|
|
);
|
295 |
|
|
|
296 |
|
|
-----------------------------------------------------------------------------
|
297 |
|
|
-- RS-232 Transmitter --
|
298 |
|
|
-----------------------------------------------------------------------------
|
299 |
|
|
send : uartt port map(
|
300 |
|
|
si => uartti,
|
301 |
|
|
so => uartto,
|
302 |
|
|
-- Non-Wishbone Signals
|
303 |
|
|
RS232_DCE_TXD => RS232_DCE_TXD
|
304 |
|
|
);
|
305 |
|
|
|
306 |
|
|
-----------------------------------------------------------------------------
|
307 |
|
|
-- Shared Bus --
|
308 |
|
|
-----------------------------------------------------------------------------
|
309 |
|
|
sbus : intercon port map(
|
310 |
|
|
CLK50_I => clk50MHz,
|
311 |
|
|
CLK25_I => clk25MHz0D,
|
312 |
|
|
RST_I => rst,
|
313 |
|
|
mi => mi,
|
314 |
|
|
mo => mo,
|
315 |
|
|
brami => brami,
|
316 |
|
|
bramo => bramo,
|
317 |
|
|
flasi => flasi,
|
318 |
|
|
flaso => flaso,
|
319 |
|
|
ddri => ddri,
|
320 |
|
|
ddro => ddro,
|
321 |
|
|
dispi => dispi,
|
322 |
|
|
dispo => dispo,
|
323 |
|
|
keybi => keybi,
|
324 |
|
|
keybo => keybo,
|
325 |
|
|
piti => piti,
|
326 |
|
|
pito => pito,
|
327 |
|
|
uartri => uartri,
|
328 |
|
|
uartro => uartro,
|
329 |
|
|
uartti => uartti,
|
330 |
|
|
uartto => uartto
|
331 |
|
|
);
|
332 |
|
|
end rtl;
|