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

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [SoC/] [mips_soc.vhdl] - Blame information for rev 233

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 ja_rd
--------------------------------------------------------------------------------
2 224 ja_rd
-- Synthesizable ION SoC -- CPU + cache + bootstrap ROM (BRAM) + UART
3 46 ja_rd
--------------------------------------------------------------------------------
4 224 ja_rd
-- This SoC is meant as a vehicle for building demos around the ION CPU, and not
5
-- really as an useable SoC. 
6
--------------------------------------------------------------------------------
7
--
8
-- This SoC includes a small BRAM block mapped at 0xbfc00000 and used to hold
9
-- the application's bootstrap code.
10
-- The bootstrap object code is passed as a generic in the form of a byte array
11
-- (type t_obj_code, defined in mips_pkg). This byte array can be generated with
12
-- script 'build_pkg.py', included in the tools directory. 
13
-- In the present implementation, the boot BRAM can't be omitted even if the 
14
-- memory map is changed or its size is set to zero.
15
--
16
--------------------------------------------------------------------------------
17
-- Generics
18
------------
19
--
20
-- BOOT_BRAM_SIZE:  Size of boot BRAM in 32-bit words. Can't be zero.
21 233 ja_rd
-- OBJECT_CODE:     Bootstrap object code (mapped at 0xbfc00000).
22 224 ja_rd
-- SRAM_ADDR_SIZE:  Size of address bus for SRAM interface.
23
-- CLOCK_FREQ:      Clock rate in Hz. Used for the UART configuration.
24
-- BAUD_RATE:       UART baud rate.
25
--
26
--------------------------------------------------------------------------------
27
-- Memory map
28
--------------
29
--
30
-- The memory map used in this SoC is defined in package mips_pkg, in function 
31
-- decode_addr_mips1. It is used in the module 'mips_cache.vhdl', where 
32
-- the I- and D-Caches are implemented along with the memory controller -- see
33
-- the project doc.
34
-- This map has been chosen for development convenience and includes all the 
35
-- external memory types available in the development target, Terasic's DE-1 
36
-- board. It is meant to change as development progresses.
37
--
38
-- A[31..27]
39
-- 00000    => Static, 16-bit (SRAM)
40
-- 10000    => Static, 16-bit (SRAM)
41
-- 00100    => I/O
42
-- 10110    => Static, 8-bit (flash)
43
-- 10111    => Internal BRAM (boot BRAM)
44
--
45
-- I/O devices
46
---------------
47
--
48
-- The only I/O device in this SoC is an UART (module 'uart.vhdl':
49
--
50
-- 2XXX0XXX0h => UART register 0
51
-- 2XXX0XXX4h => UART register 1
52
-- 2XXX0XXX8h => UART register 2
53
-- 2XXX0XXXch => UART register 3
54
--
55
-- The UART is hardwired to a fixed baud rate and can be configured through
56
-- generics.
57
--------------------------------------------------------------------------------
58
-- Copyright (C) 2012 Jose A. Ruiz
59 188 ja_rd
--                                                              
60
-- This source file may be used and distributed without         
61
-- restriction provided that this copyright statement is not    
62
-- removed from the file and that any derivative work contains  
63
-- the original copyright notice and the associated disclaimer. 
64
--                                                              
65
-- This source file is free software; you can redistribute it   
66
-- and/or modify it under the terms of the GNU Lesser General   
67
-- Public License as published by the Free Software Foundation; 
68
-- either version 2.1 of the License, or (at your option) any   
69
-- later version.                                               
70
--                                                              
71
-- This source is distributed in the hope that it will be       
72
-- useful, but WITHOUT ANY WARRANTY; without even the implied   
73
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
74
-- PURPOSE.  See the GNU Lesser General Public License for more 
75
-- details.                                                     
76
--                                                              
77
-- You should have received a copy of the GNU Lesser General    
78
-- Public License along with this source; if not, download it   
79
-- from http://www.opencores.org/lgpl.shtml
80
--------------------------------------------------------------------------------
81 46 ja_rd
 
82 2 ja_rd
library ieee;
83
use ieee.std_logic_1164.all;
84
use ieee.std_logic_arith.all;
85
use ieee.std_logic_unsigned.all;
86
use work.mips_pkg.all;
87
 
88 224 ja_rd
entity mips_soc is
89 46 ja_rd
    generic (
90 224 ja_rd
        CLOCK_FREQ :        integer := 50000000;
91
        BAUD_RATE :         integer := 19200;
92
        BOOT_BRAM_SIZE :    integer := 1024;
93
        -- FIXME Boot BRAM can't be omitted
94 233 ja_rd
        OBJECT_CODE :       t_obj_code := default_object_code;
95 224 ja_rd
        SRAM_ADDR_SIZE :    integer := 17           -- < 10 to disable SRAM I/F
96
        -- FIXME SRAM I/F can't be disabled
97 2 ja_rd
    );
98
    port(
99
        clk             : in std_logic;
100
        reset           : in std_logic;
101 200 ja_rd
        interrupt       : in std_logic_vector(7 downto 0);
102 2 ja_rd
 
103 46 ja_rd
        -- interface to FPGA i/o devices
104
        io_rd_data      : in std_logic_vector(31 downto 0);
105
        io_rd_addr      : out std_logic_vector(31 downto 2);
106
        io_wr_addr      : out std_logic_vector(31 downto 2);
107
        io_wr_data      : out std_logic_vector(31 downto 0);
108
        io_rd_vma       : out std_logic;
109
        io_byte_we      : out std_logic_vector(3 downto 0);
110 2 ja_rd
 
111 46 ja_rd
        -- interface to asynchronous 16-bit-wide EXTERNAL SRAM
112 224 ja_rd
        sram_address    : out std_logic_vector(SRAM_ADDR_SIZE-1 downto 0);
113 76 ja_rd
        sram_data_wr    : out std_logic_vector(15 downto 0);
114
        sram_data_rd    : in std_logic_vector(15 downto 0);
115 46 ja_rd
        sram_byte_we_n  : out std_logic_vector(1 downto 0);
116
        sram_oe_n       : out std_logic;
117
 
118
        -- UART 
119 2 ja_rd
        uart_rxd        : in std_logic;
120 138 ja_rd
        uart_txd        : out std_logic;
121
 
122 224 ja_rd
        -- Debug info register output
123 138 ja_rd
        debug_info      : out t_debug_info
124 2 ja_rd
    );
125 224 ja_rd
end; --entity mips_soc
126 2 ja_rd
 
127 224 ja_rd
architecture rtl of mips_soc is
128 2 ja_rd
 
129 224 ja_rd
-- Interface cpu-cache
130 98 ja_rd
signal cpu_data_addr :      t_word;
131 46 ja_rd
signal cpu_data_rd_vma :    std_logic;
132
signal cpu_data_rd :        t_word;
133
signal cpu_code_rd_addr :   t_pc;
134
signal cpu_code_rd :        t_word;
135
signal cpu_code_rd_vma :    std_logic;
136
signal cpu_data_wr :        t_word;
137
signal cpu_byte_we :        std_logic_vector(3 downto 0);
138
signal cpu_mem_wait :       std_logic;
139 119 ja_rd
signal cpu_ic_invalidate :  std_logic;
140
signal cpu_cache_enable :   std_logic;
141 138 ja_rd
signal unmapped_access :    std_logic;
142 2 ja_rd
 
143 224 ja_rd
-- Interface to i/o
144 46 ja_rd
signal mpu_io_rd_data :     std_logic_vector(31 downto 0);
145
signal mpu_io_wr_data :     std_logic_vector(31 downto 0);
146
signal mpu_io_rd_addr :     std_logic_vector(31 downto 2);
147
signal mpu_io_wr_addr :     std_logic_vector(31 downto 2);
148
signal mpu_io_rd_vma :      std_logic;
149
signal mpu_io_byte_we :     std_logic_vector(3 downto 0);
150 2 ja_rd
 
151 224 ja_rd
-- Interface to UARTs
152
signal uart_ce :            std_logic;
153
signal uart_irq :           std_logic;
154
signal uart_rd_byte :       std_logic_vector(7 downto 0);
155 2 ja_rd
 
156 224 ja_rd
-- Bootstrap code BRAM
157
constant BOOT_BRAM_ADDR_SIZE : integer := log2(BOOT_BRAM_SIZE);
158
subtype t_boot_bram_address is std_logic_vector(BOOT_BRAM_ADDR_SIZE-1 downto 0);
159
-- Boot BRAM, initialized with constant object code table
160
signal boot_bram :          t_word_table(0 to BOOT_BRAM_SIZE-1) :=
161 233 ja_rd
                                objcode_to_wtable(OBJECT_CODE, BOOT_BRAM_SIZE);
162 224 ja_rd
 
163 191 ja_rd
-- NOTE: 'write' signals are a remnant from a previous version, to be removed
164 224 ja_rd
signal bram_rd_addr :       t_boot_bram_address;
165
signal bram_wr_addr :       t_boot_bram_address;
166 46 ja_rd
signal bram_rd_data :       t_word;
167
signal bram_wr_data :       t_word;
168
signal bram_byte_we :       std_logic_vector(3 downto 0);
169 224 ja_rd
 
170
 
171 46 ja_rd
--------------------------------------------------------------------------------
172 2 ja_rd
begin
173
 
174 46 ja_rd
cpu: entity work.mips_cpu
175 2 ja_rd
    port map (
176 200 ja_rd
        interrupt   => interrupt,
177 2 ja_rd
 
178 98 ja_rd
        data_addr   => cpu_data_addr,
179 46 ja_rd
        data_rd_vma => cpu_data_rd_vma,
180
        data_rd     => cpu_data_rd,
181 2 ja_rd
 
182 46 ja_rd
        code_rd_addr=> cpu_code_rd_addr,
183
        code_rd     => cpu_code_rd,
184
        code_rd_vma => cpu_code_rd_vma,
185 2 ja_rd
 
186 46 ja_rd
        data_wr     => cpu_data_wr,
187 2 ja_rd
        byte_we     => cpu_byte_we,
188 46 ja_rd
 
189
        mem_wait    => cpu_mem_wait,
190 119 ja_rd
        cache_enable=> cpu_cache_enable,
191
        ic_invalidate=>cpu_ic_invalidate,
192 2 ja_rd
 
193
        clk         => clk,
194 46 ja_rd
        reset       => reset
195 2 ja_rd
    );
196
 
197 119 ja_rd
cache: entity work.mips_cache
198 46 ja_rd
    generic map (
199 224 ja_rd
        BRAM_ADDR_SIZE => BOOT_BRAM_ADDR_SIZE,
200 46 ja_rd
        SRAM_ADDR_SIZE => SRAM_ADDR_SIZE
201
    )
202
    port map (
203
        clk             => clk,
204
        reset           => reset,
205
 
206
        -- Interface to CPU core
207 98 ja_rd
        data_addr       => cpu_data_addr,
208 46 ja_rd
        data_rd         => cpu_data_rd,
209
        data_rd_vma     => cpu_data_rd_vma,
210
 
211
        code_rd_addr    => cpu_code_rd_addr,
212
        code_rd         => cpu_code_rd,
213
        code_rd_vma     => cpu_code_rd_vma,
214
 
215
        byte_we         => cpu_byte_we,
216
        data_wr         => cpu_data_wr,
217
 
218
        mem_wait        => cpu_mem_wait,
219 119 ja_rd
        cache_enable    => cpu_cache_enable,
220
        ic_invalidate   => cpu_ic_invalidate,
221 138 ja_rd
        unmapped        => unmapped_access,
222 46 ja_rd
 
223
        -- interface to FPGA i/o devices
224
        io_rd_data      => mpu_io_rd_data,
225
        io_wr_data      => mpu_io_wr_data,
226
        io_rd_addr      => mpu_io_rd_addr,
227
        io_wr_addr      => mpu_io_wr_addr,
228
        io_rd_vma       => mpu_io_rd_vma,
229
        io_byte_we      => mpu_io_byte_we,
230 2 ja_rd
 
231 46 ja_rd
        -- interface to synchronous 32-bit-wide FPGA BRAM
232
        bram_rd_data    => bram_rd_data,
233
        bram_wr_data    => bram_wr_data,
234
        bram_rd_addr    => bram_rd_addr,
235
        bram_wr_addr    => bram_wr_addr,
236
        bram_byte_we    => bram_byte_we,
237
 
238
        -- interface to asynchronous 16-bit-wide external SRAM
239
        sram_address    => sram_address,
240 76 ja_rd
        sram_data_rd    => sram_data_rd,
241
        sram_data_wr    => sram_data_wr,
242 46 ja_rd
        sram_byte_we_n  => sram_byte_we_n,
243
        sram_oe_n       => sram_oe_n
244
    );
245 2 ja_rd
 
246
 
247 46 ja_rd
--------------------------------------------------------------------------------
248 224 ja_rd
-- BRAM interface -- read only 
249 2 ja_rd
 
250 46 ja_rd
fpga_ram_block:
251
process(clk)
252
begin
253
    if clk'event and clk='1' then
254 224 ja_rd
        bram_rd_data <= boot_bram(conv_integer(unsigned(bram_rd_addr)));
255 46 ja_rd
    end if;
256
end process fpga_ram_block;
257 2 ja_rd
 
258
 
259
--------------------------------------------------------------------------------
260 138 ja_rd
-- Debug stuff
261 2 ja_rd
 
262 138 ja_rd
-- Register some debug signals. These are meant to be connected to LEDs on a 
263
-- dev board, or maybe to logic analyzer probes. They are not useful once
264
-- the core is fully debugged.
265
debug_info_register:
266
process(clk)
267
begin
268
    if clk'event and clk='1' then
269
        if reset='1' then
270
            debug_info.unmapped_access <= '0';
271
        else
272
            if unmapped_access='1' then
273
                -- This flag will be asserted permanently after any kind of 
274
                -- unmapped access (code, data read or data write).
275
                debug_info.unmapped_access <= '1';
276
            end if;
277
        end if;
278 224 ja_rd
        -- This flag will be asserted as long as the cache is enabled
279 138 ja_rd
        debug_info.cache_enabled <= cpu_cache_enable;
280
    end if;
281
end process debug_info_register;
282 2 ja_rd
 
283 138 ja_rd
 
284 2 ja_rd
--------------------------------------------------------------------------------
285 224 ja_rd
-- UART -- 8-bit interface, connected to LOW byte of word (address *3h)
286 2 ja_rd
 
287 224 ja_rd
uart : entity work.uart
288
generic map (
289
        BAUD_RATE =>    BAUD_RATE,
290
        CLOCK_FREQ =>   CLOCK_FREQ
291 119 ja_rd
    )
292 224 ja_rd
    port map (
293
        clk_i =>        clk,
294
        reset_i =>      reset,
295
 
296
        irq_o =>        uart_irq,
297
        data_i =>       mpu_io_wr_data(7 downto 0),
298
        data_o =>       uart_rd_byte,
299
        addr_rd_i =>    mpu_io_rd_addr(3 downto 2),
300
        addr_wr_i =>    mpu_io_wr_addr(3 downto 2),
301
 
302
        ce_i =>         uart_ce,
303
        wr_i =>         mpu_io_byte_we(3),
304
        rd_i =>         mpu_io_rd_vma,
305
 
306
        rxd_i =>        uart_rxd,
307
        txd_o =>        uart_txd
308
  );
309
 
310
-- UART chip enable
311
uart_ce <= '1'
312
    when (mpu_io_rd_addr(15 downto 12)=X"0" or
313
          mpu_io_wr_addr(15 downto 12)=X"0")
314 94 ja_rd
    else '0';
315
 
316 224 ja_rd
 
317
--------------------------------------------------------------------------------
318
-- I/O port multiplexor 
319
 
320
 
321
-- IO Rd mux: either the UART data/status word or the IO coming from outside
322 68 ja_rd
mpu_io_rd_data <=
323 224 ja_rd
    X"000000" & uart_rd_byte when mpu_io_rd_addr(19 downto 12)=X"00" else
324 68 ja_rd
    io_rd_data;
325 2 ja_rd
 
326 46 ja_rd
-- io_rd_data 
327
io_rd_addr <= mpu_io_rd_addr;
328
io_wr_addr <= mpu_io_wr_addr;
329
io_wr_data <= mpu_io_wr_data;
330
io_rd_vma <= mpu_io_rd_vma;
331
io_byte_we <= mpu_io_byte_we;
332
 
333
 
334 2 ja_rd
end architecture rtl;

powered by: WebSVN 2.1.0

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