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

Subversion Repositories ion

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

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

powered by: WebSVN 2.1.0

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