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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_package.vhd] - Blame information for rev 37

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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