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