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

Subversion Repositories ion

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

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