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