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

Subversion Repositories neorv32

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

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