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

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [mips_mpu1_template.vhdl] - Blame information for rev 140

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

Line No. Rev Author Line
1 55 ja_rd
--------------------------------------------------------------------------------
2
-- This file was generated automatically from '/src/mips_mpu2_template.vhdl'.
3
--------------------------------------------------------------------------------
4
-- Synthesizable MPU -- CPU + cache + bootstrap BRAM + UART
5
--
6
-- This module uses the 'stub' version of the cache: a cache which actually is 
7
-- only an interface between the cpu and external static memory. This is useful 
8
-- to test external memory interface and cache-cpu interface without the cache
9
-- functionality getting in the way.
10
--------------------------------------------------------------------------------
11
 
12
library ieee;
13
use ieee.std_logic_1164.all;
14
use ieee.std_logic_arith.all;
15
use ieee.std_logic_unsigned.all;
16
use work.mips_pkg.all;
17
 
18
entity mips_mpu is
19
    generic (
20 113 ja_rd
        CLOCK_FREQ     : integer := 50000000;
21 55 ja_rd
        SRAM_ADDR_SIZE : integer := 17
22
    );
23
    port(
24
        clk             : in std_logic;
25
        reset           : in std_logic;
26
        interrupt       : in std_logic;
27
 
28
        -- interface to FPGA i/o devices
29
        io_rd_data      : in std_logic_vector(31 downto 0);
30
        io_rd_addr      : out std_logic_vector(31 downto 2);
31
        io_wr_addr      : out std_logic_vector(31 downto 2);
32
        io_wr_data      : out std_logic_vector(31 downto 0);
33
        io_rd_vma       : out std_logic;
34
        io_byte_we      : out std_logic_vector(3 downto 0);
35
 
36
        -- interface to asynchronous 16-bit-wide EXTERNAL SRAM
37
        sram_address    : out std_logic_vector(SRAM_ADDR_SIZE downto 1);
38 77 ja_rd
        sram_data_wr    : out std_logic_vector(15 downto 0);
39
        sram_data_rd    : in std_logic_vector(15 downto 0);
40 55 ja_rd
        sram_byte_we_n  : out std_logic_vector(1 downto 0);
41
        sram_oe_n       : out std_logic;
42
 
43
        -- UART 
44
        uart_rxd        : in std_logic;
45 135 ja_rd
        uart_txd        : out std_logic;
46
 
47
        -- Debug info
48
        debug_info      : out t_debug_info
49 55 ja_rd
    );
50
end; --entity mips_mpu
51
 
52
architecture rtl of mips_mpu is
53
 
54
-- interface cpu-cache
55 97 ja_rd
signal cpu_data_addr :      t_word;
56 55 ja_rd
signal cpu_data_rd_vma :    std_logic;
57
signal cpu_data_rd :        t_word;
58
signal cpu_code_rd_addr :   t_pc;
59
signal cpu_code_rd :        t_word;
60
signal cpu_code_rd_vma :    std_logic;
61
signal cpu_data_wr :        t_word;
62
signal cpu_byte_we :        std_logic_vector(3 downto 0);
63
signal cpu_mem_wait :       std_logic;
64 102 ja_rd
signal cpu_ic_invalidate :  std_logic;
65
signal cpu_cache_enable :   std_logic;
66 135 ja_rd
signal unmapped_access :    std_logic;
67 55 ja_rd
 
68 102 ja_rd
 
69 55 ja_rd
-- interface to i/o
70
signal mpu_io_rd_data :     std_logic_vector(31 downto 0);
71
signal mpu_io_wr_data :     std_logic_vector(31 downto 0);
72
signal mpu_io_rd_addr :     std_logic_vector(31 downto 2);
73
signal mpu_io_wr_addr :     std_logic_vector(31 downto 2);
74
signal mpu_io_rd_vma :      std_logic;
75
signal mpu_io_byte_we :     std_logic_vector(3 downto 0);
76
 
77
-- interface to UARTs
78 87 ja_rd
signal uart_rd_word :       t_word;
79 55 ja_rd
signal uart_tx_rdy :        std_logic := '1';
80
signal uart_rx_rdy :        std_logic := '1';
81 87 ja_rd
signal uart_write :         std_logic;
82
signal uart_read :          std_logic;
83 55 ja_rd
signal uart_read_rx :       std_logic;
84 87 ja_rd
signal uart_data_rx :       std_logic_vector(7 downto 0);
85 55 ja_rd
 
86
 
87
-- Block ram
88
constant BRAM_SIZE : integer := @code_table_size@;
89
constant BRAM_ADDR_SIZE : integer := log2(BRAM_SIZE);
90
 
91 56 ja_rd
--type t_bram is array(0 to BRAM_SIZE-1) of std_logic_vector(7 downto 0);
92
type t_bram is array(0 to (BRAM_SIZE)-1) of t_word;
93 55 ja_rd
 
94
-- bram0 is LSB, bram3 is MSB
95 56 ja_rd
--signal bram3 :              t_bram := (@ code3@);
96
--signal bram2 :              t_bram := (@ code2@);
97
--signal bram1 :              t_bram := (@ code1@);
98
--signal bram0 :              t_bram := (@ code0@);
99 55 ja_rd
 
100 56 ja_rd
signal bram :               t_bram := (@code-32bit@);
101
 
102 55 ja_rd
subtype t_bram_address is std_logic_vector(BRAM_ADDR_SIZE-1 downto 0);
103
 
104
signal bram_rd_addr :       t_bram_address;
105
signal bram_wr_addr :       t_bram_address;
106
signal bram_rd_data :       t_word;
107
signal bram_wr_data :       t_word;
108
signal bram_byte_we :       std_logic_vector(3 downto 0);
109
 
110
 
111
--------------------------------------------------------------------------------
112
begin
113
 
114
cpu: entity work.mips_cpu
115
    port map (
116
        interrupt   => '0',
117
 
118 97 ja_rd
        data_addr   => cpu_data_addr,
119 55 ja_rd
        data_rd_vma => cpu_data_rd_vma,
120
        data_rd     => cpu_data_rd,
121
 
122
        code_rd_addr=> cpu_code_rd_addr,
123
        code_rd     => cpu_code_rd,
124
        code_rd_vma => cpu_code_rd_vma,
125
 
126
        data_wr     => cpu_data_wr,
127
        byte_we     => cpu_byte_we,
128
 
129
        mem_wait    => cpu_mem_wait,
130 102 ja_rd
        cache_enable=> cpu_cache_enable,
131
        ic_invalidate=>cpu_ic_invalidate,
132 55 ja_rd
 
133
        clk         => clk,
134
        reset       => reset
135
    );
136
 
137 125 ja_rd
cache: entity work.mips_cache
138 55 ja_rd
    generic map (
139
        BRAM_ADDR_SIZE => BRAM_ADDR_SIZE,
140
        SRAM_ADDR_SIZE => SRAM_ADDR_SIZE
141
    )
142
    port map (
143
        clk             => clk,
144
        reset           => reset,
145
 
146
        -- Interface to CPU core
147 97 ja_rd
        data_addr       => cpu_data_addr,
148 55 ja_rd
        data_rd         => cpu_data_rd,
149
        data_rd_vma     => cpu_data_rd_vma,
150
 
151
        code_rd_addr    => cpu_code_rd_addr,
152
        code_rd         => cpu_code_rd,
153
        code_rd_vma     => cpu_code_rd_vma,
154
 
155
        byte_we         => cpu_byte_we,
156
        data_wr         => cpu_data_wr,
157
 
158
        mem_wait        => cpu_mem_wait,
159 102 ja_rd
        cache_enable    => cpu_cache_enable,
160
        ic_invalidate   => cpu_ic_invalidate,
161 135 ja_rd
        unmapped        => unmapped_access,
162 55 ja_rd
 
163
        -- interface to FPGA i/o devices
164
        io_rd_data      => mpu_io_rd_data,
165
        io_wr_data      => mpu_io_wr_data,
166
        io_rd_addr      => mpu_io_rd_addr,
167
        io_wr_addr      => mpu_io_wr_addr,
168
        io_rd_vma       => mpu_io_rd_vma,
169
        io_byte_we      => mpu_io_byte_we,
170
 
171
        -- interface to synchronous 32-bit-wide FPGA BRAM
172
        bram_rd_data    => bram_rd_data,
173
        bram_wr_data    => bram_wr_data,
174
        bram_rd_addr    => bram_rd_addr,
175
        bram_wr_addr    => bram_wr_addr,
176
        bram_byte_we    => bram_byte_we,
177
 
178
        -- interface to asynchronous 16-bit-wide external SRAM
179
        sram_address    => sram_address,
180 77 ja_rd
        sram_data_rd    => sram_data_rd,
181
        sram_data_wr    => sram_data_wr,
182 55 ja_rd
        sram_byte_we_n  => sram_byte_we_n,
183
        sram_oe_n       => sram_oe_n
184
    );
185
 
186
 
187
--------------------------------------------------------------------------------
188
-- BRAM interface 
189
 
190
fpga_ram_block:
191
process(clk)
192
begin
193
    if clk'event and clk='1' then
194
 
195 56 ja_rd
        --bram_rd_data <= 
196
        --    bram3(conv_integer(unsigned(bram_rd_addr))) &
197
        --    bram2(conv_integer(unsigned(bram_rd_addr))) &
198
        --    bram1(conv_integer(unsigned(bram_rd_addr))) &
199
        --    bram0(conv_integer(unsigned(bram_rd_addr)));
200
        bram_rd_data <= bram(conv_integer(unsigned(bram_rd_addr)));
201 55 ja_rd
 
202
    end if;
203
end process fpga_ram_block;
204
 
205
 
206
--------------------------------------------------------------------------------
207 135 ja_rd
-- Debug stuff
208 55 ja_rd
 
209 135 ja_rd
-- Register some debug signals. These are meant to be connected to LEDs on a 
210
-- dev board, or maybe to logic analyzer probes. They are not useful once
211
-- the core is fully debugged.
212
debug_info_register:
213
process(clk)
214
begin
215
    if clk'event and clk='1' then
216
        if reset='1' then
217
            debug_info.unmapped_access <= '0';
218
        else
219
            if unmapped_access='1' then
220
                -- This flag will be asserted permanently after any kind of 
221
                -- unmapped access (code, data read or data write).
222
                debug_info.unmapped_access <= '1';
223
            end if;
224
        end if;
225
 
226
        debug_info.cache_enabled <= cpu_cache_enable;
227
    end if;
228
end process debug_info_register;
229 55 ja_rd
 
230 135 ja_rd
 
231 55 ja_rd
--------------------------------------------------------------------------------
232
 
233
serial_rx : entity work.rs232_rx
234 113 ja_rd
    generic map (
235
        CLOCK_FREQ => CLOCK_FREQ
236
    )
237 55 ja_rd
    port map(
238
        rxd =>      uart_rxd,
239 87 ja_rd
        data_rx =>  uart_data_rx,
240 55 ja_rd
        rx_rdy =>   uart_rx_rdy,
241 87 ja_rd
        read_rx =>  uart_read_rx,
242 55 ja_rd
        clk =>      clk,
243 59 ja_rd
        reset =>    reset
244 55 ja_rd
    );
245
 
246
 
247 87 ja_rd
-- '1'-> Read some UART register (0x2---0---)
248
uart_read <= '1'
249
    when mpu_io_rd_vma='1' and
250
         mpu_io_rd_addr(31 downto 28)=X"2" and
251
         mpu_io_rd_addr(15 downto 12)=X"0"
252
    else '0';
253
 
254
-- '1'-> Read UART Rx data (0x2---0-0-)
255
-- (This signal clears the RX 1-char buffer)
256
uart_read_rx <= '1'
257
    when uart_read='1' and
258
         mpu_io_rd_addr( 7 downto  4)=X"0"
259
    else '0';
260
 
261
-- '1'-> Write UART Tx register (trigger UART Tx)  (0x20000000)
262
uart_write <= '1'
263 65 ja_rd
    when mpu_io_byte_we/="0000" and
264
         mpu_io_wr_addr(31 downto 28)=X"2" and
265
         mpu_io_wr_addr(15 downto 12)=X"0"
266 55 ja_rd
    else '0';
267
 
268
serial_tx : entity work.rs232_tx
269 113 ja_rd
    generic map (
270
        CLOCK_FREQ => CLOCK_FREQ
271
    )
272 55 ja_rd
    port map(
273
        clk =>      clk,
274 59 ja_rd
        reset =>    reset,
275 55 ja_rd
        rdy =>      uart_tx_rdy,
276 87 ja_rd
        load =>     uart_write,
277 55 ja_rd
        data_i =>   mpu_io_wr_data(7 downto 0),
278
        txd =>      uart_txd
279
    );
280
 
281 87 ja_rd
-- Both UART rd addresses 000 and 020 read the same word (save a mux), but only
282
-- address 000 clears the rx buffer.
283
uart_rd_word <= uart_data_rx & X"00000" & "00" & uart_tx_rdy & uart_rx_rdy;
284 55 ja_rd
 
285 87 ja_rd
-- IO Rd mux: either the UART data/status word od the IO coming from outside
286 65 ja_rd
mpu_io_rd_data <=
287 87 ja_rd
    uart_rd_word when mpu_io_rd_addr(15 downto 12)=X"0" else
288 65 ja_rd
    io_rd_data;
289 55 ja_rd
 
290
-- io_rd_data 
291
io_rd_addr <= mpu_io_rd_addr;
292
io_wr_addr <= mpu_io_wr_addr;
293
io_wr_data <= mpu_io_wr_data;
294
io_rd_vma <= mpu_io_rd_vma;
295
io_byte_we <= mpu_io_byte_we;
296
 
297
 
298
end architecture rtl;

powered by: WebSVN 2.1.0

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