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

Subversion Repositories neorv32

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

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