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

Subversion Repositories ion

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

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
        uart_txd        : out std_logic
46
    );
47
end; --entity mips_mpu
48
 
49
architecture rtl of mips_mpu is
50
 
51
-- interface cpu-cache
52 97 ja_rd
signal cpu_data_addr :      t_word;
53 55 ja_rd
signal cpu_data_rd_vma :    std_logic;
54
signal cpu_data_rd :        t_word;
55
signal cpu_code_rd_addr :   t_pc;
56
signal cpu_code_rd :        t_word;
57
signal cpu_code_rd_vma :    std_logic;
58
signal cpu_data_wr :        t_word;
59
signal cpu_byte_we :        std_logic_vector(3 downto 0);
60
signal cpu_mem_wait :       std_logic;
61 102 ja_rd
signal cpu_ic_invalidate :  std_logic;
62
signal cpu_cache_enable :   std_logic;
63 55 ja_rd
 
64 102 ja_rd
 
65 55 ja_rd
-- interface to i/o
66
signal mpu_io_rd_data :     std_logic_vector(31 downto 0);
67
signal mpu_io_wr_data :     std_logic_vector(31 downto 0);
68
signal mpu_io_rd_addr :     std_logic_vector(31 downto 2);
69
signal mpu_io_wr_addr :     std_logic_vector(31 downto 2);
70
signal mpu_io_rd_vma :      std_logic;
71
signal mpu_io_byte_we :     std_logic_vector(3 downto 0);
72
 
73
-- interface to UARTs
74 87 ja_rd
signal uart_rd_word :       t_word;
75 55 ja_rd
signal uart_tx_rdy :        std_logic := '1';
76
signal uart_rx_rdy :        std_logic := '1';
77 87 ja_rd
signal uart_write :         std_logic;
78
signal uart_read :          std_logic;
79 55 ja_rd
signal uart_read_rx :       std_logic;
80 87 ja_rd
signal uart_data_rx :       std_logic_vector(7 downto 0);
81 55 ja_rd
 
82
 
83
-- Block ram
84
constant BRAM_SIZE : integer := @code_table_size@;
85
constant BRAM_ADDR_SIZE : integer := log2(BRAM_SIZE);
86
 
87 56 ja_rd
--type t_bram is array(0 to BRAM_SIZE-1) of std_logic_vector(7 downto 0);
88
type t_bram is array(0 to (BRAM_SIZE)-1) of t_word;
89 55 ja_rd
 
90
-- bram0 is LSB, bram3 is MSB
91 56 ja_rd
--signal bram3 :              t_bram := (@ code3@);
92
--signal bram2 :              t_bram := (@ code2@);
93
--signal bram1 :              t_bram := (@ code1@);
94
--signal bram0 :              t_bram := (@ code0@);
95 55 ja_rd
 
96 56 ja_rd
signal bram :               t_bram := (@code-32bit@);
97
 
98 55 ja_rd
subtype t_bram_address is std_logic_vector(BRAM_ADDR_SIZE-1 downto 0);
99
 
100
signal bram_rd_addr :       t_bram_address;
101
signal bram_wr_addr :       t_bram_address;
102
signal bram_rd_data :       t_word;
103
signal bram_wr_data :       t_word;
104
signal bram_byte_we :       std_logic_vector(3 downto 0);
105
 
106
 
107
--------------------------------------------------------------------------------
108
begin
109
 
110
cpu: entity work.mips_cpu
111
    port map (
112
        interrupt   => '0',
113
 
114 97 ja_rd
        data_addr   => cpu_data_addr,
115 55 ja_rd
        data_rd_vma => cpu_data_rd_vma,
116
        data_rd     => cpu_data_rd,
117
 
118
        code_rd_addr=> cpu_code_rd_addr,
119
        code_rd     => cpu_code_rd,
120
        code_rd_vma => cpu_code_rd_vma,
121
 
122
        data_wr     => cpu_data_wr,
123
        byte_we     => cpu_byte_we,
124
 
125
        mem_wait    => cpu_mem_wait,
126 102 ja_rd
        cache_enable=> cpu_cache_enable,
127
        ic_invalidate=>cpu_ic_invalidate,
128 55 ja_rd
 
129
        clk         => clk,
130
        reset       => reset
131
    );
132
 
133 125 ja_rd
cache: entity work.mips_cache
134 55 ja_rd
    generic map (
135
        BRAM_ADDR_SIZE => BRAM_ADDR_SIZE,
136
        SRAM_ADDR_SIZE => SRAM_ADDR_SIZE
137
    )
138
    port map (
139
        clk             => clk,
140
        reset           => reset,
141
 
142
        -- Interface to CPU core
143 97 ja_rd
        data_addr       => cpu_data_addr,
144 55 ja_rd
        data_rd         => cpu_data_rd,
145
        data_rd_vma     => cpu_data_rd_vma,
146
 
147
        code_rd_addr    => cpu_code_rd_addr,
148
        code_rd         => cpu_code_rd,
149
        code_rd_vma     => cpu_code_rd_vma,
150
 
151
        byte_we         => cpu_byte_we,
152
        data_wr         => cpu_data_wr,
153
 
154
        mem_wait        => cpu_mem_wait,
155 102 ja_rd
        cache_enable    => cpu_cache_enable,
156
        ic_invalidate   => cpu_ic_invalidate,
157 55 ja_rd
 
158
        -- interface to FPGA i/o devices
159
        io_rd_data      => mpu_io_rd_data,
160
        io_wr_data      => mpu_io_wr_data,
161
        io_rd_addr      => mpu_io_rd_addr,
162
        io_wr_addr      => mpu_io_wr_addr,
163
        io_rd_vma       => mpu_io_rd_vma,
164
        io_byte_we      => mpu_io_byte_we,
165
 
166
        -- interface to synchronous 32-bit-wide FPGA BRAM
167
        bram_rd_data    => bram_rd_data,
168
        bram_wr_data    => bram_wr_data,
169
        bram_rd_addr    => bram_rd_addr,
170
        bram_wr_addr    => bram_wr_addr,
171
        bram_byte_we    => bram_byte_we,
172
 
173
        -- interface to asynchronous 16-bit-wide external SRAM
174
        sram_address    => sram_address,
175 77 ja_rd
        sram_data_rd    => sram_data_rd,
176
        sram_data_wr    => sram_data_wr,
177 55 ja_rd
        sram_byte_we_n  => sram_byte_we_n,
178
        sram_oe_n       => sram_oe_n
179
    );
180
 
181
 
182
--------------------------------------------------------------------------------
183
-- BRAM interface 
184
 
185
fpga_ram_block:
186
process(clk)
187
begin
188
    if clk'event and clk='1' then
189
 
190 56 ja_rd
        --bram_rd_data <= 
191
        --    bram3(conv_integer(unsigned(bram_rd_addr))) &
192
        --    bram2(conv_integer(unsigned(bram_rd_addr))) &
193
        --    bram1(conv_integer(unsigned(bram_rd_addr))) &
194
        --    bram0(conv_integer(unsigned(bram_rd_addr)));
195
        bram_rd_data <= bram(conv_integer(unsigned(bram_rd_addr)));
196 55 ja_rd
 
197
    end if;
198
end process fpga_ram_block;
199
 
200
 
201
--------------------------------------------------------------------------------
202
 
203
 
204
--------------------------------------------------------------------------------
205
 
206
serial_rx : entity work.rs232_rx
207 113 ja_rd
    generic map (
208
        CLOCK_FREQ => CLOCK_FREQ
209
    )
210 55 ja_rd
    port map(
211
        rxd =>      uart_rxd,
212 87 ja_rd
        data_rx =>  uart_data_rx,
213 55 ja_rd
        rx_rdy =>   uart_rx_rdy,
214 87 ja_rd
        read_rx =>  uart_read_rx,
215 55 ja_rd
        clk =>      clk,
216 59 ja_rd
        reset =>    reset
217 55 ja_rd
    );
218
 
219
 
220 87 ja_rd
-- '1'-> Read some UART register (0x2---0---)
221
uart_read <= '1'
222
    when mpu_io_rd_vma='1' and
223
         mpu_io_rd_addr(31 downto 28)=X"2" and
224
         mpu_io_rd_addr(15 downto 12)=X"0"
225
    else '0';
226
 
227
-- '1'-> Read UART Rx data (0x2---0-0-)
228
-- (This signal clears the RX 1-char buffer)
229
uart_read_rx <= '1'
230
    when uart_read='1' and
231
         mpu_io_rd_addr( 7 downto  4)=X"0"
232
    else '0';
233
 
234
-- '1'-> Write UART Tx register (trigger UART Tx)  (0x20000000)
235
uart_write <= '1'
236 65 ja_rd
    when mpu_io_byte_we/="0000" and
237
         mpu_io_wr_addr(31 downto 28)=X"2" and
238
         mpu_io_wr_addr(15 downto 12)=X"0"
239 55 ja_rd
    else '0';
240
 
241
serial_tx : entity work.rs232_tx
242 113 ja_rd
    generic map (
243
        CLOCK_FREQ => CLOCK_FREQ
244
    )
245 55 ja_rd
    port map(
246
        clk =>      clk,
247 59 ja_rd
        reset =>    reset,
248 55 ja_rd
        rdy =>      uart_tx_rdy,
249 87 ja_rd
        load =>     uart_write,
250 55 ja_rd
        data_i =>   mpu_io_wr_data(7 downto 0),
251
        txd =>      uart_txd
252
    );
253
 
254 87 ja_rd
-- Both UART rd addresses 000 and 020 read the same word (save a mux), but only
255
-- address 000 clears the rx buffer.
256
uart_rd_word <= uart_data_rx & X"00000" & "00" & uart_tx_rdy & uart_rx_rdy;
257 55 ja_rd
 
258 87 ja_rd
-- IO Rd mux: either the UART data/status word od the IO coming from outside
259 65 ja_rd
mpu_io_rd_data <=
260 87 ja_rd
    uart_rd_word when mpu_io_rd_addr(15 downto 12)=X"0" else
261 65 ja_rd
    io_rd_data;
262 55 ja_rd
 
263
-- io_rd_data 
264
io_rd_addr <= mpu_io_rd_addr;
265
io_wr_addr <= mpu_io_wr_addr;
266
io_wr_data <= mpu_io_wr_data;
267
io_rd_vma <= mpu_io_rd_vma;
268
io_byte_we <= mpu_io_byte_we;
269
 
270
 
271
end architecture rtl;

powered by: WebSVN 2.1.0

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