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

Subversion Repositories neorv32

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

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