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

Subversion Repositories neorv32

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

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