| 1 |
2 |
zero_gravi |
-- #################################################################################################
|
| 2 |
|
|
-- # << NEORV32 - Main VHDL package file >> #
|
| 3 |
|
|
-- # ********************************************************************************************* #
|
| 4 |
|
|
-- # BSD 3-Clause License #
|
| 5 |
|
|
-- # #
|
| 6 |
|
|
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved. #
|
| 7 |
|
|
-- # #
|
| 8 |
|
|
-- # Redistribution and use in source and binary forms, with or without modification, are #
|
| 9 |
|
|
-- # permitted provided that the following conditions are met: #
|
| 10 |
|
|
-- # #
|
| 11 |
|
|
-- # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
| 12 |
|
|
-- # conditions and the following disclaimer. #
|
| 13 |
|
|
-- # #
|
| 14 |
|
|
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
|
| 15 |
|
|
-- # conditions and the following disclaimer in the documentation and/or other materials #
|
| 16 |
|
|
-- # provided with the distribution. #
|
| 17 |
|
|
-- # #
|
| 18 |
|
|
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
|
| 19 |
|
|
-- # endorse or promote products derived from this software without specific prior written #
|
| 20 |
|
|
-- # permission. #
|
| 21 |
|
|
-- # #
|
| 22 |
|
|
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
|
| 23 |
|
|
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
|
| 24 |
|
|
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
|
| 25 |
|
|
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
|
| 26 |
|
|
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
|
| 27 |
|
|
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
|
| 28 |
|
|
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
|
| 29 |
|
|
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
|
| 30 |
|
|
-- # OF THE POSSIBILITY OF SUCH DAMAGE. #
|
| 31 |
|
|
-- # ********************************************************************************************* #
|
| 32 |
|
|
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting #
|
| 33 |
|
|
-- #################################################################################################
|
| 34 |
|
|
|
| 35 |
|
|
library ieee;
|
| 36 |
|
|
use ieee.std_logic_1164.all;
|
| 37 |
|
|
use ieee.numeric_std.all;
|
| 38 |
|
|
|
| 39 |
|
|
package neorv32_package is
|
| 40 |
|
|
|
| 41 |
27 |
zero_gravi |
-- Architecture Constants -----------------------------------------------------------------
|
| 42 |
2 |
zero_gravi |
-- -------------------------------------------------------------------------------------------
|
| 43 |
27 |
zero_gravi |
constant data_width_c : natural := 32; -- data width - do not change!
|
| 44 |
|
|
constant hw_version_c : std_ulogic_vector(31 downto 0) := x"01040309"; -- no touchy!
|
| 45 |
|
|
constant pmp_max_r_c : natural := 8; -- max PMP regions - FIXED!
|
| 46 |
|
|
|
| 47 |
|
|
-- Architecture Configuration -------------------------------------------------------------
|
| 48 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 49 |
|
|
constant ispace_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"00000000"; -- default instruction memory address space base address
|
| 50 |
|
|
constant dspace_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"80000000"; -- default data memory address space base address
|
| 51 |
25 |
zero_gravi |
constant ipb_entries_c : natural := 2; -- entries in instruction prefetch buffer, must be a power of 2, default=2
|
| 52 |
|
|
constant rf_r0_is_reg_c : boolean := true; -- reg_file.r0 is a physical register that has to be initialized to zero
|
| 53 |
2 |
zero_gravi |
|
| 54 |
12 |
zero_gravi |
-- Helper Functions -----------------------------------------------------------------------
|
| 55 |
2 |
zero_gravi |
-- -------------------------------------------------------------------------------------------
|
| 56 |
|
|
function index_size_f(input : natural) return natural;
|
| 57 |
|
|
function cond_sel_natural_f(cond : boolean; val_t : natural; val_f : natural) return natural;
|
| 58 |
|
|
function cond_sel_stdulogicvector_f(cond : boolean; val_t : std_ulogic_vector; val_f : std_ulogic_vector) return std_ulogic_vector;
|
| 59 |
|
|
function bool_to_ulogic_f(cond : boolean) return std_ulogic;
|
| 60 |
15 |
zero_gravi |
function or_all_f(a : std_ulogic_vector) return std_ulogic;
|
| 61 |
|
|
function and_all_f(a : std_ulogic_vector) return std_ulogic;
|
| 62 |
|
|
function xor_all_f(a : std_ulogic_vector) return std_ulogic;
|
| 63 |
2 |
zero_gravi |
function xnor_all_f(a : std_ulogic_vector) return std_ulogic;
|
| 64 |
6 |
zero_gravi |
function to_hexchar_f(input : std_ulogic_vector(3 downto 0)) return character;
|
| 65 |
2 |
zero_gravi |
|
| 66 |
15 |
zero_gravi |
-- Internal Types -------------------------------------------------------------------------
|
| 67 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 68 |
|
|
type pmp_ctrl_if_t is array (0 to pmp_max_r_c-1) of std_ulogic_vector(7 downto 0);
|
| 69 |
|
|
type pmp_addr_if_t is array (0 to pmp_max_r_c-1) of std_ulogic_vector(33 downto 0);
|
| 70 |
|
|
|
| 71 |
23 |
zero_gravi |
-- Processor-Internal Address Space Layout ------------------------------------------------
|
| 72 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 73 |
|
|
-- Internal Instruction Memory (IMEM) --
|
| 74 |
|
|
constant imem_base_c : std_ulogic_vector(data_width_c-1 downto 0) := ispace_base_c; -- internal instruction memory base address
|
| 75 |
|
|
--> size is configured via top's generic
|
| 76 |
2 |
zero_gravi |
|
| 77 |
23 |
zero_gravi |
-- Internal Data Memory (DMEM) --
|
| 78 |
|
|
constant dmem_base_c : std_ulogic_vector(data_width_c-1 downto 0) := dspace_base_c; -- internal data memory base address
|
| 79 |
|
|
--> size is configured via top's generic
|
| 80 |
|
|
|
| 81 |
|
|
-- Internal Bootloader ROM --
|
| 82 |
|
|
constant boot_rom_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFF0000"; -- bootloader base address, fixed!
|
| 83 |
|
|
constant boot_rom_size_c : natural := 4*1024; -- bytes
|
| 84 |
|
|
constant boot_rom_max_size_c : natural := 32*1024; -- bytes, fixed!
|
| 85 |
|
|
|
| 86 |
2 |
zero_gravi |
-- IO: Peripheral Devices ("IO") Area --
|
| 87 |
|
|
-- Control register(s) (including the device-enable) should be located at the base address of each device
|
| 88 |
|
|
constant io_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF80";
|
| 89 |
|
|
constant io_size_c : natural := 32*4; -- bytes, fixed!
|
| 90 |
|
|
|
| 91 |
|
|
-- General Purpose Input/Output Unit (GPIO) --
|
| 92 |
|
|
constant gpio_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF80"; -- base address, fixed!
|
| 93 |
23 |
zero_gravi |
constant gpio_size_c : natural := 2*4; -- bytes
|
| 94 |
|
|
constant gpio_in_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF80";
|
| 95 |
|
|
constant gpio_out_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF84";
|
| 96 |
2 |
zero_gravi |
|
| 97 |
18 |
zero_gravi |
-- Dummy Device (with SIMULATION output) (DEVNULL) --
|
| 98 |
|
|
constant devnull_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF88"; -- base address, fixed!
|
| 99 |
23 |
zero_gravi |
constant devnull_size_c : natural := 1*4; -- bytes
|
| 100 |
|
|
constant devnull_data_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF88";
|
| 101 |
2 |
zero_gravi |
|
| 102 |
|
|
-- Watch Dog Timer (WDT) --
|
| 103 |
|
|
constant wdt_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF8C"; -- base address, fixed!
|
| 104 |
23 |
zero_gravi |
constant wdt_size_c : natural := 1*4; -- bytes
|
| 105 |
|
|
constant wdt_ctrl_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF8C";
|
| 106 |
2 |
zero_gravi |
|
| 107 |
|
|
-- Machine System Timer (MTIME) --
|
| 108 |
|
|
constant mtime_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF90"; -- base address, fixed!
|
| 109 |
23 |
zero_gravi |
constant mtime_size_c : natural := 4*4; -- bytes
|
| 110 |
|
|
constant mtime_time_lo_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF90";
|
| 111 |
|
|
constant mtime_time_hi_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF94";
|
| 112 |
|
|
constant mtime_cmp_lo_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF98";
|
| 113 |
|
|
constant mtime_cmp_hi_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF9C";
|
| 114 |
2 |
zero_gravi |
|
| 115 |
|
|
-- Universal Asynchronous Receiver/Transmitter (UART) --
|
| 116 |
|
|
constant uart_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFA0"; -- base address, fixed!
|
| 117 |
23 |
zero_gravi |
constant uart_size_c : natural := 2*4; -- bytes
|
| 118 |
|
|
constant uart_ctrl_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFA0";
|
| 119 |
|
|
constant uart_rtx_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFA4";
|
| 120 |
2 |
zero_gravi |
|
| 121 |
|
|
-- Serial Peripheral Interface (SPI) --
|
| 122 |
|
|
constant spi_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFA8"; -- base address, fixed!
|
| 123 |
23 |
zero_gravi |
constant spi_size_c : natural := 2*4; -- bytes
|
| 124 |
|
|
constant spi_ctrl_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFA8";
|
| 125 |
|
|
constant spi_rtx_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFAC";
|
| 126 |
2 |
zero_gravi |
|
| 127 |
|
|
-- Two Wire Interface (TWI) --
|
| 128 |
|
|
constant twi_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFB0"; -- base address, fixed!
|
| 129 |
23 |
zero_gravi |
constant twi_size_c : natural := 2*4; -- bytes
|
| 130 |
|
|
constant twi_ctrl_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFB0";
|
| 131 |
|
|
constant twi_rtx_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFB4";
|
| 132 |
2 |
zero_gravi |
|
| 133 |
|
|
-- Pulse-Width Modulation Controller (PWM) --
|
| 134 |
|
|
constant pwm_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFB8"; -- base address, fixed!
|
| 135 |
23 |
zero_gravi |
constant pwm_size_c : natural := 2*4; -- bytes
|
| 136 |
|
|
constant pwm_ctrl_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFB8";
|
| 137 |
|
|
constant pwm_duty_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFBC";
|
| 138 |
2 |
zero_gravi |
|
| 139 |
23 |
zero_gravi |
-- True Random Number Generator (TRNG) --
|
| 140 |
2 |
zero_gravi |
constant trng_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFC0"; -- base address, fixed!
|
| 141 |
23 |
zero_gravi |
constant trng_size_c : natural := 1*4; -- bytes
|
| 142 |
|
|
constant trng_ctrl_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFC0";
|
| 143 |
2 |
zero_gravi |
|
| 144 |
12 |
zero_gravi |
-- RESERVED --
|
| 145 |
23 |
zero_gravi |
--constant ???_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFC4"; -- base address, fixed!
|
| 146 |
|
|
--constant ???_size_c : natural := 3*4; -- bytes
|
| 147 |
12 |
zero_gravi |
|
| 148 |
23 |
zero_gravi |
-- Custom Functions Unit (CFU) --
|
| 149 |
|
|
constant cfu_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFD0"; -- base address, fixed!
|
| 150 |
|
|
constant cfu_size_c : natural := 4*4; -- bytes
|
| 151 |
|
|
constant cfu_reg0_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFD0";
|
| 152 |
|
|
constant cfu_reg1_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFD4";
|
| 153 |
|
|
constant cfu_reg2_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFD8";
|
| 154 |
|
|
constant cfu_reg3_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFDC";
|
| 155 |
|
|
|
| 156 |
|
|
-- System Information Memory (SYSINFO) --
|
| 157 |
12 |
zero_gravi |
constant sysinfo_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFE0"; -- base address, fixed!
|
| 158 |
23 |
zero_gravi |
constant sysinfo_size_c : natural := 8*4; -- bytes
|
| 159 |
12 |
zero_gravi |
|
| 160 |
2 |
zero_gravi |
-- Main Control Bus -----------------------------------------------------------------------
|
| 161 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 162 |
|
|
-- register file --
|
| 163 |
|
|
constant ctrl_rf_in_mux_lsb_c : natural := 0; -- input source select lsb (00=ALU, 01=MEM)
|
| 164 |
|
|
constant ctrl_rf_in_mux_msb_c : natural := 1; -- input source select msb (10=PC, 11=CSR)
|
| 165 |
|
|
constant ctrl_rf_rs1_adr0_c : natural := 2; -- source register 1 address bit 0
|
| 166 |
|
|
constant ctrl_rf_rs1_adr1_c : natural := 3; -- source register 1 address bit 1
|
| 167 |
|
|
constant ctrl_rf_rs1_adr2_c : natural := 4; -- source register 1 address bit 2
|
| 168 |
|
|
constant ctrl_rf_rs1_adr3_c : natural := 5; -- source register 1 address bit 3
|
| 169 |
|
|
constant ctrl_rf_rs1_adr4_c : natural := 6; -- source register 1 address bit 4
|
| 170 |
|
|
constant ctrl_rf_rs2_adr0_c : natural := 7; -- source register 2 address bit 0
|
| 171 |
|
|
constant ctrl_rf_rs2_adr1_c : natural := 8; -- source register 2 address bit 1
|
| 172 |
|
|
constant ctrl_rf_rs2_adr2_c : natural := 9; -- source register 2 address bit 2
|
| 173 |
|
|
constant ctrl_rf_rs2_adr3_c : natural := 10; -- source register 2 address bit 3
|
| 174 |
|
|
constant ctrl_rf_rs2_adr4_c : natural := 11; -- source register 2 address bit 4
|
| 175 |
|
|
constant ctrl_rf_rd_adr0_c : natural := 12; -- destiantion register address bit 0
|
| 176 |
|
|
constant ctrl_rf_rd_adr1_c : natural := 13; -- destiantion register address bit 1
|
| 177 |
|
|
constant ctrl_rf_rd_adr2_c : natural := 14; -- destiantion register address bit 2
|
| 178 |
|
|
constant ctrl_rf_rd_adr3_c : natural := 15; -- destiantion register address bit 3
|
| 179 |
|
|
constant ctrl_rf_rd_adr4_c : natural := 16; -- destiantion register address bit 4
|
| 180 |
|
|
constant ctrl_rf_wb_en_c : natural := 17; -- write back enable
|
| 181 |
25 |
zero_gravi |
constant ctrl_rf_r0_we_c : natural := 18; -- allow write access to r0 (zero), also forces dst=r0
|
| 182 |
2 |
zero_gravi |
-- alu --
|
| 183 |
24 |
zero_gravi |
constant ctrl_alu_cmd0_c : natural := 19; -- ALU command bit 0
|
| 184 |
|
|
constant ctrl_alu_cmd1_c : natural := 20; -- ALU command bit 1
|
| 185 |
|
|
constant ctrl_alu_cmd2_c : natural := 21; -- ALU command bit 2
|
| 186 |
27 |
zero_gravi |
constant ctrl_alu_opa_mux_c : natural := 22; -- operand A select (0=rs1, 1=PC)
|
| 187 |
|
|
constant ctrl_alu_opb_mux_c : natural := 23; -- operand B select (0=rs2, 1=IMM)
|
| 188 |
|
|
constant ctrl_alu_opc_mux_c : natural := 24; -- operand C select (0=rs2, 1=IMM)
|
| 189 |
|
|
constant ctrl_alu_unsigned_c : natural := 25; -- is unsigned ALU operation
|
| 190 |
|
|
constant ctrl_alu_shift_dir_c : natural := 26; -- shift direction (0=left, 1=right)
|
| 191 |
|
|
constant ctrl_alu_shift_ar_c : natural := 27; -- is arithmetic shift
|
| 192 |
2 |
zero_gravi |
-- bus interface --
|
| 193 |
27 |
zero_gravi |
constant ctrl_bus_size_lsb_c : natural := 28; -- transfer size lsb (00=byte, 01=half-word)
|
| 194 |
|
|
constant ctrl_bus_size_msb_c : natural := 29; -- transfer size msb (10=word, 11=?)
|
| 195 |
|
|
constant ctrl_bus_rd_c : natural := 30; -- read data request
|
| 196 |
|
|
constant ctrl_bus_wr_c : natural := 31; -- write data request
|
| 197 |
|
|
constant ctrl_bus_if_c : natural := 32; -- instruction fetch request
|
| 198 |
|
|
constant ctrl_bus_mar_we_c : natural := 33; -- memory address register write enable
|
| 199 |
|
|
constant ctrl_bus_mdo_we_c : natural := 34; -- memory data out register write enable
|
| 200 |
|
|
constant ctrl_bus_mdi_we_c : natural := 35; -- memory data in register write enable
|
| 201 |
|
|
constant ctrl_bus_unsigned_c : natural := 36; -- is unsigned load
|
| 202 |
|
|
constant ctrl_bus_ierr_ack_c : natural := 37; -- acknowledge instruction fetch bus exceptions
|
| 203 |
|
|
constant ctrl_bus_derr_ack_c : natural := 38; -- acknowledge data access bus exceptions
|
| 204 |
|
|
constant ctrl_bus_fence_c : natural := 39; -- executed fence operation
|
| 205 |
|
|
constant ctrl_bus_fencei_c : natural := 40; -- executed fencei operation
|
| 206 |
26 |
zero_gravi |
-- co-processors --
|
| 207 |
27 |
zero_gravi |
constant ctrl_cp_use_c : natural := 41; -- is cp operation
|
| 208 |
|
|
constant ctrl_cp_id_lsb_c : natural := 42; -- cp select ID lsb
|
| 209 |
|
|
constant ctrl_cp_id_msb_c : natural := 43; -- cp select ID msb
|
| 210 |
|
|
constant ctrl_cp_cmd0_c : natural := 44; -- cp command bit 0
|
| 211 |
|
|
constant ctrl_cp_cmd1_c : natural := 45; -- cp command bit 1
|
| 212 |
|
|
constant ctrl_cp_cmd2_c : natural := 46; -- cp command bit 2
|
| 213 |
2 |
zero_gravi |
-- control bus size --
|
| 214 |
27 |
zero_gravi |
constant ctrl_width_c : natural := 47; -- control bus size
|
| 215 |
2 |
zero_gravi |
|
| 216 |
27 |
zero_gravi |
constant ctrl_alu_aopb_inv_c : natural := 48;
|
| 217 |
|
|
|
| 218 |
2 |
zero_gravi |
-- ALU Comparator Bus ---------------------------------------------------------------------
|
| 219 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 220 |
|
|
constant alu_cmp_equal_c : natural := 0;
|
| 221 |
6 |
zero_gravi |
constant alu_cmp_less_c : natural := 1; -- for signed and unsigned comparisons
|
| 222 |
2 |
zero_gravi |
|
| 223 |
|
|
-- RISC-V Opcode Layout -------------------------------------------------------------------
|
| 224 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 225 |
|
|
constant instr_opcode_lsb_c : natural := 0; -- opcode bit 0
|
| 226 |
|
|
constant instr_opcode_msb_c : natural := 6; -- opcode bit 6
|
| 227 |
|
|
constant instr_rd_lsb_c : natural := 7; -- destination register address bit 0
|
| 228 |
|
|
constant instr_rd_msb_c : natural := 11; -- destination register address bit 4
|
| 229 |
|
|
constant instr_funct3_lsb_c : natural := 12; -- funct3 bit 0
|
| 230 |
|
|
constant instr_funct3_msb_c : natural := 14; -- funct3 bit 2
|
| 231 |
|
|
constant instr_rs1_lsb_c : natural := 15; -- source register 1 address bit 0
|
| 232 |
|
|
constant instr_rs1_msb_c : natural := 19; -- source register 1 address bit 4
|
| 233 |
|
|
constant instr_rs2_lsb_c : natural := 20; -- source register 2 address bit 0
|
| 234 |
|
|
constant instr_rs2_msb_c : natural := 24; -- source register 2 address bit 4
|
| 235 |
|
|
constant instr_funct7_lsb_c : natural := 25; -- funct7 bit 0
|
| 236 |
|
|
constant instr_funct7_msb_c : natural := 31; -- funct7 bit 6
|
| 237 |
|
|
constant instr_funct12_lsb_c : natural := 20; -- funct12 bit 0
|
| 238 |
|
|
constant instr_funct12_msb_c : natural := 31; -- funct12 bit 11
|
| 239 |
|
|
constant instr_imm12_lsb_c : natural := 20; -- immediate12 bit 0
|
| 240 |
|
|
constant instr_imm12_msb_c : natural := 31; -- immediate12 bit 11
|
| 241 |
|
|
constant instr_imm20_lsb_c : natural := 12; -- immediate20 bit 0
|
| 242 |
|
|
constant instr_imm20_msb_c : natural := 31; -- immediate20 bit 21
|
| 243 |
|
|
constant instr_csr_id_lsb_c : natural := 20; -- csr select bit 0
|
| 244 |
|
|
constant instr_csr_id_msb_c : natural := 31; -- csr select bit 11
|
| 245 |
|
|
|
| 246 |
|
|
-- RISC-V Opcodes -------------------------------------------------------------------------
|
| 247 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 248 |
|
|
-- alu --
|
| 249 |
|
|
constant opcode_lui_c : std_ulogic_vector(6 downto 0) := "0110111"; -- load upper immediate
|
| 250 |
|
|
constant opcode_auipc_c : std_ulogic_vector(6 downto 0) := "0010111"; -- add upper immediate to PC
|
| 251 |
|
|
constant opcode_alui_c : std_ulogic_vector(6 downto 0) := "0010011"; -- ALU operation with immediate (operation via funct3 and funct7)
|
| 252 |
|
|
constant opcode_alu_c : std_ulogic_vector(6 downto 0) := "0110011"; -- ALU operation (operation via funct3 and funct7)
|
| 253 |
|
|
-- control flow --
|
| 254 |
|
|
constant opcode_jal_c : std_ulogic_vector(6 downto 0) := "1101111"; -- jump and link
|
| 255 |
|
|
constant opcode_jalr_c : std_ulogic_vector(6 downto 0) := "1100111"; -- jump and register
|
| 256 |
|
|
constant opcode_branch_c : std_ulogic_vector(6 downto 0) := "1100011"; -- branch (condition set via funct3)
|
| 257 |
|
|
-- memory access --
|
| 258 |
|
|
constant opcode_load_c : std_ulogic_vector(6 downto 0) := "0000011"; -- load (data type via funct3)
|
| 259 |
|
|
constant opcode_store_c : std_ulogic_vector(6 downto 0) := "0100011"; -- store (data type via funct3)
|
| 260 |
|
|
-- system/csr --
|
| 261 |
8 |
zero_gravi |
constant opcode_fence_c : std_ulogic_vector(6 downto 0) := "0001111"; -- fence / fence.i
|
| 262 |
2 |
zero_gravi |
constant opcode_syscsr_c : std_ulogic_vector(6 downto 0) := "1110011"; -- system/csr access (type via funct3)
|
| 263 |
|
|
|
| 264 |
|
|
-- RISC-V Funct3 --------------------------------------------------------------------------
|
| 265 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 266 |
|
|
-- control flow --
|
| 267 |
|
|
constant funct3_beq_c : std_ulogic_vector(2 downto 0) := "000"; -- branch if equal
|
| 268 |
|
|
constant funct3_bne_c : std_ulogic_vector(2 downto 0) := "001"; -- branch if not equal
|
| 269 |
|
|
constant funct3_blt_c : std_ulogic_vector(2 downto 0) := "100"; -- branch if less than
|
| 270 |
|
|
constant funct3_bge_c : std_ulogic_vector(2 downto 0) := "101"; -- branch if greater than or equal
|
| 271 |
|
|
constant funct3_bltu_c : std_ulogic_vector(2 downto 0) := "110"; -- branch if less than (unsigned)
|
| 272 |
|
|
constant funct3_bgeu_c : std_ulogic_vector(2 downto 0) := "111"; -- branch if greater than or equal (unsigned)
|
| 273 |
|
|
-- memory access --
|
| 274 |
|
|
constant funct3_lb_c : std_ulogic_vector(2 downto 0) := "000"; -- load byte
|
| 275 |
|
|
constant funct3_lh_c : std_ulogic_vector(2 downto 0) := "001"; -- load half word
|
| 276 |
|
|
constant funct3_lw_c : std_ulogic_vector(2 downto 0) := "010"; -- load word
|
| 277 |
|
|
constant funct3_lbu_c : std_ulogic_vector(2 downto 0) := "100"; -- load byte (unsigned)
|
| 278 |
|
|
constant funct3_lhu_c : std_ulogic_vector(2 downto 0) := "101"; -- load half word (unsigned)
|
| 279 |
|
|
constant funct3_sb_c : std_ulogic_vector(2 downto 0) := "000"; -- store byte
|
| 280 |
|
|
constant funct3_sh_c : std_ulogic_vector(2 downto 0) := "001"; -- store half word
|
| 281 |
|
|
constant funct3_sw_c : std_ulogic_vector(2 downto 0) := "010"; -- store word
|
| 282 |
|
|
-- alu --
|
| 283 |
|
|
constant funct3_subadd_c : std_ulogic_vector(2 downto 0) := "000"; -- sub/add via funct7
|
| 284 |
|
|
constant funct3_sll_c : std_ulogic_vector(2 downto 0) := "001"; -- shift logical left
|
| 285 |
|
|
constant funct3_slt_c : std_ulogic_vector(2 downto 0) := "010"; -- set on less
|
| 286 |
|
|
constant funct3_sltu_c : std_ulogic_vector(2 downto 0) := "011"; -- set on less unsigned
|
| 287 |
|
|
constant funct3_xor_c : std_ulogic_vector(2 downto 0) := "100"; -- xor
|
| 288 |
|
|
constant funct3_sr_c : std_ulogic_vector(2 downto 0) := "101"; -- shift right via funct7
|
| 289 |
|
|
constant funct3_or_c : std_ulogic_vector(2 downto 0) := "110"; -- or
|
| 290 |
|
|
constant funct3_and_c : std_ulogic_vector(2 downto 0) := "111"; -- and
|
| 291 |
|
|
-- system/csr --
|
| 292 |
|
|
constant funct3_env_c : std_ulogic_vector(2 downto 0) := "000"; -- ecall, ebreak, mret, wfi
|
| 293 |
|
|
constant funct3_csrrw_c : std_ulogic_vector(2 downto 0) := "001"; -- atomic r/w
|
| 294 |
|
|
constant funct3_csrrs_c : std_ulogic_vector(2 downto 0) := "010"; -- atomic read & set bit
|
| 295 |
|
|
constant funct3_csrrc_c : std_ulogic_vector(2 downto 0) := "011"; -- atomic read & clear bit
|
| 296 |
|
|
--
|
| 297 |
|
|
constant funct3_csrrwi_c : std_ulogic_vector(2 downto 0) := "101"; -- atomic r/w immediate
|
| 298 |
|
|
constant funct3_csrrsi_c : std_ulogic_vector(2 downto 0) := "110"; -- atomic read & set bit immediate
|
| 299 |
|
|
constant funct3_csrrci_c : std_ulogic_vector(2 downto 0) := "111"; -- atomic read & clear bit immediate
|
| 300 |
8 |
zero_gravi |
-- fence --
|
| 301 |
|
|
constant funct3_fence_c : std_ulogic_vector(2 downto 0) := "000"; -- fence - order IO/memory access (->NOP)
|
| 302 |
|
|
constant funct3_fencei_c : std_ulogic_vector(2 downto 0) := "001"; -- fencei - instructon stream sync
|
| 303 |
2 |
zero_gravi |
|
| 304 |
11 |
zero_gravi |
-- RISC-V Funct12 --------------------------------------------------------------------------
|
| 305 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 306 |
|
|
-- system --
|
| 307 |
|
|
constant funct12_ecall_c : std_ulogic_vector(11 downto 0) := x"000"; -- ECALL
|
| 308 |
|
|
constant funct12_ebreak_c : std_ulogic_vector(11 downto 0) := x"001"; -- EBREAK
|
| 309 |
|
|
constant funct12_mret_c : std_ulogic_vector(11 downto 0) := x"302"; -- MRET
|
| 310 |
|
|
constant funct12_wfi_c : std_ulogic_vector(11 downto 0) := x"105"; -- WFI
|
| 311 |
|
|
|
| 312 |
2 |
zero_gravi |
-- Co-Processor Operations ----------------------------------------------------------------
|
| 313 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 314 |
|
|
-- cp ids --
|
| 315 |
|
|
constant cp_sel_muldiv_c : std_ulogic_vector(1 downto 0) := "00"; -- MULDIV CP
|
| 316 |
|
|
-- muldiv cp --
|
| 317 |
6 |
zero_gravi |
constant cp_op_mul_c : std_ulogic_vector(2 downto 0) := "000"; -- mul
|
| 318 |
|
|
constant cp_op_mulh_c : std_ulogic_vector(2 downto 0) := "001"; -- mulh
|
| 319 |
|
|
constant cp_op_mulhsu_c : std_ulogic_vector(2 downto 0) := "010"; -- mulhsu
|
| 320 |
|
|
constant cp_op_mulhu_c : std_ulogic_vector(2 downto 0) := "011"; -- mulhu
|
| 321 |
|
|
constant cp_op_div_c : std_ulogic_vector(2 downto 0) := "100"; -- div
|
| 322 |
|
|
constant cp_op_divu_c : std_ulogic_vector(2 downto 0) := "101"; -- divu
|
| 323 |
|
|
constant cp_op_rem_c : std_ulogic_vector(2 downto 0) := "110"; -- rem
|
| 324 |
|
|
constant cp_op_remu_c : std_ulogic_vector(2 downto 0) := "111"; -- remu
|
| 325 |
2 |
zero_gravi |
|
| 326 |
|
|
-- ALU Function Codes ---------------------------------------------------------------------
|
| 327 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 328 |
|
|
constant alu_cmd_add_c : std_ulogic_vector(2 downto 0) := "000"; -- r <= A + B
|
| 329 |
|
|
constant alu_cmd_sub_c : std_ulogic_vector(2 downto 0) := "001"; -- r <= A - B
|
| 330 |
|
|
constant alu_cmd_slt_c : std_ulogic_vector(2 downto 0) := "010"; -- r <= A < B
|
| 331 |
|
|
constant alu_cmd_shift_c : std_ulogic_vector(2 downto 0) := "011"; -- r <= A <</>> B
|
| 332 |
|
|
constant alu_cmd_xor_c : std_ulogic_vector(2 downto 0) := "100"; -- r <= A xor B
|
| 333 |
|
|
constant alu_cmd_or_c : std_ulogic_vector(2 downto 0) := "101"; -- r <= A or B
|
| 334 |
|
|
constant alu_cmd_and_c : std_ulogic_vector(2 downto 0) := "110"; -- r <= A and B
|
| 335 |
27 |
zero_gravi |
constant alu_cmd_movb_c : std_ulogic_vector(2 downto 0) := "111"; -- r <= B
|
| 336 |
2 |
zero_gravi |
|
| 337 |
12 |
zero_gravi |
-- Trap ID Codes --------------------------------------------------------------------------
|
| 338 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 339 |
14 |
zero_gravi |
-- risc-v compliant --
|
| 340 |
|
|
constant trap_ima_c : std_ulogic_vector(5 downto 0) := "000000"; -- 0.0: instruction misaligned
|
| 341 |
|
|
constant trap_iba_c : std_ulogic_vector(5 downto 0) := "000001"; -- 0.1: instruction access fault
|
| 342 |
|
|
constant trap_iil_c : std_ulogic_vector(5 downto 0) := "000010"; -- 0.2: illegal instruction
|
| 343 |
|
|
constant trap_brk_c : std_ulogic_vector(5 downto 0) := "000011"; -- 0.3: breakpoint
|
| 344 |
|
|
constant trap_lma_c : std_ulogic_vector(5 downto 0) := "000100"; -- 0.4: load address misaligned
|
| 345 |
|
|
constant trap_lbe_c : std_ulogic_vector(5 downto 0) := "000101"; -- 0.5: load access fault
|
| 346 |
|
|
constant trap_sma_c : std_ulogic_vector(5 downto 0) := "000110"; -- 0.6: store address misaligned
|
| 347 |
|
|
constant trap_sbe_c : std_ulogic_vector(5 downto 0) := "000111"; -- 0.7: store access fault
|
| 348 |
|
|
constant trap_menv_c : std_ulogic_vector(5 downto 0) := "001011"; -- 0.11: environment call from m-mode
|
| 349 |
|
|
--
|
| 350 |
|
|
constant trap_msi_c : std_ulogic_vector(5 downto 0) := "100011"; -- 1.3: machine software interrupt
|
| 351 |
|
|
constant trap_mti_c : std_ulogic_vector(5 downto 0) := "100111"; -- 1.7: machine timer interrupt
|
| 352 |
|
|
constant trap_mei_c : std_ulogic_vector(5 downto 0) := "101011"; -- 1.11: machine external interrupt
|
| 353 |
|
|
-- custom --
|
| 354 |
|
|
constant trap_firq0_c : std_ulogic_vector(5 downto 0) := "110000"; -- 1.16: fast interrupt 0
|
| 355 |
|
|
constant trap_firq1_c : std_ulogic_vector(5 downto 0) := "110001"; -- 1.17: fast interrupt 1
|
| 356 |
|
|
constant trap_firq2_c : std_ulogic_vector(5 downto 0) := "110010"; -- 1.18: fast interrupt 2
|
| 357 |
|
|
constant trap_firq3_c : std_ulogic_vector(5 downto 0) := "110011"; -- 1.19: fast interrupt 3
|
| 358 |
12 |
zero_gravi |
|
| 359 |
2 |
zero_gravi |
-- CPU Control Exception System -----------------------------------------------------------
|
| 360 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 361 |
|
|
-- exception source bits --
|
| 362 |
|
|
constant exception_iaccess_c : natural := 0; -- instrution access fault
|
| 363 |
|
|
constant exception_iillegal_c : natural := 1; -- illegal instrution
|
| 364 |
|
|
constant exception_ialign_c : natural := 2; -- instrution address misaligned
|
| 365 |
|
|
constant exception_m_envcall_c : natural := 3; -- ENV call from m-mode
|
| 366 |
|
|
constant exception_break_c : natural := 4; -- breakpoint
|
| 367 |
|
|
constant exception_salign_c : natural := 5; -- store address misaligned
|
| 368 |
|
|
constant exception_lalign_c : natural := 6; -- load address misaligned
|
| 369 |
|
|
constant exception_saccess_c : natural := 7; -- store access fault
|
| 370 |
|
|
constant exception_laccess_c : natural := 8; -- load access fault
|
| 371 |
14 |
zero_gravi |
--
|
| 372 |
2 |
zero_gravi |
constant exception_width_c : natural := 9; -- length of this list in bits
|
| 373 |
|
|
-- interrupt source bits --
|
| 374 |
12 |
zero_gravi |
constant interrupt_msw_irq_c : natural := 0; -- machine software interrupt
|
| 375 |
|
|
constant interrupt_mtime_irq_c : natural := 1; -- machine timer interrupt
|
| 376 |
2 |
zero_gravi |
constant interrupt_mext_irq_c : natural := 2; -- machine external interrupt
|
| 377 |
14 |
zero_gravi |
constant interrupt_firq_0_c : natural := 3; -- fast interrupt channel 0
|
| 378 |
|
|
constant interrupt_firq_1_c : natural := 4; -- fast interrupt channel 1
|
| 379 |
|
|
constant interrupt_firq_2_c : natural := 5; -- fast interrupt channel 2
|
| 380 |
|
|
constant interrupt_firq_3_c : natural := 6; -- fast interrupt channel 3
|
| 381 |
|
|
--
|
| 382 |
|
|
constant interrupt_width_c : natural := 7; -- length of this list in bits
|
| 383 |
2 |
zero_gravi |
|
| 384 |
15 |
zero_gravi |
-- CPU Privilege Modes --------------------------------------------------------------------
|
| 385 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 386 |
|
|
constant m_priv_mode_c : std_ulogic_vector(1 downto 0) := "11"; -- machine mode
|
| 387 |
|
|
constant u_priv_mode_c : std_ulogic_vector(1 downto 0) := "00"; -- user mode
|
| 388 |
|
|
|
| 389 |
2 |
zero_gravi |
-- Clock Generator -------------------------------------------------------------------------
|
| 390 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 391 |
|
|
constant clk_div2_c : natural := 0;
|
| 392 |
|
|
constant clk_div4_c : natural := 1;
|
| 393 |
|
|
constant clk_div8_c : natural := 2;
|
| 394 |
|
|
constant clk_div64_c : natural := 3;
|
| 395 |
|
|
constant clk_div128_c : natural := 4;
|
| 396 |
|
|
constant clk_div1024_c : natural := 5;
|
| 397 |
|
|
constant clk_div2048_c : natural := 6;
|
| 398 |
|
|
constant clk_div4096_c : natural := 7;
|
| 399 |
|
|
|
| 400 |
|
|
-- Component: NEORV32 Processor Top Entity ------------------------------------------------
|
| 401 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 402 |
|
|
component neorv32_top
|
| 403 |
|
|
generic (
|
| 404 |
|
|
-- General --
|
| 405 |
12 |
zero_gravi |
CLOCK_FREQUENCY : natural := 0; -- clock frequency of clk_i in Hz
|
| 406 |
8 |
zero_gravi |
BOOTLOADER_USE : boolean := true; -- implement processor-internal bootloader?
|
| 407 |
12 |
zero_gravi |
USER_CODE : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom user code
|
| 408 |
2 |
zero_gravi |
-- RISC-V CPU Extensions --
|
| 409 |
18 |
zero_gravi |
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
| 410 |
8 |
zero_gravi |
CPU_EXTENSION_RISCV_E : boolean := false; -- implement embedded RF extension?
|
| 411 |
18 |
zero_gravi |
CPU_EXTENSION_RISCV_M : boolean := false; -- implement muld/div extension?
|
| 412 |
|
|
CPU_EXTENSION_RISCV_U : boolean := false; -- implement user mode extension?
|
| 413 |
8 |
zero_gravi |
CPU_EXTENSION_RISCV_Zicsr : boolean := true; -- implement CSR system?
|
| 414 |
|
|
CPU_EXTENSION_RISCV_Zifencei : boolean := true; -- implement instruction stream sync.?
|
| 415 |
19 |
zero_gravi |
-- Extension Options --
|
| 416 |
|
|
FAST_MUL_EN : boolean := false; -- use DSPs for M extension's multiplier
|
| 417 |
15 |
zero_gravi |
-- Physical Memory Protection (PMP) --
|
| 418 |
|
|
PMP_USE : boolean := false; -- implement PMP?
|
| 419 |
16 |
zero_gravi |
PMP_NUM_REGIONS : natural := 4; -- number of regions (max 8)
|
| 420 |
|
|
PMP_GRANULARITY : natural := 14; -- minimal region granularity (1=8B, 2=16B, 3=32B, ...) default is 64k
|
| 421 |
23 |
zero_gravi |
-- Internal Instruction memory --
|
| 422 |
8 |
zero_gravi |
MEM_INT_IMEM_USE : boolean := true; -- implement processor-internal instruction memory
|
| 423 |
|
|
MEM_INT_IMEM_SIZE : natural := 16*1024; -- size of processor-internal instruction memory in bytes
|
| 424 |
|
|
MEM_INT_IMEM_ROM : boolean := false; -- implement processor-internal instruction memory as ROM
|
| 425 |
23 |
zero_gravi |
-- Internal Data memory --
|
| 426 |
8 |
zero_gravi |
MEM_INT_DMEM_USE : boolean := true; -- implement processor-internal data memory
|
| 427 |
|
|
MEM_INT_DMEM_SIZE : natural := 8*1024; -- size of processor-internal data memory in bytes
|
| 428 |
23 |
zero_gravi |
-- External memory interface --
|
| 429 |
8 |
zero_gravi |
MEM_EXT_USE : boolean := false; -- implement external memory bus interface?
|
| 430 |
|
|
MEM_EXT_REG_STAGES : natural := 2; -- number of interface register stages (0,1,2)
|
| 431 |
|
|
MEM_EXT_TIMEOUT : natural := 15; -- cycles after which a valid bus access will timeout (>=1)
|
| 432 |
2 |
zero_gravi |
-- Processor peripherals --
|
| 433 |
8 |
zero_gravi |
IO_GPIO_USE : boolean := true; -- implement general purpose input/output port unit (GPIO)?
|
| 434 |
|
|
IO_MTIME_USE : boolean := true; -- implement machine system timer (MTIME)?
|
| 435 |
|
|
IO_UART_USE : boolean := true; -- implement universal asynchronous receiver/transmitter (UART)?
|
| 436 |
|
|
IO_SPI_USE : boolean := true; -- implement serial peripheral interface (SPI)?
|
| 437 |
|
|
IO_TWI_USE : boolean := true; -- implement two-wire interface (TWI)?
|
| 438 |
|
|
IO_PWM_USE : boolean := true; -- implement pulse-width modulation unit (PWM)?
|
| 439 |
|
|
IO_WDT_USE : boolean := true; -- implement watch dog timer (WDT)?
|
| 440 |
|
|
IO_TRNG_USE : boolean := false; -- implement true random number generator (TRNG)?
|
| 441 |
23 |
zero_gravi |
IO_DEVNULL_USE : boolean := true; -- implement dummy device (DEVNULL)?
|
| 442 |
|
|
IO_CFU_USE : boolean := false -- implement custom functions unit (CFU)?
|
| 443 |
2 |
zero_gravi |
);
|
| 444 |
|
|
port (
|
| 445 |
|
|
-- Global control --
|
| 446 |
|
|
clk_i : in std_ulogic := '0'; -- global clock, rising edge
|
| 447 |
|
|
rstn_i : in std_ulogic := '0'; -- global reset, low-active, async
|
| 448 |
|
|
-- Wishbone bus interface --
|
| 449 |
|
|
wb_adr_o : out std_ulogic_vector(31 downto 0); -- address
|
| 450 |
|
|
wb_dat_i : in std_ulogic_vector(31 downto 0) := (others => '0'); -- read data
|
| 451 |
|
|
wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
|
| 452 |
|
|
wb_we_o : out std_ulogic; -- read/write
|
| 453 |
|
|
wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
| 454 |
|
|
wb_stb_o : out std_ulogic; -- strobe
|
| 455 |
|
|
wb_cyc_o : out std_ulogic; -- valid cycle
|
| 456 |
|
|
wb_ack_i : in std_ulogic := '0'; -- transfer acknowledge
|
| 457 |
|
|
wb_err_i : in std_ulogic := '0'; -- transfer error
|
| 458 |
12 |
zero_gravi |
-- Advanced memory control signals (available if MEM_EXT_USE = true) --
|
| 459 |
|
|
fence_o : out std_ulogic; -- indicates an executed FENCE operation
|
| 460 |
|
|
fencei_o : out std_ulogic; -- indicates an executed FENCEI operation
|
| 461 |
2 |
zero_gravi |
-- GPIO --
|
| 462 |
22 |
zero_gravi |
gpio_o : out std_ulogic_vector(31 downto 0); -- parallel output
|
| 463 |
|
|
gpio_i : in std_ulogic_vector(31 downto 0) := (others => '0'); -- parallel input
|
| 464 |
2 |
zero_gravi |
-- UART --
|
| 465 |
|
|
uart_txd_o : out std_ulogic; -- UART send data
|
| 466 |
|
|
uart_rxd_i : in std_ulogic := '0'; -- UART receive data
|
| 467 |
|
|
-- SPI --
|
| 468 |
6 |
zero_gravi |
spi_sck_o : out std_ulogic; -- SPI serial clock
|
| 469 |
|
|
spi_sdo_o : out std_ulogic; -- controller data out, peripheral data in
|
| 470 |
14 |
zero_gravi |
spi_sdi_i : in std_ulogic := '0'; -- controller data in, peripheral data out
|
| 471 |
2 |
zero_gravi |
spi_csn_o : out std_ulogic_vector(07 downto 0); -- SPI CS
|
| 472 |
|
|
-- TWI --
|
| 473 |
|
|
twi_sda_io : inout std_logic := 'H'; -- twi serial data line
|
| 474 |
|
|
twi_scl_io : inout std_logic := 'H'; -- twi serial clock line
|
| 475 |
|
|
-- PWM --
|
| 476 |
|
|
pwm_o : out std_ulogic_vector(03 downto 0); -- pwm channels
|
| 477 |
|
|
-- Interrupts --
|
| 478 |
14 |
zero_gravi |
msw_irq_i : in std_ulogic := '0'; -- machine software interrupt
|
| 479 |
|
|
mext_irq_i : in std_ulogic := '0' -- machine external interrupt
|
| 480 |
2 |
zero_gravi |
);
|
| 481 |
|
|
end component;
|
| 482 |
|
|
|
| 483 |
4 |
zero_gravi |
-- Component: CPU Top Entity --------------------------------------------------------------
|
| 484 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 485 |
|
|
component neorv32_cpu
|
| 486 |
|
|
generic (
|
| 487 |
|
|
-- General --
|
| 488 |
14 |
zero_gravi |
HW_THREAD_ID : std_ulogic_vector(31 downto 0):= (others => '0'); -- hardware thread id
|
| 489 |
|
|
CPU_BOOT_ADDR : std_ulogic_vector(31 downto 0):= (others => '0'); -- cpu boot address
|
| 490 |
4 |
zero_gravi |
-- RISC-V CPU Extensions --
|
| 491 |
12 |
zero_gravi |
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
| 492 |
|
|
CPU_EXTENSION_RISCV_E : boolean := false; -- implement embedded RF extension?
|
| 493 |
|
|
CPU_EXTENSION_RISCV_M : boolean := false; -- implement muld/div extension?
|
| 494 |
15 |
zero_gravi |
CPU_EXTENSION_RISCV_U : boolean := false; -- implement user mode extension?
|
| 495 |
12 |
zero_gravi |
CPU_EXTENSION_RISCV_Zicsr : boolean := true; -- implement CSR system?
|
| 496 |
|
|
CPU_EXTENSION_RISCV_Zifencei : boolean := true; -- implement instruction stream sync.?
|
| 497 |
19 |
zero_gravi |
-- Extension Options --
|
| 498 |
|
|
FAST_MUL_EN : boolean := false; -- use DSPs for M extension's multiplier
|
| 499 |
15 |
zero_gravi |
-- Physical Memory Protection (PMP) --
|
| 500 |
|
|
PMP_USE : boolean := false; -- implement PMP?
|
| 501 |
16 |
zero_gravi |
PMP_NUM_REGIONS : natural := 4; -- number of regions (max 8)
|
| 502 |
|
|
PMP_GRANULARITY : natural := 14; -- minimal region granularity (1=8B, 2=16B, 3=32B, ...) default is 64k
|
| 503 |
14 |
zero_gravi |
-- Bus Interface --
|
| 504 |
|
|
BUS_TIMEOUT : natural := 15 -- cycles after which a valid bus access will timeout
|
| 505 |
4 |
zero_gravi |
);
|
| 506 |
|
|
port (
|
| 507 |
|
|
-- global control --
|
| 508 |
14 |
zero_gravi |
clk_i : in std_ulogic := '0'; -- global clock, rising edge
|
| 509 |
|
|
rstn_i : in std_ulogic := '0'; -- global reset, low-active, async
|
| 510 |
12 |
zero_gravi |
-- instruction bus interface --
|
| 511 |
|
|
i_bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
| 512 |
14 |
zero_gravi |
i_bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0) := (others => '0'); -- bus read data
|
| 513 |
12 |
zero_gravi |
i_bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
| 514 |
|
|
i_bus_ben_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
| 515 |
|
|
i_bus_we_o : out std_ulogic; -- write enable
|
| 516 |
|
|
i_bus_re_o : out std_ulogic; -- read enable
|
| 517 |
|
|
i_bus_cancel_o : out std_ulogic; -- cancel current bus transaction
|
| 518 |
14 |
zero_gravi |
i_bus_ack_i : in std_ulogic := '0'; -- bus transfer acknowledge
|
| 519 |
|
|
i_bus_err_i : in std_ulogic := '0'; -- bus transfer error
|
| 520 |
12 |
zero_gravi |
i_bus_fence_o : out std_ulogic; -- executed FENCEI operation
|
| 521 |
|
|
-- data bus interface --
|
| 522 |
|
|
d_bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
| 523 |
14 |
zero_gravi |
d_bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0) := (others => '0'); -- bus read data
|
| 524 |
12 |
zero_gravi |
d_bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
| 525 |
|
|
d_bus_ben_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
| 526 |
|
|
d_bus_we_o : out std_ulogic; -- write enable
|
| 527 |
|
|
d_bus_re_o : out std_ulogic; -- read enable
|
| 528 |
|
|
d_bus_cancel_o : out std_ulogic; -- cancel current bus transaction
|
| 529 |
14 |
zero_gravi |
d_bus_ack_i : in std_ulogic := '0'; -- bus transfer acknowledge
|
| 530 |
|
|
d_bus_err_i : in std_ulogic := '0'; -- bus transfer error
|
| 531 |
12 |
zero_gravi |
d_bus_fence_o : out std_ulogic; -- executed FENCE operation
|
| 532 |
11 |
zero_gravi |
-- system time input from MTIME --
|
| 533 |
14 |
zero_gravi |
time_i : in std_ulogic_vector(63 downto 0) := (others => '0'); -- current system time
|
| 534 |
|
|
-- interrupts (risc-v compliant) --
|
| 535 |
|
|
msw_irq_i : in std_ulogic := '0'; -- machine software interrupt
|
| 536 |
|
|
mext_irq_i : in std_ulogic := '0'; -- machine external interrupt
|
| 537 |
|
|
mtime_irq_i : in std_ulogic := '0'; -- machine timer interrupt
|
| 538 |
|
|
-- fast interrupts (custom) --
|
| 539 |
|
|
firq_i : in std_ulogic_vector(3 downto 0) := (others => '0')
|
| 540 |
4 |
zero_gravi |
);
|
| 541 |
|
|
end component;
|
| 542 |
|
|
|
| 543 |
2 |
zero_gravi |
-- Component: CPU Control -----------------------------------------------------------------
|
| 544 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 545 |
|
|
component neorv32_cpu_control
|
| 546 |
|
|
generic (
|
| 547 |
|
|
-- General --
|
| 548 |
12 |
zero_gravi |
HW_THREAD_ID : std_ulogic_vector(31 downto 0):= x"00000000"; -- hardware thread id
|
| 549 |
|
|
CPU_BOOT_ADDR : std_ulogic_vector(31 downto 0):= x"00000000"; -- cpu boot address
|
| 550 |
2 |
zero_gravi |
-- RISC-V CPU Extensions --
|
| 551 |
12 |
zero_gravi |
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
| 552 |
|
|
CPU_EXTENSION_RISCV_E : boolean := false; -- implement embedded RF extension?
|
| 553 |
|
|
CPU_EXTENSION_RISCV_M : boolean := false; -- implement muld/div extension?
|
| 554 |
15 |
zero_gravi |
CPU_EXTENSION_RISCV_U : boolean := false; -- implement user mode extension?
|
| 555 |
12 |
zero_gravi |
CPU_EXTENSION_RISCV_Zicsr : boolean := true; -- implement CSR system?
|
| 556 |
15 |
zero_gravi |
CPU_EXTENSION_RISCV_Zifencei : boolean := true; -- implement instruction stream sync.?
|
| 557 |
|
|
-- Physical memory protection (PMP) --
|
| 558 |
|
|
PMP_USE : boolean := false; -- implement physical memory protection?
|
| 559 |
|
|
PMP_NUM_REGIONS : natural := 4; -- number of regions (1..4)
|
| 560 |
|
|
PMP_GRANULARITY : natural := 0 -- granularity (0=none, 1=8B, 2=16B, 3=32B, ...)
|
| 561 |
2 |
zero_gravi |
);
|
| 562 |
|
|
port (
|
| 563 |
|
|
-- global control --
|
| 564 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
| 565 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
| 566 |
|
|
ctrl_o : out std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
| 567 |
|
|
-- status input --
|
| 568 |
|
|
alu_wait_i : in std_ulogic; -- wait for ALU
|
| 569 |
12 |
zero_gravi |
bus_i_wait_i : in std_ulogic; -- wait for bus
|
| 570 |
|
|
bus_d_wait_i : in std_ulogic; -- wait for bus
|
| 571 |
2 |
zero_gravi |
-- data input --
|
| 572 |
|
|
instr_i : in std_ulogic_vector(data_width_c-1 downto 0); -- instruction
|
| 573 |
|
|
cmp_i : in std_ulogic_vector(1 downto 0); -- comparator status
|
| 574 |
|
|
alu_add_i : in std_ulogic_vector(data_width_c-1 downto 0); -- ALU.add result
|
| 575 |
27 |
zero_gravi |
alu_res_i : in std_ulogic_vector(data_width_c-1 downto 0); -- ALU processing result
|
| 576 |
2 |
zero_gravi |
-- data output --
|
| 577 |
|
|
imm_o : out std_ulogic_vector(data_width_c-1 downto 0); -- immediate
|
| 578 |
6 |
zero_gravi |
fetch_pc_o : out std_ulogic_vector(data_width_c-1 downto 0); -- PC for instruction fetch
|
| 579 |
|
|
curr_pc_o : out std_ulogic_vector(data_width_c-1 downto 0); -- current PC (corresponding to current instruction)
|
| 580 |
|
|
next_pc_o : out std_ulogic_vector(data_width_c-1 downto 0); -- next PC (corresponding to current instruction)
|
| 581 |
2 |
zero_gravi |
csr_rdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- CSR read data
|
| 582 |
14 |
zero_gravi |
-- interrupts (risc-v compliant) --
|
| 583 |
|
|
msw_irq_i : in std_ulogic; -- machine software interrupt
|
| 584 |
|
|
mext_irq_i : in std_ulogic; -- machine external interrupt
|
| 585 |
2 |
zero_gravi |
mtime_irq_i : in std_ulogic; -- machine timer interrupt
|
| 586 |
14 |
zero_gravi |
-- fast interrupts (custom) --
|
| 587 |
|
|
firq_i : in std_ulogic_vector(3 downto 0);
|
| 588 |
11 |
zero_gravi |
-- system time input from MTIME --
|
| 589 |
|
|
time_i : in std_ulogic_vector(63 downto 0); -- current system time
|
| 590 |
15 |
zero_gravi |
-- physical memory protection --
|
| 591 |
|
|
pmp_addr_o : out pmp_addr_if_t; -- addresses
|
| 592 |
|
|
pmp_ctrl_o : out pmp_ctrl_if_t; -- configs
|
| 593 |
|
|
priv_mode_o : out std_ulogic_vector(1 downto 0); -- current CPU privilege level
|
| 594 |
2 |
zero_gravi |
-- bus access exceptions --
|
| 595 |
|
|
mar_i : in std_ulogic_vector(data_width_c-1 downto 0); -- memory address register
|
| 596 |
|
|
ma_instr_i : in std_ulogic; -- misaligned instruction address
|
| 597 |
|
|
ma_load_i : in std_ulogic; -- misaligned load data address
|
| 598 |
|
|
ma_store_i : in std_ulogic; -- misaligned store data address
|
| 599 |
|
|
be_instr_i : in std_ulogic; -- bus error on instruction access
|
| 600 |
|
|
be_load_i : in std_ulogic; -- bus error on load data access
|
| 601 |
12 |
zero_gravi |
be_store_i : in std_ulogic -- bus error on store data access
|
| 602 |
2 |
zero_gravi |
);
|
| 603 |
|
|
end component;
|
| 604 |
|
|
|
| 605 |
|
|
-- Component: CPU Register File -----------------------------------------------------------
|
| 606 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 607 |
|
|
component neorv32_cpu_regfile
|
| 608 |
|
|
generic (
|
| 609 |
|
|
CPU_EXTENSION_RISCV_E : boolean := false -- implement embedded RF extension?
|
| 610 |
|
|
);
|
| 611 |
|
|
port (
|
| 612 |
|
|
-- global control --
|
| 613 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
| 614 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
| 615 |
|
|
-- data input --
|
| 616 |
|
|
mem_i : in std_ulogic_vector(data_width_c-1 downto 0); -- memory read data
|
| 617 |
|
|
alu_i : in std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
|
| 618 |
|
|
csr_i : in std_ulogic_vector(data_width_c-1 downto 0); -- CSR read data
|
| 619 |
|
|
pc_i : in std_ulogic_vector(data_width_c-1 downto 0); -- current pc
|
| 620 |
|
|
-- data output --
|
| 621 |
|
|
rs1_o : out std_ulogic_vector(data_width_c-1 downto 0); -- operand 1
|
| 622 |
|
|
rs2_o : out std_ulogic_vector(data_width_c-1 downto 0) -- operand 2
|
| 623 |
|
|
);
|
| 624 |
|
|
end component;
|
| 625 |
|
|
|
| 626 |
|
|
-- Component: CPU ALU ---------------------------------------------------------------------
|
| 627 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 628 |
|
|
component neorv32_cpu_alu
|
| 629 |
11 |
zero_gravi |
generic (
|
| 630 |
|
|
CPU_EXTENSION_RISCV_M : boolean := true -- implement muld/div extension?
|
| 631 |
|
|
);
|
| 632 |
2 |
zero_gravi |
port (
|
| 633 |
|
|
-- global control --
|
| 634 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
| 635 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
| 636 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
| 637 |
|
|
-- data input --
|
| 638 |
|
|
rs1_i : in std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
|
| 639 |
|
|
rs2_i : in std_ulogic_vector(data_width_c-1 downto 0); -- rf source 2
|
| 640 |
|
|
pc2_i : in std_ulogic_vector(data_width_c-1 downto 0); -- delayed PC
|
| 641 |
|
|
imm_i : in std_ulogic_vector(data_width_c-1 downto 0); -- immediate
|
| 642 |
|
|
-- data output --
|
| 643 |
|
|
cmp_o : out std_ulogic_vector(1 downto 0); -- comparator status
|
| 644 |
|
|
add_o : out std_ulogic_vector(data_width_c-1 downto 0); -- OPA + OPB
|
| 645 |
|
|
res_o : out std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
|
| 646 |
|
|
-- co-processor interface --
|
| 647 |
19 |
zero_gravi |
cp0_start_o : out std_ulogic; -- trigger co-processor 0
|
| 648 |
2 |
zero_gravi |
cp0_data_i : in std_ulogic_vector(data_width_c-1 downto 0); -- co-processor 0 result
|
| 649 |
|
|
cp0_valid_i : in std_ulogic; -- co-processor 0 result valid
|
| 650 |
19 |
zero_gravi |
cp1_start_o : out std_ulogic; -- trigger co-processor 1
|
| 651 |
2 |
zero_gravi |
cp1_data_i : in std_ulogic_vector(data_width_c-1 downto 0); -- co-processor 1 result
|
| 652 |
|
|
cp1_valid_i : in std_ulogic; -- co-processor 1 result valid
|
| 653 |
|
|
-- status --
|
| 654 |
|
|
wait_o : out std_ulogic -- busy due to iterative processing units
|
| 655 |
|
|
);
|
| 656 |
|
|
end component;
|
| 657 |
|
|
|
| 658 |
|
|
-- Component: CPU Co-Processor MULDIV -----------------------------------------------------
|
| 659 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 660 |
|
|
component neorv32_cpu_cp_muldiv
|
| 661 |
19 |
zero_gravi |
generic (
|
| 662 |
|
|
FAST_MUL_EN : boolean := false -- use DSPs for faster multiplication
|
| 663 |
|
|
);
|
| 664 |
2 |
zero_gravi |
port (
|
| 665 |
|
|
-- global control --
|
| 666 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
| 667 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
| 668 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
| 669 |
|
|
-- data input --
|
| 670 |
19 |
zero_gravi |
start_i : in std_ulogic; -- trigger operation
|
| 671 |
2 |
zero_gravi |
rs1_i : in std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
|
| 672 |
|
|
rs2_i : in std_ulogic_vector(data_width_c-1 downto 0); -- rf source 2
|
| 673 |
|
|
-- result and status --
|
| 674 |
|
|
res_o : out std_ulogic_vector(data_width_c-1 downto 0); -- operation result
|
| 675 |
|
|
valid_o : out std_ulogic -- data output valid
|
| 676 |
|
|
);
|
| 677 |
|
|
end component;
|
| 678 |
|
|
|
| 679 |
|
|
-- Component: CPU Bus Interface -----------------------------------------------------------
|
| 680 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 681 |
|
|
component neorv32_cpu_bus
|
| 682 |
|
|
generic (
|
| 683 |
11 |
zero_gravi |
CPU_EXTENSION_RISCV_C : boolean := true; -- implement compressed extension?
|
| 684 |
15 |
zero_gravi |
BUS_TIMEOUT : natural := 15; -- cycles after which a valid bus access will timeout
|
| 685 |
|
|
-- Physical memory protection (PMP) --
|
| 686 |
|
|
PMP_USE : boolean := false; -- implement physical memory protection?
|
| 687 |
|
|
PMP_NUM_REGIONS : natural := 4; -- number of regions (1..4)
|
| 688 |
18 |
zero_gravi |
PMP_GRANULARITY : natural := 0 -- granularity (1=8B, 2=16B, 3=32B, ...)
|
| 689 |
2 |
zero_gravi |
);
|
| 690 |
|
|
port (
|
| 691 |
|
|
-- global control --
|
| 692 |
12 |
zero_gravi |
clk_i : in std_ulogic; -- global clock, rising edge
|
| 693 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
| 694 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
| 695 |
|
|
-- cpu instruction fetch interface --
|
| 696 |
|
|
fetch_pc_i : in std_ulogic_vector(data_width_c-1 downto 0); -- PC for instruction fetch
|
| 697 |
|
|
instr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- instruction
|
| 698 |
|
|
i_wait_o : out std_ulogic; -- wait for fetch to complete
|
| 699 |
|
|
--
|
| 700 |
|
|
ma_instr_o : out std_ulogic; -- misaligned instruction address
|
| 701 |
|
|
be_instr_o : out std_ulogic; -- bus error on instruction access
|
| 702 |
|
|
-- cpu data access interface --
|
| 703 |
|
|
addr_i : in std_ulogic_vector(data_width_c-1 downto 0); -- ALU result -> access address
|
| 704 |
|
|
wdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- write data
|
| 705 |
|
|
rdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- read data
|
| 706 |
|
|
mar_o : out std_ulogic_vector(data_width_c-1 downto 0); -- current memory address register
|
| 707 |
|
|
d_wait_o : out std_ulogic; -- wait for access to complete
|
| 708 |
|
|
--
|
| 709 |
|
|
ma_load_o : out std_ulogic; -- misaligned load data address
|
| 710 |
|
|
ma_store_o : out std_ulogic; -- misaligned store data address
|
| 711 |
|
|
be_load_o : out std_ulogic; -- bus error on load data access
|
| 712 |
|
|
be_store_o : out std_ulogic; -- bus error on store data access
|
| 713 |
15 |
zero_gravi |
-- physical memory protection --
|
| 714 |
|
|
pmp_addr_i : in pmp_addr_if_t; -- addresses
|
| 715 |
|
|
pmp_ctrl_i : in pmp_ctrl_if_t; -- configs
|
| 716 |
|
|
priv_mode_i : in std_ulogic_vector(1 downto 0); -- current CPU privilege level
|
| 717 |
12 |
zero_gravi |
-- instruction bus --
|
| 718 |
|
|
i_bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
| 719 |
|
|
i_bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
|
| 720 |
|
|
i_bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
| 721 |
|
|
i_bus_ben_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
| 722 |
|
|
i_bus_we_o : out std_ulogic; -- write enable
|
| 723 |
|
|
i_bus_re_o : out std_ulogic; -- read enable
|
| 724 |
|
|
i_bus_cancel_o : out std_ulogic; -- cancel current bus transaction
|
| 725 |
|
|
i_bus_ack_i : in std_ulogic; -- bus transfer acknowledge
|
| 726 |
|
|
i_bus_err_i : in std_ulogic; -- bus transfer error
|
| 727 |
|
|
i_bus_fence_o : out std_ulogic; -- fence operation
|
| 728 |
|
|
-- data bus --
|
| 729 |
|
|
d_bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
| 730 |
|
|
d_bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
|
| 731 |
|
|
d_bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
| 732 |
|
|
d_bus_ben_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
| 733 |
|
|
d_bus_we_o : out std_ulogic; -- write enable
|
| 734 |
|
|
d_bus_re_o : out std_ulogic; -- read enable
|
| 735 |
|
|
d_bus_cancel_o : out std_ulogic; -- cancel current bus transaction
|
| 736 |
|
|
d_bus_ack_i : in std_ulogic; -- bus transfer acknowledge
|
| 737 |
|
|
d_bus_err_i : in std_ulogic; -- bus transfer error
|
| 738 |
|
|
d_bus_fence_o : out std_ulogic -- fence operation
|
| 739 |
2 |
zero_gravi |
);
|
| 740 |
|
|
end component;
|
| 741 |
|
|
|
| 742 |
12 |
zero_gravi |
-- Component: CPU Bus Switch --------------------------------------------------------------
|
| 743 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 744 |
|
|
component neorv32_busswitch
|
| 745 |
|
|
generic (
|
| 746 |
|
|
PORT_CA_READ_ONLY : boolean := false; -- set if controller port A is read-only
|
| 747 |
|
|
PORT_CB_READ_ONLY : boolean := false -- set if controller port B is read-only
|
| 748 |
|
|
);
|
| 749 |
|
|
port (
|
| 750 |
|
|
-- global control --
|
| 751 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
| 752 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
| 753 |
|
|
-- controller interface a --
|
| 754 |
|
|
ca_bus_addr_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
| 755 |
|
|
ca_bus_rdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
|
| 756 |
|
|
ca_bus_wdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
| 757 |
|
|
ca_bus_ben_i : in std_ulogic_vector(03 downto 0); -- byte enable
|
| 758 |
|
|
ca_bus_we_i : in std_ulogic; -- write enable
|
| 759 |
|
|
ca_bus_re_i : in std_ulogic; -- read enable
|
| 760 |
|
|
ca_bus_cancel_i : in std_ulogic; -- cancel current bus transaction
|
| 761 |
|
|
ca_bus_ack_o : out std_ulogic; -- bus transfer acknowledge
|
| 762 |
|
|
ca_bus_err_o : out std_ulogic; -- bus transfer error
|
| 763 |
|
|
-- controller interface b --
|
| 764 |
|
|
cb_bus_addr_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
| 765 |
|
|
cb_bus_rdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
|
| 766 |
|
|
cb_bus_wdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
| 767 |
|
|
cb_bus_ben_i : in std_ulogic_vector(03 downto 0); -- byte enable
|
| 768 |
|
|
cb_bus_we_i : in std_ulogic; -- write enable
|
| 769 |
|
|
cb_bus_re_i : in std_ulogic; -- read enable
|
| 770 |
|
|
cb_bus_cancel_i : in std_ulogic; -- cancel current bus transaction
|
| 771 |
|
|
cb_bus_ack_o : out std_ulogic; -- bus transfer acknowledge
|
| 772 |
|
|
cb_bus_err_o : out std_ulogic; -- bus transfer error
|
| 773 |
|
|
-- peripheral bus --
|
| 774 |
|
|
p_bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
| 775 |
|
|
p_bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
|
| 776 |
|
|
p_bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
| 777 |
|
|
p_bus_ben_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
| 778 |
|
|
p_bus_we_o : out std_ulogic; -- write enable
|
| 779 |
|
|
p_bus_re_o : out std_ulogic; -- read enable
|
| 780 |
|
|
p_bus_cancel_o : out std_ulogic; -- cancel current bus transaction
|
| 781 |
|
|
p_bus_ack_i : in std_ulogic; -- bus transfer acknowledge
|
| 782 |
|
|
p_bus_err_i : in std_ulogic -- bus transfer error
|
| 783 |
|
|
);
|
| 784 |
|
|
end component;
|
| 785 |
|
|
|
| 786 |
2 |
zero_gravi |
-- Component: CPU Compressed Instructions Decompressor ------------------------------------
|
| 787 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 788 |
|
|
component neorv32_cpu_decompressor
|
| 789 |
|
|
port (
|
| 790 |
|
|
-- instruction input --
|
| 791 |
|
|
ci_instr16_i : in std_ulogic_vector(15 downto 0); -- compressed instruction input
|
| 792 |
|
|
-- instruction output --
|
| 793 |
|
|
ci_illegal_o : out std_ulogic; -- is an illegal compressed instruction
|
| 794 |
|
|
ci_instr32_o : out std_ulogic_vector(31 downto 0) -- 32-bit decompressed instruction
|
| 795 |
|
|
);
|
| 796 |
|
|
end component;
|
| 797 |
|
|
|
| 798 |
|
|
-- Component: Processor-internal instruction memory (IMEM) --------------------------------
|
| 799 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 800 |
|
|
component neorv32_imem
|
| 801 |
|
|
generic (
|
| 802 |
|
|
IMEM_BASE : std_ulogic_vector(31 downto 0) := x"00000000"; -- memory base address
|
| 803 |
|
|
IMEM_SIZE : natural := 4*1024; -- processor-internal instruction memory size in bytes
|
| 804 |
|
|
IMEM_AS_ROM : boolean := false; -- implement IMEM as read-only memory?
|
| 805 |
|
|
BOOTLOADER_USE : boolean := true -- implement and use bootloader?
|
| 806 |
|
|
);
|
| 807 |
|
|
port (
|
| 808 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 809 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 810 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 811 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
| 812 |
|
|
upen_i : in std_ulogic; -- update enable
|
| 813 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 814 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 815 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 816 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
| 817 |
|
|
);
|
| 818 |
|
|
end component;
|
| 819 |
|
|
|
| 820 |
|
|
-- Component: Processor-internal data memory (DMEM) ---------------------------------------
|
| 821 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 822 |
|
|
component neorv32_dmem
|
| 823 |
|
|
generic (
|
| 824 |
|
|
DMEM_BASE : std_ulogic_vector(31 downto 0) := x"80000000"; -- memory base address
|
| 825 |
|
|
DMEM_SIZE : natural := 4*1024 -- processor-internal instruction memory size in bytes
|
| 826 |
|
|
);
|
| 827 |
|
|
port (
|
| 828 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 829 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 830 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 831 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
| 832 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 833 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 834 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 835 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
| 836 |
|
|
);
|
| 837 |
|
|
end component;
|
| 838 |
|
|
|
| 839 |
|
|
-- Component: Processor-internal bootloader ROM (BOOTROM) ---------------------------------
|
| 840 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 841 |
|
|
component neorv32_boot_rom
|
| 842 |
23 |
zero_gravi |
generic (
|
| 843 |
|
|
BOOTROM_BASE : std_ulogic_vector(31 downto 0) := x"FFFF0000"; -- boot ROM base address
|
| 844 |
|
|
BOOTROM_SIZE : natural := 4*1024 -- processor-internal boot ROM memory size in bytes
|
| 845 |
|
|
);
|
| 846 |
2 |
zero_gravi |
port (
|
| 847 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 848 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 849 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 850 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 851 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
| 852 |
|
|
);
|
| 853 |
|
|
end component;
|
| 854 |
|
|
|
| 855 |
|
|
-- Component: Machine System Timer (mtime) ------------------------------------------------
|
| 856 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 857 |
|
|
component neorv32_mtime
|
| 858 |
|
|
port (
|
| 859 |
|
|
-- host access --
|
| 860 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 861 |
4 |
zero_gravi |
rstn_i : in std_ulogic := '0'; -- global reset, low-active, async
|
| 862 |
2 |
zero_gravi |
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 863 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 864 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 865 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 866 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 867 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
| 868 |
11 |
zero_gravi |
-- time output for CPU --
|
| 869 |
|
|
time_o : out std_ulogic_vector(63 downto 0); -- current system time
|
| 870 |
2 |
zero_gravi |
-- interrupt --
|
| 871 |
|
|
irq_o : out std_ulogic -- interrupt request
|
| 872 |
|
|
);
|
| 873 |
|
|
end component;
|
| 874 |
|
|
|
| 875 |
|
|
-- Component: General Purpose Input/Output Port (GPIO) ------------------------------------
|
| 876 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 877 |
|
|
component neorv32_gpio
|
| 878 |
|
|
port (
|
| 879 |
|
|
-- host access --
|
| 880 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 881 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 882 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 883 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 884 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 885 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 886 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
| 887 |
|
|
-- parallel io --
|
| 888 |
22 |
zero_gravi |
gpio_o : out std_ulogic_vector(31 downto 0);
|
| 889 |
|
|
gpio_i : in std_ulogic_vector(31 downto 0);
|
| 890 |
2 |
zero_gravi |
-- interrupt --
|
| 891 |
|
|
irq_o : out std_ulogic
|
| 892 |
|
|
);
|
| 893 |
|
|
end component;
|
| 894 |
|
|
|
| 895 |
|
|
-- Component: Watchdog Timer (WDT) --------------------------------------------------------
|
| 896 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 897 |
|
|
component neorv32_wdt
|
| 898 |
|
|
port (
|
| 899 |
|
|
-- host access --
|
| 900 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 901 |
|
|
rstn_i : in std_ulogic; -- global reset line, low-active
|
| 902 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 903 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 904 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 905 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 906 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 907 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
| 908 |
|
|
-- clock generator --
|
| 909 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
| 910 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
| 911 |
|
|
-- timeout event --
|
| 912 |
|
|
irq_o : out std_ulogic; -- timeout IRQ
|
| 913 |
|
|
rstn_o : out std_ulogic -- timeout reset, low_active, use it as async!
|
| 914 |
|
|
);
|
| 915 |
|
|
end component;
|
| 916 |
|
|
|
| 917 |
|
|
-- Component: Universal Asynchronous Receiver and Transmitter (UART) ----------------------
|
| 918 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 919 |
|
|
component neorv32_uart
|
| 920 |
|
|
port (
|
| 921 |
|
|
-- host access --
|
| 922 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 923 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 924 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 925 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 926 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 927 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 928 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
| 929 |
|
|
-- clock generator --
|
| 930 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
| 931 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
| 932 |
|
|
-- com lines --
|
| 933 |
|
|
uart_txd_o : out std_ulogic;
|
| 934 |
|
|
uart_rxd_i : in std_ulogic;
|
| 935 |
|
|
-- interrupts --
|
| 936 |
|
|
uart_irq_o : out std_ulogic -- uart rx/tx interrupt
|
| 937 |
|
|
);
|
| 938 |
|
|
end component;
|
| 939 |
|
|
|
| 940 |
|
|
-- Component: Serial Peripheral Interface (SPI) -------------------------------------------
|
| 941 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 942 |
|
|
component neorv32_spi
|
| 943 |
|
|
port (
|
| 944 |
|
|
-- host access --
|
| 945 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 946 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 947 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 948 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 949 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 950 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 951 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
| 952 |
|
|
-- clock generator --
|
| 953 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
| 954 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
| 955 |
|
|
-- com lines --
|
| 956 |
6 |
zero_gravi |
spi_sck_o : out std_ulogic; -- SPI serial clock
|
| 957 |
|
|
spi_sdo_o : out std_ulogic; -- controller data out, peripheral data in
|
| 958 |
|
|
spi_sdi_i : in std_ulogic; -- controller data in, peripheral data out
|
| 959 |
2 |
zero_gravi |
spi_csn_o : out std_ulogic_vector(07 downto 0); -- SPI CS
|
| 960 |
|
|
-- interrupt --
|
| 961 |
|
|
spi_irq_o : out std_ulogic -- transmission done interrupt
|
| 962 |
|
|
);
|
| 963 |
|
|
end component;
|
| 964 |
|
|
|
| 965 |
|
|
-- Component: Two-Wire Interface (TWI) ----------------------------------------------------
|
| 966 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 967 |
|
|
component neorv32_twi
|
| 968 |
|
|
port (
|
| 969 |
|
|
-- host access --
|
| 970 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 971 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 972 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 973 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 974 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 975 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 976 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
| 977 |
|
|
-- clock generator --
|
| 978 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
| 979 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
| 980 |
|
|
-- com lines --
|
| 981 |
|
|
twi_sda_io : inout std_logic; -- serial data line
|
| 982 |
|
|
twi_scl_io : inout std_logic; -- serial clock line
|
| 983 |
|
|
-- interrupt --
|
| 984 |
|
|
twi_irq_o : out std_ulogic -- transfer done IRQ
|
| 985 |
|
|
);
|
| 986 |
|
|
end component;
|
| 987 |
|
|
|
| 988 |
|
|
-- Component: Pulse-Width Modulation Controller (PWM) -------------------------------------
|
| 989 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 990 |
|
|
component neorv32_pwm
|
| 991 |
|
|
port (
|
| 992 |
|
|
-- host access --
|
| 993 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 994 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 995 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 996 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 997 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 998 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 999 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
| 1000 |
|
|
-- clock generator --
|
| 1001 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
| 1002 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
| 1003 |
|
|
-- pwm output channels --
|
| 1004 |
|
|
pwm_o : out std_ulogic_vector(03 downto 0)
|
| 1005 |
|
|
);
|
| 1006 |
|
|
end component;
|
| 1007 |
|
|
|
| 1008 |
|
|
-- Component: True Random Number Generator (TRNG) -----------------------------------------
|
| 1009 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1010 |
|
|
component neorv32_trng
|
| 1011 |
|
|
port (
|
| 1012 |
|
|
-- host access --
|
| 1013 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 1014 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 1015 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 1016 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 1017 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 1018 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 1019 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
| 1020 |
|
|
);
|
| 1021 |
|
|
end component;
|
| 1022 |
|
|
|
| 1023 |
|
|
-- Component: Wishbone Bus Gateway (WISHBONE) ---------------------------------------------
|
| 1024 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1025 |
|
|
component neorv32_wishbone
|
| 1026 |
|
|
generic (
|
| 1027 |
|
|
INTERFACE_REG_STAGES : natural := 2; -- number of interface register stages (0,1,2)
|
| 1028 |
23 |
zero_gravi |
-- Internal instruction memory --
|
| 1029 |
2 |
zero_gravi |
MEM_INT_IMEM_USE : boolean := true; -- implement processor-internal instruction memory
|
| 1030 |
|
|
MEM_INT_IMEM_SIZE : natural := 8*1024; -- size of processor-internal instruction memory in bytes
|
| 1031 |
23 |
zero_gravi |
-- Internal data memory --
|
| 1032 |
2 |
zero_gravi |
MEM_INT_DMEM_USE : boolean := true; -- implement processor-internal data memory
|
| 1033 |
|
|
MEM_INT_DMEM_SIZE : natural := 4*1024 -- size of processor-internal data memory in bytes
|
| 1034 |
|
|
);
|
| 1035 |
|
|
port (
|
| 1036 |
|
|
-- global control --
|
| 1037 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 1038 |
|
|
rstn_i : in std_ulogic; -- global reset line, low-active
|
| 1039 |
|
|
-- host access --
|
| 1040 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 1041 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 1042 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 1043 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
| 1044 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 1045 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 1046 |
11 |
zero_gravi |
cancel_i : in std_ulogic; -- cancel current bus transaction
|
| 1047 |
2 |
zero_gravi |
ack_o : out std_ulogic; -- transfer acknowledge
|
| 1048 |
|
|
err_o : out std_ulogic; -- transfer error
|
| 1049 |
|
|
-- wishbone interface --
|
| 1050 |
|
|
wb_adr_o : out std_ulogic_vector(31 downto 0); -- address
|
| 1051 |
|
|
wb_dat_i : in std_ulogic_vector(31 downto 0); -- read data
|
| 1052 |
|
|
wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
|
| 1053 |
|
|
wb_we_o : out std_ulogic; -- read/write
|
| 1054 |
|
|
wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
| 1055 |
|
|
wb_stb_o : out std_ulogic; -- strobe
|
| 1056 |
|
|
wb_cyc_o : out std_ulogic; -- valid cycle
|
| 1057 |
|
|
wb_ack_i : in std_ulogic; -- transfer acknowledge
|
| 1058 |
|
|
wb_err_i : in std_ulogic -- transfer error
|
| 1059 |
|
|
);
|
| 1060 |
|
|
end component;
|
| 1061 |
|
|
|
| 1062 |
23 |
zero_gravi |
-- Component: Dummy Device with SIM Output (DEVNULL) --------------------------------------
|
| 1063 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1064 |
3 |
zero_gravi |
component neorv32_devnull
|
| 1065 |
|
|
port (
|
| 1066 |
|
|
-- host access --
|
| 1067 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 1068 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 1069 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 1070 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 1071 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 1072 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 1073 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
| 1074 |
|
|
);
|
| 1075 |
|
|
end component;
|
| 1076 |
|
|
|
| 1077 |
23 |
zero_gravi |
-- Component: Custom Functions Unit (CFU) -------------------------------------------------
|
| 1078 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1079 |
|
|
component neorv32_cfu
|
| 1080 |
|
|
port (
|
| 1081 |
|
|
-- host access --
|
| 1082 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 1083 |
|
|
rstn_i : in std_ulogic; -- global reset line, low-active, use as async
|
| 1084 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 1085 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 1086 |
|
|
wren_i : in std_ulogic; -- write enable
|
| 1087 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
| 1088 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 1089 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
| 1090 |
|
|
-- clock generator --
|
| 1091 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
| 1092 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0); -- "clock" inputs
|
| 1093 |
|
|
-- interrupt --
|
| 1094 |
|
|
irq_o : out std_ulogic
|
| 1095 |
|
|
-- custom io --
|
| 1096 |
|
|
-- ...
|
| 1097 |
|
|
);
|
| 1098 |
|
|
end component;
|
| 1099 |
|
|
|
| 1100 |
|
|
-- Component: System Configuration Information Memory (SYSINFO) ---------------------------
|
| 1101 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1102 |
12 |
zero_gravi |
component neorv32_sysinfo
|
| 1103 |
|
|
generic (
|
| 1104 |
|
|
-- General --
|
| 1105 |
|
|
CLOCK_FREQUENCY : natural := 0; -- clock frequency of clk_i in Hz
|
| 1106 |
|
|
BOOTLOADER_USE : boolean := true; -- implement processor-internal bootloader?
|
| 1107 |
|
|
USER_CODE : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom user code
|
| 1108 |
23 |
zero_gravi |
-- Internal Instruction memory --
|
| 1109 |
12 |
zero_gravi |
MEM_INT_IMEM_USE : boolean := true; -- implement processor-internal instruction memory
|
| 1110 |
|
|
MEM_INT_IMEM_SIZE : natural := 8*1024; -- size of processor-internal instruction memory in bytes
|
| 1111 |
|
|
MEM_INT_IMEM_ROM : boolean := false; -- implement processor-internal instruction memory as ROM
|
| 1112 |
23 |
zero_gravi |
-- Internal Data memory --
|
| 1113 |
12 |
zero_gravi |
MEM_INT_DMEM_USE : boolean := true; -- implement processor-internal data memory
|
| 1114 |
|
|
MEM_INT_DMEM_SIZE : natural := 4*1024; -- size of processor-internal data memory in bytes
|
| 1115 |
23 |
zero_gravi |
-- External memory interface --
|
| 1116 |
12 |
zero_gravi |
MEM_EXT_USE : boolean := false; -- implement external memory bus interface?
|
| 1117 |
|
|
-- Processor peripherals --
|
| 1118 |
|
|
IO_GPIO_USE : boolean := true; -- implement general purpose input/output port unit (GPIO)?
|
| 1119 |
|
|
IO_MTIME_USE : boolean := true; -- implement machine system timer (MTIME)?
|
| 1120 |
|
|
IO_UART_USE : boolean := true; -- implement universal asynchronous receiver/transmitter (UART)?
|
| 1121 |
|
|
IO_SPI_USE : boolean := true; -- implement serial peripheral interface (SPI)?
|
| 1122 |
|
|
IO_TWI_USE : boolean := true; -- implement two-wire interface (TWI)?
|
| 1123 |
|
|
IO_PWM_USE : boolean := true; -- implement pulse-width modulation unit (PWM)?
|
| 1124 |
|
|
IO_WDT_USE : boolean := true; -- implement watch dog timer (WDT)?
|
| 1125 |
|
|
IO_TRNG_USE : boolean := true; -- implement true random number generator (TRNG)?
|
| 1126 |
23 |
zero_gravi |
IO_DEVNULL_USE : boolean := true; -- implement dummy device (DEVNULL)?
|
| 1127 |
|
|
IO_CFU_USE : boolean := true -- implement custom functions unit (CFU)?
|
| 1128 |
12 |
zero_gravi |
);
|
| 1129 |
|
|
port (
|
| 1130 |
|
|
-- host access --
|
| 1131 |
|
|
clk_i : in std_ulogic; -- global clock line
|
| 1132 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
| 1133 |
|
|
rden_i : in std_ulogic; -- read enable
|
| 1134 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
| 1135 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
| 1136 |
|
|
);
|
| 1137 |
|
|
end component;
|
| 1138 |
|
|
|
| 1139 |
2 |
zero_gravi |
end neorv32_package;
|
| 1140 |
|
|
|
| 1141 |
|
|
package body neorv32_package is
|
| 1142 |
|
|
|
| 1143 |
|
|
-- Function: Minimal required bit width ---------------------------------------------------
|
| 1144 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1145 |
|
|
function index_size_f(input : natural) return natural is
|
| 1146 |
|
|
begin
|
| 1147 |
|
|
for i in 0 to natural'high loop
|
| 1148 |
|
|
if (2**i >= input) then
|
| 1149 |
|
|
return i;
|
| 1150 |
|
|
end if;
|
| 1151 |
|
|
end loop; -- i
|
| 1152 |
|
|
return 0;
|
| 1153 |
|
|
end function index_size_f;
|
| 1154 |
|
|
|
| 1155 |
|
|
-- Function: Conditional select natural ---------------------------------------------------
|
| 1156 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1157 |
|
|
function cond_sel_natural_f(cond : boolean; val_t : natural; val_f : natural) return natural is
|
| 1158 |
|
|
begin
|
| 1159 |
|
|
if (cond = true) then
|
| 1160 |
|
|
return val_t;
|
| 1161 |
|
|
else
|
| 1162 |
|
|
return val_f;
|
| 1163 |
|
|
end if;
|
| 1164 |
|
|
end function cond_sel_natural_f;
|
| 1165 |
|
|
|
| 1166 |
|
|
-- Function: Conditional select std_ulogic_vector -----------------------------------------
|
| 1167 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1168 |
|
|
function cond_sel_stdulogicvector_f(cond : boolean; val_t : std_ulogic_vector; val_f : std_ulogic_vector) return std_ulogic_vector is
|
| 1169 |
|
|
begin
|
| 1170 |
|
|
if (cond = true) then
|
| 1171 |
|
|
return val_t;
|
| 1172 |
|
|
else
|
| 1173 |
|
|
return val_f;
|
| 1174 |
|
|
end if;
|
| 1175 |
|
|
end function cond_sel_stdulogicvector_f;
|
| 1176 |
|
|
|
| 1177 |
|
|
-- Function: Convert BOOL to STD_ULOGIC ---------------------------------------------------
|
| 1178 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1179 |
|
|
function bool_to_ulogic_f(cond : boolean) return std_ulogic is
|
| 1180 |
|
|
begin
|
| 1181 |
|
|
if (cond = true) then
|
| 1182 |
|
|
return '1';
|
| 1183 |
|
|
else
|
| 1184 |
|
|
return '0';
|
| 1185 |
|
|
end if;
|
| 1186 |
|
|
end function bool_to_ulogic_f;
|
| 1187 |
|
|
|
| 1188 |
|
|
-- Function: OR all bits ------------------------------------------------------------------
|
| 1189 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1190 |
|
|
function or_all_f(a : std_ulogic_vector) return std_ulogic is
|
| 1191 |
|
|
variable tmp_v : std_ulogic;
|
| 1192 |
|
|
begin
|
| 1193 |
|
|
tmp_v := a(a'low);
|
| 1194 |
15 |
zero_gravi |
if (a'low < a'high) then -- not null range?
|
| 1195 |
|
|
for i in a'low+1 to a'high loop
|
| 1196 |
|
|
tmp_v := tmp_v or a(i);
|
| 1197 |
|
|
end loop; -- i
|
| 1198 |
|
|
end if;
|
| 1199 |
2 |
zero_gravi |
return tmp_v;
|
| 1200 |
|
|
end function or_all_f;
|
| 1201 |
|
|
|
| 1202 |
|
|
-- Function: AND all bits -----------------------------------------------------------------
|
| 1203 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1204 |
|
|
function and_all_f(a : std_ulogic_vector) return std_ulogic is
|
| 1205 |
|
|
variable tmp_v : std_ulogic;
|
| 1206 |
|
|
begin
|
| 1207 |
|
|
tmp_v := a(a'low);
|
| 1208 |
15 |
zero_gravi |
if (a'low < a'high) then -- not null range?
|
| 1209 |
|
|
for i in a'low+1 to a'high loop
|
| 1210 |
|
|
tmp_v := tmp_v and a(i);
|
| 1211 |
|
|
end loop; -- i
|
| 1212 |
|
|
end if;
|
| 1213 |
2 |
zero_gravi |
return tmp_v;
|
| 1214 |
|
|
end function and_all_f;
|
| 1215 |
|
|
|
| 1216 |
|
|
-- Function: XOR all bits -----------------------------------------------------------------
|
| 1217 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1218 |
|
|
function xor_all_f(a : std_ulogic_vector) return std_ulogic is
|
| 1219 |
|
|
variable tmp_v : std_ulogic;
|
| 1220 |
|
|
begin
|
| 1221 |
|
|
tmp_v := a(a'low);
|
| 1222 |
15 |
zero_gravi |
if (a'low < a'high) then -- not null range?
|
| 1223 |
|
|
for i in a'low+1 to a'high loop
|
| 1224 |
|
|
tmp_v := tmp_v xor a(i);
|
| 1225 |
|
|
end loop; -- i
|
| 1226 |
|
|
end if;
|
| 1227 |
2 |
zero_gravi |
return tmp_v;
|
| 1228 |
|
|
end function xor_all_f;
|
| 1229 |
|
|
|
| 1230 |
|
|
-- Function: XNOR all bits ----------------------------------------------------------------
|
| 1231 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1232 |
|
|
function xnor_all_f(a : std_ulogic_vector) return std_ulogic is
|
| 1233 |
|
|
variable tmp_v : std_ulogic;
|
| 1234 |
|
|
begin
|
| 1235 |
|
|
tmp_v := a(a'low);
|
| 1236 |
15 |
zero_gravi |
if (a'low < a'high) then -- not null range?
|
| 1237 |
|
|
for i in a'low+1 to a'high loop
|
| 1238 |
|
|
tmp_v := tmp_v xnor a(i);
|
| 1239 |
|
|
end loop; -- i
|
| 1240 |
|
|
end if;
|
| 1241 |
2 |
zero_gravi |
return tmp_v;
|
| 1242 |
|
|
end function xnor_all_f;
|
| 1243 |
|
|
|
| 1244 |
6 |
zero_gravi |
-- Function: Convert to hex char ----------------------------------------------------------
|
| 1245 |
|
|
-- -------------------------------------------------------------------------------------------
|
| 1246 |
|
|
function to_hexchar_f(input : std_ulogic_vector(3 downto 0)) return character is
|
| 1247 |
|
|
variable output_v : character;
|
| 1248 |
|
|
begin
|
| 1249 |
|
|
case input is
|
| 1250 |
7 |
zero_gravi |
when x"0" => output_v := '0';
|
| 1251 |
|
|
when x"1" => output_v := '1';
|
| 1252 |
|
|
when x"2" => output_v := '2';
|
| 1253 |
|
|
when x"3" => output_v := '3';
|
| 1254 |
|
|
when x"4" => output_v := '4';
|
| 1255 |
|
|
when x"5" => output_v := '5';
|
| 1256 |
|
|
when x"6" => output_v := '6';
|
| 1257 |
|
|
when x"7" => output_v := '7';
|
| 1258 |
|
|
when x"8" => output_v := '8';
|
| 1259 |
|
|
when x"9" => output_v := '9';
|
| 1260 |
|
|
when x"a" => output_v := 'a';
|
| 1261 |
|
|
when x"b" => output_v := 'b';
|
| 1262 |
|
|
when x"c" => output_v := 'c';
|
| 1263 |
|
|
when x"d" => output_v := 'd';
|
| 1264 |
|
|
when x"e" => output_v := 'e';
|
| 1265 |
|
|
when x"f" => output_v := 'f';
|
| 1266 |
6 |
zero_gravi |
when others => output_v := '?';
|
| 1267 |
|
|
end case;
|
| 1268 |
|
|
return output_v;
|
| 1269 |
|
|
end function to_hexchar_f;
|
| 1270 |
|
|
|
| 1271 |
2 |
zero_gravi |
end neorv32_package;
|