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

Subversion Repositories ion

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

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 234 ja_rd
        -- I/O ports
123
        p0_out          : out std_logic_vector(31 downto 0);
124
        p1_in           : in std_logic_vector(31 downto 0);
125
 
126 224 ja_rd
        -- Debug info register output
127 138 ja_rd
        debug_info      : out t_debug_info
128 2 ja_rd
    );
129 224 ja_rd
end; --entity mips_soc
130 2 ja_rd
 
131 224 ja_rd
architecture rtl of mips_soc is
132 2 ja_rd
 
133 224 ja_rd
-- Interface cpu-cache
134 98 ja_rd
signal cpu_data_addr :      t_word;
135 46 ja_rd
signal cpu_data_rd_vma :    std_logic;
136
signal cpu_data_rd :        t_word;
137
signal cpu_code_rd_addr :   t_pc;
138
signal cpu_code_rd :        t_word;
139
signal cpu_code_rd_vma :    std_logic;
140
signal cpu_data_wr :        t_word;
141
signal cpu_byte_we :        std_logic_vector(3 downto 0);
142
signal cpu_mem_wait :       std_logic;
143 119 ja_rd
signal cpu_ic_invalidate :  std_logic;
144
signal cpu_cache_enable :   std_logic;
145 138 ja_rd
signal unmapped_access :    std_logic;
146 2 ja_rd
 
147 224 ja_rd
-- Interface to i/o
148 46 ja_rd
signal mpu_io_rd_data :     std_logic_vector(31 downto 0);
149
signal mpu_io_wr_data :     std_logic_vector(31 downto 0);
150
signal mpu_io_rd_addr :     std_logic_vector(31 downto 2);
151
signal mpu_io_wr_addr :     std_logic_vector(31 downto 2);
152
signal mpu_io_rd_vma :      std_logic;
153
signal mpu_io_byte_we :     std_logic_vector(3 downto 0);
154 2 ja_rd
 
155 224 ja_rd
-- Interface to UARTs
156
signal uart_ce :            std_logic;
157
signal uart_irq :           std_logic;
158
signal uart_rd_byte :       std_logic_vector(7 downto 0);
159 2 ja_rd
 
160 234 ja_rd
-- I/O registers
161
signal p0_reg :             std_logic_vector(31 downto 0);
162
signal p1_reg :             std_logic_vector(31 downto 0);
163
signal gpio_rd_data :       std_logic_vector(31 downto 0);
164
 
165 224 ja_rd
-- Bootstrap code BRAM
166
constant BOOT_BRAM_ADDR_SIZE : integer := log2(BOOT_BRAM_SIZE);
167
subtype t_boot_bram_address is std_logic_vector(BOOT_BRAM_ADDR_SIZE-1 downto 0);
168
-- Boot BRAM, initialized with constant object code table
169
signal boot_bram :          t_word_table(0 to BOOT_BRAM_SIZE-1) :=
170 233 ja_rd
                                objcode_to_wtable(OBJECT_CODE, BOOT_BRAM_SIZE);
171 224 ja_rd
 
172 191 ja_rd
-- NOTE: 'write' signals are a remnant from a previous version, to be removed
173 224 ja_rd
signal bram_rd_addr :       t_boot_bram_address;
174
signal bram_wr_addr :       t_boot_bram_address;
175 46 ja_rd
signal bram_rd_data :       t_word;
176
signal bram_wr_data :       t_word;
177
signal bram_byte_we :       std_logic_vector(3 downto 0);
178 224 ja_rd
 
179
 
180 46 ja_rd
--------------------------------------------------------------------------------
181 2 ja_rd
begin
182
 
183 46 ja_rd
cpu: entity work.mips_cpu
184 2 ja_rd
    port map (
185 200 ja_rd
        interrupt   => interrupt,
186 2 ja_rd
 
187 98 ja_rd
        data_addr   => cpu_data_addr,
188 46 ja_rd
        data_rd_vma => cpu_data_rd_vma,
189
        data_rd     => cpu_data_rd,
190 2 ja_rd
 
191 46 ja_rd
        code_rd_addr=> cpu_code_rd_addr,
192
        code_rd     => cpu_code_rd,
193
        code_rd_vma => cpu_code_rd_vma,
194 2 ja_rd
 
195 46 ja_rd
        data_wr     => cpu_data_wr,
196 2 ja_rd
        byte_we     => cpu_byte_we,
197 46 ja_rd
 
198
        mem_wait    => cpu_mem_wait,
199 119 ja_rd
        cache_enable=> cpu_cache_enable,
200
        ic_invalidate=>cpu_ic_invalidate,
201 2 ja_rd
 
202
        clk         => clk,
203 46 ja_rd
        reset       => reset
204 2 ja_rd
    );
205
 
206 119 ja_rd
cache: entity work.mips_cache
207 46 ja_rd
    generic map (
208 224 ja_rd
        BRAM_ADDR_SIZE => BOOT_BRAM_ADDR_SIZE,
209 46 ja_rd
        SRAM_ADDR_SIZE => SRAM_ADDR_SIZE
210
    )
211
    port map (
212
        clk             => clk,
213
        reset           => reset,
214
 
215
        -- Interface to CPU core
216 98 ja_rd
        data_addr       => cpu_data_addr,
217 46 ja_rd
        data_rd         => cpu_data_rd,
218
        data_rd_vma     => cpu_data_rd_vma,
219
 
220
        code_rd_addr    => cpu_code_rd_addr,
221
        code_rd         => cpu_code_rd,
222
        code_rd_vma     => cpu_code_rd_vma,
223
 
224
        byte_we         => cpu_byte_we,
225
        data_wr         => cpu_data_wr,
226
 
227
        mem_wait        => cpu_mem_wait,
228 119 ja_rd
        cache_enable    => cpu_cache_enable,
229
        ic_invalidate   => cpu_ic_invalidate,
230 138 ja_rd
        unmapped        => unmapped_access,
231 46 ja_rd
 
232
        -- interface to FPGA i/o devices
233
        io_rd_data      => mpu_io_rd_data,
234
        io_wr_data      => mpu_io_wr_data,
235
        io_rd_addr      => mpu_io_rd_addr,
236
        io_wr_addr      => mpu_io_wr_addr,
237
        io_rd_vma       => mpu_io_rd_vma,
238
        io_byte_we      => mpu_io_byte_we,
239 2 ja_rd
 
240 46 ja_rd
        -- interface to synchronous 32-bit-wide FPGA BRAM
241
        bram_rd_data    => bram_rd_data,
242
        bram_wr_data    => bram_wr_data,
243
        bram_rd_addr    => bram_rd_addr,
244
        bram_wr_addr    => bram_wr_addr,
245
        bram_byte_we    => bram_byte_we,
246
 
247
        -- interface to asynchronous 16-bit-wide external SRAM
248
        sram_address    => sram_address,
249 76 ja_rd
        sram_data_rd    => sram_data_rd,
250
        sram_data_wr    => sram_data_wr,
251 46 ja_rd
        sram_byte_we_n  => sram_byte_we_n,
252
        sram_oe_n       => sram_oe_n
253
    );
254 2 ja_rd
 
255
 
256 46 ja_rd
--------------------------------------------------------------------------------
257 224 ja_rd
-- BRAM interface -- read only 
258 2 ja_rd
 
259 46 ja_rd
fpga_ram_block:
260
process(clk)
261
begin
262
    if clk'event and clk='1' then
263 224 ja_rd
        bram_rd_data <= boot_bram(conv_integer(unsigned(bram_rd_addr)));
264 46 ja_rd
    end if;
265
end process fpga_ram_block;
266 2 ja_rd
 
267
 
268
--------------------------------------------------------------------------------
269 138 ja_rd
-- Debug stuff
270 2 ja_rd
 
271 138 ja_rd
-- Register some debug signals. These are meant to be connected to LEDs on a 
272
-- dev board, or maybe to logic analyzer probes. They are not useful once
273
-- the core is fully debugged.
274
debug_info_register:
275
process(clk)
276
begin
277
    if clk'event and clk='1' then
278
        if reset='1' then
279
            debug_info.unmapped_access <= '0';
280
        else
281
            if unmapped_access='1' then
282
                -- This flag will be asserted permanently after any kind of 
283
                -- unmapped access (code, data read or data write).
284
                debug_info.unmapped_access <= '1';
285
            end if;
286
        end if;
287 224 ja_rd
        -- This flag will be asserted as long as the cache is enabled
288 138 ja_rd
        debug_info.cache_enabled <= cpu_cache_enable;
289
    end if;
290
end process debug_info_register;
291 2 ja_rd
 
292 138 ja_rd
 
293 2 ja_rd
--------------------------------------------------------------------------------
294 224 ja_rd
-- UART -- 8-bit interface, connected to LOW byte of word (address *3h)
295 2 ja_rd
 
296 224 ja_rd
uart : entity work.uart
297
generic map (
298
        BAUD_RATE =>    BAUD_RATE,
299
        CLOCK_FREQ =>   CLOCK_FREQ
300 119 ja_rd
    )
301 224 ja_rd
    port map (
302
        clk_i =>        clk,
303
        reset_i =>      reset,
304
 
305
        irq_o =>        uart_irq,
306
        data_i =>       mpu_io_wr_data(7 downto 0),
307
        data_o =>       uart_rd_byte,
308
        addr_rd_i =>    mpu_io_rd_addr(3 downto 2),
309
        addr_wr_i =>    mpu_io_wr_addr(3 downto 2),
310
 
311
        ce_i =>         uart_ce,
312
        wr_i =>         mpu_io_byte_we(3),
313
        rd_i =>         mpu_io_rd_vma,
314
 
315
        rxd_i =>        uart_rxd,
316
        txd_o =>        uart_txd
317
  );
318
 
319
-- UART chip enable
320
uart_ce <= '1'
321
    when (mpu_io_rd_addr(15 downto 12)=X"0" or
322
          mpu_io_wr_addr(15 downto 12)=X"0")
323 94 ja_rd
    else '0';
324
 
325 224 ja_rd
 
326
--------------------------------------------------------------------------------
327 234 ja_rd
-- GPIO registers
328
 
329
gpio_output_registers:
330
process(clk)
331
begin
332
    if clk'event and clk='1' then
333
        if reset='1' then
334
            p0_reg <= (others => '0');
335
        else
336
            if mpu_io_wr_addr(19 downto 12)=X"01" then
337
                if mpu_io_byte_we(0)='1' then
338
                    p0_reg( 7 downto  0) <= mpu_io_wr_data( 7 downto  0);
339
                end if;
340
                if mpu_io_byte_we(1)='1' then
341
                    p0_reg(15 downto  8) <= mpu_io_wr_data(15 downto  8);
342
                end if;
343
                if mpu_io_byte_we(2)='1' then
344
                    p0_reg(23 downto 16) <= mpu_io_wr_data(23 downto 16);
345
                end if;
346
                if mpu_io_byte_we(3)='1' then
347
                    p0_reg(31 downto 24) <= mpu_io_wr_data(31 downto 24);
348
                end if;
349
            end if;
350
        end if;
351
    end if;
352
end process gpio_output_registers;
353
 
354
p0_out <= p0_reg;
355
 
356
gpio_input_registers:
357
process(clk)
358
begin
359
    -- Note the input register needs no reset value.
360
    if clk'event and clk='1' then
361
        p1_reg <= p1_in;
362
    end if;
363
end process gpio_input_registers;
364
 
365
with mpu_io_rd_addr(2) select gpio_rd_data <=
366
    p0_reg      when '0',
367
    p1_reg      when others;
368
 
369
 
370
--------------------------------------------------------------------------------
371 224 ja_rd
-- I/O port multiplexor 
372
 
373
 
374
-- IO Rd mux: either the UART data/status word or the IO coming from outside
375 234 ja_rd
with mpu_io_rd_addr(19 downto 12) select mpu_io_rd_data <=
376
    X"000000" & uart_rd_byte    when X"00",
377
    gpio_rd_data                when X"01",
378
    io_rd_data                  when others;
379 2 ja_rd
 
380 46 ja_rd
-- io_rd_data 
381
io_rd_addr <= mpu_io_rd_addr;
382
io_wr_addr <= mpu_io_wr_addr;
383
io_wr_data <= mpu_io_wr_data;
384
io_rd_vma <= mpu_io_rd_vma;
385
io_byte_we <= mpu_io_byte_we;
386
 
387
 
388 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.