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

Subversion Repositories neorv32

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

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