OpenCores
URL https://opencores.org/ocsvn/zpu/zpu/trunk

Subversion Repositories zpu

[/] [zpu/] [trunk/] [zpu/] [example/] [sim_small_fpga_top.vhd] - Blame information for rev 93

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.