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 |
|
|
-- Architecture Constants -----------------------------------------------------------------
|
42 |
|
|
-- -------------------------------------------------------------------------------------------
|
43 |
|
|
constant data_width_c : natural := 32; -- data width - FIXED!
|
44 |
|
|
constant hw_version_c : std_ulogic_vector(31 downto 0) := x"00000203"; -- no touchy!
|
45 |
|
|
|
46 |
|
|
-- Internal Functions ---------------------------------------------------------------------
|
47 |
|
|
-- -------------------------------------------------------------------------------------------
|
48 |
|
|
function index_size_f(input : natural) return natural;
|
49 |
|
|
function cond_sel_natural_f(cond : boolean; val_t : natural; val_f : natural) return natural;
|
50 |
|
|
function cond_sel_stdulogicvector_f(cond : boolean; val_t : std_ulogic_vector; val_f : std_ulogic_vector) return std_ulogic_vector;
|
51 |
|
|
function bool_to_ulogic_f(cond : boolean) return std_ulogic;
|
52 |
|
|
function or_all_f(a : std_ulogic_vector) return std_ulogic;
|
53 |
|
|
function and_all_f(a : std_ulogic_vector) return std_ulogic;
|
54 |
|
|
function xor_all_f(a : std_ulogic_vector) return std_ulogic;
|
55 |
|
|
function xnor_all_f(a : std_ulogic_vector) return std_ulogic;
|
56 |
|
|
|
57 |
|
|
-- Processor-internal Address Space Layout ------------------------------------------------
|
58 |
|
|
-- -------------------------------------------------------------------------------------------
|
59 |
|
|
-- Instruction Memory & Data Memory --
|
60 |
|
|
-- => configured via top's generics
|
61 |
|
|
|
62 |
|
|
-- Bootloader ROM --
|
63 |
|
|
constant boot_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFF0000"; -- bootloader base address, fixed!
|
64 |
|
|
constant boot_size_c : natural := 4*1024; -- bytes
|
65 |
|
|
constant boot_max_size_c : natural := 32*1024; -- bytes, fixed!
|
66 |
|
|
|
67 |
|
|
-- IO: Peripheral Devices ("IO") Area --
|
68 |
|
|
-- Control register(s) (including the device-enable) should be located at the base address of each device
|
69 |
|
|
constant io_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF80";
|
70 |
|
|
constant io_size_c : natural := 32*4; -- bytes, fixed!
|
71 |
|
|
|
72 |
|
|
-- General Purpose Input/Output Unit (GPIO) --
|
73 |
|
|
constant gpio_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF80"; -- base address, fixed!
|
74 |
|
|
constant gpio_size_c : natural := 2*4; -- bytes, fixed!
|
75 |
|
|
constant gpio_in_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(gpio_base_c) + x"00000000");
|
76 |
|
|
constant gpio_out_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(gpio_base_c) + x"00000004");
|
77 |
|
|
|
78 |
|
|
-- Core-Local Interrupt Controller (CLIC) --
|
79 |
|
|
constant clic_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF88"; -- base address, fixed!
|
80 |
|
|
constant clic_size_c : natural := 1*4; -- bytes, fixed!
|
81 |
|
|
constant clic_ctrl_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(clic_base_c) + x"00000000");
|
82 |
|
|
|
83 |
|
|
-- Watch Dog Timer (WDT) --
|
84 |
|
|
constant wdt_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF8C"; -- base address, fixed!
|
85 |
|
|
constant wdt_size_c : natural := 1*4; -- bytes, fixed!
|
86 |
|
|
constant wdt_ctrl_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(wdt_base_c) + x"00000000");
|
87 |
|
|
|
88 |
|
|
-- Machine System Timer (MTIME) --
|
89 |
|
|
constant mtime_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFF90"; -- base address, fixed!
|
90 |
|
|
constant mtime_size_c : natural := 4*4; -- bytes, fixed!
|
91 |
|
|
constant mtime_time_lo_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(mtime_base_c) + x"00000000");
|
92 |
|
|
constant mtime_time_hi_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(mtime_base_c) + x"00000004");
|
93 |
|
|
constant mtime_cmp_lo_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(mtime_base_c) + x"00000008");
|
94 |
|
|
constant mtime_cmp_hi_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(mtime_base_c) + x"0000000C");
|
95 |
|
|
|
96 |
|
|
-- Universal Asynchronous Receiver/Transmitter (UART) --
|
97 |
|
|
constant uart_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFA0"; -- base address, fixed!
|
98 |
|
|
constant uart_size_c : natural := 2*4; -- bytes, fixed!
|
99 |
|
|
constant uart_ctrl_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(uart_base_c) + x"00000000");
|
100 |
|
|
constant uart_rtx_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(uart_base_c) + x"00000004");
|
101 |
|
|
|
102 |
|
|
-- Serial Peripheral Interface (SPI) --
|
103 |
|
|
constant spi_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFA8"; -- base address, fixed!
|
104 |
|
|
constant spi_size_c : natural := 2*4; -- bytes, fixed!
|
105 |
|
|
constant spi_ctrl_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(spi_base_c) + x"00000000");
|
106 |
|
|
constant spi_rtx_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(spi_base_c) + x"00000004");
|
107 |
|
|
|
108 |
|
|
-- Two Wire Interface (TWI) --
|
109 |
|
|
constant twi_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFB0"; -- base address, fixed!
|
110 |
|
|
constant twi_size_c : natural := 2*4; -- bytes, fixed!
|
111 |
|
|
constant twi_ctrl_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(twi_base_c) + x"00000000");
|
112 |
|
|
constant twi_rtx_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(twi_base_c) + x"00000004");
|
113 |
|
|
|
114 |
|
|
-- Pulse-Width Modulation Controller (PWM) --
|
115 |
|
|
constant pwm_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFB8"; -- base address, fixed!
|
116 |
|
|
constant pwm_size_c : natural := 2*4; -- bytes, fixed!
|
117 |
|
|
constant pwm_ctrl_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(pwm_base_c) + x"00000000");
|
118 |
|
|
constant pwm_duty_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(pwm_base_c) + x"00000004");
|
119 |
|
|
|
120 |
|
|
-- True Random Number generator (TRNG) --
|
121 |
|
|
constant trng_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFC0"; -- base address, fixed!
|
122 |
|
|
constant trng_size_c : natural := 2*4; -- bytes, fixed!
|
123 |
|
|
constant trng_ctrl_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(trng_base_c) + x"00000000");
|
124 |
|
|
constant trng_data_addr_c : std_ulogic_vector(31 downto 0) := std_ulogic_vector(unsigned(trng_base_c) + x"00000004");
|
125 |
|
|
|
126 |
|
|
-- RESERVED --
|
127 |
|
|
--constant ???_base_c : std_ulogic_vector(data_width_c-1 downto 0) := x"FFFFFFC8"; -- base address, fixed!
|
128 |
|
|
--constant ???_size_c : natural := 14*4; -- bytes, fixed!
|
129 |
|
|
|
130 |
|
|
-- Main Control Bus -----------------------------------------------------------------------
|
131 |
|
|
-- -------------------------------------------------------------------------------------------
|
132 |
|
|
-- register file --
|
133 |
|
|
constant ctrl_rf_in_mux_lsb_c : natural := 0; -- input source select lsb (00=ALU, 01=MEM)
|
134 |
|
|
constant ctrl_rf_in_mux_msb_c : natural := 1; -- input source select msb (10=PC, 11=CSR)
|
135 |
|
|
constant ctrl_rf_rs1_adr0_c : natural := 2; -- source register 1 address bit 0
|
136 |
|
|
constant ctrl_rf_rs1_adr1_c : natural := 3; -- source register 1 address bit 1
|
137 |
|
|
constant ctrl_rf_rs1_adr2_c : natural := 4; -- source register 1 address bit 2
|
138 |
|
|
constant ctrl_rf_rs1_adr3_c : natural := 5; -- source register 1 address bit 3
|
139 |
|
|
constant ctrl_rf_rs1_adr4_c : natural := 6; -- source register 1 address bit 4
|
140 |
|
|
constant ctrl_rf_rs2_adr0_c : natural := 7; -- source register 2 address bit 0
|
141 |
|
|
constant ctrl_rf_rs2_adr1_c : natural := 8; -- source register 2 address bit 1
|
142 |
|
|
constant ctrl_rf_rs2_adr2_c : natural := 9; -- source register 2 address bit 2
|
143 |
|
|
constant ctrl_rf_rs2_adr3_c : natural := 10; -- source register 2 address bit 3
|
144 |
|
|
constant ctrl_rf_rs2_adr4_c : natural := 11; -- source register 2 address bit 4
|
145 |
|
|
constant ctrl_rf_rd_adr0_c : natural := 12; -- destiantion register address bit 0
|
146 |
|
|
constant ctrl_rf_rd_adr1_c : natural := 13; -- destiantion register address bit 1
|
147 |
|
|
constant ctrl_rf_rd_adr2_c : natural := 14; -- destiantion register address bit 2
|
148 |
|
|
constant ctrl_rf_rd_adr3_c : natural := 15; -- destiantion register address bit 3
|
149 |
|
|
constant ctrl_rf_rd_adr4_c : natural := 16; -- destiantion register address bit 4
|
150 |
|
|
constant ctrl_rf_wb_en_c : natural := 17; -- write back enable
|
151 |
|
|
constant ctrl_rf_clear_rs1_c : natural := 18; -- force rs1=r0
|
152 |
|
|
constant ctrl_rf_clear_rs2_c : natural := 19; -- force rs2=r0
|
153 |
|
|
-- alu --
|
154 |
|
|
constant ctrl_alu_cmd0_c : natural := 20; -- ALU command bit 0
|
155 |
|
|
constant ctrl_alu_cmd1_c : natural := 21; -- ALU command bit 1
|
156 |
|
|
constant ctrl_alu_cmd2_c : natural := 22; -- ALU command bit 2
|
157 |
|
|
constant ctrl_alu_opa_mux_lsb_c : natural := 23; -- operand A select lsb (00=rs1, 01=PC)
|
158 |
|
|
constant ctrl_alu_opa_mux_msb_c : natural := 24; -- operand A select msb (10=CSR, 11=CSR)
|
159 |
|
|
constant ctrl_alu_opb_mux_lsb_c : natural := 25; -- operand B select lsb (00=rs2, 01=PC)
|
160 |
|
|
constant ctrl_alu_opb_mux_msb_c : natural := 26; -- operand B select msb (10=rs1, 11=PC_increment(2/4))
|
161 |
|
|
constant ctrl_alu_opc_mux_c : natural := 27; -- operand C select (0=IMM, 1=rs2)
|
162 |
|
|
constant ctrl_alu_unsigned_c : natural := 28; -- is unsigned ALU operation
|
163 |
|
|
constant ctrl_alu_shift_dir_c : natural := 29; -- shift direction (0=left, 1=right)
|
164 |
|
|
constant ctrl_alu_shift_ar_c : natural := 30; -- is arithmetic shift
|
165 |
|
|
-- bus interface --
|
166 |
|
|
constant ctrl_bus_size_lsb_c : natural := 31; -- transfer size lsb (00=byte, 01=half-word)
|
167 |
|
|
constant ctrl_bus_size_msb_c : natural := 32; -- transfer size msb (10=word, 11=?)
|
168 |
|
|
constant ctrl_bus_rd_c : natural := 33; -- read data request
|
169 |
|
|
constant ctrl_bus_wr_c : natural := 34; -- write data request
|
170 |
|
|
constant ctrl_bus_if_c : natural := 35; -- instruction fetch request (output PC, otherwise output MAR)
|
171 |
|
|
constant ctrl_bus_mar_we_c : natural := 36; -- memory address register write enable
|
172 |
|
|
constant ctrl_bus_mdo_we_c : natural := 37; -- memory data out register write enable
|
173 |
|
|
constant ctrl_bus_mdi_we_c : natural := 38; -- memory data in register write enable
|
174 |
|
|
constant ctrl_bus_unsigned_c : natural := 39; -- is unsigned load
|
175 |
|
|
-- csr/system --
|
176 |
|
|
constant ctrl_csr_pc_we_c : natural := 40; -- PC write enable
|
177 |
|
|
constant ctrl_csr_re_c : natural := 41; -- valid CSR read
|
178 |
|
|
constant ctrl_csr_we_c : natural := 42; -- valid CSR write
|
179 |
|
|
-- co-processor --
|
180 |
|
|
constant ctrl_cp_use_c : natural := 43; -- is cp operation
|
181 |
|
|
constant ctrl_cp_id_lsb_c : natural := 44; -- cp select lsb
|
182 |
|
|
constant ctrl_cp_id_msb_c : natural := 45; -- cp select msb
|
183 |
|
|
constant ctrl_cp_cmd0_c : natural := 46; -- cp command bit 0
|
184 |
|
|
constant ctrl_cp_cmd1_c : natural := 47; -- cp command bit 1
|
185 |
|
|
constant ctrl_cp_cmd2_c : natural := 48; -- cp command bit 2
|
186 |
|
|
-- control bus size --
|
187 |
|
|
constant ctrl_width_c : natural := 49; -- control bus size
|
188 |
|
|
|
189 |
|
|
-- ALU Comparator Bus ---------------------------------------------------------------------
|
190 |
|
|
-- -------------------------------------------------------------------------------------------
|
191 |
|
|
constant alu_cmp_equal_c : natural := 0;
|
192 |
|
|
constant alu_cmp_less_c : natural := 1; -- for signed and unsigned
|
193 |
|
|
|
194 |
|
|
-- RISC-V Opcode Layout -------------------------------------------------------------------
|
195 |
|
|
-- -------------------------------------------------------------------------------------------
|
196 |
|
|
constant instr_opcode_lsb_c : natural := 0; -- opcode bit 0
|
197 |
|
|
constant instr_opcode_msb_c : natural := 6; -- opcode bit 6
|
198 |
|
|
constant instr_rd_lsb_c : natural := 7; -- destination register address bit 0
|
199 |
|
|
constant instr_rd_msb_c : natural := 11; -- destination register address bit 4
|
200 |
|
|
constant instr_funct3_lsb_c : natural := 12; -- funct3 bit 0
|
201 |
|
|
constant instr_funct3_msb_c : natural := 14; -- funct3 bit 2
|
202 |
|
|
constant instr_rs1_lsb_c : natural := 15; -- source register 1 address bit 0
|
203 |
|
|
constant instr_rs1_msb_c : natural := 19; -- source register 1 address bit 4
|
204 |
|
|
constant instr_rs2_lsb_c : natural := 20; -- source register 2 address bit 0
|
205 |
|
|
constant instr_rs2_msb_c : natural := 24; -- source register 2 address bit 4
|
206 |
|
|
constant instr_funct7_lsb_c : natural := 25; -- funct7 bit 0
|
207 |
|
|
constant instr_funct7_msb_c : natural := 31; -- funct7 bit 6
|
208 |
|
|
constant instr_funct12_lsb_c : natural := 20; -- funct12 bit 0
|
209 |
|
|
constant instr_funct12_msb_c : natural := 31; -- funct12 bit 11
|
210 |
|
|
constant instr_imm12_lsb_c : natural := 20; -- immediate12 bit 0
|
211 |
|
|
constant instr_imm12_msb_c : natural := 31; -- immediate12 bit 11
|
212 |
|
|
constant instr_imm20_lsb_c : natural := 12; -- immediate20 bit 0
|
213 |
|
|
constant instr_imm20_msb_c : natural := 31; -- immediate20 bit 21
|
214 |
|
|
constant instr_csr_id_lsb_c : natural := 20; -- csr select bit 0
|
215 |
|
|
constant instr_csr_id_msb_c : natural := 31; -- csr select bit 11
|
216 |
|
|
|
217 |
|
|
-- RISC-V Opcodes -------------------------------------------------------------------------
|
218 |
|
|
-- -------------------------------------------------------------------------------------------
|
219 |
|
|
-- alu --
|
220 |
|
|
constant opcode_lui_c : std_ulogic_vector(6 downto 0) := "0110111"; -- load upper immediate
|
221 |
|
|
constant opcode_auipc_c : std_ulogic_vector(6 downto 0) := "0010111"; -- add upper immediate to PC
|
222 |
|
|
constant opcode_alui_c : std_ulogic_vector(6 downto 0) := "0010011"; -- ALU operation with immediate (operation via funct3 and funct7)
|
223 |
|
|
constant opcode_alu_c : std_ulogic_vector(6 downto 0) := "0110011"; -- ALU operation (operation via funct3 and funct7)
|
224 |
|
|
-- control flow --
|
225 |
|
|
constant opcode_jal_c : std_ulogic_vector(6 downto 0) := "1101111"; -- jump and link
|
226 |
|
|
constant opcode_jalr_c : std_ulogic_vector(6 downto 0) := "1100111"; -- jump and register
|
227 |
|
|
constant opcode_branch_c : std_ulogic_vector(6 downto 0) := "1100011"; -- branch (condition set via funct3)
|
228 |
|
|
-- memory access --
|
229 |
|
|
constant opcode_load_c : std_ulogic_vector(6 downto 0) := "0000011"; -- load (data type via funct3)
|
230 |
|
|
constant opcode_store_c : std_ulogic_vector(6 downto 0) := "0100011"; -- store (data type via funct3)
|
231 |
|
|
-- system/csr --
|
232 |
|
|
constant opcode_fence_c : std_ulogic_vector(6 downto 0) := "0001111"; -- fence
|
233 |
|
|
constant opcode_syscsr_c : std_ulogic_vector(6 downto 0) := "1110011"; -- system/csr access (type via funct3)
|
234 |
|
|
|
235 |
|
|
-- RISC-V Funct3 --------------------------------------------------------------------------
|
236 |
|
|
-- -------------------------------------------------------------------------------------------
|
237 |
|
|
-- control flow --
|
238 |
|
|
constant funct3_beq_c : std_ulogic_vector(2 downto 0) := "000"; -- branch if equal
|
239 |
|
|
constant funct3_bne_c : std_ulogic_vector(2 downto 0) := "001"; -- branch if not equal
|
240 |
|
|
constant funct3_blt_c : std_ulogic_vector(2 downto 0) := "100"; -- branch if less than
|
241 |
|
|
constant funct3_bge_c : std_ulogic_vector(2 downto 0) := "101"; -- branch if greater than or equal
|
242 |
|
|
constant funct3_bltu_c : std_ulogic_vector(2 downto 0) := "110"; -- branch if less than (unsigned)
|
243 |
|
|
constant funct3_bgeu_c : std_ulogic_vector(2 downto 0) := "111"; -- branch if greater than or equal (unsigned)
|
244 |
|
|
-- memory access --
|
245 |
|
|
constant funct3_lb_c : std_ulogic_vector(2 downto 0) := "000"; -- load byte
|
246 |
|
|
constant funct3_lh_c : std_ulogic_vector(2 downto 0) := "001"; -- load half word
|
247 |
|
|
constant funct3_lw_c : std_ulogic_vector(2 downto 0) := "010"; -- load word
|
248 |
|
|
constant funct3_lbu_c : std_ulogic_vector(2 downto 0) := "100"; -- load byte (unsigned)
|
249 |
|
|
constant funct3_lhu_c : std_ulogic_vector(2 downto 0) := "101"; -- load half word (unsigned)
|
250 |
|
|
constant funct3_sb_c : std_ulogic_vector(2 downto 0) := "000"; -- store byte
|
251 |
|
|
constant funct3_sh_c : std_ulogic_vector(2 downto 0) := "001"; -- store half word
|
252 |
|
|
constant funct3_sw_c : std_ulogic_vector(2 downto 0) := "010"; -- store word
|
253 |
|
|
-- alu --
|
254 |
|
|
constant funct3_subadd_c : std_ulogic_vector(2 downto 0) := "000"; -- sub/add via funct7
|
255 |
|
|
constant funct3_sll_c : std_ulogic_vector(2 downto 0) := "001"; -- shift logical left
|
256 |
|
|
constant funct3_slt_c : std_ulogic_vector(2 downto 0) := "010"; -- set on less
|
257 |
|
|
constant funct3_sltu_c : std_ulogic_vector(2 downto 0) := "011"; -- set on less unsigned
|
258 |
|
|
constant funct3_xor_c : std_ulogic_vector(2 downto 0) := "100"; -- xor
|
259 |
|
|
constant funct3_sr_c : std_ulogic_vector(2 downto 0) := "101"; -- shift right via funct7
|
260 |
|
|
constant funct3_or_c : std_ulogic_vector(2 downto 0) := "110"; -- or
|
261 |
|
|
constant funct3_and_c : std_ulogic_vector(2 downto 0) := "111"; -- and
|
262 |
|
|
-- system/csr --
|
263 |
|
|
constant funct3_env_c : std_ulogic_vector(2 downto 0) := "000"; -- ecall, ebreak, mret, wfi
|
264 |
|
|
constant funct3_csrrw_c : std_ulogic_vector(2 downto 0) := "001"; -- atomic r/w
|
265 |
|
|
constant funct3_csrrs_c : std_ulogic_vector(2 downto 0) := "010"; -- atomic read & set bit
|
266 |
|
|
constant funct3_csrrc_c : std_ulogic_vector(2 downto 0) := "011"; -- atomic read & clear bit
|
267 |
|
|
--
|
268 |
|
|
constant funct3_csrrwi_c : std_ulogic_vector(2 downto 0) := "101"; -- atomic r/w immediate
|
269 |
|
|
constant funct3_csrrsi_c : std_ulogic_vector(2 downto 0) := "110"; -- atomic read & set bit immediate
|
270 |
|
|
constant funct3_csrrci_c : std_ulogic_vector(2 downto 0) := "111"; -- atomic read & clear bit immediate
|
271 |
|
|
|
272 |
|
|
-- Co-Processor Operations ----------------------------------------------------------------
|
273 |
|
|
-- -------------------------------------------------------------------------------------------
|
274 |
|
|
-- cp ids --
|
275 |
|
|
constant cp_sel_muldiv_c : std_ulogic_vector(1 downto 0) := "00"; -- MULDIV CP
|
276 |
|
|
-- muldiv cp --
|
277 |
|
|
constant cp_op_mul_c : std_ulogic_vector(2 downto 0) := "000"; -- mul
|
278 |
|
|
constant cp_op_mulh_c : std_ulogic_vector(2 downto 0) := "001"; -- mulh
|
279 |
|
|
constant cp_op_mulhsu_c : std_ulogic_vector(2 downto 0) := "010"; -- mulhsu
|
280 |
|
|
constant cp_op_mulhu_c : std_ulogic_vector(2 downto 0) := "011"; -- mulhu
|
281 |
|
|
constant cp_op_div_c : std_ulogic_vector(2 downto 0) := "100"; -- div
|
282 |
|
|
constant cp_op_divu_c : std_ulogic_vector(2 downto 0) := "101"; -- divu
|
283 |
|
|
constant cp_op_rem_c : std_ulogic_vector(2 downto 0) := "110"; -- rem
|
284 |
|
|
constant cp_op_remu_c : std_ulogic_vector(2 downto 0) := "111"; -- remu
|
285 |
|
|
|
286 |
|
|
-- ALU Function Codes ---------------------------------------------------------------------
|
287 |
|
|
-- -------------------------------------------------------------------------------------------
|
288 |
|
|
constant alu_cmd_add_c : std_ulogic_vector(2 downto 0) := "000"; -- r <= A + B
|
289 |
|
|
constant alu_cmd_sub_c : std_ulogic_vector(2 downto 0) := "001"; -- r <= A - B
|
290 |
|
|
constant alu_cmd_slt_c : std_ulogic_vector(2 downto 0) := "010"; -- r <= A < B
|
291 |
|
|
constant alu_cmd_shift_c : std_ulogic_vector(2 downto 0) := "011"; -- r <= A <</>> B
|
292 |
|
|
constant alu_cmd_xor_c : std_ulogic_vector(2 downto 0) := "100"; -- r <= A xor B
|
293 |
|
|
constant alu_cmd_or_c : std_ulogic_vector(2 downto 0) := "101"; -- r <= A or B
|
294 |
|
|
constant alu_cmd_and_c : std_ulogic_vector(2 downto 0) := "110"; -- r <= A and B
|
295 |
|
|
constant alu_cmd_bitc_c : std_ulogic_vector(2 downto 0) := "111"; -- r <= A and (not B)
|
296 |
|
|
|
297 |
|
|
-- CPU Control Exception System -----------------------------------------------------------
|
298 |
|
|
-- -------------------------------------------------------------------------------------------
|
299 |
|
|
-- exception source bits --
|
300 |
|
|
constant exception_iaccess_c : natural := 0; -- instrution access fault
|
301 |
|
|
constant exception_iillegal_c : natural := 1; -- illegal instrution
|
302 |
|
|
constant exception_ialign_c : natural := 2; -- instrution address misaligned
|
303 |
|
|
constant exception_m_envcall_c : natural := 3; -- ENV call from m-mode
|
304 |
|
|
constant exception_break_c : natural := 4; -- breakpoint
|
305 |
|
|
constant exception_salign_c : natural := 5; -- store address misaligned
|
306 |
|
|
constant exception_lalign_c : natural := 6; -- load address misaligned
|
307 |
|
|
constant exception_saccess_c : natural := 7; -- store access fault
|
308 |
|
|
constant exception_laccess_c : natural := 8; -- load access fault
|
309 |
|
|
constant exception_width_c : natural := 9; -- length of this list in bits
|
310 |
|
|
-- interrupt source bits --
|
311 |
|
|
constant interrupt_mtime_irq_c : natural := 0; -- machine timer interrupt
|
312 |
|
|
constant interrupt_msw_irq_c : natural := 1; -- machine sw interrupt
|
313 |
|
|
constant interrupt_mext_irq_c : natural := 2; -- machine external interrupt
|
314 |
|
|
constant interrupt_width_c : natural := 3; -- length of this list in bits
|
315 |
|
|
|
316 |
|
|
-- Clock Generator -------------------------------------------------------------------------
|
317 |
|
|
-- -------------------------------------------------------------------------------------------
|
318 |
|
|
constant clk_div2_c : natural := 0;
|
319 |
|
|
constant clk_div4_c : natural := 1;
|
320 |
|
|
constant clk_div8_c : natural := 2;
|
321 |
|
|
constant clk_div64_c : natural := 3;
|
322 |
|
|
constant clk_div128_c : natural := 4;
|
323 |
|
|
constant clk_div1024_c : natural := 5;
|
324 |
|
|
constant clk_div2048_c : natural := 6;
|
325 |
|
|
constant clk_div4096_c : natural := 7;
|
326 |
|
|
|
327 |
|
|
-- Component: NEORV32 Processor Top Entity ------------------------------------------------
|
328 |
|
|
-- -------------------------------------------------------------------------------------------
|
329 |
|
|
component neorv32_top
|
330 |
|
|
generic (
|
331 |
|
|
-- General --
|
332 |
|
|
CLOCK_FREQUENCY : natural := 0; -- clock frequency of clk_i in Hz
|
333 |
|
|
HART_ID : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom hardware thread ID
|
334 |
|
|
BOOTLOADER_USE : boolean := true; -- implement processor-internal bootloader?
|
335 |
|
|
-- RISC-V CPU Extensions --
|
336 |
|
|
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
337 |
|
|
CPU_EXTENSION_RISCV_E : boolean := false; -- implement embedded RF extension?
|
338 |
|
|
CPU_EXTENSION_RISCV_M : boolean := false; -- implement muld/div extension?
|
339 |
|
|
CPU_EXTENSION_RISCV_Zicsr : boolean := true; -- implement CSR system?
|
340 |
|
|
-- Memory configuration: Instruction memory --
|
341 |
|
|
MEM_ISPACE_BASE : std_ulogic_vector(31 downto 0) := x"00000000"; -- base address of instruction memory space
|
342 |
|
|
MEM_ISPACE_SIZE : natural := 16*1024; -- total size of instruction memory space in byte
|
343 |
|
|
MEM_INT_IMEM_USE : boolean := true; -- implement processor-internal instruction memory
|
344 |
|
|
MEM_INT_IMEM_SIZE : natural := 16*1024; -- size of processor-internal instruction memory in bytes
|
345 |
|
|
MEM_INT_IMEM_ROM : boolean := false; -- implement processor-internal instruction memory as ROM
|
346 |
|
|
-- Memory configuration: Data memory --
|
347 |
|
|
MEM_DSPACE_BASE : std_ulogic_vector(31 downto 0) := x"80000000"; -- base address of data memory space
|
348 |
|
|
MEM_DSPACE_SIZE : natural := 8*1024; -- total size of data memory space in byte
|
349 |
|
|
MEM_INT_DMEM_USE : boolean := true; -- implement processor-internal data memory
|
350 |
|
|
MEM_INT_DMEM_SIZE : natural := 8*1024; -- size of processor-internal data memory in bytes
|
351 |
|
|
-- Memory configuration: External memory interface --
|
352 |
|
|
MEM_EXT_USE : boolean := false; -- implement external memory bus interface?
|
353 |
|
|
MEM_EXT_REG_STAGES : natural := 2; -- number of interface register stages (0,1,2)
|
354 |
|
|
MEM_EXT_TIMEOUT : natural := 15; -- cycles after which a valid bus access will timeout (>=1)
|
355 |
|
|
-- Processor peripherals --
|
356 |
|
|
IO_GPIO_USE : boolean := true; -- implement general purpose input/output port unit (GPIO)?
|
357 |
|
|
IO_MTIME_USE : boolean := true; -- implement machine system timer (MTIME)?
|
358 |
|
|
IO_UART_USE : boolean := true; -- implement universal asynchronous receiver/transmitter (UART)?
|
359 |
|
|
IO_SPI_USE : boolean := true; -- implement serial peripheral interface (SPI)?
|
360 |
|
|
IO_TWI_USE : boolean := true; -- implement two-wire interface (TWI)?
|
361 |
|
|
IO_PWM_USE : boolean := true; -- implement pulse-width modulation unit (PWM)?
|
362 |
|
|
IO_WDT_USE : boolean := true; -- implement watch dog timer (WDT)?
|
363 |
|
|
IO_CLIC_USE : boolean := true; -- implement core local interrupt controller (CLIC)?
|
364 |
|
|
IO_TRNG_USE : boolean := false -- implement true random number generator (TRNG)?
|
365 |
|
|
);
|
366 |
|
|
port (
|
367 |
|
|
-- Global control --
|
368 |
|
|
clk_i : in std_ulogic := '0'; -- global clock, rising edge
|
369 |
|
|
rstn_i : in std_ulogic := '0'; -- global reset, low-active, async
|
370 |
|
|
-- Wishbone bus interface --
|
371 |
|
|
wb_adr_o : out std_ulogic_vector(31 downto 0); -- address
|
372 |
|
|
wb_dat_i : in std_ulogic_vector(31 downto 0) := (others => '0'); -- read data
|
373 |
|
|
wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
|
374 |
|
|
wb_we_o : out std_ulogic; -- read/write
|
375 |
|
|
wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
376 |
|
|
wb_stb_o : out std_ulogic; -- strobe
|
377 |
|
|
wb_cyc_o : out std_ulogic; -- valid cycle
|
378 |
|
|
wb_ack_i : in std_ulogic := '0'; -- transfer acknowledge
|
379 |
|
|
wb_err_i : in std_ulogic := '0'; -- transfer error
|
380 |
|
|
-- GPIO --
|
381 |
|
|
gpio_o : out std_ulogic_vector(15 downto 0); -- parallel output
|
382 |
|
|
gpio_i : in std_ulogic_vector(15 downto 0) := (others => '0'); -- parallel input
|
383 |
|
|
-- UART --
|
384 |
|
|
uart_txd_o : out std_ulogic; -- UART send data
|
385 |
|
|
uart_rxd_i : in std_ulogic := '0'; -- UART receive data
|
386 |
|
|
-- SPI --
|
387 |
|
|
spi_sclk_o : out std_ulogic; -- serial clock line
|
388 |
|
|
spi_mosi_o : out std_ulogic; -- serial data line out
|
389 |
|
|
spi_miso_i : in std_ulogic := '0'; -- serial data line in
|
390 |
|
|
spi_csn_o : out std_ulogic_vector(07 downto 0); -- SPI CS
|
391 |
|
|
-- TWI --
|
392 |
|
|
twi_sda_io : inout std_logic := 'H'; -- twi serial data line
|
393 |
|
|
twi_scl_io : inout std_logic := 'H'; -- twi serial clock line
|
394 |
|
|
-- PWM --
|
395 |
|
|
pwm_o : out std_ulogic_vector(03 downto 0); -- pwm channels
|
396 |
|
|
-- Interrupts --
|
397 |
|
|
ext_irq_i : in std_ulogic_vector(01 downto 0) := (others => '0'); -- external interrupt request
|
398 |
|
|
ext_ack_o : out std_ulogic_vector(01 downto 0) -- external interrupt request acknowledge
|
399 |
|
|
);
|
400 |
|
|
end component;
|
401 |
|
|
|
402 |
|
|
-- Component: CPU Control -----------------------------------------------------------------
|
403 |
|
|
-- -------------------------------------------------------------------------------------------
|
404 |
|
|
component neorv32_cpu_control
|
405 |
|
|
generic (
|
406 |
|
|
-- General --
|
407 |
|
|
CLOCK_FREQUENCY : natural := 0; -- clock frequency of clk_i in Hz
|
408 |
|
|
HART_ID : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom hardware thread ID
|
409 |
|
|
BOOTLOADER_USE : boolean := true; -- implement processor-internal bootloader?
|
410 |
|
|
-- RISC-V CPU Extensions --
|
411 |
|
|
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
412 |
|
|
CPU_EXTENSION_RISCV_E : boolean := false; -- implement embedded RF extension?
|
413 |
|
|
CPU_EXTENSION_RISCV_M : boolean := false; -- implement muld/div extension?
|
414 |
|
|
CPU_EXTENSION_RISCV_Zicsr : boolean := true; -- implement CSR system?
|
415 |
|
|
-- Memory configuration: Instruction memory --
|
416 |
|
|
MEM_ISPACE_BASE : std_ulogic_vector(31 downto 0) := x"00000000"; -- base address of instruction memory space
|
417 |
|
|
MEM_ISPACE_SIZE : natural := 16*1024; -- total size of instruction memory space in byte
|
418 |
|
|
MEM_INT_IMEM_USE : boolean := true; -- implement processor-internal instruction memory
|
419 |
|
|
MEM_INT_IMEM_SIZE : natural := 16*1024; -- size of processor-internal instruction memory in bytes
|
420 |
|
|
MEM_INT_IMEM_ROM : boolean := false; -- implement processor-internal instruction memory as ROM
|
421 |
|
|
-- Memory configuration: Data memory --
|
422 |
|
|
MEM_DSPACE_BASE : std_ulogic_vector(31 downto 0) := x"80000000"; -- base address of data memory space
|
423 |
|
|
MEM_DSPACE_SIZE : natural := 8*1024; -- total size of data memory space in byte
|
424 |
|
|
MEM_INT_DMEM_USE : boolean := true; -- implement processor-internal data memory
|
425 |
|
|
MEM_INT_DMEM_SIZE : natural := 8*1024; -- size of processor-internal data memory in bytes
|
426 |
|
|
-- Memory configuration: External memory interface --
|
427 |
|
|
MEM_EXT_USE : boolean := false; -- implement external memory bus interface?
|
428 |
|
|
-- Processor peripherals --
|
429 |
|
|
IO_GPIO_USE : boolean := true; -- implement general purpose input/output port unit (GPIO)?
|
430 |
|
|
IO_MTIME_USE : boolean := true; -- implement machine system timer (MTIME)?
|
431 |
|
|
IO_UART_USE : boolean := true; -- implement universal asynchronous receiver/transmitter (UART)?
|
432 |
|
|
IO_SPI_USE : boolean := true; -- implement serial peripheral interface (SPI)?
|
433 |
|
|
IO_TWI_USE : boolean := true; -- implement two-wire interface (TWI)?
|
434 |
|
|
IO_PWM_USE : boolean := true; -- implement pulse-width modulation unit (PWM)?
|
435 |
|
|
IO_WDT_USE : boolean := true; -- implement watch dog timer (WDT)?
|
436 |
|
|
IO_CLIC_USE : boolean := true; -- implement core local interrupt controller (CLIC)?
|
437 |
|
|
IO_TRNG_USE : boolean := true -- implement true random number generator (TRNG)?
|
438 |
|
|
);
|
439 |
|
|
port (
|
440 |
|
|
-- global control --
|
441 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
442 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
443 |
|
|
ctrl_o : out std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
444 |
|
|
-- status input --
|
445 |
|
|
alu_wait_i : in std_ulogic; -- wait for ALU
|
446 |
|
|
bus_wait_i : in std_ulogic; -- wait for bus
|
447 |
|
|
-- data input --
|
448 |
|
|
instr_i : in std_ulogic_vector(data_width_c-1 downto 0); -- instruction
|
449 |
|
|
cmp_i : in std_ulogic_vector(1 downto 0); -- comparator status
|
450 |
|
|
alu_add_i : in std_ulogic_vector(data_width_c-1 downto 0); -- ALU.add result
|
451 |
|
|
-- data output --
|
452 |
|
|
imm_o : out std_ulogic_vector(data_width_c-1 downto 0); -- immediate
|
453 |
|
|
pc_o : out std_ulogic_vector(data_width_c-1 downto 0); -- current PC
|
454 |
|
|
alu_pc_o : out std_ulogic_vector(data_width_c-1 downto 0); -- delayed PC for ALU
|
455 |
|
|
-- csr interface --
|
456 |
|
|
csr_wdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- CSR write data
|
457 |
|
|
csr_rdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- CSR read data
|
458 |
|
|
-- external interrupt --
|
459 |
|
|
clic_irq_i : in std_ulogic; -- CLIC interrupt request
|
460 |
|
|
mtime_irq_i : in std_ulogic; -- machine timer interrupt
|
461 |
|
|
-- bus access exceptions --
|
462 |
|
|
mar_i : in std_ulogic_vector(data_width_c-1 downto 0); -- memory address register
|
463 |
|
|
ma_instr_i : in std_ulogic; -- misaligned instruction address
|
464 |
|
|
ma_load_i : in std_ulogic; -- misaligned load data address
|
465 |
|
|
ma_store_i : in std_ulogic; -- misaligned store data address
|
466 |
|
|
be_instr_i : in std_ulogic; -- bus error on instruction access
|
467 |
|
|
be_load_i : in std_ulogic; -- bus error on load data access
|
468 |
|
|
be_store_i : in std_ulogic; -- bus error on store data access
|
469 |
|
|
bus_exc_ack_o : out std_ulogic -- bus exception error acknowledge
|
470 |
|
|
);
|
471 |
|
|
end component;
|
472 |
|
|
|
473 |
|
|
-- Component: CPU Register File -----------------------------------------------------------
|
474 |
|
|
-- -------------------------------------------------------------------------------------------
|
475 |
|
|
component neorv32_cpu_regfile
|
476 |
|
|
generic (
|
477 |
|
|
CPU_EXTENSION_RISCV_E : boolean := false -- implement embedded RF extension?
|
478 |
|
|
);
|
479 |
|
|
port (
|
480 |
|
|
-- global control --
|
481 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
482 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
483 |
|
|
-- data input --
|
484 |
|
|
mem_i : in std_ulogic_vector(data_width_c-1 downto 0); -- memory read data
|
485 |
|
|
alu_i : in std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
|
486 |
|
|
csr_i : in std_ulogic_vector(data_width_c-1 downto 0); -- CSR read data
|
487 |
|
|
pc_i : in std_ulogic_vector(data_width_c-1 downto 0); -- current pc
|
488 |
|
|
-- data output --
|
489 |
|
|
rs1_o : out std_ulogic_vector(data_width_c-1 downto 0); -- operand 1
|
490 |
|
|
rs2_o : out std_ulogic_vector(data_width_c-1 downto 0) -- operand 2
|
491 |
|
|
);
|
492 |
|
|
end component;
|
493 |
|
|
|
494 |
|
|
-- Component: CPU ALU ---------------------------------------------------------------------
|
495 |
|
|
-- -------------------------------------------------------------------------------------------
|
496 |
|
|
component neorv32_cpu_alu
|
497 |
|
|
generic (
|
498 |
|
|
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
499 |
|
|
CPU_EXTENSION_RISCV_M : boolean := false -- implement mul/div extension?
|
500 |
|
|
);
|
501 |
|
|
port (
|
502 |
|
|
-- global control --
|
503 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
504 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
505 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
506 |
|
|
-- data input --
|
507 |
|
|
rs1_i : in std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
|
508 |
|
|
rs2_i : in std_ulogic_vector(data_width_c-1 downto 0); -- rf source 2
|
509 |
|
|
pc_i : in std_ulogic_vector(data_width_c-1 downto 0); -- current PC
|
510 |
|
|
pc2_i : in std_ulogic_vector(data_width_c-1 downto 0); -- delayed PC
|
511 |
|
|
imm_i : in std_ulogic_vector(data_width_c-1 downto 0); -- immediate
|
512 |
|
|
csr_i : in std_ulogic_vector(data_width_c-1 downto 0); -- csr read data
|
513 |
|
|
-- data output --
|
514 |
|
|
cmp_o : out std_ulogic_vector(1 downto 0); -- comparator status
|
515 |
|
|
add_o : out std_ulogic_vector(data_width_c-1 downto 0); -- OPA + OPB
|
516 |
|
|
res_o : out std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
|
517 |
|
|
-- co-processor interface --
|
518 |
|
|
cp0_data_i : in std_ulogic_vector(data_width_c-1 downto 0); -- co-processor 0 result
|
519 |
|
|
cp0_valid_i : in std_ulogic; -- co-processor 0 result valid
|
520 |
|
|
cp1_data_i : in std_ulogic_vector(data_width_c-1 downto 0); -- co-processor 1 result
|
521 |
|
|
cp1_valid_i : in std_ulogic; -- co-processor 1 result valid
|
522 |
|
|
-- status --
|
523 |
|
|
wait_o : out std_ulogic -- busy due to iterative processing units
|
524 |
|
|
);
|
525 |
|
|
end component;
|
526 |
|
|
|
527 |
|
|
-- Component: CPU Co-Processor MULDIV -----------------------------------------------------
|
528 |
|
|
-- -------------------------------------------------------------------------------------------
|
529 |
|
|
component neorv32_cpu_cp_muldiv
|
530 |
|
|
port (
|
531 |
|
|
-- global control --
|
532 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
533 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
534 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
535 |
|
|
-- data input --
|
536 |
|
|
rs1_i : in std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
|
537 |
|
|
rs2_i : in std_ulogic_vector(data_width_c-1 downto 0); -- rf source 2
|
538 |
|
|
-- result and status --
|
539 |
|
|
res_o : out std_ulogic_vector(data_width_c-1 downto 0); -- operation result
|
540 |
|
|
valid_o : out std_ulogic -- data output valid
|
541 |
|
|
);
|
542 |
|
|
end component;
|
543 |
|
|
|
544 |
|
|
-- Component: CPU Bus Interface -----------------------------------------------------------
|
545 |
|
|
-- -------------------------------------------------------------------------------------------
|
546 |
|
|
component neorv32_cpu_bus
|
547 |
|
|
generic (
|
548 |
|
|
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
549 |
|
|
MEM_EXT_TIMEOUT : natural := 15 -- cycles after which a valid bus access will timeout
|
550 |
|
|
);
|
551 |
|
|
port (
|
552 |
|
|
-- global control --
|
553 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
554 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
555 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
|
556 |
|
|
-- data input --
|
557 |
|
|
wdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- write data
|
558 |
|
|
pc_i : in std_ulogic_vector(data_width_c-1 downto 0); -- current PC
|
559 |
|
|
alu_i : in std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
|
560 |
|
|
-- data output --
|
561 |
|
|
instr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- instruction
|
562 |
|
|
rdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- read data
|
563 |
|
|
-- status --
|
564 |
|
|
mar_o : out std_ulogic_vector(data_width_c-1 downto 0); -- current memory address register
|
565 |
|
|
ma_instr_o : out std_ulogic; -- misaligned instruction address
|
566 |
|
|
ma_load_o : out std_ulogic; -- misaligned load data address
|
567 |
|
|
ma_store_o : out std_ulogic; -- misaligned store data address
|
568 |
|
|
be_instr_o : out std_ulogic; -- bus error on instruction access
|
569 |
|
|
be_load_o : out std_ulogic; -- bus error on load data access
|
570 |
|
|
be_store_o : out std_ulogic; -- bus error on store data
|
571 |
|
|
bus_wait_o : out std_ulogic; -- wait for bus operation to finish
|
572 |
|
|
exc_ack_i : in std_ulogic; -- exception controller ACK
|
573 |
|
|
-- bus system --
|
574 |
|
|
bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
575 |
|
|
bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
|
576 |
|
|
bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
577 |
|
|
bus_ben_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
578 |
|
|
bus_we_o : out std_ulogic; -- write enable
|
579 |
|
|
bus_re_o : out std_ulogic; -- read enable
|
580 |
|
|
bus_ack_i : in std_ulogic; -- bus transfer acknowledge
|
581 |
|
|
bus_err_i : in std_ulogic -- bus transfer error
|
582 |
|
|
);
|
583 |
|
|
end component;
|
584 |
|
|
|
585 |
|
|
-- Component: CPU Compressed Instructions Decompressor ------------------------------------
|
586 |
|
|
-- -------------------------------------------------------------------------------------------
|
587 |
|
|
component neorv32_cpu_decompressor
|
588 |
|
|
port (
|
589 |
|
|
-- instruction input --
|
590 |
|
|
ci_instr16_i : in std_ulogic_vector(15 downto 0); -- compressed instruction input
|
591 |
|
|
-- instruction output --
|
592 |
|
|
ci_valid_o : out std_ulogic; -- is a compressed instruction
|
593 |
|
|
ci_illegal_o : out std_ulogic; -- is an illegal compressed instruction
|
594 |
|
|
ci_instr32_o : out std_ulogic_vector(31 downto 0) -- 32-bit decompressed instruction
|
595 |
|
|
);
|
596 |
|
|
end component;
|
597 |
|
|
|
598 |
|
|
-- Component: CPU Top Entity --------------------------------------------------------------
|
599 |
|
|
-- -------------------------------------------------------------------------------------------
|
600 |
|
|
component neorv32_cpu
|
601 |
|
|
generic (
|
602 |
|
|
-- General --
|
603 |
|
|
CLOCK_FREQUENCY : natural := 0; -- clock frequency of clk_i in Hz
|
604 |
|
|
HART_ID : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom hardware thread ID
|
605 |
|
|
BOOTLOADER_USE : boolean := true; -- implement processor-internal bootloader?
|
606 |
|
|
-- RISC-V CPU Extensions --
|
607 |
|
|
CPU_EXTENSION_RISCV_C : boolean := false; -- implement compressed extension?
|
608 |
|
|
CPU_EXTENSION_RISCV_E : boolean := false; -- implement embedded RF extension?
|
609 |
|
|
CPU_EXTENSION_RISCV_M : boolean := false; -- implement muld/div extension?
|
610 |
|
|
CPU_EXTENSION_RISCV_Zicsr : boolean := true; -- implement CSR system?
|
611 |
|
|
-- Memory configuration: Instruction memory --
|
612 |
|
|
MEM_ISPACE_BASE : std_ulogic_vector(31 downto 0) := x"00000000"; -- base address of instruction memory space
|
613 |
|
|
MEM_ISPACE_SIZE : natural := 8*1024; -- total size of instruction memory space in byte
|
614 |
|
|
MEM_INT_IMEM_USE : boolean := true; -- implement processor-internal instruction memory
|
615 |
|
|
MEM_INT_IMEM_SIZE : natural := 8*1024; -- size of processor-internal instruction memory in bytes
|
616 |
|
|
MEM_INT_IMEM_ROM : boolean := false; -- implement processor-internal instruction memory as ROM
|
617 |
|
|
-- Memory configuration: Data memory --
|
618 |
|
|
MEM_DSPACE_BASE : std_ulogic_vector(31 downto 0) := x"80000000"; -- base address of data memory space
|
619 |
|
|
MEM_DSPACE_SIZE : natural := 4*1024; -- total size of data memory space in byte
|
620 |
|
|
MEM_INT_DMEM_USE : boolean := true; -- implement processor-internal data memory
|
621 |
|
|
MEM_INT_DMEM_SIZE : natural := 4*1024; -- size of processor-internal data memory in bytes
|
622 |
|
|
-- Memory configuration: External memory interface --
|
623 |
|
|
MEM_EXT_USE : boolean := false; -- implement external memory bus interface?
|
624 |
|
|
MEM_EXT_TIMEOUT : natural := 15; -- cycles after which a valid bus access will timeout
|
625 |
|
|
-- Processor peripherals --
|
626 |
|
|
IO_GPIO_USE : boolean := true; -- implement general purpose input/output port unit (GPIO)?
|
627 |
|
|
IO_MTIME_USE : boolean := true; -- implement machine system timer (MTIME)?
|
628 |
|
|
IO_UART_USE : boolean := true; -- implement universal asynchronous receiver/transmitter (UART)?
|
629 |
|
|
IO_SPI_USE : boolean := true; -- implement serial peripheral interface (SPI)?
|
630 |
|
|
IO_TWI_USE : boolean := true; -- implement two-wire interface (TWI)?
|
631 |
|
|
IO_PWM_USE : boolean := true; -- implement pulse-width modulation unit (PWM)?
|
632 |
|
|
IO_WDT_USE : boolean := true; -- implement watch dog timer (WDT)?
|
633 |
|
|
IO_CLIC_USE : boolean := true; -- implement core local interrupt controller (CLIC)?
|
634 |
|
|
IO_TRNG_USE : boolean := true -- implement true random number generator (TRNG)?
|
635 |
|
|
);
|
636 |
|
|
port (
|
637 |
|
|
-- global control --
|
638 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
639 |
|
|
rstn_i : in std_ulogic; -- global reset, low-active, async
|
640 |
|
|
-- bus interface --
|
641 |
|
|
bus_addr_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
|
642 |
|
|
bus_rdata_i : in std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
|
643 |
|
|
bus_wdata_o : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
|
644 |
|
|
bus_ben_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
645 |
|
|
bus_we_o : out std_ulogic; -- write enable
|
646 |
|
|
bus_re_o : out std_ulogic; -- read enable
|
647 |
|
|
bus_ack_i : in std_ulogic; -- bus transfer acknowledge
|
648 |
|
|
bus_err_i : in std_ulogic; -- bus transfer error
|
649 |
|
|
-- external interrupts --
|
650 |
|
|
clic_irq_i : in std_ulogic; -- CLIC interrupt request
|
651 |
|
|
mtime_irq_i : in std_ulogic -- machine timer interrupt
|
652 |
|
|
);
|
653 |
|
|
end component;
|
654 |
|
|
|
655 |
|
|
-- Component: Processor-internal instruction memory (IMEM) --------------------------------
|
656 |
|
|
-- -------------------------------------------------------------------------------------------
|
657 |
|
|
component neorv32_imem
|
658 |
|
|
generic (
|
659 |
|
|
IMEM_BASE : std_ulogic_vector(31 downto 0) := x"00000000"; -- memory base address
|
660 |
|
|
IMEM_SIZE : natural := 4*1024; -- processor-internal instruction memory size in bytes
|
661 |
|
|
IMEM_AS_ROM : boolean := false; -- implement IMEM as read-only memory?
|
662 |
|
|
BOOTLOADER_USE : boolean := true -- implement and use bootloader?
|
663 |
|
|
);
|
664 |
|
|
port (
|
665 |
|
|
clk_i : in std_ulogic; -- global clock line
|
666 |
|
|
rden_i : in std_ulogic; -- read enable
|
667 |
|
|
wren_i : in std_ulogic; -- write enable
|
668 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
669 |
|
|
upen_i : in std_ulogic; -- update enable
|
670 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
671 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
672 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
673 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
674 |
|
|
);
|
675 |
|
|
end component;
|
676 |
|
|
|
677 |
|
|
-- Component: Processor-internal data memory (DMEM) ---------------------------------------
|
678 |
|
|
-- -------------------------------------------------------------------------------------------
|
679 |
|
|
component neorv32_dmem
|
680 |
|
|
generic (
|
681 |
|
|
DMEM_BASE : std_ulogic_vector(31 downto 0) := x"80000000"; -- memory base address
|
682 |
|
|
DMEM_SIZE : natural := 4*1024 -- processor-internal instruction memory size in bytes
|
683 |
|
|
);
|
684 |
|
|
port (
|
685 |
|
|
clk_i : in std_ulogic; -- global clock line
|
686 |
|
|
rden_i : in std_ulogic; -- read enable
|
687 |
|
|
wren_i : in std_ulogic; -- write enable
|
688 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
689 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
690 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
691 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
692 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
693 |
|
|
);
|
694 |
|
|
end component;
|
695 |
|
|
|
696 |
|
|
-- Component: Processor-internal bootloader ROM (BOOTROM) ---------------------------------
|
697 |
|
|
-- -------------------------------------------------------------------------------------------
|
698 |
|
|
component neorv32_boot_rom
|
699 |
|
|
port (
|
700 |
|
|
clk_i : in std_ulogic; -- global clock line
|
701 |
|
|
rden_i : in std_ulogic; -- read enable
|
702 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
703 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
704 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
705 |
|
|
);
|
706 |
|
|
end component;
|
707 |
|
|
|
708 |
|
|
-- Component: Machine System Timer (mtime) ------------------------------------------------
|
709 |
|
|
-- -------------------------------------------------------------------------------------------
|
710 |
|
|
component neorv32_mtime
|
711 |
|
|
port (
|
712 |
|
|
-- host access --
|
713 |
|
|
clk_i : in std_ulogic; -- global clock line
|
714 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
715 |
|
|
rden_i : in std_ulogic; -- read enable
|
716 |
|
|
wren_i : in std_ulogic; -- write enable
|
717 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
718 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
719 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
720 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
721 |
|
|
-- interrupt --
|
722 |
|
|
irq_o : out std_ulogic -- interrupt request
|
723 |
|
|
);
|
724 |
|
|
end component;
|
725 |
|
|
|
726 |
|
|
-- Component: General Purpose Input/Output Port (GPIO) ------------------------------------
|
727 |
|
|
-- -------------------------------------------------------------------------------------------
|
728 |
|
|
component neorv32_gpio
|
729 |
|
|
port (
|
730 |
|
|
-- host access --
|
731 |
|
|
clk_i : in std_ulogic; -- global clock line
|
732 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
733 |
|
|
rden_i : in std_ulogic; -- read enable
|
734 |
|
|
wren_i : in std_ulogic; -- write enable
|
735 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
736 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
737 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
738 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
739 |
|
|
-- parallel io --
|
740 |
|
|
gpio_o : out std_ulogic_vector(15 downto 0);
|
741 |
|
|
gpio_i : in std_ulogic_vector(15 downto 0);
|
742 |
|
|
-- interrupt --
|
743 |
|
|
irq_o : out std_ulogic
|
744 |
|
|
);
|
745 |
|
|
end component;
|
746 |
|
|
|
747 |
|
|
-- Component: Core Local Interrupt Controller (CLIC) --------------------------------------
|
748 |
|
|
-- -------------------------------------------------------------------------------------------
|
749 |
|
|
component neorv32_clic
|
750 |
|
|
port (
|
751 |
|
|
-- host access --
|
752 |
|
|
clk_i : in std_ulogic; -- global clock line
|
753 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
754 |
|
|
rden_i : in std_ulogic; -- read enable
|
755 |
|
|
wren_i : in std_ulogic; -- write enable
|
756 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
757 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
758 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
759 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
760 |
|
|
-- cpu interrupt --
|
761 |
|
|
cpu_irq_o : out std_ulogic; -- trigger CPU's external IRQ
|
762 |
|
|
-- external interrupt lines --
|
763 |
|
|
ext_irq_i : in std_ulogic_vector(07 downto 0); -- IRQ, triggering on HIGH level
|
764 |
|
|
ext_ack_o : out std_ulogic_vector(07 downto 0) -- acknowledge
|
765 |
|
|
);
|
766 |
|
|
end component;
|
767 |
|
|
|
768 |
|
|
-- Component: Watchdog Timer (WDT) --------------------------------------------------------
|
769 |
|
|
-- -------------------------------------------------------------------------------------------
|
770 |
|
|
component neorv32_wdt
|
771 |
|
|
port (
|
772 |
|
|
-- host access --
|
773 |
|
|
clk_i : in std_ulogic; -- global clock line
|
774 |
|
|
rstn_i : in std_ulogic; -- global reset line, low-active
|
775 |
|
|
rden_i : in std_ulogic; -- read enable
|
776 |
|
|
wren_i : in std_ulogic; -- write enable
|
777 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
778 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
779 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
780 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
781 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
782 |
|
|
-- clock generator --
|
783 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
784 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
785 |
|
|
-- timeout event --
|
786 |
|
|
irq_o : out std_ulogic; -- timeout IRQ
|
787 |
|
|
rstn_o : out std_ulogic -- timeout reset, low_active, use it as async!
|
788 |
|
|
);
|
789 |
|
|
end component;
|
790 |
|
|
|
791 |
|
|
-- Component: Universal Asynchronous Receiver and Transmitter (UART) ----------------------
|
792 |
|
|
-- -------------------------------------------------------------------------------------------
|
793 |
|
|
component neorv32_uart
|
794 |
|
|
port (
|
795 |
|
|
-- host access --
|
796 |
|
|
clk_i : in std_ulogic; -- global clock line
|
797 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
798 |
|
|
rden_i : in std_ulogic; -- read enable
|
799 |
|
|
wren_i : in std_ulogic; -- write enable
|
800 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
801 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
802 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
803 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
804 |
|
|
-- clock generator --
|
805 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
806 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
807 |
|
|
-- com lines --
|
808 |
|
|
uart_txd_o : out std_ulogic;
|
809 |
|
|
uart_rxd_i : in std_ulogic;
|
810 |
|
|
-- interrupts --
|
811 |
|
|
uart_irq_o : out std_ulogic -- uart rx/tx interrupt
|
812 |
|
|
);
|
813 |
|
|
end component;
|
814 |
|
|
|
815 |
|
|
-- Component: Serial Peripheral Interface (SPI) -------------------------------------------
|
816 |
|
|
-- -------------------------------------------------------------------------------------------
|
817 |
|
|
component neorv32_spi
|
818 |
|
|
port (
|
819 |
|
|
-- host access --
|
820 |
|
|
clk_i : in std_ulogic; -- global clock line
|
821 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
822 |
|
|
rden_i : in std_ulogic; -- read enable
|
823 |
|
|
wren_i : in std_ulogic; -- write enable
|
824 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
825 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
826 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
827 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
828 |
|
|
-- clock generator --
|
829 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
830 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
831 |
|
|
-- com lines --
|
832 |
|
|
spi_sclk_o : out std_ulogic; -- SPI serial clock
|
833 |
|
|
spi_mosi_o : out std_ulogic; -- SPI master out, slave in
|
834 |
|
|
spi_miso_i : in std_ulogic; -- SPI master in, slave out
|
835 |
|
|
spi_csn_o : out std_ulogic_vector(07 downto 0); -- SPI CS
|
836 |
|
|
-- interrupt --
|
837 |
|
|
spi_irq_o : out std_ulogic -- transmission done interrupt
|
838 |
|
|
);
|
839 |
|
|
end component;
|
840 |
|
|
|
841 |
|
|
-- Component: Two-Wire Interface (TWI) ----------------------------------------------------
|
842 |
|
|
-- -------------------------------------------------------------------------------------------
|
843 |
|
|
component neorv32_twi
|
844 |
|
|
port (
|
845 |
|
|
-- host access --
|
846 |
|
|
clk_i : in std_ulogic; -- global clock line
|
847 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
848 |
|
|
rden_i : in std_ulogic; -- read enable
|
849 |
|
|
wren_i : in std_ulogic; -- write enable
|
850 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
851 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
852 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
853 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
854 |
|
|
-- clock generator --
|
855 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
856 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
857 |
|
|
-- com lines --
|
858 |
|
|
twi_sda_io : inout std_logic; -- serial data line
|
859 |
|
|
twi_scl_io : inout std_logic; -- serial clock line
|
860 |
|
|
-- interrupt --
|
861 |
|
|
twi_irq_o : out std_ulogic -- transfer done IRQ
|
862 |
|
|
);
|
863 |
|
|
end component;
|
864 |
|
|
|
865 |
|
|
-- Component: Pulse-Width Modulation Controller (PWM) -------------------------------------
|
866 |
|
|
-- -------------------------------------------------------------------------------------------
|
867 |
|
|
component neorv32_pwm
|
868 |
|
|
port (
|
869 |
|
|
-- host access --
|
870 |
|
|
clk_i : in std_ulogic; -- global clock line
|
871 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
872 |
|
|
rden_i : in std_ulogic; -- read enable
|
873 |
|
|
wren_i : in std_ulogic; -- write enable
|
874 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
875 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
876 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
877 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
878 |
|
|
-- clock generator --
|
879 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
880 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
881 |
|
|
-- pwm output channels --
|
882 |
|
|
pwm_o : out std_ulogic_vector(03 downto 0)
|
883 |
|
|
);
|
884 |
|
|
end component;
|
885 |
|
|
|
886 |
|
|
-- Component: True Random Number Generator (TRNG) -----------------------------------------
|
887 |
|
|
-- -------------------------------------------------------------------------------------------
|
888 |
|
|
component neorv32_trng
|
889 |
|
|
port (
|
890 |
|
|
-- host access --
|
891 |
|
|
clk_i : in std_ulogic; -- global clock line
|
892 |
|
|
addr_i : in std_ulogic_vector(31 downto 0); -- address
|
893 |
|
|
rden_i : in std_ulogic; -- read enable
|
894 |
|
|
wren_i : in std_ulogic; -- write enable
|
895 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
896 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
897 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
898 |
|
|
ack_o : out std_ulogic -- transfer acknowledge
|
899 |
|
|
);
|
900 |
|
|
end component;
|
901 |
|
|
|
902 |
|
|
-- Component: Wishbone Bus Gateway (WISHBONE) ---------------------------------------------
|
903 |
|
|
-- -------------------------------------------------------------------------------------------
|
904 |
|
|
component neorv32_wishbone
|
905 |
|
|
generic (
|
906 |
|
|
INTERFACE_REG_STAGES : natural := 2; -- number of interface register stages (0,1,2)
|
907 |
|
|
-- Memory configuration: Instruction memory --
|
908 |
|
|
MEM_ISPACE_BASE : std_ulogic_vector(31 downto 0) := x"00000000"; -- base address of instruction memory space
|
909 |
|
|
MEM_ISPACE_SIZE : natural := 8*1024; -- total size of instruction memory space in byte
|
910 |
|
|
MEM_INT_IMEM_USE : boolean := true; -- implement processor-internal instruction memory
|
911 |
|
|
MEM_INT_IMEM_SIZE : natural := 8*1024; -- size of processor-internal instruction memory in bytes
|
912 |
|
|
-- Memory configuration: Data memory --
|
913 |
|
|
MEM_DSPACE_BASE : std_ulogic_vector(31 downto 0) := x"80000000"; -- base address of data memory space
|
914 |
|
|
MEM_DSPACE_SIZE : natural := 4*1024; -- total size of data memory space in byte
|
915 |
|
|
MEM_INT_DMEM_USE : boolean := true; -- implement processor-internal data memory
|
916 |
|
|
MEM_INT_DMEM_SIZE : natural := 4*1024 -- size of processor-internal data memory in bytes
|
917 |
|
|
);
|
918 |
|
|
port (
|
919 |
|
|
-- global control --
|
920 |
|
|
clk_i : in std_ulogic; -- global clock line
|
921 |
|
|
rstn_i : in std_ulogic; -- global reset line, low-active
|
922 |
|
|
-- host access --
|
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 |
|
|
ben_i : in std_ulogic_vector(03 downto 0); -- byte write enable
|
927 |
|
|
data_i : in std_ulogic_vector(31 downto 0); -- data in
|
928 |
|
|
data_o : out std_ulogic_vector(31 downto 0); -- data out
|
929 |
|
|
ack_o : out std_ulogic; -- transfer acknowledge
|
930 |
|
|
err_o : out std_ulogic; -- transfer error
|
931 |
|
|
-- wishbone interface --
|
932 |
|
|
wb_adr_o : out std_ulogic_vector(31 downto 0); -- address
|
933 |
|
|
wb_dat_i : in std_ulogic_vector(31 downto 0); -- read data
|
934 |
|
|
wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
|
935 |
|
|
wb_we_o : out std_ulogic; -- read/write
|
936 |
|
|
wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
937 |
|
|
wb_stb_o : out std_ulogic; -- strobe
|
938 |
|
|
wb_cyc_o : out std_ulogic; -- valid cycle
|
939 |
|
|
wb_ack_i : in std_ulogic; -- transfer acknowledge
|
940 |
|
|
wb_err_i : in std_ulogic -- transfer error
|
941 |
|
|
);
|
942 |
|
|
end component;
|
943 |
|
|
|
944 |
|
|
end neorv32_package;
|
945 |
|
|
|
946 |
|
|
package body neorv32_package is
|
947 |
|
|
|
948 |
|
|
-- Function: Minimal required bit width ---------------------------------------------------
|
949 |
|
|
-- -------------------------------------------------------------------------------------------
|
950 |
|
|
function index_size_f(input : natural) return natural is
|
951 |
|
|
begin
|
952 |
|
|
for i in 0 to natural'high loop
|
953 |
|
|
if (2**i >= input) then
|
954 |
|
|
return i;
|
955 |
|
|
end if;
|
956 |
|
|
end loop; -- i
|
957 |
|
|
return 0;
|
958 |
|
|
end function index_size_f;
|
959 |
|
|
|
960 |
|
|
-- Function: Conditional select natural ---------------------------------------------------
|
961 |
|
|
-- -------------------------------------------------------------------------------------------
|
962 |
|
|
function cond_sel_natural_f(cond : boolean; val_t : natural; val_f : natural) return natural is
|
963 |
|
|
begin
|
964 |
|
|
if (cond = true) then
|
965 |
|
|
return val_t;
|
966 |
|
|
else
|
967 |
|
|
return val_f;
|
968 |
|
|
end if;
|
969 |
|
|
end function cond_sel_natural_f;
|
970 |
|
|
|
971 |
|
|
-- Function: Conditional select std_ulogic_vector -----------------------------------------
|
972 |
|
|
-- -------------------------------------------------------------------------------------------
|
973 |
|
|
function cond_sel_stdulogicvector_f(cond : boolean; val_t : std_ulogic_vector; val_f : std_ulogic_vector) return std_ulogic_vector is
|
974 |
|
|
begin
|
975 |
|
|
if (cond = true) then
|
976 |
|
|
return val_t;
|
977 |
|
|
else
|
978 |
|
|
return val_f;
|
979 |
|
|
end if;
|
980 |
|
|
end function cond_sel_stdulogicvector_f;
|
981 |
|
|
|
982 |
|
|
-- Function: Convert BOOL to STD_ULOGIC ---------------------------------------------------
|
983 |
|
|
-- -------------------------------------------------------------------------------------------
|
984 |
|
|
function bool_to_ulogic_f(cond : boolean) return std_ulogic is
|
985 |
|
|
begin
|
986 |
|
|
if (cond = true) then
|
987 |
|
|
return '1';
|
988 |
|
|
else
|
989 |
|
|
return '0';
|
990 |
|
|
end if;
|
991 |
|
|
end function bool_to_ulogic_f;
|
992 |
|
|
|
993 |
|
|
-- Function: OR all bits ------------------------------------------------------------------
|
994 |
|
|
-- -------------------------------------------------------------------------------------------
|
995 |
|
|
function or_all_f(a : std_ulogic_vector) return std_ulogic is
|
996 |
|
|
variable tmp_v : std_ulogic;
|
997 |
|
|
begin
|
998 |
|
|
tmp_v := a(a'low);
|
999 |
|
|
for i in a'low+1 to a'high loop
|
1000 |
|
|
tmp_v := tmp_v or a(i);
|
1001 |
|
|
end loop; -- i
|
1002 |
|
|
return tmp_v;
|
1003 |
|
|
end function or_all_f;
|
1004 |
|
|
|
1005 |
|
|
-- Function: AND all bits -----------------------------------------------------------------
|
1006 |
|
|
-- -------------------------------------------------------------------------------------------
|
1007 |
|
|
function and_all_f(a : std_ulogic_vector) return std_ulogic is
|
1008 |
|
|
variable tmp_v : std_ulogic;
|
1009 |
|
|
begin
|
1010 |
|
|
tmp_v := a(a'low);
|
1011 |
|
|
for i in a'low+1 to a'high loop
|
1012 |
|
|
tmp_v := tmp_v and a(i);
|
1013 |
|
|
end loop; -- i
|
1014 |
|
|
return tmp_v;
|
1015 |
|
|
end function and_all_f;
|
1016 |
|
|
|
1017 |
|
|
-- Function: XOR all bits -----------------------------------------------------------------
|
1018 |
|
|
-- -------------------------------------------------------------------------------------------
|
1019 |
|
|
function xor_all_f(a : std_ulogic_vector) return std_ulogic is
|
1020 |
|
|
variable tmp_v : std_ulogic;
|
1021 |
|
|
begin
|
1022 |
|
|
tmp_v := a(a'low);
|
1023 |
|
|
for i in a'low+1 to a'high loop
|
1024 |
|
|
tmp_v := tmp_v xor a(i);
|
1025 |
|
|
end loop; -- i
|
1026 |
|
|
return tmp_v;
|
1027 |
|
|
end function xor_all_f;
|
1028 |
|
|
|
1029 |
|
|
-- Function: XNOR all bits ----------------------------------------------------------------
|
1030 |
|
|
-- -------------------------------------------------------------------------------------------
|
1031 |
|
|
function xnor_all_f(a : std_ulogic_vector) return std_ulogic is
|
1032 |
|
|
variable tmp_v : std_ulogic;
|
1033 |
|
|
begin
|
1034 |
|
|
tmp_v := a(a'low);
|
1035 |
|
|
for i in a'low+1 to a'high loop
|
1036 |
|
|
tmp_v := tmp_v xnor a(i);
|
1037 |
|
|
end loop; -- i
|
1038 |
|
|
return tmp_v;
|
1039 |
|
|
end function xnor_all_f;
|
1040 |
|
|
|
1041 |
|
|
end neorv32_package;
|