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

Subversion Repositories ion

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

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

Line No. Rev Author Line
1 46 ja_rd
--------------------------------------------------------------------------------
2 193 ja_rd
-- Synthesizable MPU -- CPU + cache + bootstrap ROM (BRAM) + UART
3 46 ja_rd
--------------------------------------------------------------------------------
4 188 ja_rd
-- Copyright (C) 2011 Jose A. Ruiz
5
--                                                              
6
-- This source file may be used and distributed without         
7
-- restriction provided that this copyright statement is not    
8
-- removed from the file and that any derivative work contains  
9
-- the original copyright notice and the associated disclaimer. 
10
--                                                              
11
-- This source file is free software; you can redistribute it   
12
-- and/or modify it under the terms of the GNU Lesser General   
13
-- Public License as published by the Free Software Foundation; 
14
-- either version 2.1 of the License, or (at your option) any   
15
-- later version.                                               
16
--                                                              
17
-- This source is distributed in the hope that it will be       
18
-- useful, but WITHOUT ANY WARRANTY; without even the implied   
19
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
20
-- PURPOSE.  See the GNU Lesser General Public License for more 
21
-- details.                                                     
22
--                                                              
23
-- You should have received a copy of the GNU Lesser General    
24
-- Public License along with this source; if not, download it   
25
-- from http://www.opencores.org/lgpl.shtml
26
--------------------------------------------------------------------------------
27 46 ja_rd
 
28 2 ja_rd
library ieee;
29
use ieee.std_logic_1164.all;
30
use ieee.std_logic_arith.all;
31
use ieee.std_logic_unsigned.all;
32
use work.mips_pkg.all;
33 191 ja_rd
use work.code_rom_pkg.all;
34 2 ja_rd
 
35
entity mips_mpu is
36 46 ja_rd
    generic (
37 119 ja_rd
        CLOCK_FREQ     : integer := 50000000;
38 46 ja_rd
        SRAM_ADDR_SIZE : integer := 17
39 2 ja_rd
    );
40
    port(
41
        clk             : in std_logic;
42
        reset           : in std_logic;
43 200 ja_rd
        interrupt       : in std_logic_vector(7 downto 0);
44 2 ja_rd
 
45 46 ja_rd
        -- interface to FPGA i/o devices
46
        io_rd_data      : in std_logic_vector(31 downto 0);
47
        io_rd_addr      : out std_logic_vector(31 downto 2);
48
        io_wr_addr      : out std_logic_vector(31 downto 2);
49
        io_wr_data      : out std_logic_vector(31 downto 0);
50
        io_rd_vma       : out std_logic;
51
        io_byte_we      : out std_logic_vector(3 downto 0);
52 2 ja_rd
 
53 46 ja_rd
        -- interface to asynchronous 16-bit-wide EXTERNAL SRAM
54
        sram_address    : out std_logic_vector(SRAM_ADDR_SIZE downto 1);
55 76 ja_rd
        sram_data_wr    : out std_logic_vector(15 downto 0);
56
        sram_data_rd    : in std_logic_vector(15 downto 0);
57 46 ja_rd
        sram_byte_we_n  : out std_logic_vector(1 downto 0);
58
        sram_oe_n       : out std_logic;
59
 
60
        -- UART 
61 2 ja_rd
        uart_rxd        : in std_logic;
62 138 ja_rd
        uart_txd        : out std_logic;
63
 
64
        -- Debug info
65
        debug_info      : out t_debug_info
66 2 ja_rd
    );
67
end; --entity mips_mpu
68
 
69
architecture rtl of mips_mpu is
70
 
71 46 ja_rd
-- interface cpu-cache
72 98 ja_rd
signal cpu_data_addr :      t_word;
73 46 ja_rd
signal cpu_data_rd_vma :    std_logic;
74
signal cpu_data_rd :        t_word;
75
signal cpu_code_rd_addr :   t_pc;
76
signal cpu_code_rd :        t_word;
77
signal cpu_code_rd_vma :    std_logic;
78
signal cpu_data_wr :        t_word;
79
signal cpu_byte_we :        std_logic_vector(3 downto 0);
80
signal cpu_mem_wait :       std_logic;
81 119 ja_rd
signal cpu_ic_invalidate :  std_logic;
82
signal cpu_cache_enable :   std_logic;
83 138 ja_rd
signal unmapped_access :    std_logic;
84 2 ja_rd
 
85 119 ja_rd
 
86 46 ja_rd
-- interface to i/o
87
signal mpu_io_rd_data :     std_logic_vector(31 downto 0);
88
signal mpu_io_wr_data :     std_logic_vector(31 downto 0);
89
signal mpu_io_rd_addr :     std_logic_vector(31 downto 2);
90
signal mpu_io_wr_addr :     std_logic_vector(31 downto 2);
91
signal mpu_io_rd_vma :      std_logic;
92
signal mpu_io_byte_we :     std_logic_vector(3 downto 0);
93 2 ja_rd
 
94 46 ja_rd
-- interface to UARTs
95 94 ja_rd
signal uart_rd_word :       t_word;
96 46 ja_rd
signal uart_tx_rdy :        std_logic := '1';
97
signal uart_rx_rdy :        std_logic := '1';
98 94 ja_rd
signal uart_write :         std_logic;
99
signal uart_read :          std_logic;
100 46 ja_rd
signal uart_read_rx :       std_logic;
101 94 ja_rd
signal uart_data_rx :       std_logic_vector(7 downto 0);
102 2 ja_rd
 
103 193 ja_rd
-- interface to bootstrap code BRAM
104 191 ja_rd
-- NOTE: 'write' signals are a remnant from a previous version, to be removed
105 46 ja_rd
signal bram_rd_addr :       t_bram_address;
106
signal bram_wr_addr :       t_bram_address;
107
signal bram_rd_data :       t_word;
108
signal bram_wr_data :       t_word;
109
signal bram_byte_we :       std_logic_vector(3 downto 0);
110 2 ja_rd
 
111
 
112 46 ja_rd
--------------------------------------------------------------------------------
113 2 ja_rd
begin
114
 
115 46 ja_rd
cpu: entity work.mips_cpu
116 2 ja_rd
    port map (
117 200 ja_rd
        interrupt   => interrupt,
118 2 ja_rd
 
119 98 ja_rd
        data_addr   => cpu_data_addr,
120 46 ja_rd
        data_rd_vma => cpu_data_rd_vma,
121
        data_rd     => cpu_data_rd,
122 2 ja_rd
 
123 46 ja_rd
        code_rd_addr=> cpu_code_rd_addr,
124
        code_rd     => cpu_code_rd,
125
        code_rd_vma => cpu_code_rd_vma,
126 2 ja_rd
 
127 46 ja_rd
        data_wr     => cpu_data_wr,
128 2 ja_rd
        byte_we     => cpu_byte_we,
129 46 ja_rd
 
130
        mem_wait    => cpu_mem_wait,
131 119 ja_rd
        cache_enable=> cpu_cache_enable,
132
        ic_invalidate=>cpu_ic_invalidate,
133 2 ja_rd
 
134
        clk         => clk,
135 46 ja_rd
        reset       => reset
136 2 ja_rd
    );
137
 
138 119 ja_rd
cache: entity work.mips_cache
139 46 ja_rd
    generic map (
140 191 ja_rd
        BRAM_ADDR_SIZE => CODE_BRAM_ADDR_SIZE,
141 46 ja_rd
        SRAM_ADDR_SIZE => SRAM_ADDR_SIZE
142
    )
143
    port map (
144
        clk             => clk,
145
        reset           => reset,
146
 
147
        -- Interface to CPU core
148 98 ja_rd
        data_addr       => cpu_data_addr,
149 46 ja_rd
        data_rd         => cpu_data_rd,
150
        data_rd_vma     => cpu_data_rd_vma,
151
 
152
        code_rd_addr    => cpu_code_rd_addr,
153
        code_rd         => cpu_code_rd,
154
        code_rd_vma     => cpu_code_rd_vma,
155
 
156
        byte_we         => cpu_byte_we,
157
        data_wr         => cpu_data_wr,
158
 
159
        mem_wait        => cpu_mem_wait,
160 119 ja_rd
        cache_enable    => cpu_cache_enable,
161
        ic_invalidate   => cpu_ic_invalidate,
162 138 ja_rd
        unmapped        => unmapped_access,
163 46 ja_rd
 
164
        -- interface to FPGA i/o devices
165
        io_rd_data      => mpu_io_rd_data,
166
        io_wr_data      => mpu_io_wr_data,
167
        io_rd_addr      => mpu_io_rd_addr,
168
        io_wr_addr      => mpu_io_wr_addr,
169
        io_rd_vma       => mpu_io_rd_vma,
170
        io_byte_we      => mpu_io_byte_we,
171 2 ja_rd
 
172 46 ja_rd
        -- interface to synchronous 32-bit-wide FPGA BRAM
173
        bram_rd_data    => bram_rd_data,
174
        bram_wr_data    => bram_wr_data,
175
        bram_rd_addr    => bram_rd_addr,
176
        bram_wr_addr    => bram_wr_addr,
177
        bram_byte_we    => bram_byte_we,
178
 
179
        -- interface to asynchronous 16-bit-wide external SRAM
180
        sram_address    => sram_address,
181 76 ja_rd
        sram_data_rd    => sram_data_rd,
182
        sram_data_wr    => sram_data_wr,
183 46 ja_rd
        sram_byte_we_n  => sram_byte_we_n,
184
        sram_oe_n       => sram_oe_n
185
    );
186 2 ja_rd
 
187
 
188 46 ja_rd
--------------------------------------------------------------------------------
189
-- BRAM interface 
190 2 ja_rd
 
191 46 ja_rd
fpga_ram_block:
192
process(clk)
193
begin
194
    if clk'event and clk='1' then
195 191 ja_rd
        bram_rd_data <= code_bram(conv_integer(unsigned(bram_rd_addr)));
196 46 ja_rd
    end if;
197
end process fpga_ram_block;
198 2 ja_rd
 
199
 
200
--------------------------------------------------------------------------------
201 138 ja_rd
-- Debug stuff
202 2 ja_rd
 
203 138 ja_rd
-- Register some debug signals. These are meant to be connected to LEDs on a 
204
-- dev board, or maybe to logic analyzer probes. They are not useful once
205
-- the core is fully debugged.
206
debug_info_register:
207
process(clk)
208
begin
209
    if clk'event and clk='1' then
210
        if reset='1' then
211
            debug_info.unmapped_access <= '0';
212
        else
213
            if unmapped_access='1' then
214
                -- This flag will be asserted permanently after any kind of 
215
                -- unmapped access (code, data read or data write).
216
                debug_info.unmapped_access <= '1';
217
            end if;
218
        end if;
219
 
220
        debug_info.cache_enabled <= cpu_cache_enable;
221
    end if;
222
end process debug_info_register;
223 2 ja_rd
 
224 138 ja_rd
 
225 2 ja_rd
--------------------------------------------------------------------------------
226
 
227 46 ja_rd
serial_rx : entity work.rs232_rx
228 119 ja_rd
    generic map (
229
        CLOCK_FREQ => CLOCK_FREQ
230
    )
231 46 ja_rd
    port map(
232
        rxd =>      uart_rxd,
233 94 ja_rd
        data_rx =>  uart_data_rx,
234 46 ja_rd
        rx_rdy =>   uart_rx_rdy,
235 94 ja_rd
        read_rx =>  uart_read_rx,
236 46 ja_rd
        clk =>      clk,
237 59 ja_rd
        reset =>    reset
238 46 ja_rd
    );
239 2 ja_rd
 
240
 
241 94 ja_rd
-- '1'-> Read some UART register (0x2---0---)
242
uart_read <= '1'
243
    when mpu_io_rd_vma='1' and
244
         mpu_io_rd_addr(31 downto 28)=X"2" and
245
         mpu_io_rd_addr(15 downto 12)=X"0"
246
    else '0';
247
 
248
-- '1'-> Read UART Rx data (0x2---0-0-)
249
-- (This signal clears the RX 1-char buffer)
250
uart_read_rx <= '1'
251
    when uart_read='1' and
252
         mpu_io_rd_addr( 7 downto  4)=X"0"
253
    else '0';
254
 
255
-- '1'-> Write UART Tx register (trigger UART Tx)  (0x20000000)
256
uart_write <= '1'
257 68 ja_rd
    when mpu_io_byte_we/="0000" and
258
         mpu_io_wr_addr(31 downto 28)=X"2" and
259
         mpu_io_wr_addr(15 downto 12)=X"0"
260 46 ja_rd
    else '0';
261 2 ja_rd
 
262 46 ja_rd
serial_tx : entity work.rs232_tx
263 119 ja_rd
    generic map (
264
        CLOCK_FREQ => CLOCK_FREQ
265
    )
266 46 ja_rd
    port map(
267
        clk =>      clk,
268 59 ja_rd
        reset =>    reset,
269 46 ja_rd
        rdy =>      uart_tx_rdy,
270 94 ja_rd
        load =>     uart_write,
271 46 ja_rd
        data_i =>   mpu_io_wr_data(7 downto 0),
272
        txd =>      uart_txd
273
    );
274 2 ja_rd
 
275 94 ja_rd
-- Both UART rd addresses 000 and 020 read the same word (save a mux), but only
276
-- address 000 clears the rx buffer.
277
uart_rd_word <= uart_data_rx & X"00000" & "00" & uart_tx_rdy & uart_rx_rdy;
278 2 ja_rd
 
279 94 ja_rd
-- IO Rd mux: either the UART data/status word od the IO coming from outside
280 68 ja_rd
mpu_io_rd_data <=
281 191 ja_rd
    uart_rd_word when mpu_io_rd_addr(15 downto 12)=X"0" else
282 68 ja_rd
    io_rd_data;
283 2 ja_rd
 
284 46 ja_rd
-- io_rd_data 
285
io_rd_addr <= mpu_io_rd_addr;
286
io_wr_addr <= mpu_io_wr_addr;
287
io_wr_data <= mpu_io_wr_data;
288
io_rd_vma <= mpu_io_rd_vma;
289
io_byte_we <= mpu_io_byte_we;
290
 
291
 
292 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.