add: GPIO module to zealot SoC
[zpu.git] / zpu / hdl / example_medium / sim_fpga_top.vhd
blob962caad1f4bc80a883aa8ccd9c16fe1bd9a03450
1 --------------------------------------------------------------------------------
2 -- ZPU
3 --
4 -- Copyright 2004-2008 oharboe - Øyvind Harboe - oyvind.harboe@zylin.com
5 --
6 -- The FreeBSD license
7 --
8 -- Redistribution and use in source and binary forms, with or without
9 -- modification, are permitted provided that the following conditions
10 -- are met:
11 --
12 -- 1. Redistributions of source code must retain the above copyright
13 -- notice, this list of conditions and the following disclaimer.
14 -- 2. Redistributions in binary form must reproduce the above
15 -- copyright notice, this list of conditions and the following
16 -- disclaimer in the documentation and/or other materials
17 -- provided with the distribution.
18 --
19 -- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY
20 -- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 -- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 -- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 -- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 -- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 -- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 --
32 -- The views and conclusions contained in the software and documentation
33 -- are those of the authors and should not be interpreted as representing
34 -- official policies, either expressed or implied, of the ZPU Project.
35 --------------------------------------------------------------------------------
37 library ieee;
38 use ieee.std_logic_1164.all;
40 library work;
41 use work.zpu_config.all;
44 entity fpga_top is
45 end fpga_top;
47 use work.zpupkg.all;
49 architecture behave of fpga_top is
52 signal clk : std_logic;
54 signal areset : std_logic := '1';
57 component zpu_io is
58 generic (
59 log_file: string := "log.txt"
61 port (
62 clk : in std_logic;
63 areset : in std_logic;
64 busy : out std_logic;
65 writeEnable : in std_logic;
66 readEnable : in std_logic;
67 write : in std_logic_vector(wordSize-1 downto 0);
68 read : out std_logic_vector(wordSize-1 downto 0);
69 addr : in std_logic_vector(maxAddrBit downto minAddrBit)
71 end component;
74 signal mem_busy : std_logic;
75 signal mem_read : std_logic_vector(wordSize-1 downto 0);
76 signal mem_write : std_logic_vector(wordSize-1 downto 0);
77 signal mem_addr : std_logic_vector(maxAddrBitIncIO downto 0);
78 signal mem_writeEnable : std_logic;
79 signal mem_readEnable : std_logic;
80 signal mem_writeMask : std_logic_vector(wordBytes-1 downto 0);
82 signal enable : std_logic;
84 signal dram_mem_busy : std_logic;
85 signal dram_mem_read : std_logic_vector(wordSize-1 downto 0);
86 signal dram_mem_write : std_logic_vector(wordSize-1 downto 0);
87 signal dram_mem_writeEnable : std_logic;
88 signal dram_mem_readEnable : std_logic;
89 signal dram_mem_writeMask : std_logic_vector(wordBytes-1 downto 0);
91 signal io_busy : std_logic;
93 signal io_mem_read : std_logic_vector(wordSize-1 downto 0);
94 signal io_mem_writeEnable : std_logic;
95 signal io_mem_readEnable : std_logic;
97 signal dram_ready : std_logic;
98 signal io_ready : std_logic;
99 signal io_reading : std_logic;
101 signal break : std_logic;
103 begin
105 zpu: zpu_core
106 port map (
107 clk => clk,
108 reset => areset,
109 enable => enable,
110 in_mem_busy => mem_busy,
111 mem_read => mem_read,
112 mem_write => mem_write,
113 out_mem_addr => mem_addr,
114 out_mem_writeEnable => mem_writeEnable,
115 out_mem_readEnable => mem_readEnable,
116 mem_writeMask => mem_writeMask,
117 interrupt => '0',
118 break => break
121 dram_imp: dram
122 port map (
123 clk => clk ,
124 areset => areset,
125 mem_busy => dram_mem_busy,
126 mem_read => dram_mem_read,
127 mem_write => mem_write,
128 mem_addr => mem_addr(maxAddrBit downto 0),
129 mem_writeEnable => dram_mem_writeEnable,
130 mem_readEnable => dram_mem_readEnable,
131 mem_writeMask => mem_writeMask
135 ioMap: zpu_io
136 port map (
137 clk => clk,
138 areset => areset,
139 busy => io_busy,
140 writeEnable => io_mem_writeEnable,
141 readEnable => io_mem_readEnable,
142 write => mem_write(wordSize-1 downto 0),
143 read => io_mem_read,
144 addr => mem_addr(maxAddrBit downto minAddrBit)
147 dram_mem_writeEnable <= mem_writeEnable and not mem_addr(ioBit);
148 dram_mem_readEnable <= mem_readEnable and not mem_addr(ioBit);
149 io_mem_writeEnable <= mem_writeEnable and mem_addr(ioBit);
150 io_mem_readEnable <= mem_readEnable and mem_addr(ioBit);
151 mem_busy <= io_busy or dram_mem_busy or io_busy;
154 -- Memory reads either come from IO or DRAM. We need to pick the right one.
155 memorycontrol: process(dram_mem_read, dram_ready, io_ready, io_mem_read)
156 begin
157 mem_read <= (others => 'U');
158 if dram_ready='1' then
159 mem_read <= dram_mem_read;
160 end if;
162 if io_ready='1' then
163 mem_read <= io_mem_read;
164 end if;
165 end process;
168 io_ready <= (io_reading or io_mem_readEnable) and not io_busy;
170 memoryControlSync: process(clk, areset)
171 begin
172 if areset = '1' then
173 enable <= '0';
174 io_reading <= '0';
175 dram_ready <= '0';
176 elsif rising_edge(clk) then
177 enable <= '1';
178 io_reading <= io_busy or io_mem_readEnable;
179 dram_ready <= dram_mem_readEnable;
180 end if;
181 end process;
183 -- wiggle the clock @ 100MHz
184 clock : process
185 begin
186 clk <= '0';
187 wait for 5 ns;
188 clk <= '1';
189 wait for 5 ns;
190 areset <= '0';
191 end process clock;
194 end architecture behave;