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

Subversion Repositories neorv32

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

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 42 zero_gravi
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
7 2 zero_gravi
-- #                                                                                               #
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 36 zero_gravi
  -- Architecture Configuration -------------------------------------------------------------
42
  -- -------------------------------------------------------------------------------------------
43 40 zero_gravi
  -- address space --
44
  constant ispace_base_c : std_ulogic_vector(31 downto 0) := x"00000000"; -- default instruction memory address space base address
45
  constant dspace_base_c : std_ulogic_vector(31 downto 0) := x"80000000"; -- default data memory address space base address
46 36 zero_gravi
 
47 40 zero_gravi
  -- CPU core --
48 66 zero_gravi
  constant dedicated_reset_c : boolean := false; -- use dedicated hardware reset value for UNCRITICAL registers (FALSE=reset value is irrelevant (might simplify HW), default; TRUE=defined LOW reset value)
49 56 zero_gravi
  constant cp_timeout_en_c   : boolean := false; -- auto-terminate pending co-processor operations after 256 cycles (for debugging only), default = false
50 40 zero_gravi
 
51 54 zero_gravi
  -- "critical" number of implemented PMP regions --
52
  -- if more PMP regions (> pmp_num_regions_critical_c) are defined, another register stage is automatically inserted into the memory interfaces
53
  -- increasing instruction fetch & data access latency by +1 cycle but also reducing critical path length
54
  constant pmp_num_regions_critical_c : natural := 8; -- default=8
55 47 zero_gravi
 
56 69 zero_gravi
  -- "response time window" for processor-internal modules --
57 57 zero_gravi
  constant max_proc_int_response_time_c : natural := 15; -- cycles after which an *unacknowledged* internal bus access will timeout and trigger a bus fault exception (min 2)
58
 
59 59 zero_gravi
  -- jtag tap - identifier --
60
  constant jtag_tap_idcode_version_c : std_ulogic_vector(03 downto 0) := x"0"; -- version
61
  constant jtag_tap_idcode_partid_c  : std_ulogic_vector(15 downto 0) := x"cafe"; -- part number
62
  constant jtag_tap_idcode_manid_c   : std_ulogic_vector(10 downto 0) := "00000000000"; -- manufacturer id
63
 
64 61 zero_gravi
  -- Architecture Constants (do not modify!) ------------------------------------------------
65
  -- -------------------------------------------------------------------------------------------
66 62 zero_gravi
  constant data_width_c : natural := 32; -- native data path width - do not change!
67 69 zero_gravi
  constant hw_version_c : std_ulogic_vector(31 downto 0) := x"01060500"; -- no touchy!
68 62 zero_gravi
  constant archid_c     : natural := 19; -- official NEORV32 architecture ID - hands off!
69 61 zero_gravi
 
70 69 zero_gravi
  -- Check if we're inside the Matrix -------------------------------------------------------
71
  -- -------------------------------------------------------------------------------------------
72
  constant is_simulation_c : boolean := false -- seems like we're on real hardware
73
-- pragma translate_off
74
-- synthesis translate_off
75
-- synthesis synthesis_off
76
-- RTL_SYNTHESIS OFF
77
  or true -- this MIGHT be a simulation
78
-- RTL_SYNTHESIS ON
79
-- synthesis synthesis_on
80
-- synthesis translate_on
81
-- pragma translate_on
82
  ;
83
 
84 61 zero_gravi
  -- External Interface Types ---------------------------------------------------------------
85
  -- -------------------------------------------------------------------------------------------
86
  type sdata_8x32_t  is array (0 to 7)  of std_ulogic_vector(31 downto 0);
87
  type sdata_8x32r_t is array (0 to 7)  of std_logic_vector(31 downto 0); -- resolved type
88
 
89
  -- Internal Interface Types ---------------------------------------------------------------
90
  -- -------------------------------------------------------------------------------------------
91
  type pmp_ctrl_if_t is array (0 to 63) of std_ulogic_vector(07 downto 0);
92
  type pmp_addr_if_t is array (0 to 63) of std_ulogic_vector(33 downto 0);
93
  type cp_data_if_t  is array (0 to 3)  of std_ulogic_vector(data_width_c-1 downto 0);
94
 
95
  -- Internal Memory Types Configuration Types ----------------------------------------------
96
  -- -------------------------------------------------------------------------------------------
97
  type mem32_t is array (natural range <>) of std_ulogic_vector(31 downto 0); -- memory with 32-bit entries
98
  type mem8_t  is array (natural range <>) of std_ulogic_vector(07 downto 0); -- memory with 8-bit entries
99
 
100 12 zero_gravi
  -- Helper Functions -----------------------------------------------------------------------
101 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
102
  function index_size_f(input : natural) return natural;
103
  function cond_sel_natural_f(cond : boolean; val_t : natural; val_f : natural) return natural;
104 56 zero_gravi
  function cond_sel_int_f(cond : boolean; val_t : integer; val_f : integer) return integer;
105 2 zero_gravi
  function cond_sel_stdulogicvector_f(cond : boolean; val_t : std_ulogic_vector; val_f : std_ulogic_vector) return std_ulogic_vector;
106 56 zero_gravi
  function cond_sel_stdulogic_f(cond : boolean; val_t : std_ulogic; val_f : std_ulogic) return std_ulogic;
107 50 zero_gravi
  function cond_sel_string_f(cond : boolean; val_t : string; val_f : string) return string;
108 2 zero_gravi
  function bool_to_ulogic_f(cond : boolean) return std_ulogic;
109 60 zero_gravi
  function or_reduce_f(a : std_ulogic_vector) return std_ulogic;
110
  function and_reduce_f(a : std_ulogic_vector) return std_ulogic;
111
  function xor_reduce_f(a : std_ulogic_vector) return std_ulogic;
112 6 zero_gravi
  function to_hexchar_f(input : std_ulogic_vector(3 downto 0)) return character;
113 40 zero_gravi
  function hexchar_to_stdulogicvector_f(input : character) return std_ulogic_vector;
114 32 zero_gravi
  function bit_rev_f(input : std_ulogic_vector) return std_ulogic_vector;
115 36 zero_gravi
  function is_power_of_two_f(input : natural) return boolean;
116 40 zero_gravi
  function bswap32_f(input : std_ulogic_vector) return std_ulogic_vector;
117 62 zero_gravi
  function char_to_lower_f(ch : character) return character;
118 61 zero_gravi
  function str_equal_f(str0 : string; str1 : string) return boolean;
119 63 zero_gravi
  function popcount_f(input : std_ulogic_vector) return natural;
120
  function leading_zeros_f(input : std_ulogic_vector) return natural;
121 61 zero_gravi
  impure function mem32_init_f(init : mem32_t; depth : natural) return mem32_t;
122 2 zero_gravi
 
123 61 zero_gravi
  -- Internal (auto-generated) Configurations -----------------------------------------------
124 56 zero_gravi
  -- -------------------------------------------------------------------------------------------
125 61 zero_gravi
  constant def_rst_val_c : std_ulogic := cond_sel_stdulogic_f(dedicated_reset_c, '0', '-');
126 56 zero_gravi
 
127 23 zero_gravi
  -- Processor-Internal Address Space Layout ------------------------------------------------
128
  -- -------------------------------------------------------------------------------------------
129 34 zero_gravi
  -- Internal Instruction Memory (IMEM) and Date Memory (DMEM) --
130 39 zero_gravi
  constant imem_base_c          : std_ulogic_vector(data_width_c-1 downto 0) := ispace_base_c; -- internal instruction memory base address
131
  constant dmem_base_c          : std_ulogic_vector(data_width_c-1 downto 0) := dspace_base_c; -- internal data memory base address
132 42 zero_gravi
  --> internal data/instruction memory sizes are configured via top's generics
133 2 zero_gravi
 
134 64 zero_gravi
  -- !!! IMPORTANT: The base address of each component/module has to be aligned to the !!!
135
  -- !!! total size of the module's occupied address space. The occupied address space !!!
136
  -- !!! has to be a power of two (minimum 4 bytes). Address spaces must not overlap.  !!!
137
 
138 23 zero_gravi
  -- Internal Bootloader ROM --
139 61 zero_gravi
  -- Actual bootloader size is determined during runtime via the length of the bootloader initialization image
140 56 zero_gravi
  constant boot_rom_base_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"ffff0000"; -- bootloader base address, fixed!
141 61 zero_gravi
  constant boot_rom_max_size_c  : natural := 32*1024; -- max module's address space size in bytes, fixed!
142 23 zero_gravi
 
143 59 zero_gravi
  -- On-Chip Debugger: Debug Module --
144
  constant dm_base_c            : std_ulogic_vector(data_width_c-1 downto 0) := x"fffff800"; -- base address, fixed!
145 61 zero_gravi
  constant dm_size_c            : natural := 4*32*4; -- debug ROM address space size in bytes, fixed
146 59 zero_gravi
  constant dm_code_base_c       : std_ulogic_vector(data_width_c-1 downto 0) := x"fffff800";
147
  constant dm_pbuf_base_c       : std_ulogic_vector(data_width_c-1 downto 0) := x"fffff880";
148
  constant dm_data_base_c       : std_ulogic_vector(data_width_c-1 downto 0) := x"fffff900";
149
  constant dm_sreg_base_c       : std_ulogic_vector(data_width_c-1 downto 0) := x"fffff980";
150
 
151 2 zero_gravi
  -- IO: Peripheral Devices ("IO") Area --
152
  -- Control register(s) (including the device-enable) should be located at the base address of each device
153 60 zero_gravi
  constant io_base_c            : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe00";
154 61 zero_gravi
  constant io_size_c            : natural := 512; -- IO address space size in bytes, fixed!
155 2 zero_gravi
 
156 47 zero_gravi
  -- Custom Functions Subsystem (CFS) --
157 60 zero_gravi
  constant cfs_base_c           : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe00"; -- base address
158 61 zero_gravi
  constant cfs_size_c           : natural := 32*4; -- module's address space in bytes
159 60 zero_gravi
  constant cfs_reg0_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe00";
160
  constant cfs_reg1_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe04";
161
  constant cfs_reg2_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe08";
162
  constant cfs_reg3_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe0c";
163
  constant cfs_reg4_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe10";
164
  constant cfs_reg5_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe14";
165
  constant cfs_reg6_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe18";
166
  constant cfs_reg7_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe1c";
167
  constant cfs_reg8_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe20";
168
  constant cfs_reg9_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe24";
169
  constant cfs_reg10_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe28";
170
  constant cfs_reg11_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe2c";
171
  constant cfs_reg12_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe30";
172
  constant cfs_reg13_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe34";
173
  constant cfs_reg14_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe38";
174
  constant cfs_reg15_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe3c";
175
  constant cfs_reg16_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe40";
176
  constant cfs_reg17_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe44";
177
  constant cfs_reg18_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe48";
178
  constant cfs_reg19_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe4c";
179
  constant cfs_reg20_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe50";
180
  constant cfs_reg21_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe54";
181
  constant cfs_reg22_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe58";
182
  constant cfs_reg23_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe5c";
183
  constant cfs_reg24_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe60";
184
  constant cfs_reg25_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe64";
185
  constant cfs_reg26_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe68";
186
  constant cfs_reg27_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe6c";
187
  constant cfs_reg28_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe70";
188
  constant cfs_reg29_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe74";
189
  constant cfs_reg30_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe78";
190
  constant cfs_reg31_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe7c";
191 47 zero_gravi
 
192 60 zero_gravi
  -- Pulse-Width Modulation Controller (PWM) --
193
  constant pwm_base_c           : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe80"; -- base address
194 61 zero_gravi
  constant pwm_size_c           : natural := 16*4; -- module's address space size in bytes
195 60 zero_gravi
  constant pwm_ctrl_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe80";
196
  constant pwm_duty0_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe84";
197
  constant pwm_duty1_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe88";
198
  constant pwm_duty2_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe8c";
199
  constant pwm_duty3_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe90";
200
  constant pwm_duty4_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe94";
201
  constant pwm_duty5_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe98";
202
  constant pwm_duty6_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffe9c";
203
  constant pwm_duty7_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffea0";
204
  constant pwm_duty8_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffea4";
205
  constant pwm_duty9_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffea8";
206
  constant pwm_duty10_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffeac";
207
  constant pwm_duty11_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffeb0";
208
  constant pwm_duty12_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffeb4";
209
  constant pwm_duty13_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffeb8";
210
  constant pwm_duty14_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffebc";
211
 
212 63 zero_gravi
  -- Stream Link Interface (SLINK) --
213 61 zero_gravi
  constant slink_base_c         : std_ulogic_vector(data_width_c-1 downto 0) := x"fffffec0"; -- base address
214
  constant slink_size_c         : natural := 16*4; -- module's address space size in bytes
215 60 zero_gravi
 
216
  -- reserved --
217
--constant reserved_base_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff00"; -- base address
218 63 zero_gravi
--constant reserved_size_c      : natural := 16*4; -- module's address space size in bytes
219 60 zero_gravi
 
220 63 zero_gravi
  -- reserved --
221
--constant reserved_base_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff40"; -- base address
222
--constant reserved_size_c      : natural := 8*4; -- module's address space size in bytes
223
 
224 67 zero_gravi
  -- General Purpose Timer (GPTMR) --
225
  constant gptmr_base_c         : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff60"; -- base address
226
  constant gptmr_size_c         : natural := 4*4; -- module's address space size in bytes
227
  constant gptmr_ctrl_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff60";
228
  constant gptmr_thres_addr_c   : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff64";
229
  constant gptmr_count_addr_c   : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff68";
230
--constant gptmr_reserve_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff6c";
231 63 zero_gravi
 
232
  -- reserved --
233
--constant reserved_base_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff70"; -- base address
234
--constant reserved_size_c      : natural := 2*4; -- module's address space size in bytes
235
 
236
  -- reserved --
237
--constant reserved_base_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff78"; -- base address
238 66 zero_gravi
--constant reserved_size_c      : natural := 1*4; -- module's address space size in bytes
239 63 zero_gravi
 
240 66 zero_gravi
  -- Bus Access Monitor (BUSKEEPER) --
241
  constant buskeeper_base_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff7c"; -- base address
242
  constant buskeeper_size_c     : natural := 1*4; -- module's address space size in bytes
243
 
244 61 zero_gravi
  -- External Interrupt Controller (XIRQ) --
245
  constant xirq_base_c          : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff80"; -- base address
246
  constant xirq_size_c          : natural := 4*4; -- module's address space size in bytes
247
  constant xirq_enable_addr_c   : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff80";
248
  constant xirq_pending_addr_c  : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff84";
249
  constant xirq_source_addr_c   : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff88";
250 62 zero_gravi
--constant xirq_reserved_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff8c";
251 2 zero_gravi
 
252
  -- Machine System Timer (MTIME) --
253 56 zero_gravi
  constant mtime_base_c         : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff90"; -- base address
254 61 zero_gravi
  constant mtime_size_c         : natural := 4*4; -- module's address space size in bytes
255 56 zero_gravi
  constant mtime_time_lo_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff90";
256
  constant mtime_time_hi_addr_c : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff94";
257
  constant mtime_cmp_lo_addr_c  : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff98";
258
  constant mtime_cmp_hi_addr_c  : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffff9c";
259 2 zero_gravi
 
260 58 zero_gravi
  -- Primary Universal Asynchronous Receiver/Transmitter (UART0) --
261 56 zero_gravi
  constant uart0_base_c         : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffa0"; -- base address
262 61 zero_gravi
  constant uart0_size_c         : natural := 2*4; -- module's address space size in bytes
263 56 zero_gravi
  constant uart0_ctrl_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffa0";
264
  constant uart0_rtx_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffa4";
265 2 zero_gravi
 
266
  -- Serial Peripheral Interface (SPI) --
267 56 zero_gravi
  constant spi_base_c           : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffa8"; -- base address
268 61 zero_gravi
  constant spi_size_c           : natural := 2*4; -- module's address space size in bytes
269 56 zero_gravi
  constant spi_ctrl_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffa8";
270
  constant spi_rtx_addr_c       : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffac";
271 2 zero_gravi
 
272
  -- Two Wire Interface (TWI) --
273 56 zero_gravi
  constant twi_base_c           : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffb0"; -- base address
274 61 zero_gravi
  constant twi_size_c           : natural := 2*4; -- module's address space size in bytes
275 56 zero_gravi
  constant twi_ctrl_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffb0";
276
  constant twi_rtx_addr_c       : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffb4";
277 2 zero_gravi
 
278 61 zero_gravi
  -- True Random Number Generator (TRNG) --
279
  constant trng_base_c          : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffb8"; -- base address
280
  constant trng_size_c          : natural := 1*4; -- module's address space size in bytes
281
  constant trng_ctrl_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffb8";
282
 
283
  -- Watch Dog Timer (WDT) --
284
  constant wdt_base_c           : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffbc"; -- base address
285
  constant wdt_size_c           : natural := 1*4; -- module's address space size in bytes
286
  constant wdt_ctrl_addr_c      : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffbc";
287
 
288 63 zero_gravi
  -- General Purpose Input/Output Controller (GPIO) --
289 61 zero_gravi
  constant gpio_base_c          : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffc0"; -- base address
290
  constant gpio_size_c          : natural := 4*4; -- module's address space size in bytes
291
  constant gpio_in_lo_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffc0";
292
  constant gpio_in_hi_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffc4";
293
  constant gpio_out_lo_addr_c   : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffc8";
294
  constant gpio_out_hi_addr_c   : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffcc";
295 2 zero_gravi
 
296 58 zero_gravi
  -- Secondary Universal Asynchronous Receiver/Transmitter (UART1) --
297 56 zero_gravi
  constant uart1_base_c         : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffd0"; -- base address
298 61 zero_gravi
  constant uart1_size_c         : natural := 2*4; -- module's address space size in bytes
299 56 zero_gravi
  constant uart1_ctrl_addr_c    : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffd0";
300
  constant uart1_rtx_addr_c     : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffd4";
301 50 zero_gravi
 
302 52 zero_gravi
  -- Smart LED (WS2811/WS2812) Interface (NEOLED) --
303 56 zero_gravi
  constant neoled_base_c        : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffd8"; -- base address
304 61 zero_gravi
  constant neoled_size_c        : natural := 2*4; -- module's address space size in bytes
305 56 zero_gravi
  constant neoled_ctrl_addr_c   : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffd8";
306
  constant neoled_data_addr_c   : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffdc";
307 12 zero_gravi
 
308 23 zero_gravi
  -- System Information Memory (SYSINFO) --
309 56 zero_gravi
  constant sysinfo_base_c       : std_ulogic_vector(data_width_c-1 downto 0) := x"ffffffe0"; -- base address
310 61 zero_gravi
  constant sysinfo_size_c       : natural := 8*4; -- module's address space size in bytes
311 12 zero_gravi
 
312 59 zero_gravi
  -- Main CPU Control Bus -------------------------------------------------------------------
313 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
314
  -- register file --
315 49 zero_gravi
  constant ctrl_rf_in_mux_c     : natural :=  0; -- input source select lsb (0=MEM, 1=ALU)
316
  constant ctrl_rf_rs1_adr0_c   : natural :=  1; -- source register 1 address bit 0
317
  constant ctrl_rf_rs1_adr1_c   : natural :=  2; -- source register 1 address bit 1
318
  constant ctrl_rf_rs1_adr2_c   : natural :=  3; -- source register 1 address bit 2
319
  constant ctrl_rf_rs1_adr3_c   : natural :=  4; -- source register 1 address bit 3
320
  constant ctrl_rf_rs1_adr4_c   : natural :=  5; -- source register 1 address bit 4
321
  constant ctrl_rf_rs2_adr0_c   : natural :=  6; -- source register 2 address bit 0
322
  constant ctrl_rf_rs2_adr1_c   : natural :=  7; -- source register 2 address bit 1
323
  constant ctrl_rf_rs2_adr2_c   : natural :=  8; -- source register 2 address bit 2
324
  constant ctrl_rf_rs2_adr3_c   : natural :=  9; -- source register 2 address bit 3
325
  constant ctrl_rf_rs2_adr4_c   : natural := 10; -- source register 2 address bit 4
326 58 zero_gravi
  constant ctrl_rf_rd_adr0_c    : natural := 11; -- destination register address bit 0
327
  constant ctrl_rf_rd_adr1_c    : natural := 12; -- destination register address bit 1
328
  constant ctrl_rf_rd_adr2_c    : natural := 13; -- destination register address bit 2
329
  constant ctrl_rf_rd_adr3_c    : natural := 14; -- destination register address bit 3
330
  constant ctrl_rf_rd_adr4_c    : natural := 15; -- destination register address bit 4
331 49 zero_gravi
  constant ctrl_rf_wb_en_c      : natural := 16; -- write back enable
332 2 zero_gravi
  -- alu --
333 68 zero_gravi
  constant ctrl_alu_op0_c       : natural := 17; -- ALU operation select bit 0
334
  constant ctrl_alu_op1_c       : natural := 18; -- ALU operation select bit 1
335
  constant ctrl_alu_op2_c       : natural := 19; -- ALU operation select bit 2
336 62 zero_gravi
  constant ctrl_alu_func0_c     : natural := 20; -- ALU function select command bit 0
337
  constant ctrl_alu_func1_c     : natural := 21; -- ALU function select command bit 1
338 68 zero_gravi
  constant ctrl_alu_opa_mux_c   : natural := 22; -- operand A select (0=rs1, 1=PC)
339
  constant ctrl_alu_opb_mux_c   : natural := 23; -- operand B select (0=rs2, 1=IMM)
340
  constant ctrl_alu_unsigned_c  : natural := 24; -- is unsigned ALU operation
341
  constant ctrl_alu_shift_dir_c : natural := 25; -- shift direction (0=left, 1=right)
342
  constant ctrl_alu_shift_ar_c  : natural := 26; -- is arithmetic shift
343
  constant ctrl_alu_frm0_c      : natural := 27; -- FPU rounding mode bit 0
344
  constant ctrl_alu_frm1_c      : natural := 28; -- FPU rounding mode bit 1
345
  constant ctrl_alu_frm2_c      : natural := 29; -- FPU rounding mode bit 2
346 2 zero_gravi
  -- bus interface --
347 68 zero_gravi
  constant ctrl_bus_size_lsb_c  : natural := 30; -- transfer size lsb (00=byte, 01=half-word)
348
  constant ctrl_bus_size_msb_c  : natural := 31; -- transfer size msb (10=word, 11=?)
349
  constant ctrl_bus_rd_c        : natural := 32; -- read data request
350
  constant ctrl_bus_wr_c        : natural := 33; -- write data request
351
  constant ctrl_bus_if_c        : natural := 34; -- instruction fetch request
352
  constant ctrl_bus_mo_we_c     : natural := 35; -- memory address and data output register write enable
353
  constant ctrl_bus_mi_we_c     : natural := 36; -- memory data input register write enable
354
  constant ctrl_bus_unsigned_c  : natural := 37; -- is unsigned load
355
  constant ctrl_bus_ierr_ack_c  : natural := 38; -- acknowledge instruction fetch bus exceptions
356
  constant ctrl_bus_derr_ack_c  : natural := 39; -- acknowledge data access bus exceptions
357
  constant ctrl_bus_fence_c     : natural := 40; -- executed fence operation
358
  constant ctrl_bus_fencei_c    : natural := 41; -- executed fencei operation
359
  constant ctrl_bus_lock_c      : natural := 42; -- make atomic/exclusive access lock
360
  constant ctrl_bus_de_lock_c   : natural := 43; -- remove atomic/exclusive access 
361
  constant ctrl_bus_ch_lock_c   : natural := 44; -- evaluate atomic/exclusive lock (SC operation)
362 26 zero_gravi
  -- co-processors --
363 68 zero_gravi
  constant ctrl_cp_id_lsb_c     : natural := 45; -- cp select ID lsb
364
  constant ctrl_cp_id_msb_c     : natural := 46; -- cp select ID msb
365 44 zero_gravi
  -- instruction's control blocks (used by cpu co-processors) --
366 68 zero_gravi
  constant ctrl_ir_funct3_0_c   : natural := 47; -- funct3 bit 0
367
  constant ctrl_ir_funct3_1_c   : natural := 48; -- funct3 bit 1
368
  constant ctrl_ir_funct3_2_c   : natural := 49; -- funct3 bit 2
369
  constant ctrl_ir_funct12_0_c  : natural := 50; -- funct12 bit 0
370
  constant ctrl_ir_funct12_1_c  : natural := 51; -- funct12 bit 1
371
  constant ctrl_ir_funct12_2_c  : natural := 52; -- funct12 bit 2
372
  constant ctrl_ir_funct12_3_c  : natural := 53; -- funct12 bit 3
373
  constant ctrl_ir_funct12_4_c  : natural := 54; -- funct12 bit 4
374
  constant ctrl_ir_funct12_5_c  : natural := 55; -- funct12 bit 5
375
  constant ctrl_ir_funct12_6_c  : natural := 56; -- funct12 bit 6
376
  constant ctrl_ir_funct12_7_c  : natural := 57; -- funct12 bit 7
377
  constant ctrl_ir_funct12_8_c  : natural := 58; -- funct12 bit 8
378
  constant ctrl_ir_funct12_9_c  : natural := 59; -- funct12 bit 9
379
  constant ctrl_ir_funct12_10_c : natural := 60; -- funct12 bit 10
380
  constant ctrl_ir_funct12_11_c : natural := 61; -- funct12 bit 11
381
  constant ctrl_ir_opcode7_0_c  : natural := 62; -- opcode7 bit 0
382
  constant ctrl_ir_opcode7_1_c  : natural := 63; -- opcode7 bit 1
383
  constant ctrl_ir_opcode7_2_c  : natural := 64; -- opcode7 bit 2
384
  constant ctrl_ir_opcode7_3_c  : natural := 65; -- opcode7 bit 3
385
  constant ctrl_ir_opcode7_4_c  : natural := 66; -- opcode7 bit 4
386
  constant ctrl_ir_opcode7_5_c  : natural := 67; -- opcode7 bit 5
387
  constant ctrl_ir_opcode7_6_c  : natural := 68; -- opcode7 bit 6
388 47 zero_gravi
  -- CPU status --
389 68 zero_gravi
  constant ctrl_priv_lvl_lsb_c  : natural := 69; -- privilege level lsb
390
  constant ctrl_priv_lvl_msb_c  : natural := 70; -- privilege level msb
391
  constant ctrl_sleep_c         : natural := 71; -- set when CPU is in sleep mode
392
  constant ctrl_trap_c          : natural := 72; -- set when CPU is entering trap execution
393
  constant ctrl_debug_running_c : natural := 73; -- CPU is in debug mode when set
394 2 zero_gravi
  -- control bus size --
395 68 zero_gravi
  constant ctrl_width_c         : natural := 74; -- control bus size
396 2 zero_gravi
 
397 47 zero_gravi
  -- Comparator Bus -------------------------------------------------------------------------
398 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
399 47 zero_gravi
  constant cmp_equal_c : natural := 0;
400
  constant cmp_less_c  : natural := 1; -- for signed and unsigned comparisons
401 2 zero_gravi
 
402
  -- RISC-V Opcode Layout -------------------------------------------------------------------
403
  -- -------------------------------------------------------------------------------------------
404
  constant instr_opcode_lsb_c  : natural :=  0; -- opcode bit 0
405
  constant instr_opcode_msb_c  : natural :=  6; -- opcode bit 6
406
  constant instr_rd_lsb_c      : natural :=  7; -- destination register address bit 0
407
  constant instr_rd_msb_c      : natural := 11; -- destination register address bit 4
408
  constant instr_funct3_lsb_c  : natural := 12; -- funct3 bit 0
409
  constant instr_funct3_msb_c  : natural := 14; -- funct3 bit 2
410
  constant instr_rs1_lsb_c     : natural := 15; -- source register 1 address bit 0
411
  constant instr_rs1_msb_c     : natural := 19; -- source register 1 address bit 4
412
  constant instr_rs2_lsb_c     : natural := 20; -- source register 2 address bit 0
413
  constant instr_rs2_msb_c     : natural := 24; -- source register 2 address bit 4
414
  constant instr_funct7_lsb_c  : natural := 25; -- funct7 bit 0
415
  constant instr_funct7_msb_c  : natural := 31; -- funct7 bit 6
416
  constant instr_funct12_lsb_c : natural := 20; -- funct12 bit 0
417
  constant instr_funct12_msb_c : natural := 31; -- funct12 bit 11
418
  constant instr_imm12_lsb_c   : natural := 20; -- immediate12 bit 0
419
  constant instr_imm12_msb_c   : natural := 31; -- immediate12 bit 11
420
  constant instr_imm20_lsb_c   : natural := 12; -- immediate20 bit 0
421
  constant instr_imm20_msb_c   : natural := 31; -- immediate20 bit 21
422
  constant instr_csr_id_lsb_c  : natural := 20; -- csr select bit 0
423
  constant instr_csr_id_msb_c  : natural := 31; -- csr select bit 11
424 39 zero_gravi
  constant instr_funct5_lsb_c  : natural := 27; -- funct5 select bit 0
425
  constant instr_funct5_msb_c  : natural := 31; -- funct5 select bit 4
426 2 zero_gravi
 
427
  -- RISC-V Opcodes -------------------------------------------------------------------------
428
  -- -------------------------------------------------------------------------------------------
429
  -- alu --
430
  constant opcode_lui_c    : std_ulogic_vector(6 downto 0) := "0110111"; -- load upper immediate
431
  constant opcode_auipc_c  : std_ulogic_vector(6 downto 0) := "0010111"; -- add upper immediate to PC
432
  constant opcode_alui_c   : std_ulogic_vector(6 downto 0) := "0010011"; -- ALU operation with immediate (operation via funct3 and funct7)
433
  constant opcode_alu_c    : std_ulogic_vector(6 downto 0) := "0110011"; -- ALU operation (operation via funct3 and funct7)
434
  -- control flow --
435
  constant opcode_jal_c    : std_ulogic_vector(6 downto 0) := "1101111"; -- jump and link
436 29 zero_gravi
  constant opcode_jalr_c   : std_ulogic_vector(6 downto 0) := "1100111"; -- jump and link with register
437 2 zero_gravi
  constant opcode_branch_c : std_ulogic_vector(6 downto 0) := "1100011"; -- branch (condition set via funct3)
438
  -- memory access --
439
  constant opcode_load_c   : std_ulogic_vector(6 downto 0) := "0000011"; -- load (data type via funct3)
440
  constant opcode_store_c  : std_ulogic_vector(6 downto 0) := "0100011"; -- store (data type via funct3)
441
  -- system/csr --
442 8 zero_gravi
  constant opcode_fence_c  : std_ulogic_vector(6 downto 0) := "0001111"; -- fence / fence.i
443 2 zero_gravi
  constant opcode_syscsr_c : std_ulogic_vector(6 downto 0) := "1110011"; -- system/csr access (type via funct3)
444 52 zero_gravi
  -- atomic memory access (A) --
445 39 zero_gravi
  constant opcode_atomic_c : std_ulogic_vector(6 downto 0) := "0101111"; -- atomic operations (A extension)
446 53 zero_gravi
  -- floating point operations (Zfinx-only) (F/D/H/Q) --
447 66 zero_gravi
  constant opcode_fop_c    : std_ulogic_vector(6 downto 0) := "1010011"; -- dual/single operand instruction
448 2 zero_gravi
 
449
  -- RISC-V Funct3 --------------------------------------------------------------------------
450
  -- -------------------------------------------------------------------------------------------
451
  -- control flow --
452
  constant funct3_beq_c    : std_ulogic_vector(2 downto 0) := "000"; -- branch if equal
453
  constant funct3_bne_c    : std_ulogic_vector(2 downto 0) := "001"; -- branch if not equal
454
  constant funct3_blt_c    : std_ulogic_vector(2 downto 0) := "100"; -- branch if less than
455
  constant funct3_bge_c    : std_ulogic_vector(2 downto 0) := "101"; -- branch if greater than or equal
456
  constant funct3_bltu_c   : std_ulogic_vector(2 downto 0) := "110"; -- branch if less than (unsigned)
457
  constant funct3_bgeu_c   : std_ulogic_vector(2 downto 0) := "111"; -- branch if greater than or equal (unsigned)
458
  -- memory access --
459
  constant funct3_lb_c     : std_ulogic_vector(2 downto 0) := "000"; -- load byte
460
  constant funct3_lh_c     : std_ulogic_vector(2 downto 0) := "001"; -- load half word
461
  constant funct3_lw_c     : std_ulogic_vector(2 downto 0) := "010"; -- load word
462
  constant funct3_lbu_c    : std_ulogic_vector(2 downto 0) := "100"; -- load byte (unsigned)
463
  constant funct3_lhu_c    : std_ulogic_vector(2 downto 0) := "101"; -- load half word (unsigned)
464
  constant funct3_sb_c     : std_ulogic_vector(2 downto 0) := "000"; -- store byte
465
  constant funct3_sh_c     : std_ulogic_vector(2 downto 0) := "001"; -- store half word
466
  constant funct3_sw_c     : std_ulogic_vector(2 downto 0) := "010"; -- store word
467
  -- alu --
468
  constant funct3_subadd_c : std_ulogic_vector(2 downto 0) := "000"; -- sub/add via funct7
469
  constant funct3_sll_c    : std_ulogic_vector(2 downto 0) := "001"; -- shift logical left
470
  constant funct3_slt_c    : std_ulogic_vector(2 downto 0) := "010"; -- set on less
471
  constant funct3_sltu_c   : std_ulogic_vector(2 downto 0) := "011"; -- set on less unsigned
472
  constant funct3_xor_c    : std_ulogic_vector(2 downto 0) := "100"; -- xor
473
  constant funct3_sr_c     : std_ulogic_vector(2 downto 0) := "101"; -- shift right via funct7
474
  constant funct3_or_c     : std_ulogic_vector(2 downto 0) := "110"; -- or
475
  constant funct3_and_c    : std_ulogic_vector(2 downto 0) := "111"; -- and
476
  -- system/csr --
477 59 zero_gravi
  constant funct3_env_c    : std_ulogic_vector(2 downto 0) := "000"; -- ecall, ebreak, mret, wfi, ...
478 2 zero_gravi
  constant funct3_csrrw_c  : std_ulogic_vector(2 downto 0) := "001"; -- atomic r/w
479
  constant funct3_csrrs_c  : std_ulogic_vector(2 downto 0) := "010"; -- atomic read & set bit
480
  constant funct3_csrrc_c  : std_ulogic_vector(2 downto 0) := "011"; -- atomic read & clear bit
481
  constant funct3_csrrwi_c : std_ulogic_vector(2 downto 0) := "101"; -- atomic r/w immediate
482
  constant funct3_csrrsi_c : std_ulogic_vector(2 downto 0) := "110"; -- atomic read & set bit immediate
483
  constant funct3_csrrci_c : std_ulogic_vector(2 downto 0) := "111"; -- atomic read & clear bit immediate
484 8 zero_gravi
  -- fence --
485
  constant funct3_fence_c  : std_ulogic_vector(2 downto 0) := "000"; -- fence - order IO/memory access (->NOP)
486 66 zero_gravi
  constant funct3_fencei_c : std_ulogic_vector(2 downto 0) := "001"; -- fencei - instruction stream sync
487 2 zero_gravi
 
488 39 zero_gravi
  -- RISC-V Funct12 -------------------------------------------------------------------------
489 11 zero_gravi
  -- -------------------------------------------------------------------------------------------
490
  -- system --
491
  constant funct12_ecall_c  : std_ulogic_vector(11 downto 0) := x"000"; -- ECALL
492
  constant funct12_ebreak_c : std_ulogic_vector(11 downto 0) := x"001"; -- EBREAK
493
  constant funct12_mret_c   : std_ulogic_vector(11 downto 0) := x"302"; -- MRET
494
  constant funct12_wfi_c    : std_ulogic_vector(11 downto 0) := x"105"; -- WFI
495 59 zero_gravi
  constant funct12_dret_c   : std_ulogic_vector(11 downto 0) := x"7b2"; -- DRET
496 11 zero_gravi
 
497 39 zero_gravi
  -- RISC-V Funct5 --------------------------------------------------------------------------
498
  -- -------------------------------------------------------------------------------------------
499
  -- atomic operations --
500
  constant funct5_a_lr_c : std_ulogic_vector(4 downto 0) := "00010"; -- LR
501
  constant funct5_a_sc_c : std_ulogic_vector(4 downto 0) := "00011"; -- SC
502
 
503 54 zero_gravi
  -- RISC-V Floating-Point Stuff ------------------------------------------------------------
504 52 zero_gravi
  -- -------------------------------------------------------------------------------------------
505 54 zero_gravi
  -- formats --
506
  constant float_single_c : std_ulogic_vector(1 downto 0) := "00"; -- single-precision (32-bit)
507
  constant float_double_c : std_ulogic_vector(1 downto 0) := "01"; -- double-precision (64-bit)
508
  constant float_half_c   : std_ulogic_vector(1 downto 0) := "10"; -- half-precision (16-bit)
509
  constant float_quad_c   : std_ulogic_vector(1 downto 0) := "11"; -- quad-precision (128-bit)
510 52 zero_gravi
 
511 54 zero_gravi
  -- number class flags --
512
  constant fp_class_neg_inf_c    : natural := 0; -- negative infinity
513
  constant fp_class_neg_norm_c   : natural := 1; -- negative normal number
514
  constant fp_class_neg_denorm_c : natural := 2; -- negative subnormal number
515
  constant fp_class_neg_zero_c   : natural := 3; -- negative zero
516
  constant fp_class_pos_zero_c   : natural := 4; -- positive zero
517
  constant fp_class_pos_denorm_c : natural := 5; -- positive subnormal number
518
  constant fp_class_pos_norm_c   : natural := 6; -- positive normal number
519
  constant fp_class_pos_inf_c    : natural := 7; -- positive infinity
520
  constant fp_class_snan_c       : natural := 8; -- signaling NaN (sNaN)
521
  constant fp_class_qnan_c       : natural := 9; -- quiet NaN (qNaN)
522
 
523
  -- exception flags --
524
  constant fp_exc_nv_c : natural := 0; -- invalid operation
525
  constant fp_exc_dz_c : natural := 1; -- divide by zero
526
  constant fp_exc_of_c : natural := 2; -- overflow
527
  constant fp_exc_uf_c : natural := 3; -- underflow
528
  constant fp_exc_nx_c : natural := 4; -- inexact
529
 
530
  -- special values (single-precision) --
531
  constant fp_single_qnan_c     : std_ulogic_vector(31 downto 0) := x"7fc00000"; -- quiet NaN
532
  constant fp_single_snan_c     : std_ulogic_vector(31 downto 0) := x"7fa00000"; -- signaling NaN
533
  constant fp_single_pos_inf_c  : std_ulogic_vector(31 downto 0) := x"7f800000"; -- positive infinity
534
  constant fp_single_neg_inf_c  : std_ulogic_vector(31 downto 0) := x"ff800000"; -- negative infinity
535
  constant fp_single_pos_zero_c : std_ulogic_vector(31 downto 0) := x"00000000"; -- positive zero
536
  constant fp_single_neg_zero_c : std_ulogic_vector(31 downto 0) := x"80000000"; -- negative zero
537
 
538 29 zero_gravi
  -- RISC-V CSR Addresses -------------------------------------------------------------------
539
  -- -------------------------------------------------------------------------------------------
540 56 zero_gravi
  -- <<< standard read/write CSRs >>> --
541
  -- user floating-point CSRs --
542 68 zero_gravi
  constant csr_class_float_c    : std_ulogic_vector(09 downto 0) := x"00" & "00"; -- floating point
543 52 zero_gravi
  constant csr_fflags_c         : std_ulogic_vector(11 downto 0) := x"001";
544
  constant csr_frm_c            : std_ulogic_vector(11 downto 0) := x"002";
545
  constant csr_fcsr_c           : std_ulogic_vector(11 downto 0) := x"003";
546 56 zero_gravi
  -- machine trap setup --
547 63 zero_gravi
  constant csr_class_setup_c    : std_ulogic_vector(08 downto 0) := x"30" & '0'; -- trap setup
548 42 zero_gravi
  constant csr_mstatus_c        : std_ulogic_vector(11 downto 0) := x"300";
549
  constant csr_misa_c           : std_ulogic_vector(11 downto 0) := x"301";
550
  constant csr_mie_c            : std_ulogic_vector(11 downto 0) := x"304";
551
  constant csr_mtvec_c          : std_ulogic_vector(11 downto 0) := x"305";
552
  constant csr_mcounteren_c     : std_ulogic_vector(11 downto 0) := x"306";
553 62 zero_gravi
  --
554
  constant csr_mstatush_c       : std_ulogic_vector(11 downto 0) := x"310";
555 64 zero_gravi
  -- machine configuration --
556
  constant csr_class_envcfg_c   : std_ulogic_vector(06 downto 0) := x"3" & "000"; -- configuration
557
  constant csr_menvcfg_c        : std_ulogic_vector(11 downto 0) := x"30a";
558
  constant csr_menvcfgh_c       : std_ulogic_vector(11 downto 0) := x"31a";
559 56 zero_gravi
  -- machine counter setup --
560
  constant csr_cnt_setup_c      : std_ulogic_vector(06 downto 0) := x"3" & "001"; -- counter setup
561 42 zero_gravi
  constant csr_mcountinhibit_c  : std_ulogic_vector(11 downto 0) := x"320";
562
  constant csr_mhpmevent3_c     : std_ulogic_vector(11 downto 0) := x"323";
563
  constant csr_mhpmevent4_c     : std_ulogic_vector(11 downto 0) := x"324";
564
  constant csr_mhpmevent5_c     : std_ulogic_vector(11 downto 0) := x"325";
565
  constant csr_mhpmevent6_c     : std_ulogic_vector(11 downto 0) := x"326";
566
  constant csr_mhpmevent7_c     : std_ulogic_vector(11 downto 0) := x"327";
567
  constant csr_mhpmevent8_c     : std_ulogic_vector(11 downto 0) := x"328";
568
  constant csr_mhpmevent9_c     : std_ulogic_vector(11 downto 0) := x"329";
569
  constant csr_mhpmevent10_c    : std_ulogic_vector(11 downto 0) := x"32a";
570
  constant csr_mhpmevent11_c    : std_ulogic_vector(11 downto 0) := x"32b";
571
  constant csr_mhpmevent12_c    : std_ulogic_vector(11 downto 0) := x"32c";
572
  constant csr_mhpmevent13_c    : std_ulogic_vector(11 downto 0) := x"32d";
573
  constant csr_mhpmevent14_c    : std_ulogic_vector(11 downto 0) := x"32e";
574
  constant csr_mhpmevent15_c    : std_ulogic_vector(11 downto 0) := x"32f";
575
  constant csr_mhpmevent16_c    : std_ulogic_vector(11 downto 0) := x"330";
576
  constant csr_mhpmevent17_c    : std_ulogic_vector(11 downto 0) := x"331";
577
  constant csr_mhpmevent18_c    : std_ulogic_vector(11 downto 0) := x"332";
578
  constant csr_mhpmevent19_c    : std_ulogic_vector(11 downto 0) := x"333";
579
  constant csr_mhpmevent20_c    : std_ulogic_vector(11 downto 0) := x"334";
580
  constant csr_mhpmevent21_c    : std_ulogic_vector(11 downto 0) := x"335";
581
  constant csr_mhpmevent22_c    : std_ulogic_vector(11 downto 0) := x"336";
582
  constant csr_mhpmevent23_c    : std_ulogic_vector(11 downto 0) := x"337";
583
  constant csr_mhpmevent24_c    : std_ulogic_vector(11 downto 0) := x"338";
584
  constant csr_mhpmevent25_c    : std_ulogic_vector(11 downto 0) := x"339";
585
  constant csr_mhpmevent26_c    : std_ulogic_vector(11 downto 0) := x"33a";
586
  constant csr_mhpmevent27_c    : std_ulogic_vector(11 downto 0) := x"33b";
587
  constant csr_mhpmevent28_c    : std_ulogic_vector(11 downto 0) := x"33c";
588
  constant csr_mhpmevent29_c    : std_ulogic_vector(11 downto 0) := x"33d";
589
  constant csr_mhpmevent30_c    : std_ulogic_vector(11 downto 0) := x"33e";
590
  constant csr_mhpmevent31_c    : std_ulogic_vector(11 downto 0) := x"33f";
591 56 zero_gravi
  -- machine trap handling --
592 69 zero_gravi
  constant csr_class_trap_c     : std_ulogic_vector(07 downto 0) := x"34"; -- machine trap handling
593 42 zero_gravi
  constant csr_mscratch_c       : std_ulogic_vector(11 downto 0) := x"340";
594
  constant csr_mepc_c           : std_ulogic_vector(11 downto 0) := x"341";
595
  constant csr_mcause_c         : std_ulogic_vector(11 downto 0) := x"342";
596
  constant csr_mtval_c          : std_ulogic_vector(11 downto 0) := x"343";
597
  constant csr_mip_c            : std_ulogic_vector(11 downto 0) := x"344";
598 56 zero_gravi
  -- physical memory protection - configuration --
599 52 zero_gravi
  constant csr_class_pmpcfg_c   : std_ulogic_vector(07 downto 0) := x"3a"; -- pmp configuration
600 42 zero_gravi
  constant csr_pmpcfg0_c        : std_ulogic_vector(11 downto 0) := x"3a0";
601
  constant csr_pmpcfg1_c        : std_ulogic_vector(11 downto 0) := x"3a1";
602
  constant csr_pmpcfg2_c        : std_ulogic_vector(11 downto 0) := x"3a2";
603
  constant csr_pmpcfg3_c        : std_ulogic_vector(11 downto 0) := x"3a3";
604
  constant csr_pmpcfg4_c        : std_ulogic_vector(11 downto 0) := x"3a4";
605
  constant csr_pmpcfg5_c        : std_ulogic_vector(11 downto 0) := x"3a5";
606
  constant csr_pmpcfg6_c        : std_ulogic_vector(11 downto 0) := x"3a6";
607
  constant csr_pmpcfg7_c        : std_ulogic_vector(11 downto 0) := x"3a7";
608
  constant csr_pmpcfg8_c        : std_ulogic_vector(11 downto 0) := x"3a8";
609
  constant csr_pmpcfg9_c        : std_ulogic_vector(11 downto 0) := x"3a9";
610
  constant csr_pmpcfg10_c       : std_ulogic_vector(11 downto 0) := x"3aa";
611
  constant csr_pmpcfg11_c       : std_ulogic_vector(11 downto 0) := x"3ab";
612
  constant csr_pmpcfg12_c       : std_ulogic_vector(11 downto 0) := x"3ac";
613
  constant csr_pmpcfg13_c       : std_ulogic_vector(11 downto 0) := x"3ad";
614
  constant csr_pmpcfg14_c       : std_ulogic_vector(11 downto 0) := x"3ae";
615
  constant csr_pmpcfg15_c       : std_ulogic_vector(11 downto 0) := x"3af";
616 56 zero_gravi
  -- physical memory protection - address --
617 42 zero_gravi
  constant csr_pmpaddr0_c       : std_ulogic_vector(11 downto 0) := x"3b0";
618
  constant csr_pmpaddr1_c       : std_ulogic_vector(11 downto 0) := x"3b1";
619
  constant csr_pmpaddr2_c       : std_ulogic_vector(11 downto 0) := x"3b2";
620
  constant csr_pmpaddr3_c       : std_ulogic_vector(11 downto 0) := x"3b3";
621
  constant csr_pmpaddr4_c       : std_ulogic_vector(11 downto 0) := x"3b4";
622
  constant csr_pmpaddr5_c       : std_ulogic_vector(11 downto 0) := x"3b5";
623
  constant csr_pmpaddr6_c       : std_ulogic_vector(11 downto 0) := x"3b6";
624
  constant csr_pmpaddr7_c       : std_ulogic_vector(11 downto 0) := x"3b7";
625
  constant csr_pmpaddr8_c       : std_ulogic_vector(11 downto 0) := x"3b8";
626
  constant csr_pmpaddr9_c       : std_ulogic_vector(11 downto 0) := x"3b9";
627
  constant csr_pmpaddr10_c      : std_ulogic_vector(11 downto 0) := x"3ba";
628
  constant csr_pmpaddr11_c      : std_ulogic_vector(11 downto 0) := x"3bb";
629
  constant csr_pmpaddr12_c      : std_ulogic_vector(11 downto 0) := x"3bc";
630
  constant csr_pmpaddr13_c      : std_ulogic_vector(11 downto 0) := x"3bd";
631
  constant csr_pmpaddr14_c      : std_ulogic_vector(11 downto 0) := x"3be";
632
  constant csr_pmpaddr15_c      : std_ulogic_vector(11 downto 0) := x"3bf";
633
  constant csr_pmpaddr16_c      : std_ulogic_vector(11 downto 0) := x"3c0";
634
  constant csr_pmpaddr17_c      : std_ulogic_vector(11 downto 0) := x"3c1";
635
  constant csr_pmpaddr18_c      : std_ulogic_vector(11 downto 0) := x"3c2";
636
  constant csr_pmpaddr19_c      : std_ulogic_vector(11 downto 0) := x"3c3";
637
  constant csr_pmpaddr20_c      : std_ulogic_vector(11 downto 0) := x"3c4";
638
  constant csr_pmpaddr21_c      : std_ulogic_vector(11 downto 0) := x"3c5";
639
  constant csr_pmpaddr22_c      : std_ulogic_vector(11 downto 0) := x"3c6";
640
  constant csr_pmpaddr23_c      : std_ulogic_vector(11 downto 0) := x"3c7";
641
  constant csr_pmpaddr24_c      : std_ulogic_vector(11 downto 0) := x"3c8";
642
  constant csr_pmpaddr25_c      : std_ulogic_vector(11 downto 0) := x"3c9";
643
  constant csr_pmpaddr26_c      : std_ulogic_vector(11 downto 0) := x"3ca";
644
  constant csr_pmpaddr27_c      : std_ulogic_vector(11 downto 0) := x"3cb";
645
  constant csr_pmpaddr28_c      : std_ulogic_vector(11 downto 0) := x"3cc";
646
  constant csr_pmpaddr29_c      : std_ulogic_vector(11 downto 0) := x"3cd";
647
  constant csr_pmpaddr30_c      : std_ulogic_vector(11 downto 0) := x"3ce";
648
  constant csr_pmpaddr31_c      : std_ulogic_vector(11 downto 0) := x"3cf";
649
  constant csr_pmpaddr32_c      : std_ulogic_vector(11 downto 0) := x"3d0";
650
  constant csr_pmpaddr33_c      : std_ulogic_vector(11 downto 0) := x"3d1";
651
  constant csr_pmpaddr34_c      : std_ulogic_vector(11 downto 0) := x"3d2";
652
  constant csr_pmpaddr35_c      : std_ulogic_vector(11 downto 0) := x"3d3";
653
  constant csr_pmpaddr36_c      : std_ulogic_vector(11 downto 0) := x"3d4";
654
  constant csr_pmpaddr37_c      : std_ulogic_vector(11 downto 0) := x"3d5";
655
  constant csr_pmpaddr38_c      : std_ulogic_vector(11 downto 0) := x"3d6";
656
  constant csr_pmpaddr39_c      : std_ulogic_vector(11 downto 0) := x"3d7";
657
  constant csr_pmpaddr40_c      : std_ulogic_vector(11 downto 0) := x"3d8";
658
  constant csr_pmpaddr41_c      : std_ulogic_vector(11 downto 0) := x"3d9";
659
  constant csr_pmpaddr42_c      : std_ulogic_vector(11 downto 0) := x"3da";
660
  constant csr_pmpaddr43_c      : std_ulogic_vector(11 downto 0) := x"3db";
661
  constant csr_pmpaddr44_c      : std_ulogic_vector(11 downto 0) := x"3dc";
662
  constant csr_pmpaddr45_c      : std_ulogic_vector(11 downto 0) := x"3dd";
663
  constant csr_pmpaddr46_c      : std_ulogic_vector(11 downto 0) := x"3de";
664
  constant csr_pmpaddr47_c      : std_ulogic_vector(11 downto 0) := x"3df";
665
  constant csr_pmpaddr48_c      : std_ulogic_vector(11 downto 0) := x"3e0";
666
  constant csr_pmpaddr49_c      : std_ulogic_vector(11 downto 0) := x"3e1";
667
  constant csr_pmpaddr50_c      : std_ulogic_vector(11 downto 0) := x"3e2";
668
  constant csr_pmpaddr51_c      : std_ulogic_vector(11 downto 0) := x"3e3";
669
  constant csr_pmpaddr52_c      : std_ulogic_vector(11 downto 0) := x"3e4";
670
  constant csr_pmpaddr53_c      : std_ulogic_vector(11 downto 0) := x"3e5";
671
  constant csr_pmpaddr54_c      : std_ulogic_vector(11 downto 0) := x"3e6";
672
  constant csr_pmpaddr55_c      : std_ulogic_vector(11 downto 0) := x"3e7";
673
  constant csr_pmpaddr56_c      : std_ulogic_vector(11 downto 0) := x"3e8";
674
  constant csr_pmpaddr57_c      : std_ulogic_vector(11 downto 0) := x"3e9";
675
  constant csr_pmpaddr58_c      : std_ulogic_vector(11 downto 0) := x"3ea";
676
  constant csr_pmpaddr59_c      : std_ulogic_vector(11 downto 0) := x"3eb";
677
  constant csr_pmpaddr60_c      : std_ulogic_vector(11 downto 0) := x"3ec";
678
  constant csr_pmpaddr61_c      : std_ulogic_vector(11 downto 0) := x"3ed";
679
  constant csr_pmpaddr62_c      : std_ulogic_vector(11 downto 0) := x"3ee";
680
  constant csr_pmpaddr63_c      : std_ulogic_vector(11 downto 0) := x"3ef";
681 59 zero_gravi
  -- debug mode registers --
682
  constant csr_class_debug_c    : std_ulogic_vector(09 downto 0) := x"7b" & "00"; -- debug registers
683
  constant csr_dcsr_c           : std_ulogic_vector(11 downto 0) := x"7b0";
684
  constant csr_dpc_c            : std_ulogic_vector(11 downto 0) := x"7b1";
685
  constant csr_dscratch0_c      : std_ulogic_vector(11 downto 0) := x"7b2";
686 56 zero_gravi
  -- machine counters/timers --
687 42 zero_gravi
  constant csr_mcycle_c         : std_ulogic_vector(11 downto 0) := x"b00";
688
  constant csr_minstret_c       : std_ulogic_vector(11 downto 0) := x"b02";
689
  --
690
  constant csr_mhpmcounter3_c   : std_ulogic_vector(11 downto 0) := x"b03";
691
  constant csr_mhpmcounter4_c   : std_ulogic_vector(11 downto 0) := x"b04";
692
  constant csr_mhpmcounter5_c   : std_ulogic_vector(11 downto 0) := x"b05";
693
  constant csr_mhpmcounter6_c   : std_ulogic_vector(11 downto 0) := x"b06";
694
  constant csr_mhpmcounter7_c   : std_ulogic_vector(11 downto 0) := x"b07";
695
  constant csr_mhpmcounter8_c   : std_ulogic_vector(11 downto 0) := x"b08";
696
  constant csr_mhpmcounter9_c   : std_ulogic_vector(11 downto 0) := x"b09";
697
  constant csr_mhpmcounter10_c  : std_ulogic_vector(11 downto 0) := x"b0a";
698
  constant csr_mhpmcounter11_c  : std_ulogic_vector(11 downto 0) := x"b0b";
699
  constant csr_mhpmcounter12_c  : std_ulogic_vector(11 downto 0) := x"b0c";
700
  constant csr_mhpmcounter13_c  : std_ulogic_vector(11 downto 0) := x"b0d";
701
  constant csr_mhpmcounter14_c  : std_ulogic_vector(11 downto 0) := x"b0e";
702
  constant csr_mhpmcounter15_c  : std_ulogic_vector(11 downto 0) := x"b0f";
703
  constant csr_mhpmcounter16_c  : std_ulogic_vector(11 downto 0) := x"b10";
704
  constant csr_mhpmcounter17_c  : std_ulogic_vector(11 downto 0) := x"b11";
705
  constant csr_mhpmcounter18_c  : std_ulogic_vector(11 downto 0) := x"b12";
706
  constant csr_mhpmcounter19_c  : std_ulogic_vector(11 downto 0) := x"b13";
707
  constant csr_mhpmcounter20_c  : std_ulogic_vector(11 downto 0) := x"b14";
708
  constant csr_mhpmcounter21_c  : std_ulogic_vector(11 downto 0) := x"b15";
709
  constant csr_mhpmcounter22_c  : std_ulogic_vector(11 downto 0) := x"b16";
710
  constant csr_mhpmcounter23_c  : std_ulogic_vector(11 downto 0) := x"b17";
711
  constant csr_mhpmcounter24_c  : std_ulogic_vector(11 downto 0) := x"b18";
712
  constant csr_mhpmcounter25_c  : std_ulogic_vector(11 downto 0) := x"b19";
713
  constant csr_mhpmcounter26_c  : std_ulogic_vector(11 downto 0) := x"b1a";
714
  constant csr_mhpmcounter27_c  : std_ulogic_vector(11 downto 0) := x"b1b";
715
  constant csr_mhpmcounter28_c  : std_ulogic_vector(11 downto 0) := x"b1c";
716
  constant csr_mhpmcounter29_c  : std_ulogic_vector(11 downto 0) := x"b1d";
717
  constant csr_mhpmcounter30_c  : std_ulogic_vector(11 downto 0) := x"b1e";
718
  constant csr_mhpmcounter31_c  : std_ulogic_vector(11 downto 0) := x"b1f";
719
  --
720
  constant csr_mcycleh_c        : std_ulogic_vector(11 downto 0) := x"b80";
721
  constant csr_minstreth_c      : std_ulogic_vector(11 downto 0) := x"b82";
722
  --
723
  constant csr_mhpmcounter3h_c  : std_ulogic_vector(11 downto 0) := x"b83";
724
  constant csr_mhpmcounter4h_c  : std_ulogic_vector(11 downto 0) := x"b84";
725
  constant csr_mhpmcounter5h_c  : std_ulogic_vector(11 downto 0) := x"b85";
726
  constant csr_mhpmcounter6h_c  : std_ulogic_vector(11 downto 0) := x"b86";
727
  constant csr_mhpmcounter7h_c  : std_ulogic_vector(11 downto 0) := x"b87";
728
  constant csr_mhpmcounter8h_c  : std_ulogic_vector(11 downto 0) := x"b88";
729
  constant csr_mhpmcounter9h_c  : std_ulogic_vector(11 downto 0) := x"b89";
730
  constant csr_mhpmcounter10h_c : std_ulogic_vector(11 downto 0) := x"b8a";
731
  constant csr_mhpmcounter11h_c : std_ulogic_vector(11 downto 0) := x"b8b";
732
  constant csr_mhpmcounter12h_c : std_ulogic_vector(11 downto 0) := x"b8c";
733
  constant csr_mhpmcounter13h_c : std_ulogic_vector(11 downto 0) := x"b8d";
734
  constant csr_mhpmcounter14h_c : std_ulogic_vector(11 downto 0) := x"b8e";
735
  constant csr_mhpmcounter15h_c : std_ulogic_vector(11 downto 0) := x"b8f";
736
  constant csr_mhpmcounter16h_c : std_ulogic_vector(11 downto 0) := x"b90";
737
  constant csr_mhpmcounter17h_c : std_ulogic_vector(11 downto 0) := x"b91";
738
  constant csr_mhpmcounter18h_c : std_ulogic_vector(11 downto 0) := x"b92";
739
  constant csr_mhpmcounter19h_c : std_ulogic_vector(11 downto 0) := x"b93";
740
  constant csr_mhpmcounter20h_c : std_ulogic_vector(11 downto 0) := x"b94";
741
  constant csr_mhpmcounter21h_c : std_ulogic_vector(11 downto 0) := x"b95";
742
  constant csr_mhpmcounter22h_c : std_ulogic_vector(11 downto 0) := x"b96";
743
  constant csr_mhpmcounter23h_c : std_ulogic_vector(11 downto 0) := x"b97";
744
  constant csr_mhpmcounter24h_c : std_ulogic_vector(11 downto 0) := x"b98";
745
  constant csr_mhpmcounter25h_c : std_ulogic_vector(11 downto 0) := x"b99";
746
  constant csr_mhpmcounter26h_c : std_ulogic_vector(11 downto 0) := x"b9a";
747
  constant csr_mhpmcounter27h_c : std_ulogic_vector(11 downto 0) := x"b9b";
748
  constant csr_mhpmcounter28h_c : std_ulogic_vector(11 downto 0) := x"b9c";
749
  constant csr_mhpmcounter29h_c : std_ulogic_vector(11 downto 0) := x"b9d";
750
  constant csr_mhpmcounter30h_c : std_ulogic_vector(11 downto 0) := x"b9e";
751
  constant csr_mhpmcounter31h_c : std_ulogic_vector(11 downto 0) := x"b9f";
752
 
753 56 zero_gravi
  -- <<< standard read-only CSRs >>> --
754
  -- user counters/timers --
755 42 zero_gravi
  constant csr_cycle_c          : std_ulogic_vector(11 downto 0) := x"c00";
756
  constant csr_time_c           : std_ulogic_vector(11 downto 0) := x"c01";
757
  constant csr_instret_c        : std_ulogic_vector(11 downto 0) := x"c02";
758
  constant csr_cycleh_c         : std_ulogic_vector(11 downto 0) := x"c80";
759
  constant csr_timeh_c          : std_ulogic_vector(11 downto 0) := x"c81";
760
  constant csr_instreth_c       : std_ulogic_vector(11 downto 0) := x"c82";
761 56 zero_gravi
  -- machine information registers --
762 42 zero_gravi
  constant csr_mvendorid_c      : std_ulogic_vector(11 downto 0) := x"f11";
763
  constant csr_marchid_c        : std_ulogic_vector(11 downto 0) := x"f12";
764
  constant csr_mimpid_c         : std_ulogic_vector(11 downto 0) := x"f13";
765
  constant csr_mhartid_c        : std_ulogic_vector(11 downto 0) := x"f14";
766 62 zero_gravi
  constant csr_mconfigptr_c     : std_ulogic_vector(11 downto 0) := x"f15";
767 42 zero_gravi
 
768 44 zero_gravi
  -- Co-Processor IDs -----------------------------------------------------------------------
769 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
770 63 zero_gravi
  constant cp_sel_shifter_c  : std_ulogic_vector(1 downto 0) := "00"; -- shift operations (base ISA)
771
  constant cp_sel_muldiv_c   : std_ulogic_vector(1 downto 0) := "01"; -- multiplication/division operations ('M' extensions)
772
  constant cp_sel_bitmanip_c : std_ulogic_vector(1 downto 0) := "10"; -- bit manipulation ('B' extensions)
773 61 zero_gravi
  constant cp_sel_fpu_c      : std_ulogic_vector(1 downto 0) := "11"; -- floating-point unit ('Zfinx' extension)
774 2 zero_gravi
 
775
  -- ALU Function Codes ---------------------------------------------------------------------
776
  -- -------------------------------------------------------------------------------------------
777 68 zero_gravi
  -- ALU core [DO NOT CHANGE ENCODING!] --
778
  constant alu_op_add_c     : std_ulogic_vector(2 downto 0) := "000"; -- alu_result <= A + B
779
  constant alu_op_sub_c     : std_ulogic_vector(2 downto 0) := "001"; -- alu_result <= A - B
780
--constant alu_op_mova_c    : std_ulogic_vector(2 downto 0) := "010"; -- alu_result <= A (rs1)
781
  constant alu_op_slt_c     : std_ulogic_vector(2 downto 0) := "011"; -- alu_result <= A < B
782
  constant alu_op_movb_c    : std_ulogic_vector(2 downto 0) := "100"; -- alu_result <= B
783
  constant alu_op_xor_c     : std_ulogic_vector(2 downto 0) := "101"; -- alu_result <= A xor B
784
  constant alu_op_or_c      : std_ulogic_vector(2 downto 0) := "110"; -- alu_result <= A or B
785
  constant alu_op_and_c     : std_ulogic_vector(2 downto 0) := "111"; -- alu_result <= A and B
786
  -- function select (actual ALU result) --
787
  constant alu_func_core_c  : std_ulogic_vector(1 downto 0) := "00"; -- r <= alu_result
788
  constant alu_func_nxpc_c  : std_ulogic_vector(1 downto 0) := "01"; -- r <= next_PC
789
  constant alu_func_csrr_c  : std_ulogic_vector(1 downto 0) := "10"; -- r <= CSR read
790
  constant alu_func_copro_c : std_ulogic_vector(1 downto 0) := "11"; -- r <= CP result (multi-cycle)
791 2 zero_gravi
 
792 12 zero_gravi
  -- Trap ID Codes --------------------------------------------------------------------------
793
  -- -------------------------------------------------------------------------------------------
794 64 zero_gravi
  -- MSB:   1 = async exception (IRQ), 0 = sync exception (e.g. ebreak)
795
  -- MSB-1: 1 = entry to debug mode, 0 = normal trapping
796 48 zero_gravi
  -- RISC-V compliant sync. exceptions --
797 59 zero_gravi
  constant trap_ima_c      : std_ulogic_vector(6 downto 0) := "0" & "0" & "00000"; -- 0.0:  instruction misaligned
798
  constant trap_iba_c      : std_ulogic_vector(6 downto 0) := "0" & "0" & "00001"; -- 0.1:  instruction access fault
799
  constant trap_iil_c      : std_ulogic_vector(6 downto 0) := "0" & "0" & "00010"; -- 0.2:  illegal instruction
800
  constant trap_brk_c      : std_ulogic_vector(6 downto 0) := "0" & "0" & "00011"; -- 0.3:  breakpoint
801
  constant trap_lma_c      : std_ulogic_vector(6 downto 0) := "0" & "0" & "00100"; -- 0.4:  load address misaligned
802
  constant trap_lbe_c      : std_ulogic_vector(6 downto 0) := "0" & "0" & "00101"; -- 0.5:  load access fault
803
  constant trap_sma_c      : std_ulogic_vector(6 downto 0) := "0" & "0" & "00110"; -- 0.6:  store address misaligned
804
  constant trap_sbe_c      : std_ulogic_vector(6 downto 0) := "0" & "0" & "00111"; -- 0.7:  store access fault
805
  constant trap_uenv_c     : std_ulogic_vector(6 downto 0) := "0" & "0" & "01000"; -- 0.8:  environment call from u-mode
806
  constant trap_menv_c     : std_ulogic_vector(6 downto 0) := "0" & "0" & "01011"; -- 0.11: environment call from m-mode
807 48 zero_gravi
  -- RISC-V compliant interrupts (async. exceptions) --
808 59 zero_gravi
  constant trap_msi_c      : std_ulogic_vector(6 downto 0) := "1" & "0" & "00011"; -- 1.3:  machine software interrupt
809
  constant trap_mti_c      : std_ulogic_vector(6 downto 0) := "1" & "0" & "00111"; -- 1.7:  machine timer interrupt
810
  constant trap_mei_c      : std_ulogic_vector(6 downto 0) := "1" & "0" & "01011"; -- 1.11: machine external interrupt
811 48 zero_gravi
  -- NEORV32-specific (custom) interrupts (async. exceptions) --
812 59 zero_gravi
  constant trap_firq0_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "10000"; -- 1.16: fast interrupt 0
813
  constant trap_firq1_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "10001"; -- 1.17: fast interrupt 1
814
  constant trap_firq2_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "10010"; -- 1.18: fast interrupt 2
815
  constant trap_firq3_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "10011"; -- 1.19: fast interrupt 3
816
  constant trap_firq4_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "10100"; -- 1.20: fast interrupt 4
817
  constant trap_firq5_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "10101"; -- 1.21: fast interrupt 5
818
  constant trap_firq6_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "10110"; -- 1.22: fast interrupt 6
819
  constant trap_firq7_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "10111"; -- 1.23: fast interrupt 7
820
  constant trap_firq8_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "11000"; -- 1.24: fast interrupt 8
821
  constant trap_firq9_c    : std_ulogic_vector(6 downto 0) := "1" & "0" & "11001"; -- 1.25: fast interrupt 9
822
  constant trap_firq10_c   : std_ulogic_vector(6 downto 0) := "1" & "0" & "11010"; -- 1.26: fast interrupt 10
823
  constant trap_firq11_c   : std_ulogic_vector(6 downto 0) := "1" & "0" & "11011"; -- 1.27: fast interrupt 11
824
  constant trap_firq12_c   : std_ulogic_vector(6 downto 0) := "1" & "0" & "11100"; -- 1.28: fast interrupt 12
825
  constant trap_firq13_c   : std_ulogic_vector(6 downto 0) := "1" & "0" & "11101"; -- 1.29: fast interrupt 13
826
  constant trap_firq14_c   : std_ulogic_vector(6 downto 0) := "1" & "0" & "11110"; -- 1.30: fast interrupt 14
827
  constant trap_firq15_c   : std_ulogic_vector(6 downto 0) := "1" & "0" & "11111"; -- 1.31: fast interrupt 15
828
  -- entering debug mode - cause --
829
  constant trap_db_break_c : std_ulogic_vector(6 downto 0) := "0" & "1" & "00010"; -- break instruction (sync / EXCEPTION)
830
  constant trap_db_halt_c  : std_ulogic_vector(6 downto 0) := "1" & "1" & "00011"; -- external halt request (async / IRQ)
831
  constant trap_db_step_c  : std_ulogic_vector(6 downto 0) := "1" & "1" & "00100"; -- single-stepping (async / IRQ)
832 12 zero_gravi
 
833 2 zero_gravi
  -- CPU Control Exception System -----------------------------------------------------------
834
  -- -------------------------------------------------------------------------------------------
835
  -- exception source bits --
836 59 zero_gravi
  constant exception_iaccess_c   : natural :=  0; -- instruction access fault
837
  constant exception_iillegal_c  : natural :=  1; -- illegal instruction
838
  constant exception_ialign_c    : natural :=  2; -- instruction address misaligned
839 47 zero_gravi
  constant exception_m_envcall_c : natural :=  3; -- ENV call from m-mode
840
  constant exception_u_envcall_c : natural :=  4; -- ENV call from u-mode
841
  constant exception_break_c     : natural :=  5; -- breakpoint
842
  constant exception_salign_c    : natural :=  6; -- store address misaligned
843
  constant exception_lalign_c    : natural :=  7; -- load address misaligned
844
  constant exception_saccess_c   : natural :=  8; -- store access fault
845
  constant exception_laccess_c   : natural :=  9; -- load access fault
846 59 zero_gravi
  -- for debug mode only --
847
  constant exception_db_break_c  : natural := 10; -- enter debug mode via ebreak instruction ("sync EXCEPTION")
848 14 zero_gravi
  --
849 59 zero_gravi
  constant exception_width_c     : natural := 11; -- length of this list in bits
850 2 zero_gravi
  -- interrupt source bits --
851 64 zero_gravi
  constant interrupt_msw_irq_c   : natural :=  0; -- machine software interrupt
852
  constant interrupt_mtime_irq_c : natural :=  1; -- machine timer interrupt
853
  constant interrupt_mext_irq_c  : natural :=  2; -- machine external interrupt
854
  constant interrupt_firq_0_c    : natural :=  3; -- fast interrupt channel 0
855
  constant interrupt_firq_1_c    : natural :=  4; -- fast interrupt channel 1
856
  constant interrupt_firq_2_c    : natural :=  5; -- fast interrupt channel 2
857
  constant interrupt_firq_3_c    : natural :=  6; -- fast interrupt channel 3
858
  constant interrupt_firq_4_c    : natural :=  7; -- fast interrupt channel 4
859
  constant interrupt_firq_5_c    : natural :=  8; -- fast interrupt channel 5
860
  constant interrupt_firq_6_c    : natural :=  9; -- fast interrupt channel 6
861
  constant interrupt_firq_7_c    : natural := 10; -- fast interrupt channel 7
862
  constant interrupt_firq_8_c    : natural := 11; -- fast interrupt channel 8
863
  constant interrupt_firq_9_c    : natural := 12; -- fast interrupt channel 9
864
  constant interrupt_firq_10_c   : natural := 13; -- fast interrupt channel 10
865
  constant interrupt_firq_11_c   : natural := 14; -- fast interrupt channel 11
866
  constant interrupt_firq_12_c   : natural := 15; -- fast interrupt channel 12
867
  constant interrupt_firq_13_c   : natural := 16; -- fast interrupt channel 13
868
  constant interrupt_firq_14_c   : natural := 17; -- fast interrupt channel 14
869
  constant interrupt_firq_15_c   : natural := 18; -- fast interrupt channel 15
870 59 zero_gravi
  -- for debug mode only --
871 64 zero_gravi
  constant interrupt_db_halt_c   : natural := 19; -- enter debug mode via external halt request ("async IRQ")
872
  constant interrupt_db_step_c   : natural := 20; -- enter debug mode via single-stepping ("async IRQ")
873 14 zero_gravi
  --
874 64 zero_gravi
  constant interrupt_width_c     : natural := 21; -- length of this list in bits
875 2 zero_gravi
 
876 15 zero_gravi
  -- CPU Privilege Modes --------------------------------------------------------------------
877
  -- -------------------------------------------------------------------------------------------
878 29 zero_gravi
  constant priv_mode_m_c : std_ulogic_vector(1 downto 0) := "11"; -- machine mode
879
  constant priv_mode_u_c : std_ulogic_vector(1 downto 0) := "00"; -- user mode
880 15 zero_gravi
 
881 42 zero_gravi
  -- HPM Event System -----------------------------------------------------------------------
882
  -- -------------------------------------------------------------------------------------------
883
  constant hpmcnt_event_cy_c      : natural := 0;  -- Active cycle
884 56 zero_gravi
  constant hpmcnt_event_never_c   : natural := 1;  -- Unused / never (actually, this would be used for TIME)
885 42 zero_gravi
  constant hpmcnt_event_ir_c      : natural := 2;  -- Retired instruction
886
  constant hpmcnt_event_cir_c     : natural := 3;  -- Retired compressed instruction
887
  constant hpmcnt_event_wait_if_c : natural := 4;  -- Instruction fetch memory wait cycle
888
  constant hpmcnt_event_wait_ii_c : natural := 5;  -- Instruction issue wait cycle
889 45 zero_gravi
  constant hpmcnt_event_wait_mc_c : natural := 6;  -- Multi-cycle ALU-operation wait cycle
890
  constant hpmcnt_event_load_c    : natural := 7;  -- Load operation
891
  constant hpmcnt_event_store_c   : natural := 8;  -- Store operation
892
  constant hpmcnt_event_wait_ls_c : natural := 9;  -- Load/store memory wait cycle
893
  constant hpmcnt_event_jump_c    : natural := 10; -- Unconditional jump
894
  constant hpmcnt_event_branch_c  : natural := 11; -- Conditional branch (taken or not taken)
895
  constant hpmcnt_event_tbranch_c : natural := 12; -- Conditional taken branch
896
  constant hpmcnt_event_trap_c    : natural := 13; -- Entered trap
897
  constant hpmcnt_event_illegal_c : natural := 14; -- Illegal instruction exception
898 42 zero_gravi
  --
899 45 zero_gravi
  constant hpmcnt_event_size_c    : natural := 15; -- length of this list
900 42 zero_gravi
 
901 39 zero_gravi
  -- Clock Generator ------------------------------------------------------------------------
902 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
903
  constant clk_div2_c    : natural := 0;
904
  constant clk_div4_c    : natural := 1;
905
  constant clk_div8_c    : natural := 2;
906
  constant clk_div64_c   : natural := 3;
907
  constant clk_div128_c  : natural := 4;
908
  constant clk_div1024_c : natural := 5;
909
  constant clk_div2048_c : natural := 6;
910
  constant clk_div4096_c : natural := 7;
911
 
912
  -- Component: NEORV32 Processor Top Entity ------------------------------------------------
913
  -- -------------------------------------------------------------------------------------------
914
  component neorv32_top
915
    generic (
916
      -- General --
917 62 zero_gravi
      CLOCK_FREQUENCY              : natural;           -- clock frequency of clk_i in Hz
918 49 zero_gravi
      HW_THREAD_ID                 : natural := 0;      -- hardware thread id (32-bit)
919 62 zero_gravi
      INT_BOOTLOADER_EN            : boolean := false;  -- boot configuration: true = boot explicit bootloader; false = boot from int/ext (I)MEM
920 59 zero_gravi
      -- On-Chip Debugger (OCD) --
921
      ON_CHIP_DEBUGGER_EN          : boolean := false;  -- implement on-chip debugger
922 2 zero_gravi
      -- RISC-V CPU Extensions --
923 39 zero_gravi
      CPU_EXTENSION_RISCV_A        : boolean := false;  -- implement atomic extension?
924 66 zero_gravi
      CPU_EXTENSION_RISCV_B        : boolean := false;  -- implement bit-manipulation extension?
925 18 zero_gravi
      CPU_EXTENSION_RISCV_C        : boolean := false;  -- implement compressed extension?
926 8 zero_gravi
      CPU_EXTENSION_RISCV_E        : boolean := false;  -- implement embedded RF extension?
927 61 zero_gravi
      CPU_EXTENSION_RISCV_M        : boolean := false;  -- implement mul/div extension?
928 18 zero_gravi
      CPU_EXTENSION_RISCV_U        : boolean := false;  -- implement user mode extension?
929 57 zero_gravi
      CPU_EXTENSION_RISCV_Zfinx    : boolean := false;  -- implement 32-bit floating-point extension (using INT regs!)
930 8 zero_gravi
      CPU_EXTENSION_RISCV_Zicsr    : boolean := true;   -- implement CSR system?
931 66 zero_gravi
      CPU_EXTENSION_RISCV_Zicntr   : boolean := true;   -- implement base counters?
932
      CPU_EXTENSION_RISCV_Zihpm    : boolean := false;  -- implement hardware performance monitors?
933 39 zero_gravi
      CPU_EXTENSION_RISCV_Zifencei : boolean := false;  -- implement instruction stream sync.?
934 62 zero_gravi
      CPU_EXTENSION_RISCV_Zmmul    : boolean := false;  -- implement multiply-only M sub-extension?
935 19 zero_gravi
      -- Extension Options --
936 34 zero_gravi
      FAST_MUL_EN                  : boolean := false;  -- use DSPs for M extension's multiplier
937
      FAST_SHIFT_EN                : boolean := false;  -- use barrel shifter for shift operations
938 56 zero_gravi
      CPU_CNT_WIDTH                : natural := 64;     -- total width of CPU cycle and instret counters (0..64)
939 62 zero_gravi
      CPU_IPB_ENTRIES              : natural := 2;      -- entries is instruction prefetch buffer, has to be a power of 2
940 15 zero_gravi
      -- Physical Memory Protection (PMP) --
941 42 zero_gravi
      PMP_NUM_REGIONS              : natural := 0;      -- number of regions (0..64)
942
      PMP_MIN_GRANULARITY          : natural := 64*1024; -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
943
      -- Hardware Performance Monitors (HPM) --
944 47 zero_gravi
      HPM_NUM_CNTS                 : natural := 0;      -- number of implemented HPM counters (0..29)
945 60 zero_gravi
      HPM_CNT_WIDTH                : natural := 40;     -- total size of HPM counters (0..64)
946 61 zero_gravi
      -- Internal Instruction memory (IMEM) --
947 62 zero_gravi
      MEM_INT_IMEM_EN              : boolean := false;  -- implement processor-internal instruction memory
948 8 zero_gravi
      MEM_INT_IMEM_SIZE            : natural := 16*1024; -- size of processor-internal instruction memory in bytes
949 61 zero_gravi
      -- Internal Data memory (DMEM) --
950 62 zero_gravi
      MEM_INT_DMEM_EN              : boolean := false;  -- implement processor-internal data memory
951 8 zero_gravi
      MEM_INT_DMEM_SIZE            : natural := 8*1024; -- size of processor-internal data memory in bytes
952 61 zero_gravi
      -- Internal Cache memory (iCACHE) --
953 44 zero_gravi
      ICACHE_EN                    : boolean := false;  -- implement instruction cache
954 41 zero_gravi
      ICACHE_NUM_BLOCKS            : natural := 4;      -- i-cache: number of blocks (min 1), has to be a power of 2
955
      ICACHE_BLOCK_SIZE            : natural := 64;     -- i-cache: block size in bytes (min 4), has to be a power of 2
956 45 zero_gravi
      ICACHE_ASSOCIATIVITY         : natural := 1;      -- i-cache: associativity / number of sets (1=direct_mapped), has to be a power of 2
957 61 zero_gravi
      -- External memory interface (WISHBONE) --
958 44 zero_gravi
      MEM_EXT_EN                   : boolean := false;  -- implement external memory bus interface?
959 57 zero_gravi
      MEM_EXT_TIMEOUT              : natural := 255;    -- cycles after a pending bus access auto-terminates (0 = disabled)
960 62 zero_gravi
      MEM_EXT_PIPE_MODE            : boolean := false;  -- protocol: false=classic/standard wishbone mode, true=pipelined wishbone mode
961
      MEM_EXT_BIG_ENDIAN           : boolean := false;  -- byte order: true=big-endian, false=little-endian
962
      MEM_EXT_ASYNC_RX             : boolean := false;  -- use register buffer for RX data when false
963 61 zero_gravi
      -- Stream link interface (SLINK) --
964
      SLINK_NUM_TX                 : natural := 0;      -- number of TX links (0..8)
965
      SLINK_NUM_RX                 : natural := 0;      -- number of TX links (0..8)
966
      SLINK_TX_FIFO                : natural := 1;      -- TX fifo depth, has to be a power of two
967
      SLINK_RX_FIFO                : natural := 1;      -- RX fifo depth, has to be a power of two
968
      -- External Interrupts Controller (XIRQ) --
969
      XIRQ_NUM_CH                  : natural := 0;      -- number of external IRQ channels (0..32)
970 62 zero_gravi
      XIRQ_TRIGGER_TYPE            : std_ulogic_vector(31 downto 0) := x"FFFFFFFF"; -- trigger type: 0=level, 1=edge
971
      XIRQ_TRIGGER_POLARITY        : std_ulogic_vector(31 downto 0) := x"FFFFFFFF"; -- trigger polarity: 0=low-level/falling-edge, 1=high-level/rising-edge
972 2 zero_gravi
      -- Processor peripherals --
973 62 zero_gravi
      IO_GPIO_EN                   : boolean := false;  -- implement general purpose input/output port unit (GPIO)?
974
      IO_MTIME_EN                  : boolean := false;  -- implement machine system timer (MTIME)?
975
      IO_UART0_EN                  : boolean := false;  -- implement primary universal asynchronous receiver/transmitter (UART0)?
976 65 zero_gravi
      IO_UART0_RX_FIFO             : natural := 1;      -- RX fifo depth, has to be a power of two, min 1
977
      IO_UART0_TX_FIFO             : natural := 1;      -- TX fifo depth, has to be a power of two, min 1
978 62 zero_gravi
      IO_UART1_EN                  : boolean := false;  -- implement secondary universal asynchronous receiver/transmitter (UART1)?
979 65 zero_gravi
      IO_UART1_RX_FIFO             : natural := 1;      -- RX fifo depth, has to be a power of two, min 1
980
      IO_UART1_TX_FIFO             : natural := 1;      -- TX fifo depth, has to be a power of two, min 1
981 62 zero_gravi
      IO_SPI_EN                    : boolean := false;  -- implement serial peripheral interface (SPI)?
982
      IO_TWI_EN                    : boolean := false;  -- implement two-wire interface (TWI)?
983
      IO_PWM_NUM_CH                : natural := 0;      -- number of PWM channels to implement (0..60); 0 = disabled
984
      IO_WDT_EN                    : boolean := false;  -- implement watch dog timer (WDT)?
985 44 zero_gravi
      IO_TRNG_EN                   : boolean := false;  -- implement true random number generator (TRNG)?
986 47 zero_gravi
      IO_CFS_EN                    : boolean := false;  -- implement custom functions subsystem (CFS)?
987 56 zero_gravi
      IO_CFS_CONFIG                : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom CFS configuration generic
988 52 zero_gravi
      IO_CFS_IN_SIZE               : positive := 32;    -- size of CFS input conduit in bits
989
      IO_CFS_OUT_SIZE              : positive := 32;    -- size of CFS output conduit in bits
990 62 zero_gravi
      IO_NEOLED_EN                 : boolean := false;  -- implement NeoPixel-compatible smart LED interface (NEOLED)?
991 67 zero_gravi
      IO_NEOLED_TX_FIFO            : natural := 1;      -- NEOLED TX FIFO depth, 1..32k, has to be a power of two
992
      IO_GPTMR_EN                  : boolean := false   -- implement general purpose timer (GPTMR)?
993 2 zero_gravi
    );
994
    port (
995
      -- Global control --
996 62 zero_gravi
      clk_i          : in  std_ulogic; -- global clock, rising edge
997
      rstn_i         : in  std_ulogic; -- global reset, low-active, async
998 59 zero_gravi
      -- JTAG on-chip debugger interface --
999 62 zero_gravi
      jtag_trst_i    : in  std_ulogic := 'U'; -- low-active TAP reset (optional)
1000
      jtag_tck_i     : in  std_ulogic := 'U'; -- serial clock
1001
      jtag_tdi_i     : in  std_ulogic := 'U'; -- serial data input
1002 61 zero_gravi
      jtag_tdo_o     : out std_ulogic;        -- serial data output
1003 62 zero_gravi
      jtag_tms_i     : in  std_ulogic := 'U'; -- mode select
1004 49 zero_gravi
      -- Wishbone bus interface (available if MEM_EXT_EN = true) --
1005 61 zero_gravi
      wb_tag_o       : out std_ulogic_vector(02 downto 0); -- request tag
1006
      wb_adr_o       : out std_ulogic_vector(31 downto 0); -- address
1007 62 zero_gravi
      wb_dat_i       : in  std_ulogic_vector(31 downto 0) := (others => 'U'); -- read data
1008 61 zero_gravi
      wb_dat_o       : out std_ulogic_vector(31 downto 0); -- write data
1009
      wb_we_o        : out std_ulogic; -- read/write
1010
      wb_sel_o       : out std_ulogic_vector(03 downto 0); -- byte enable
1011
      wb_stb_o       : out std_ulogic; -- strobe
1012
      wb_cyc_o       : out std_ulogic; -- valid cycle
1013
      wb_lock_o      : out std_ulogic; -- exclusive access request
1014 62 zero_gravi
      wb_ack_i       : in  std_ulogic := 'L'; -- transfer acknowledge
1015
      wb_err_i       : in  std_ulogic := 'L'; -- transfer error
1016 44 zero_gravi
      -- Advanced memory control signals (available if MEM_EXT_EN = true) --
1017 61 zero_gravi
      fence_o        : out std_ulogic; -- indicates an executed FENCE operation
1018
      fencei_o       : out std_ulogic; -- indicates an executed FENCEI operation
1019
      -- TX stream interfaces (available if SLINK_NUM_TX > 0) --
1020
      slink_tx_dat_o : out sdata_8x32_t; -- output data
1021
      slink_tx_val_o : out std_ulogic_vector(7 downto 0); -- valid output
1022 62 zero_gravi
      slink_tx_rdy_i : in  std_ulogic_vector(7 downto 0) := (others => 'L'); -- ready to send
1023 61 zero_gravi
      -- RX stream interfaces (available if SLINK_NUM_RX > 0) --
1024 62 zero_gravi
      slink_rx_dat_i : in  sdata_8x32_t := (others => (others => 'U')); -- input data
1025
      slink_rx_val_i : in  std_ulogic_vector(7 downto 0) := (others => 'L'); -- valid input
1026 61 zero_gravi
      slink_rx_rdy_o : out std_ulogic_vector(7 downto 0); -- ready to receive
1027 49 zero_gravi
      -- GPIO (available if IO_GPIO_EN = true) --
1028 61 zero_gravi
      gpio_o         : out std_ulogic_vector(63 downto 0); -- parallel output
1029 62 zero_gravi
      gpio_i         : in  std_ulogic_vector(63 downto 0) := (others => 'U'); -- parallel input
1030 50 zero_gravi
      -- primary UART0 (available if IO_UART0_EN = true) --
1031 61 zero_gravi
      uart0_txd_o    : out std_ulogic; -- UART0 send data
1032 62 zero_gravi
      uart0_rxd_i    : in  std_ulogic := 'U'; -- UART0 receive data
1033 61 zero_gravi
      uart0_rts_o    : out std_ulogic; -- hw flow control: UART0.RX ready to receive ("RTR"), low-active, optional
1034 62 zero_gravi
      uart0_cts_i    : in  std_ulogic := 'L'; -- hw flow control: UART0.TX allowed to transmit, low-active, optional
1035 50 zero_gravi
      -- secondary UART1 (available if IO_UART1_EN = true) --
1036 61 zero_gravi
      uart1_txd_o    : out std_ulogic; -- UART1 send data
1037 62 zero_gravi
      uart1_rxd_i    : in  std_ulogic := 'U'; -- UART1 receive data
1038 61 zero_gravi
      uart1_rts_o    : out std_ulogic; -- hw flow control: UART1.RX ready to receive ("RTR"), low-active, optional
1039 62 zero_gravi
      uart1_cts_i    : in  std_ulogic := 'L'; -- hw flow control: UART1.TX allowed to transmit, low-active, optional
1040 49 zero_gravi
      -- SPI (available if IO_SPI_EN = true) --
1041 61 zero_gravi
      spi_sck_o      : out std_ulogic; -- SPI serial clock
1042
      spi_sdo_o      : out std_ulogic; -- controller data out, peripheral data in
1043 62 zero_gravi
      spi_sdi_i      : in  std_ulogic := 'U'; -- controller data in, peripheral data out
1044 61 zero_gravi
      spi_csn_o      : out std_ulogic_vector(07 downto 0); -- SPI CS
1045 49 zero_gravi
      -- TWI (available if IO_TWI_EN = true) --
1046 62 zero_gravi
      twi_sda_io     : inout std_logic := 'U'; -- twi serial data line
1047
      twi_scl_io     : inout std_logic := 'U'; -- twi serial clock line
1048 60 zero_gravi
      -- PWM (available if IO_PWM_NUM_CH > 0) --
1049 61 zero_gravi
      pwm_o          : out std_ulogic_vector(IO_PWM_NUM_CH-1 downto 0); -- pwm channels
1050 47 zero_gravi
      -- Custom Functions Subsystem IO --
1051 62 zero_gravi
      cfs_in_i       : in  std_ulogic_vector(IO_CFS_IN_SIZE-1  downto 0) := (others => 'U'); -- custom CFS inputs conduit
1052 61 zero_gravi
      cfs_out_o      : out std_ulogic_vector(IO_CFS_OUT_SIZE-1 downto 0); -- custom CFS outputs conduit
1053 52 zero_gravi
      -- NeoPixel-compatible smart LED interface (available if IO_NEOLED_EN = true) --
1054 61 zero_gravi
      neoled_o       : out std_ulogic; -- async serial data line
1055 59 zero_gravi
      -- System time --
1056 62 zero_gravi
      mtime_i        : in  std_ulogic_vector(63 downto 0) := (others => 'U'); -- current system time from ext. MTIME (if IO_MTIME_EN = false)
1057 61 zero_gravi
      mtime_o        : out std_ulogic_vector(63 downto 0); -- current system time from int. MTIME (if IO_MTIME_EN = true)
1058
      -- External platform interrupts (available if XIRQ_NUM_CH > 0) --
1059 62 zero_gravi
      xirq_i         : in  std_ulogic_vector(XIRQ_NUM_CH-1 downto 0) := (others => 'L'); -- IRQ channels
1060 61 zero_gravi
      -- CPU Interrupts --
1061 62 zero_gravi
      mtime_irq_i    : in  std_ulogic := 'L'; -- machine timer interrupt, available if IO_MTIME_EN = false
1062
      msw_irq_i      : in  std_ulogic := 'L'; -- machine software interrupt
1063
      mext_irq_i     : in  std_ulogic := 'L'  -- machine external interrupt
1064 2 zero_gravi
    );
1065
  end component;
1066
 
1067 4 zero_gravi
  -- Component: CPU Top Entity --------------------------------------------------------------
1068
  -- -------------------------------------------------------------------------------------------
1069
  component neorv32_cpu
1070
    generic (
1071
      -- General --
1072 62 zero_gravi
      HW_THREAD_ID                 : natural; -- hardware thread id (32-bit)
1073
      CPU_BOOT_ADDR                : std_ulogic_vector(31 downto 0); -- cpu boot address
1074
      CPU_DEBUG_ADDR               : std_ulogic_vector(31 downto 0); -- cpu debug mode start address
1075 4 zero_gravi
      -- RISC-V CPU Extensions --
1076 62 zero_gravi
      CPU_EXTENSION_RISCV_A        : boolean; -- implement atomic extension?
1077 66 zero_gravi
      CPU_EXTENSION_RISCV_B        : boolean; -- implement bit-manipulation extension?
1078 62 zero_gravi
      CPU_EXTENSION_RISCV_C        : boolean; -- implement compressed extension?
1079
      CPU_EXTENSION_RISCV_E        : boolean; -- implement embedded RF extension?
1080
      CPU_EXTENSION_RISCV_M        : boolean; -- implement mul/div extension?
1081
      CPU_EXTENSION_RISCV_U        : boolean; -- implement user mode extension?
1082
      CPU_EXTENSION_RISCV_Zfinx    : boolean; -- implement 32-bit floating-point extension (using INT reg!)
1083
      CPU_EXTENSION_RISCV_Zicsr    : boolean; -- implement CSR system?
1084 66 zero_gravi
      CPU_EXTENSION_RISCV_Zicntr   : boolean; -- implement base counters?
1085
      CPU_EXTENSION_RISCV_Zihpm    : boolean; -- implement hardware performance monitors?
1086 62 zero_gravi
      CPU_EXTENSION_RISCV_Zifencei : boolean; -- implement instruction stream sync.?
1087
      CPU_EXTENSION_RISCV_Zmmul    : boolean; -- implement multiply-only M sub-extension?
1088
      CPU_EXTENSION_RISCV_DEBUG    : boolean; -- implement CPU debug mode?
1089 19 zero_gravi
      -- Extension Options --
1090 62 zero_gravi
      FAST_MUL_EN                  : boolean; -- use DSPs for M extension's multiplier
1091
      FAST_SHIFT_EN                : boolean; -- use barrel shifter for shift operations
1092
      CPU_CNT_WIDTH                : natural; -- total width of CPU cycle and instret counters (0..64)
1093
      CPU_IPB_ENTRIES              : natural; -- entries is instruction prefetch buffer, has to be a power of 2
1094 15 zero_gravi
      -- Physical Memory Protection (PMP) --
1095 62 zero_gravi
      PMP_NUM_REGIONS              : natural; -- number of regions (0..64)
1096
      PMP_MIN_GRANULARITY          : natural; -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
1097 42 zero_gravi
      -- Hardware Performance Monitors (HPM) --
1098 62 zero_gravi
      HPM_NUM_CNTS                 : natural; -- number of implemented HPM counters (0..29)
1099
      HPM_CNT_WIDTH                : natural  -- total size of HPM counters (0..64)
1100 4 zero_gravi
    );
1101
    port (
1102
      -- global control --
1103 62 zero_gravi
      clk_i          : in  std_ulogic; -- global clock, rising edge
1104
      rstn_i         : in  std_ulogic; -- global reset, low-active, async
1105 47 zero_gravi
      sleep_o        : out std_ulogic; -- cpu is in sleep mode when set
1106 69 zero_gravi
      debug_o        : out std_ulogic; -- cpu is in debug mode when set
1107 12 zero_gravi
      -- instruction bus interface --
1108
      i_bus_addr_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
1109 62 zero_gravi
      i_bus_rdata_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
1110 12 zero_gravi
      i_bus_wdata_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
1111
      i_bus_ben_o    : out std_ulogic_vector(03 downto 0); -- byte enable
1112
      i_bus_we_o     : out std_ulogic; -- write enable
1113
      i_bus_re_o     : out std_ulogic; -- read enable
1114 57 zero_gravi
      i_bus_lock_o   : out std_ulogic; -- exclusive access request
1115 62 zero_gravi
      i_bus_ack_i    : in  std_ulogic; -- bus transfer acknowledge
1116
      i_bus_err_i    : in  std_ulogic; -- bus transfer error
1117 12 zero_gravi
      i_bus_fence_o  : out std_ulogic; -- executed FENCEI operation
1118 35 zero_gravi
      i_bus_priv_o   : out std_ulogic_vector(1 downto 0); -- privilege level
1119 12 zero_gravi
      -- data bus interface --
1120
      d_bus_addr_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
1121 62 zero_gravi
      d_bus_rdata_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
1122 12 zero_gravi
      d_bus_wdata_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
1123
      d_bus_ben_o    : out std_ulogic_vector(03 downto 0); -- byte enable
1124
      d_bus_we_o     : out std_ulogic; -- write enable
1125
      d_bus_re_o     : out std_ulogic; -- read enable
1126 57 zero_gravi
      d_bus_lock_o   : out std_ulogic; -- exclusive access request
1127 62 zero_gravi
      d_bus_ack_i    : in  std_ulogic; -- bus transfer acknowledge
1128
      d_bus_err_i    : in  std_ulogic; -- bus transfer error
1129 12 zero_gravi
      d_bus_fence_o  : out std_ulogic; -- executed FENCE operation
1130 35 zero_gravi
      d_bus_priv_o   : out std_ulogic_vector(1 downto 0); -- privilege level
1131 11 zero_gravi
      -- system time input from MTIME --
1132 62 zero_gravi
      time_i         : in  std_ulogic_vector(63 downto 0); -- current system time
1133 14 zero_gravi
      -- interrupts (risc-v compliant) --
1134 62 zero_gravi
      msw_irq_i      : in  std_ulogic; -- machine software interrupt
1135
      mext_irq_i     : in  std_ulogic; -- machine external interrupt
1136
      mtime_irq_i    : in  std_ulogic; -- machine timer interrupt
1137 14 zero_gravi
      -- fast interrupts (custom) --
1138 62 zero_gravi
      firq_i         : in  std_ulogic_vector(15 downto 0);
1139 59 zero_gravi
      -- debug mode (halt) request --
1140 62 zero_gravi
      db_halt_req_i  : in  std_ulogic
1141 4 zero_gravi
    );
1142
  end component;
1143
 
1144 2 zero_gravi
  -- Component: CPU Control -----------------------------------------------------------------
1145
  -- -------------------------------------------------------------------------------------------
1146
  component neorv32_cpu_control
1147
    generic (
1148
      -- General --
1149 62 zero_gravi
      HW_THREAD_ID                 : natural;     -- hardware thread id (32-bit)
1150
      CPU_BOOT_ADDR                : std_ulogic_vector(31 downto 0); -- cpu boot address
1151
      CPU_DEBUG_ADDR               : std_ulogic_vector(31 downto 0); -- cpu debug mode start address
1152 2 zero_gravi
      -- RISC-V CPU Extensions --
1153 62 zero_gravi
      CPU_EXTENSION_RISCV_A        : boolean; -- implement atomic extension?
1154 66 zero_gravi
      CPU_EXTENSION_RISCV_B        : boolean; -- implement bit-manipulation extension?
1155 62 zero_gravi
      CPU_EXTENSION_RISCV_C        : boolean; -- implement compressed extension?
1156
      CPU_EXTENSION_RISCV_E        : boolean; -- implement embedded RF extension?
1157
      CPU_EXTENSION_RISCV_M        : boolean; -- implement mul/div extension?
1158
      CPU_EXTENSION_RISCV_U        : boolean; -- implement user mode extension?
1159
      CPU_EXTENSION_RISCV_Zfinx    : boolean; -- implement 32-bit floating-point extension (using INT reg!)
1160
      CPU_EXTENSION_RISCV_Zicsr    : boolean; -- implement CSR system?
1161 66 zero_gravi
      CPU_EXTENSION_RISCV_Zicntr   : boolean; -- implement base counters?
1162
      CPU_EXTENSION_RISCV_Zihpm    : boolean; -- implement hardware performance monitors?
1163 62 zero_gravi
      CPU_EXTENSION_RISCV_Zifencei : boolean; -- implement instruction stream sync.?
1164
      CPU_EXTENSION_RISCV_Zmmul    : boolean; -- implement multiply-only M sub-extension?
1165
      CPU_EXTENSION_RISCV_DEBUG    : boolean; -- implement CPU debug mode?
1166 56 zero_gravi
      -- Extension Options --
1167 62 zero_gravi
      CPU_CNT_WIDTH                : natural; -- total width of CPU cycle and instret counters (0..64)
1168
      CPU_IPB_ENTRIES              : natural; -- entries is instruction prefetch buffer, has to be a power of 2
1169 15 zero_gravi
      -- Physical memory protection (PMP) --
1170 62 zero_gravi
      PMP_NUM_REGIONS              : natural; -- number of regions (0..64)
1171
      PMP_MIN_GRANULARITY          : natural; -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
1172 42 zero_gravi
      -- Hardware Performance Monitors (HPM) --
1173 62 zero_gravi
      HPM_NUM_CNTS                 : natural; -- number of implemented HPM counters (0..29)
1174
      HPM_CNT_WIDTH                : natural  -- total size of HPM counters (0..64)
1175 2 zero_gravi
    );
1176
    port (
1177
      -- global control --
1178
      clk_i         : in  std_ulogic; -- global clock, rising edge
1179
      rstn_i        : in  std_ulogic; -- global reset, low-active, async
1180
      ctrl_o        : out std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
1181
      -- status input --
1182 61 zero_gravi
      alu_idone_i   : in  std_ulogic; -- ALU iterative operation done
1183 12 zero_gravi
      bus_i_wait_i  : in  std_ulogic; -- wait for bus
1184
      bus_d_wait_i  : in  std_ulogic; -- wait for bus
1185 57 zero_gravi
      excl_state_i  : in  std_ulogic; -- atomic/exclusive access lock status
1186 2 zero_gravi
      -- data input --
1187
      instr_i       : in  std_ulogic_vector(data_width_c-1 downto 0); -- instruction
1188
      cmp_i         : in  std_ulogic_vector(1 downto 0); -- comparator status
1189 36 zero_gravi
      alu_add_i     : in  std_ulogic_vector(data_width_c-1 downto 0); -- ALU address result
1190 52 zero_gravi
      rs1_i         : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
1191 2 zero_gravi
      -- data output --
1192
      imm_o         : out std_ulogic_vector(data_width_c-1 downto 0); -- immediate
1193 6 zero_gravi
      fetch_pc_o    : out std_ulogic_vector(data_width_c-1 downto 0); -- PC for instruction fetch
1194
      curr_pc_o     : out std_ulogic_vector(data_width_c-1 downto 0); -- current PC (corresponding to current instruction)
1195 68 zero_gravi
      next_pc_o     : out std_ulogic_vector(data_width_c-1 downto 0); -- next PC (corresponding to next instruction)
1196 2 zero_gravi
      csr_rdata_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- CSR read data
1197 52 zero_gravi
      -- FPU interface --
1198
      fpu_flags_i   : in  std_ulogic_vector(04 downto 0); -- exception flags
1199 59 zero_gravi
      -- debug mode (halt) request --
1200
      db_halt_req_i : in  std_ulogic;
1201 14 zero_gravi
      -- interrupts (risc-v compliant) --
1202
      msw_irq_i     : in  std_ulogic; -- machine software interrupt
1203
      mext_irq_i    : in  std_ulogic; -- machine external interrupt
1204 2 zero_gravi
      mtime_irq_i   : in  std_ulogic; -- machine timer interrupt
1205 14 zero_gravi
      -- fast interrupts (custom) --
1206 48 zero_gravi
      firq_i        : in  std_ulogic_vector(15 downto 0);
1207 11 zero_gravi
      -- system time input from MTIME --
1208
      time_i        : in  std_ulogic_vector(63 downto 0); -- current system time
1209 15 zero_gravi
      -- physical memory protection --
1210
      pmp_addr_o    : out pmp_addr_if_t; -- addresses
1211
      pmp_ctrl_o    : out pmp_ctrl_if_t; -- configs
1212 2 zero_gravi
      -- bus access exceptions --
1213
      mar_i         : in  std_ulogic_vector(data_width_c-1 downto 0); -- memory address register
1214
      ma_instr_i    : in  std_ulogic; -- misaligned instruction address
1215
      ma_load_i     : in  std_ulogic; -- misaligned load data address
1216
      ma_store_i    : in  std_ulogic; -- misaligned store data address
1217
      be_instr_i    : in  std_ulogic; -- bus error on instruction access
1218
      be_load_i     : in  std_ulogic; -- bus error on load data access
1219 12 zero_gravi
      be_store_i    : in  std_ulogic  -- bus error on store data access
1220 2 zero_gravi
    );
1221
  end component;
1222
 
1223
  -- Component: CPU Register File -----------------------------------------------------------
1224
  -- -------------------------------------------------------------------------------------------
1225
  component neorv32_cpu_regfile
1226
    generic (
1227 62 zero_gravi
      CPU_EXTENSION_RISCV_E : boolean -- implement embedded RF extension?
1228 2 zero_gravi
    );
1229
    port (
1230
      -- global control --
1231
      clk_i  : in  std_ulogic; -- global clock, rising edge
1232
      ctrl_i : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
1233
      -- data input --
1234
      mem_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- memory read data
1235
      alu_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
1236
      -- data output --
1237
      rs1_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- operand 1
1238 65 zero_gravi
      rs2_o  : out std_ulogic_vector(data_width_c-1 downto 0)  -- operand 2
1239 2 zero_gravi
    );
1240
  end component;
1241
 
1242
  -- Component: CPU ALU ---------------------------------------------------------------------
1243
  -- -------------------------------------------------------------------------------------------
1244
  component neorv32_cpu_alu
1245 11 zero_gravi
    generic (
1246 61 zero_gravi
      -- RISC-V CPU Extensions --
1247 66 zero_gravi
      CPU_EXTENSION_RISCV_B     : boolean; -- implement bit-manipulation extension?
1248 62 zero_gravi
      CPU_EXTENSION_RISCV_M     : boolean; -- implement mul/div extension?
1249
      CPU_EXTENSION_RISCV_Zmmul : boolean; -- implement multiply-only M sub-extension?
1250
      CPU_EXTENSION_RISCV_Zfinx : boolean; -- implement 32-bit floating-point extension (using INT reg!)
1251 61 zero_gravi
      -- Extension Options --
1252 62 zero_gravi
      FAST_MUL_EN               : boolean; -- use DSPs for M extension's multiplier
1253
      FAST_SHIFT_EN             : boolean  -- use barrel shifter for shift operations
1254 11 zero_gravi
    );
1255 2 zero_gravi
    port (
1256
      -- global control --
1257
      clk_i       : in  std_ulogic; -- global clock, rising edge
1258
      rstn_i      : in  std_ulogic; -- global reset, low-active, async
1259
      ctrl_i      : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
1260
      -- data input --
1261
      rs1_i       : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
1262
      rs2_i       : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 2
1263 68 zero_gravi
      pc_i        : in  std_ulogic_vector(data_width_c-1 downto 0); -- current PC
1264
      pc2_i       : in  std_ulogic_vector(data_width_c-1 downto 0); -- next PC
1265 2 zero_gravi
      imm_i       : in  std_ulogic_vector(data_width_c-1 downto 0); -- immediate
1266 61 zero_gravi
      csr_i       : in  std_ulogic_vector(data_width_c-1 downto 0); -- CSR read data
1267 2 zero_gravi
      -- data output --
1268 65 zero_gravi
      cmp_o       : out std_ulogic_vector(1 downto 0); -- comparator status
1269 2 zero_gravi
      res_o       : out std_ulogic_vector(data_width_c-1 downto 0); -- ALU result
1270 36 zero_gravi
      add_o       : out std_ulogic_vector(data_width_c-1 downto 0); -- address computation result
1271 61 zero_gravi
      fpu_flags_o : out std_ulogic_vector(4 downto 0); -- FPU exception flags
1272 2 zero_gravi
      -- status --
1273 61 zero_gravi
      idone_o     : out std_ulogic -- iterative processing units done?
1274 2 zero_gravi
    );
1275
  end component;
1276
 
1277 61 zero_gravi
  -- Component: CPU Co-Processor SHIFTER ----------------------------------------------------
1278
  -- -------------------------------------------------------------------------------------------
1279
  component neorv32_cpu_cp_shifter
1280
    generic (
1281 62 zero_gravi
      FAST_SHIFT_EN : boolean -- use barrel shifter for shift operations
1282 61 zero_gravi
    );
1283
    port (
1284
      -- global control --
1285
      clk_i   : in  std_ulogic; -- global clock, rising edge
1286
      rstn_i  : in  std_ulogic; -- global reset, low-active, async
1287
      ctrl_i  : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
1288
      start_i : in  std_ulogic; -- trigger operation
1289
      -- data input --
1290
      rs1_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
1291 66 zero_gravi
      shamt_i : in  std_ulogic_vector(index_size_f(data_width_c)-1 downto 0); -- shift amount
1292 61 zero_gravi
      -- result and status --
1293
      res_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- operation result
1294
      valid_o : out std_ulogic -- data output valid
1295
    );
1296
  end component;
1297
 
1298 44 zero_gravi
  -- Component: CPU Co-Processor MULDIV ('M' extension) -------------------------------------
1299 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
1300
  component neorv32_cpu_cp_muldiv
1301 19 zero_gravi
    generic (
1302 62 zero_gravi
      FAST_MUL_EN : boolean; -- use DSPs for faster multiplication
1303
      DIVISION_EN : boolean  -- implement divider hardware
1304 19 zero_gravi
    );
1305 2 zero_gravi
    port (
1306
      -- global control --
1307
      clk_i   : in  std_ulogic; -- global clock, rising edge
1308
      rstn_i  : in  std_ulogic; -- global reset, low-active, async
1309
      ctrl_i  : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
1310 36 zero_gravi
      start_i : in  std_ulogic; -- trigger operation
1311 2 zero_gravi
      -- data input --
1312
      rs1_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
1313
      rs2_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 2
1314
      -- result and status --
1315
      res_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- operation result
1316
      valid_o : out std_ulogic -- data output valid
1317
    );
1318
  end component;
1319
 
1320 63 zero_gravi
  -- Component: CPU Co-Processor Bit-Manipulation Unit ('B' extension) ----------------------
1321
  -- -------------------------------------------------------------------------------------------
1322
  component neorv32_cpu_cp_bitmanip is
1323
    generic (
1324 66 zero_gravi
      FAST_SHIFT_EN : boolean  -- use barrel shifter for shift operations
1325 63 zero_gravi
    );
1326
    port (
1327
      -- global control --
1328
      clk_i   : in  std_ulogic; -- global clock, rising edge
1329
      rstn_i  : in  std_ulogic; -- global reset, low-active, async
1330
      ctrl_i  : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
1331
      start_i : in  std_ulogic; -- trigger operation
1332
      -- data input --
1333
      cmp_i   : in  std_ulogic_vector(1 downto 0); -- comparator status
1334
      rs1_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
1335
      rs2_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 2
1336 66 zero_gravi
      shamt_i : in  std_ulogic_vector(index_size_f(data_width_c)-1 downto 0); -- shift amount
1337 63 zero_gravi
      -- result and status --
1338
      res_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- operation result
1339
      valid_o : out std_ulogic -- data output valid
1340
    );
1341
  end component;
1342
 
1343 53 zero_gravi
  -- Component: CPU Co-Processor 32-bit FPU ('Zfinx' extension) -----------------------------
1344 52 zero_gravi
  -- -------------------------------------------------------------------------------------------
1345
  component neorv32_cpu_cp_fpu
1346
    port (
1347
      -- global control --
1348 53 zero_gravi
      clk_i    : in  std_ulogic; -- global clock, rising edge
1349
      rstn_i   : in  std_ulogic; -- global reset, low-active, async
1350
      ctrl_i   : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
1351
      start_i  : in  std_ulogic; -- trigger operation
1352 52 zero_gravi
      -- data input --
1353 56 zero_gravi
      cmp_i    : in  std_ulogic_vector(1 downto 0); -- comparator status
1354 53 zero_gravi
      rs1_i    : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 1
1355
      rs2_i    : in  std_ulogic_vector(data_width_c-1 downto 0); -- rf source 2
1356 52 zero_gravi
      -- result and status --
1357 53 zero_gravi
      res_o    : out std_ulogic_vector(data_width_c-1 downto 0); -- operation result
1358
      fflags_o : out std_ulogic_vector(4 downto 0); -- exception flags
1359
      valid_o  : out std_ulogic -- data output valid
1360 52 zero_gravi
    );
1361
  end component;
1362
 
1363 2 zero_gravi
  -- Component: CPU Bus Interface -----------------------------------------------------------
1364
  -- -------------------------------------------------------------------------------------------
1365
  component neorv32_cpu_bus
1366
    generic (
1367 62 zero_gravi
      CPU_EXTENSION_RISCV_A : boolean; -- implement atomic extension?
1368
      CPU_EXTENSION_RISCV_C : boolean; -- implement compressed extension?
1369 15 zero_gravi
      -- Physical memory protection (PMP) --
1370 62 zero_gravi
      PMP_NUM_REGIONS       : natural; -- number of regions (0..64)
1371
      PMP_MIN_GRANULARITY   : natural  -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
1372 2 zero_gravi
    );
1373
    port (
1374
      -- global control --
1375 12 zero_gravi
      clk_i          : in  std_ulogic; -- global clock, rising edge
1376 38 zero_gravi
      rstn_i      : in  std_ulogic := '0'; -- global reset, low-active, async
1377 12 zero_gravi
      ctrl_i         : in  std_ulogic_vector(ctrl_width_c-1 downto 0); -- main control bus
1378
      -- cpu instruction fetch interface --
1379
      fetch_pc_i     : in  std_ulogic_vector(data_width_c-1 downto 0); -- PC for instruction fetch
1380
      instr_o        : out std_ulogic_vector(data_width_c-1 downto 0); -- instruction
1381
      i_wait_o       : out std_ulogic; -- wait for fetch to complete
1382
      --
1383
      ma_instr_o     : out std_ulogic; -- misaligned instruction address
1384
      be_instr_o     : out std_ulogic; -- bus error on instruction access
1385
      -- cpu data access interface --
1386
      addr_i         : in  std_ulogic_vector(data_width_c-1 downto 0); -- ALU result -> access address
1387
      wdata_i        : in  std_ulogic_vector(data_width_c-1 downto 0); -- write data
1388
      rdata_o        : out std_ulogic_vector(data_width_c-1 downto 0); -- read data
1389
      mar_o          : out std_ulogic_vector(data_width_c-1 downto 0); -- current memory address register
1390
      d_wait_o       : out std_ulogic; -- wait for access to complete
1391
      --
1392 57 zero_gravi
      excl_state_o   : out std_ulogic; -- atomic/exclusive access status
1393 12 zero_gravi
      ma_load_o      : out std_ulogic; -- misaligned load data address
1394
      ma_store_o     : out std_ulogic; -- misaligned store data address
1395
      be_load_o      : out std_ulogic; -- bus error on load data access
1396
      be_store_o     : out std_ulogic; -- bus error on store data access
1397 15 zero_gravi
      -- physical memory protection --
1398
      pmp_addr_i     : in  pmp_addr_if_t; -- addresses
1399
      pmp_ctrl_i     : in  pmp_ctrl_if_t; -- configs
1400 12 zero_gravi
      -- instruction bus --
1401
      i_bus_addr_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
1402
      i_bus_rdata_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
1403
      i_bus_wdata_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
1404
      i_bus_ben_o    : out std_ulogic_vector(03 downto 0); -- byte enable
1405
      i_bus_we_o     : out std_ulogic; -- write enable
1406
      i_bus_re_o     : out std_ulogic; -- read enable
1407 57 zero_gravi
      i_bus_lock_o   : out std_ulogic; -- exclusive access request
1408 12 zero_gravi
      i_bus_ack_i    : in  std_ulogic; -- bus transfer acknowledge
1409
      i_bus_err_i    : in  std_ulogic; -- bus transfer error
1410
      i_bus_fence_o  : out std_ulogic; -- fence operation
1411
      -- data bus --
1412
      d_bus_addr_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
1413
      d_bus_rdata_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
1414
      d_bus_wdata_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
1415
      d_bus_ben_o    : out std_ulogic_vector(03 downto 0); -- byte enable
1416
      d_bus_we_o     : out std_ulogic; -- write enable
1417
      d_bus_re_o     : out std_ulogic; -- read enable
1418 57 zero_gravi
      d_bus_lock_o   : out std_ulogic; -- exclusive access request
1419 12 zero_gravi
      d_bus_ack_i    : in  std_ulogic; -- bus transfer acknowledge
1420
      d_bus_err_i    : in  std_ulogic; -- bus transfer error
1421 57 zero_gravi
      d_bus_fence_o  : out std_ulogic  -- fence operation
1422 2 zero_gravi
    );
1423
  end component;
1424
 
1425 57 zero_gravi
  -- Component: Bus Keeper ------------------------------------------------------------------
1426
  -- -------------------------------------------------------------------------------------------
1427
  component neorv32_bus_keeper is
1428
    port (
1429
      -- host access --
1430 66 zero_gravi
      clk_i      : in  std_ulogic; -- global clock line
1431
      rstn_i     : in  std_ulogic; -- global reset, low-active, async
1432
      addr_i     : in  std_ulogic_vector(31 downto 0); -- address
1433
      rden_i     : in  std_ulogic; -- read enable
1434
      wren_i     : in  std_ulogic; -- write enable
1435
      data_o     : out std_ulogic_vector(31 downto 0); -- data out
1436
      ack_o      : out std_ulogic; -- transfer acknowledge
1437
      err_o      : out std_ulogic; -- transfer error
1438
      -- bus monitoring --
1439
      bus_addr_i : in  std_ulogic_vector(31 downto 0); -- address
1440
      bus_rden_i : in  std_ulogic; -- read enable
1441
      bus_wren_i : in  std_ulogic; -- write enable
1442
      bus_ack_i  : in  std_ulogic; -- transfer acknowledge from bus system
1443 68 zero_gravi
      bus_err_i  : in  std_ulogic; -- transfer error from bus system
1444
      bus_tmo_i  : in  std_ulogic; -- transfer timeout (external interface)
1445
      bus_ext_i  : in  std_ulogic  -- external bus access
1446 57 zero_gravi
    );
1447
  end component;
1448
 
1449 45 zero_gravi
  -- Component: CPU Instruction Cache -------------------------------------------------------
1450 41 zero_gravi
  -- -------------------------------------------------------------------------------------------
1451 45 zero_gravi
  component neorv32_icache
1452 41 zero_gravi
    generic (
1453 62 zero_gravi
      ICACHE_NUM_BLOCKS : natural; -- number of blocks (min 1), has to be a power of 2
1454
      ICACHE_BLOCK_SIZE : natural; -- block size in bytes (min 4), has to be a power of 2
1455
      ICACHE_NUM_SETS   : natural  -- associativity / number of sets (1=direct_mapped), has to be a power of 2
1456 41 zero_gravi
    );
1457
    port (
1458
      -- global control --
1459
      clk_i         : in  std_ulogic; -- global clock, rising edge
1460
      rstn_i        : in  std_ulogic; -- global reset, low-active, async
1461
      clear_i       : in  std_ulogic; -- cache clear
1462
      -- host controller interface --
1463
      host_addr_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
1464
      host_rdata_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
1465
      host_wdata_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
1466
      host_ben_i    : in  std_ulogic_vector(03 downto 0); -- byte enable
1467
      host_we_i     : in  std_ulogic; -- write enable
1468
      host_re_i     : in  std_ulogic; -- read enable
1469
      host_ack_o    : out std_ulogic; -- bus transfer acknowledge
1470
      host_err_o    : out std_ulogic; -- bus transfer error
1471
      -- peripheral bus interface --
1472
      bus_addr_o    : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
1473
      bus_rdata_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
1474
      bus_wdata_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
1475
      bus_ben_o     : out std_ulogic_vector(03 downto 0); -- byte enable
1476
      bus_we_o      : out std_ulogic; -- write enable
1477
      bus_re_o      : out std_ulogic; -- read enable
1478
      bus_ack_i     : in  std_ulogic; -- bus transfer acknowledge
1479
      bus_err_i     : in  std_ulogic  -- bus transfer error
1480
    );
1481
  end component;
1482
 
1483 12 zero_gravi
  -- Component: CPU Bus Switch --------------------------------------------------------------
1484
  -- -------------------------------------------------------------------------------------------
1485
  component neorv32_busswitch
1486
    generic (
1487 62 zero_gravi
      PORT_CA_READ_ONLY : boolean; -- set if controller port A is read-only
1488
      PORT_CB_READ_ONLY : boolean  -- set if controller port B is read-only
1489 12 zero_gravi
    );
1490
    port (
1491
      -- global control --
1492
      clk_i           : in  std_ulogic; -- global clock, rising edge
1493
      rstn_i          : in  std_ulogic; -- global reset, low-active, async
1494
      -- controller interface a --
1495
      ca_bus_addr_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
1496
      ca_bus_rdata_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
1497
      ca_bus_wdata_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
1498
      ca_bus_ben_i    : in  std_ulogic_vector(03 downto 0); -- byte enable
1499
      ca_bus_we_i     : in  std_ulogic; -- write enable
1500
      ca_bus_re_i     : in  std_ulogic; -- read enable
1501 57 zero_gravi
      ca_bus_lock_i   : in  std_ulogic; -- exclusive access request
1502 12 zero_gravi
      ca_bus_ack_o    : out std_ulogic; -- bus transfer acknowledge
1503
      ca_bus_err_o    : out std_ulogic; -- bus transfer error
1504
      -- controller interface b --
1505
      cb_bus_addr_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
1506
      cb_bus_rdata_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
1507
      cb_bus_wdata_i  : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
1508
      cb_bus_ben_i    : in  std_ulogic_vector(03 downto 0); -- byte enable
1509
      cb_bus_we_i     : in  std_ulogic; -- write enable
1510
      cb_bus_re_i     : in  std_ulogic; -- read enable
1511 57 zero_gravi
      cb_bus_lock_i   : in  std_ulogic; -- exclusive access request
1512 12 zero_gravi
      cb_bus_ack_o    : out std_ulogic; -- bus transfer acknowledge
1513
      cb_bus_err_o    : out std_ulogic; -- bus transfer error
1514
      -- peripheral bus --
1515 36 zero_gravi
      p_bus_src_o     : out std_ulogic; -- access source: 0 = A, 1 = B
1516 12 zero_gravi
      p_bus_addr_o    : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
1517
      p_bus_rdata_i   : in  std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
1518
      p_bus_wdata_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
1519
      p_bus_ben_o     : out std_ulogic_vector(03 downto 0); -- byte enable
1520
      p_bus_we_o      : out std_ulogic; -- write enable
1521
      p_bus_re_o      : out std_ulogic; -- read enable
1522 57 zero_gravi
      p_bus_lock_o    : out std_ulogic; -- exclusive access request
1523 12 zero_gravi
      p_bus_ack_i     : in  std_ulogic; -- bus transfer acknowledge
1524
      p_bus_err_i     : in  std_ulogic  -- bus transfer error
1525
    );
1526
  end component;
1527
 
1528 2 zero_gravi
  -- Component: CPU Compressed Instructions Decompressor ------------------------------------
1529
  -- -------------------------------------------------------------------------------------------
1530
  component neorv32_cpu_decompressor
1531
    port (
1532
      -- instruction input --
1533
      ci_instr16_i : in  std_ulogic_vector(15 downto 0); -- compressed instruction input
1534
      -- instruction output --
1535
      ci_illegal_o : out std_ulogic; -- is an illegal compressed instruction
1536
      ci_instr32_o : out std_ulogic_vector(31 downto 0)  -- 32-bit decompressed instruction
1537
    );
1538
  end component;
1539
 
1540
  -- Component: Processor-internal instruction memory (IMEM) --------------------------------
1541
  -- -------------------------------------------------------------------------------------------
1542
  component neorv32_imem
1543
    generic (
1544 62 zero_gravi
      IMEM_BASE    : std_ulogic_vector(31 downto 0); -- memory base address
1545
      IMEM_SIZE    : natural; -- processor-internal instruction memory size in bytes
1546
      IMEM_AS_IROM : boolean  -- implement IMEM as pre-initialized read-only memory?
1547 2 zero_gravi
    );
1548
    port (
1549
      clk_i  : in  std_ulogic; -- global clock line
1550
      rden_i : in  std_ulogic; -- read enable
1551
      wren_i : in  std_ulogic; -- write enable
1552
      ben_i  : in  std_ulogic_vector(03 downto 0); -- byte write enable
1553
      addr_i : in  std_ulogic_vector(31 downto 0); -- address
1554
      data_i : in  std_ulogic_vector(31 downto 0); -- data in
1555
      data_o : out std_ulogic_vector(31 downto 0); -- data out
1556
      ack_o  : out std_ulogic -- transfer acknowledge
1557
    );
1558
  end component;
1559
 
1560
  -- Component: Processor-internal data memory (DMEM) ---------------------------------------
1561
  -- -------------------------------------------------------------------------------------------
1562
  component neorv32_dmem
1563
    generic (
1564 62 zero_gravi
      DMEM_BASE : std_ulogic_vector(31 downto 0); -- memory base address
1565
      DMEM_SIZE : natural -- processor-internal instruction memory size in bytes
1566 2 zero_gravi
    );
1567
    port (
1568
      clk_i  : in  std_ulogic; -- global clock line
1569
      rden_i : in  std_ulogic; -- read enable
1570
      wren_i : in  std_ulogic; -- write enable
1571
      ben_i  : in  std_ulogic_vector(03 downto 0); -- byte write enable
1572
      addr_i : in  std_ulogic_vector(31 downto 0); -- address
1573
      data_i : in  std_ulogic_vector(31 downto 0); -- data in
1574
      data_o : out std_ulogic_vector(31 downto 0); -- data out
1575
      ack_o  : out std_ulogic -- transfer acknowledge
1576
    );
1577
  end component;
1578
 
1579
  -- Component: Processor-internal bootloader ROM (BOOTROM) ---------------------------------
1580
  -- -------------------------------------------------------------------------------------------
1581
  component neorv32_boot_rom
1582 23 zero_gravi
    generic (
1583 62 zero_gravi
      BOOTROM_BASE : std_ulogic_vector(31 downto 0) -- boot ROM base address
1584 23 zero_gravi
    );
1585 2 zero_gravi
    port (
1586
      clk_i  : in  std_ulogic; -- global clock line
1587
      rden_i : in  std_ulogic; -- read enable
1588
      addr_i : in  std_ulogic_vector(31 downto 0); -- address
1589
      data_o : out std_ulogic_vector(31 downto 0); -- data out
1590
      ack_o  : out std_ulogic -- transfer acknowledge
1591
    );
1592
  end component;
1593
 
1594
  -- Component: Machine System Timer (mtime) ------------------------------------------------
1595
  -- -------------------------------------------------------------------------------------------
1596
  component neorv32_mtime
1597
    port (
1598
      -- host access --
1599 60 zero_gravi
      clk_i  : in  std_ulogic; -- global clock line
1600
      addr_i : in  std_ulogic_vector(31 downto 0); -- address
1601
      rden_i : in  std_ulogic; -- read enable
1602
      wren_i : in  std_ulogic; -- write enable
1603
      data_i : in  std_ulogic_vector(31 downto 0); -- data in
1604
      data_o : out std_ulogic_vector(31 downto 0); -- data out
1605
      ack_o  : out std_ulogic; -- transfer acknowledge
1606 11 zero_gravi
      -- time output for CPU --
1607 60 zero_gravi
      time_o : out std_ulogic_vector(63 downto 0); -- current system time
1608 2 zero_gravi
      -- interrupt --
1609 60 zero_gravi
      irq_o  : out std_ulogic  -- interrupt request
1610 2 zero_gravi
    );
1611
  end component;
1612
 
1613
  -- Component: General Purpose Input/Output Port (GPIO) ------------------------------------
1614
  -- -------------------------------------------------------------------------------------------
1615
  component neorv32_gpio
1616
    port (
1617
      -- host access --
1618
      clk_i  : in  std_ulogic; -- global clock line
1619
      addr_i : in  std_ulogic_vector(31 downto 0); -- address
1620
      rden_i : in  std_ulogic; -- read enable
1621
      wren_i : in  std_ulogic; -- write enable
1622
      data_i : in  std_ulogic_vector(31 downto 0); -- data in
1623
      data_o : out std_ulogic_vector(31 downto 0); -- data out
1624
      ack_o  : out std_ulogic; -- transfer acknowledge
1625
      -- parallel io --
1626 61 zero_gravi
      gpio_o : out std_ulogic_vector(63 downto 0);
1627
      gpio_i : in  std_ulogic_vector(63 downto 0)
1628 2 zero_gravi
    );
1629
  end component;
1630
 
1631
  -- Component: Watchdog Timer (WDT) --------------------------------------------------------
1632
  -- -------------------------------------------------------------------------------------------
1633
  component neorv32_wdt
1634 69 zero_gravi
    generic (
1635
      DEBUG_EN : boolean -- CPU debug mode implemented?
1636
    );
1637 2 zero_gravi
    port (
1638
      -- host access --
1639
      clk_i       : in  std_ulogic; -- global clock line
1640
      rstn_i      : in  std_ulogic; -- global reset line, low-active
1641
      rden_i      : in  std_ulogic; -- read enable
1642
      wren_i      : in  std_ulogic; -- write enable
1643
      addr_i      : in  std_ulogic_vector(31 downto 0); -- address
1644
      data_i      : in  std_ulogic_vector(31 downto 0); -- data in
1645
      data_o      : out std_ulogic_vector(31 downto 0); -- data out
1646
      ack_o       : out std_ulogic; -- transfer acknowledge
1647 69 zero_gravi
      -- CPU in debug mode? --
1648
      cpu_debug_i : in  std_ulogic;
1649 2 zero_gravi
      -- clock generator --
1650
      clkgen_en_o : out std_ulogic; -- enable clock generator
1651
      clkgen_i    : in  std_ulogic_vector(07 downto 0);
1652
      -- timeout event --
1653
      irq_o       : out std_ulogic; -- timeout IRQ
1654
      rstn_o      : out std_ulogic  -- timeout reset, low_active, use it as async!
1655
    );
1656
  end component;
1657
 
1658
  -- Component: Universal Asynchronous Receiver and Transmitter (UART) ----------------------
1659
  -- -------------------------------------------------------------------------------------------
1660
  component neorv32_uart
1661 50 zero_gravi
    generic (
1662 65 zero_gravi
      UART_PRIMARY : boolean; -- true = primary UART (UART0), false = secondary UART (UART1)
1663
      UART_RX_FIFO : natural; -- RX fifo depth, has to be a power of two, min 1
1664
      UART_TX_FIFO : natural  -- TX fifo depth, has to be a power of two, min 1
1665 50 zero_gravi
    );
1666 2 zero_gravi
    port (
1667
      -- host access --
1668
      clk_i       : in  std_ulogic; -- global clock line
1669
      addr_i      : in  std_ulogic_vector(31 downto 0); -- address
1670
      rden_i      : in  std_ulogic; -- read enable
1671
      wren_i      : in  std_ulogic; -- write enable
1672
      data_i      : in  std_ulogic_vector(31 downto 0); -- data in
1673
      data_o      : out std_ulogic_vector(31 downto 0); -- data out
1674
      ack_o       : out std_ulogic; -- transfer acknowledge
1675
      -- clock generator --
1676
      clkgen_en_o : out std_ulogic; -- enable clock generator
1677
      clkgen_i    : in  std_ulogic_vector(07 downto 0);
1678
      -- com lines --
1679
      uart_txd_o  : out std_ulogic;
1680
      uart_rxd_i  : in  std_ulogic;
1681 51 zero_gravi
      -- hardware flow control --
1682
      uart_rts_o  : out std_ulogic; -- UART.RX ready to receive ("RTR"), low-active, optional
1683
      uart_cts_i  : in  std_ulogic; -- UART.TX allowed to transmit, low-active, optional
1684 2 zero_gravi
      -- interrupts --
1685 48 zero_gravi
      irq_rxd_o   : out std_ulogic; -- uart data received interrupt
1686
      irq_txd_o   : out std_ulogic  -- uart transmission done interrupt
1687 2 zero_gravi
    );
1688
  end component;
1689
 
1690
  -- Component: Serial Peripheral Interface (SPI) -------------------------------------------
1691
  -- -------------------------------------------------------------------------------------------
1692
  component neorv32_spi
1693
    port (
1694
      -- host access --
1695
      clk_i       : in  std_ulogic; -- global clock line
1696
      addr_i      : in  std_ulogic_vector(31 downto 0); -- address
1697
      rden_i      : in  std_ulogic; -- read enable
1698
      wren_i      : in  std_ulogic; -- write enable
1699
      data_i      : in  std_ulogic_vector(31 downto 0); -- data in
1700
      data_o      : out std_ulogic_vector(31 downto 0); -- data out
1701
      ack_o       : out std_ulogic; -- transfer acknowledge
1702
      -- clock generator --
1703
      clkgen_en_o : out std_ulogic; -- enable clock generator
1704
      clkgen_i    : in  std_ulogic_vector(07 downto 0);
1705
      -- com lines --
1706 6 zero_gravi
      spi_sck_o   : out std_ulogic; -- SPI serial clock
1707
      spi_sdo_o   : out std_ulogic; -- controller data out, peripheral data in
1708
      spi_sdi_i   : in  std_ulogic; -- controller data in, peripheral data out
1709 2 zero_gravi
      spi_csn_o   : out std_ulogic_vector(07 downto 0); -- SPI CS
1710
      -- interrupt --
1711 48 zero_gravi
      irq_o       : out std_ulogic -- transmission done interrupt
1712 2 zero_gravi
    );
1713
  end component;
1714
 
1715
  -- Component: Two-Wire Interface (TWI) ----------------------------------------------------
1716
  -- -------------------------------------------------------------------------------------------
1717
  component neorv32_twi
1718
    port (
1719
      -- host access --
1720
      clk_i       : in  std_ulogic; -- global clock line
1721
      addr_i      : in  std_ulogic_vector(31 downto 0); -- address
1722
      rden_i      : in  std_ulogic; -- read enable
1723
      wren_i      : in  std_ulogic; -- write enable
1724
      data_i      : in  std_ulogic_vector(31 downto 0); -- data in
1725
      data_o      : out std_ulogic_vector(31 downto 0); -- data out
1726
      ack_o       : out std_ulogic; -- transfer acknowledge
1727
      -- clock generator --
1728
      clkgen_en_o : out std_ulogic; -- enable clock generator
1729
      clkgen_i    : in  std_ulogic_vector(07 downto 0);
1730
      -- com lines --
1731
      twi_sda_io  : inout std_logic; -- serial data line
1732
      twi_scl_io  : inout std_logic; -- serial clock line
1733
      -- interrupt --
1734 48 zero_gravi
      irq_o       : out std_ulogic -- transfer done IRQ
1735 2 zero_gravi
    );
1736
  end component;
1737
 
1738
  -- Component: Pulse-Width Modulation Controller (PWM) -------------------------------------
1739
  -- -------------------------------------------------------------------------------------------
1740
  component neorv32_pwm
1741 60 zero_gravi
    generic (
1742 62 zero_gravi
      NUM_CHANNELS : natural -- number of PWM channels (0..60)
1743 60 zero_gravi
    );
1744 2 zero_gravi
    port (
1745
      -- host access --
1746
      clk_i       : in  std_ulogic; -- global clock line
1747
      addr_i      : in  std_ulogic_vector(31 downto 0); -- address
1748
      rden_i      : in  std_ulogic; -- read enable
1749
      wren_i      : in  std_ulogic; -- write enable
1750
      data_i      : in  std_ulogic_vector(31 downto 0); -- data in
1751
      data_o      : out std_ulogic_vector(31 downto 0); -- data out
1752
      ack_o       : out std_ulogic; -- transfer acknowledge
1753
      -- clock generator --
1754
      clkgen_en_o : out std_ulogic; -- enable clock generator
1755
      clkgen_i    : in  std_ulogic_vector(07 downto 0);
1756
      -- pwm output channels --
1757 60 zero_gravi
      pwm_o       : out std_ulogic_vector(NUM_CHANNELS-1 downto 0)
1758 2 zero_gravi
    );
1759
  end component;
1760
 
1761
  -- Component: True Random Number Generator (TRNG) -----------------------------------------
1762
  -- -------------------------------------------------------------------------------------------
1763
  component neorv32_trng
1764
    port (
1765
      -- host access --
1766
      clk_i  : in  std_ulogic; -- global clock line
1767
      addr_i : in  std_ulogic_vector(31 downto 0); -- address
1768
      rden_i : in  std_ulogic; -- read enable
1769
      wren_i : in  std_ulogic; -- write enable
1770
      data_i : in  std_ulogic_vector(31 downto 0); -- data in
1771
      data_o : out std_ulogic_vector(31 downto 0); -- data out
1772
      ack_o  : out std_ulogic  -- transfer acknowledge
1773
    );
1774
  end component;
1775
 
1776
  -- Component: Wishbone Bus Gateway (WISHBONE) ---------------------------------------------
1777
  -- -------------------------------------------------------------------------------------------
1778
  component neorv32_wishbone
1779
    generic (
1780 23 zero_gravi
      -- Internal instruction memory --
1781 62 zero_gravi
      MEM_INT_IMEM_EN   : boolean; -- implement processor-internal instruction memory
1782
      MEM_INT_IMEM_SIZE : natural; -- size of processor-internal instruction memory in bytes
1783 23 zero_gravi
      -- Internal data memory --
1784 62 zero_gravi
      MEM_INT_DMEM_EN   : boolean; -- implement processor-internal data memory
1785
      MEM_INT_DMEM_SIZE : natural; -- size of processor-internal data memory in bytes
1786
      -- Interface Configuration --
1787
      BUS_TIMEOUT       : natural; -- cycles after an UNACKNOWLEDGED bus access triggers a bus fault exception
1788
      PIPE_MODE         : boolean; -- protocol: false=classic/standard wishbone mode, true=pipelined wishbone mode
1789
      BIG_ENDIAN        : boolean; -- byte order: true=big-endian, false=little-endian
1790
      ASYNC_RX          : boolean  -- use register buffer for RX data when false
1791 2 zero_gravi
    );
1792
    port (
1793
      -- global control --
1794 57 zero_gravi
      clk_i     : in  std_ulogic; -- global clock line
1795
      rstn_i    : in  std_ulogic; -- global reset line, low-active
1796 2 zero_gravi
      -- host access --
1797 57 zero_gravi
      src_i     : in  std_ulogic; -- access type (0: data, 1:instruction)
1798
      addr_i    : in  std_ulogic_vector(31 downto 0); -- address
1799
      rden_i    : in  std_ulogic; -- read enable
1800
      wren_i    : in  std_ulogic; -- write enable
1801
      ben_i     : in  std_ulogic_vector(03 downto 0); -- byte write enable
1802
      data_i    : in  std_ulogic_vector(31 downto 0); -- data in
1803
      data_o    : out std_ulogic_vector(31 downto 0); -- data out
1804
      lock_i    : in  std_ulogic; -- exclusive access request
1805
      ack_o     : out std_ulogic; -- transfer acknowledge
1806
      err_o     : out std_ulogic; -- transfer error
1807 68 zero_gravi
      tmo_o     : out std_ulogic; -- transfer timeout
1808 57 zero_gravi
      priv_i    : in  std_ulogic_vector(01 downto 0); -- current CPU privilege level
1809 68 zero_gravi
      ext_o     : out std_ulogic; -- active external access
1810 2 zero_gravi
      -- wishbone interface --
1811 57 zero_gravi
      wb_tag_o  : out std_ulogic_vector(02 downto 0); -- request tag
1812
      wb_adr_o  : out std_ulogic_vector(31 downto 0); -- address
1813
      wb_dat_i  : in  std_ulogic_vector(31 downto 0); -- read data
1814
      wb_dat_o  : out std_ulogic_vector(31 downto 0); -- write data
1815
      wb_we_o   : out std_ulogic; -- read/write
1816
      wb_sel_o  : out std_ulogic_vector(03 downto 0); -- byte enable
1817
      wb_stb_o  : out std_ulogic; -- strobe
1818
      wb_cyc_o  : out std_ulogic; -- valid cycle
1819
      wb_lock_o : out std_ulogic; -- exclusive access request
1820
      wb_ack_i  : in  std_ulogic; -- transfer acknowledge
1821
      wb_err_i  : in  std_ulogic  -- transfer error
1822 2 zero_gravi
    );
1823
  end component;
1824
 
1825 47 zero_gravi
  -- Component: Custom Functions Subsystem (CFS) --------------------------------------------
1826 23 zero_gravi
  -- -------------------------------------------------------------------------------------------
1827 47 zero_gravi
  component neorv32_cfs
1828
    generic (
1829 52 zero_gravi
      CFS_CONFIG   : std_ulogic_vector(31 downto 0); -- custom CFS configuration generic
1830 62 zero_gravi
      CFS_IN_SIZE  : positive; -- size of CFS input conduit in bits
1831
      CFS_OUT_SIZE : positive  -- size of CFS output conduit in bits
1832 23 zero_gravi
    );
1833 34 zero_gravi
    port (
1834
      -- host access --
1835
      clk_i       : in  std_ulogic; -- global clock line
1836
      rstn_i      : in  std_ulogic; -- global reset line, low-active, use as async
1837
      addr_i      : in  std_ulogic_vector(31 downto 0); -- address
1838
      rden_i      : in  std_ulogic; -- read enable
1839 47 zero_gravi
      wren_i      : in  std_ulogic; -- word write enable
1840 34 zero_gravi
      data_i      : in  std_ulogic_vector(31 downto 0); -- data in
1841
      data_o      : out std_ulogic_vector(31 downto 0); -- data out
1842
      ack_o       : out std_ulogic; -- transfer acknowledge
1843 68 zero_gravi
      err_o       : out std_ulogic; -- transfer error
1844 34 zero_gravi
      -- clock generator --
1845
      clkgen_en_o : out std_ulogic; -- enable clock generator
1846 47 zero_gravi
      clkgen_i    : in  std_ulogic_vector(07 downto 0); -- "clock" inputs
1847
      -- interrupt --
1848
      irq_o       : out std_ulogic; -- interrupt request
1849
      -- custom io (conduit) --
1850 62 zero_gravi
      cfs_in_i    : in  std_ulogic_vector(CFS_IN_SIZE-1 downto 0); -- custom inputs
1851
      cfs_out_o   : out std_ulogic_vector(CFS_OUT_SIZE-1 downto 0) -- custom outputs
1852 34 zero_gravi
    );
1853
  end component;
1854
 
1855 61 zero_gravi
  -- Component: Smart LED (WS2811/WS2812) Interface (NEOLED) --------------------------------
1856 49 zero_gravi
  -- -------------------------------------------------------------------------------------------
1857 61 zero_gravi
  component neorv32_neoled
1858 62 zero_gravi
    generic (
1859
      FIFO_DEPTH : natural -- TX FIFO depth (1..32k, power of two)
1860
    );
1861 49 zero_gravi
    port (
1862
      -- host access --
1863
      clk_i       : in  std_ulogic; -- global clock line
1864
      addr_i      : in  std_ulogic_vector(31 downto 0); -- address
1865
      rden_i      : in  std_ulogic; -- read enable
1866
      wren_i      : in  std_ulogic; -- write enable
1867
      data_i      : in  std_ulogic_vector(31 downto 0); -- data in
1868
      data_o      : out std_ulogic_vector(31 downto 0); -- data out
1869
      ack_o       : out std_ulogic; -- transfer acknowledge
1870
      -- clock generator --
1871
      clkgen_en_o : out std_ulogic; -- enable clock generator
1872
      clkgen_i    : in  std_ulogic_vector(07 downto 0);
1873 61 zero_gravi
      -- interrupt --
1874
      irq_o       : out std_ulogic; -- interrupt request
1875
      -- NEOLED output --
1876
      neoled_o    : out std_ulogic -- serial async data line
1877 49 zero_gravi
    );
1878
  end component;
1879
 
1880 61 zero_gravi
  -- Component: Stream Link Interface (SLINK) -----------------------------------------------
1881 52 zero_gravi
  -- -------------------------------------------------------------------------------------------
1882 61 zero_gravi
  component neorv32_slink
1883
    generic (
1884 62 zero_gravi
      SLINK_NUM_TX  : natural; -- number of TX links (0..8)
1885
      SLINK_NUM_RX  : natural; -- number of TX links (0..8)
1886
      SLINK_TX_FIFO : natural; -- TX fifo depth, has to be a power of two
1887
      SLINK_RX_FIFO : natural  -- RX fifo depth, has to be a power of two
1888 61 zero_gravi
    );
1889 52 zero_gravi
    port (
1890
      -- host access --
1891 61 zero_gravi
      clk_i          : in  std_ulogic; -- global clock line
1892
      addr_i         : in  std_ulogic_vector(31 downto 0); -- address
1893
      rden_i         : in  std_ulogic; -- read enable
1894
      wren_i         : in  std_ulogic; -- write enable
1895
      data_i         : in  std_ulogic_vector(31 downto 0); -- data in
1896
      data_o         : out std_ulogic_vector(31 downto 0); -- data out
1897
      ack_o          : out std_ulogic; -- transfer acknowledge
1898 52 zero_gravi
      -- interrupt --
1899 61 zero_gravi
      irq_tx_o       : out std_ulogic; -- transmission done
1900
      irq_rx_o       : out std_ulogic; -- data received
1901
      -- TX stream interfaces --
1902
      slink_tx_dat_o : out sdata_8x32_t; -- output data
1903
      slink_tx_val_o : out std_ulogic_vector(7 downto 0); -- valid output
1904
      slink_tx_rdy_i : in  std_ulogic_vector(7 downto 0); -- ready to send
1905
      -- RX stream interfaces --
1906
      slink_rx_dat_i : in  sdata_8x32_t; -- input data
1907
      slink_rx_val_i : in  std_ulogic_vector(7 downto 0); -- valid input
1908
      slink_rx_rdy_o : out std_ulogic_vector(7 downto 0)  -- ready to receive
1909 52 zero_gravi
    );
1910
  end component;
1911
 
1912 61 zero_gravi
  -- Component: External Interrupt Controller (XIRQ) ----------------------------------------
1913
  -- -------------------------------------------------------------------------------------------
1914
  component neorv32_xirq
1915
    generic (
1916 62 zero_gravi
      XIRQ_NUM_CH           : natural; -- number of external IRQ channels (0..32)
1917
      XIRQ_TRIGGER_TYPE     : std_ulogic_vector(31 downto 0); -- trigger type: 0=level, 1=edge
1918
      XIRQ_TRIGGER_POLARITY : std_ulogic_vector(31 downto 0)  -- trigger polarity: 0=low-level/falling-edge, 1=high-level/rising-edge
1919 61 zero_gravi
    );
1920
    port (
1921
      -- host access --
1922
      clk_i     : in  std_ulogic; -- global clock line
1923
      addr_i    : in  std_ulogic_vector(31 downto 0); -- address
1924
      rden_i    : in  std_ulogic; -- read enable
1925
      wren_i    : in  std_ulogic; -- write enable
1926
      data_i    : in  std_ulogic_vector(31 downto 0); -- data in
1927
      data_o    : out std_ulogic_vector(31 downto 0); -- data out
1928
      ack_o     : out std_ulogic; -- transfer acknowledge
1929
      -- external interrupt lines --
1930
      xirq_i    : in  std_ulogic_vector(XIRQ_NUM_CH-1 downto 0);
1931
      -- CPU interrupt --
1932
      cpu_irq_o : out std_ulogic
1933
    );
1934
  end component;
1935
 
1936 67 zero_gravi
  -- Component: General Purpose Timer (GPTMR) -----------------------------------------------
1937
  -- -------------------------------------------------------------------------------------------
1938
  component neorv32_gptmr
1939
    port (
1940
      -- host access --
1941
      clk_i       : in  std_ulogic; -- global clock line
1942
      addr_i      : in  std_ulogic_vector(31 downto 0); -- address
1943
      rden_i      : in  std_ulogic; -- read enable
1944
      wren_i      : in  std_ulogic; -- write enable
1945
      data_i      : in  std_ulogic_vector(31 downto 0); -- data in
1946
      data_o      : out std_ulogic_vector(31 downto 0); -- data out
1947
      ack_o       : out std_ulogic; -- transfer acknowledge
1948
      -- clock generator --
1949
      clkgen_en_o : out std_ulogic; -- enable clock generator
1950
      clkgen_i    : in  std_ulogic_vector(07 downto 0);
1951
      -- interrupt --
1952
      irq_o       : out std_ulogic -- transmission done interrupt
1953
    );
1954
  end component;
1955
 
1956 23 zero_gravi
  -- Component: System Configuration Information Memory (SYSINFO) ---------------------------
1957
  -- -------------------------------------------------------------------------------------------
1958 12 zero_gravi
  component neorv32_sysinfo
1959
    generic (
1960
      -- General --
1961 63 zero_gravi
      CLOCK_FREQUENCY              : natural; -- clock frequency of clk_i in Hz
1962
      INT_BOOTLOADER_EN            : boolean; -- boot configuration: true = boot explicit bootloader; false = boot from int/ext (I)MEM
1963
      -- RISC-V CPU Extensions --
1964
      CPU_EXTENSION_RISCV_Zfinx    : boolean; -- implement 32-bit floating-point extension (using INT reg!)
1965
      CPU_EXTENSION_RISCV_Zicsr    : boolean; -- implement CSR system?
1966 66 zero_gravi
      CPU_EXTENSION_RISCV_Zicntr   : boolean; -- implement base counters?
1967
      CPU_EXTENSION_RISCV_Zihpm    : boolean; -- implement hardware performance monitors?
1968 63 zero_gravi
      CPU_EXTENSION_RISCV_Zifencei : boolean; -- implement instruction stream sync.?
1969
      CPU_EXTENSION_RISCV_Zmmul    : boolean; -- implement multiply-only M sub-extension?
1970
      CPU_EXTENSION_RISCV_DEBUG    : boolean; -- implement CPU debug mode?
1971
      -- Extension Options --
1972
      FAST_MUL_EN                  : boolean; -- use DSPs for M extension's multiplier
1973
      FAST_SHIFT_EN                : boolean; -- use barrel shifter for shift operations
1974
      CPU_CNT_WIDTH                : natural; -- total width of CPU cycle and instret counters (0..64)
1975
      -- Physical memory protection (PMP) --
1976
      PMP_NUM_REGIONS              : natural; -- number of regions (0..64)
1977 23 zero_gravi
      -- Internal Instruction memory --
1978 63 zero_gravi
      MEM_INT_IMEM_EN              : boolean; -- implement processor-internal instruction memory
1979
      MEM_INT_IMEM_SIZE            : natural; -- size of processor-internal instruction memory in bytes
1980 23 zero_gravi
      -- Internal Data memory --
1981 63 zero_gravi
      MEM_INT_DMEM_EN              : boolean; -- implement processor-internal data memory
1982
      MEM_INT_DMEM_SIZE            : natural; -- size of processor-internal data memory in bytes
1983 41 zero_gravi
      -- Internal Cache memory --
1984 63 zero_gravi
      ICACHE_EN                    : boolean; -- implement instruction cache
1985
      ICACHE_NUM_BLOCKS            : natural; -- i-cache: number of blocks (min 2), has to be a power of 2
1986
      ICACHE_BLOCK_SIZE            : natural; -- i-cache: block size in bytes (min 4), has to be a power of 2
1987
      ICACHE_ASSOCIATIVITY         : natural; -- i-cache: associativity (min 1), has to be a power 2
1988 23 zero_gravi
      -- External memory interface --
1989 63 zero_gravi
      MEM_EXT_EN                   : boolean; -- implement external memory bus interface?
1990
      MEM_EXT_BIG_ENDIAN           : boolean; -- byte order: true=big-endian, false=little-endian
1991 59 zero_gravi
      -- On-Chip Debugger --
1992 63 zero_gravi
      ON_CHIP_DEBUGGER_EN          : boolean; -- implement OCD?
1993 12 zero_gravi
      -- Processor peripherals --
1994 63 zero_gravi
      IO_GPIO_EN                   : boolean; -- implement general purpose input/output port unit (GPIO)?
1995
      IO_MTIME_EN                  : boolean; -- implement machine system timer (MTIME)?
1996
      IO_UART0_EN                  : boolean; -- implement primary universal asynchronous receiver/transmitter (UART0)?
1997
      IO_UART1_EN                  : boolean; -- implement secondary universal asynchronous receiver/transmitter (UART1)?
1998
      IO_SPI_EN                    : boolean; -- implement serial peripheral interface (SPI)?
1999
      IO_TWI_EN                    : boolean; -- implement two-wire interface (TWI)?
2000
      IO_PWM_NUM_CH                : natural; -- number of PWM channels to implement
2001
      IO_WDT_EN                    : boolean; -- implement watch dog timer (WDT)?
2002
      IO_TRNG_EN                   : boolean; -- implement true random number generator (TRNG)?
2003
      IO_CFS_EN                    : boolean; -- implement custom functions subsystem (CFS)?
2004
      IO_SLINK_EN                  : boolean; -- implement stream link interface?
2005
      IO_NEOLED_EN                 : boolean; -- implement NeoPixel-compatible smart LED interface (NEOLED)?
2006 67 zero_gravi
      IO_XIRQ_NUM_CH               : natural; -- number of external interrupt (XIRQ) channels to implement
2007
      IO_GPTMR_EN                  : boolean  -- implement general purpose timer (GPTMR)?
2008 12 zero_gravi
    );
2009
    port (
2010
      -- host access --
2011
      clk_i  : in  std_ulogic; -- global clock line
2012
      addr_i : in  std_ulogic_vector(31 downto 0); -- address
2013
      rden_i : in  std_ulogic; -- read enable
2014
      data_o : out std_ulogic_vector(31 downto 0); -- data out
2015
      ack_o  : out std_ulogic  -- transfer acknowledge
2016
    );
2017
  end component;
2018
 
2019 62 zero_gravi
  -- Component: General Purpose FIFO --------------------------------------------------------
2020 61 zero_gravi
  -- -------------------------------------------------------------------------------------------
2021
  component neorv32_fifo
2022
    generic (
2023 62 zero_gravi
      FIFO_DEPTH : natural; -- number of fifo entries; has to be a power of two; min 1
2024
      FIFO_WIDTH : natural; -- size of data elements in fifo
2025
      FIFO_RSYNC : boolean; -- false = async read; true = sync read
2026
      FIFO_SAFE  : boolean  -- true = allow read/write only if entry available
2027 61 zero_gravi
    );
2028
    port (
2029
      -- control --
2030
      clk_i   : in  std_ulogic; -- clock, rising edge
2031
      rstn_i  : in  std_ulogic; -- async reset, low-active
2032
      clear_i : in  std_ulogic; -- sync reset, high-active
2033 62 zero_gravi
      level_o : out std_ulogic_vector(index_size_f(FIFO_DEPTH) downto 0); -- fill level
2034 65 zero_gravi
      half_o  : out std_ulogic; -- FIFO is at least half full
2035 61 zero_gravi
      -- write port --
2036
      wdata_i : in  std_ulogic_vector(FIFO_WIDTH-1 downto 0); -- write data
2037
      we_i    : in  std_ulogic; -- write enable
2038
      free_o  : out std_ulogic; -- at least one entry is free when set
2039
      -- read port --
2040
      re_i    : in  std_ulogic; -- read enable
2041
      rdata_o : out std_ulogic_vector(FIFO_WIDTH-1 downto 0); -- read data
2042
      avail_o : out std_ulogic  -- data available when set
2043
    );
2044
  end component;
2045
 
2046 59 zero_gravi
  -- Component: On-Chip Debugger - Debug Module (DM) ----------------------------------------
2047
  -- -------------------------------------------------------------------------------------------
2048
  component neorv32_debug_dm
2049
    port (
2050
      -- global control --
2051
      clk_i            : in  std_ulogic; -- global clock line
2052
      rstn_i           : in  std_ulogic; -- global reset line, low-active
2053
      -- debug module interface (DMI) --
2054
      dmi_rstn_i       : in  std_ulogic;
2055
      dmi_req_valid_i  : in  std_ulogic;
2056
      dmi_req_ready_o  : out std_ulogic; -- DMI is allowed to make new requests when set
2057
      dmi_req_addr_i   : in  std_ulogic_vector(06 downto 0);
2058
      dmi_req_op_i     : in  std_ulogic; -- 0=read, 1=write
2059
      dmi_req_data_i   : in  std_ulogic_vector(31 downto 0);
2060
      dmi_resp_valid_o : out std_ulogic; -- response valid when set
2061
      dmi_resp_ready_i : in  std_ulogic; -- ready to receive respond
2062
      dmi_resp_data_o  : out std_ulogic_vector(31 downto 0);
2063
      dmi_resp_err_o   : out std_ulogic; -- 0=ok, 1=error
2064
      -- CPU bus access --
2065
      cpu_addr_i       : in  std_ulogic_vector(31 downto 0); -- address
2066
      cpu_rden_i       : in  std_ulogic; -- read enable
2067
      cpu_wren_i       : in  std_ulogic; -- write enable
2068
      cpu_data_i       : in  std_ulogic_vector(31 downto 0); -- data in
2069
      cpu_data_o       : out std_ulogic_vector(31 downto 0); -- data out
2070
      cpu_ack_o        : out std_ulogic; -- transfer acknowledge
2071
      -- CPU control --
2072
      cpu_ndmrstn_o    : out std_ulogic; -- soc reset
2073
      cpu_halt_req_o   : out std_ulogic  -- request hart to halt (enter debug mode)
2074
    );
2075
  end component;
2076
 
2077
  -- Component: On-Chip Debugger - Debug Transport Module (DTM) -----------------------------
2078
  -- -------------------------------------------------------------------------------------------
2079
  component neorv32_debug_dtm
2080
    generic (
2081 62 zero_gravi
      IDCODE_VERSION : std_ulogic_vector(03 downto 0); -- version
2082
      IDCODE_PARTID  : std_ulogic_vector(15 downto 0); -- part number
2083
      IDCODE_MANID   : std_ulogic_vector(10 downto 0)  -- manufacturer id
2084 59 zero_gravi
    );
2085
    port (
2086
      -- global control --
2087
      clk_i            : in  std_ulogic; -- global clock line
2088
      rstn_i           : in  std_ulogic; -- global reset line, low-active
2089
      -- jtag connection --
2090
      jtag_trst_i      : in  std_ulogic;
2091
      jtag_tck_i       : in  std_ulogic;
2092
      jtag_tdi_i       : in  std_ulogic;
2093
      jtag_tdo_o       : out std_ulogic;
2094
      jtag_tms_i       : in  std_ulogic;
2095
      -- debug module interface (DMI) --
2096
      dmi_rstn_o       : out std_ulogic;
2097
      dmi_req_valid_o  : out std_ulogic;
2098
      dmi_req_ready_i  : in  std_ulogic; -- DMI is allowed to make new requests when set
2099
      dmi_req_addr_o   : out std_ulogic_vector(06 downto 0);
2100
      dmi_req_op_o     : out std_ulogic; -- 0=read, 1=write
2101
      dmi_req_data_o   : out std_ulogic_vector(31 downto 0);
2102
      dmi_resp_valid_i : in  std_ulogic; -- response valid when set
2103
      dmi_resp_ready_o : out std_ulogic; -- ready to receive respond
2104
      dmi_resp_data_i  : in  std_ulogic_vector(31 downto 0);
2105
      dmi_resp_err_i   : in  std_ulogic -- 0=ok, 1=error
2106
    );
2107
  end component;
2108
 
2109 2 zero_gravi
end neorv32_package;
2110
 
2111
package body neorv32_package is
2112
 
2113 69 zero_gravi
  -- Function: Minimal required number of bits to represent <input> numbers -----------------
2114 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
2115
  function index_size_f(input : natural) return natural is
2116
  begin
2117
    for i in 0 to natural'high loop
2118
      if (2**i >= input) then
2119
        return i;
2120
      end if;
2121
    end loop; -- i
2122
    return 0;
2123
  end function index_size_f;
2124
 
2125
  -- Function: Conditional select natural ---------------------------------------------------
2126
  -- -------------------------------------------------------------------------------------------
2127
  function cond_sel_natural_f(cond : boolean; val_t : natural; val_f : natural) return natural is
2128
  begin
2129
    if (cond = true) then
2130
      return val_t;
2131
    else
2132
      return val_f;
2133
    end if;
2134
  end function cond_sel_natural_f;
2135
 
2136 56 zero_gravi
  -- Function: Conditional select integer ---------------------------------------------------
2137
  -- -------------------------------------------------------------------------------------------
2138
  function cond_sel_int_f(cond : boolean; val_t : integer; val_f : integer) return integer is
2139
  begin
2140
    if (cond = true) then
2141
      return val_t;
2142
    else
2143
      return val_f;
2144
    end if;
2145
  end function cond_sel_int_f;
2146
 
2147 2 zero_gravi
  -- Function: Conditional select std_ulogic_vector -----------------------------------------
2148
  -- -------------------------------------------------------------------------------------------
2149
  function cond_sel_stdulogicvector_f(cond : boolean; val_t : std_ulogic_vector; val_f : std_ulogic_vector) return std_ulogic_vector is
2150
  begin
2151
    if (cond = true) then
2152
      return val_t;
2153
    else
2154
      return val_f;
2155
    end if;
2156
  end function cond_sel_stdulogicvector_f;
2157
 
2158 56 zero_gravi
  -- Function: Conditional select std_ulogic ------------------------------------------------
2159
  -- -------------------------------------------------------------------------------------------
2160
  function cond_sel_stdulogic_f(cond : boolean; val_t : std_ulogic; val_f : std_ulogic) return std_ulogic is
2161
  begin
2162
    if (cond = true) then
2163
      return val_t;
2164
    else
2165
      return val_f;
2166
    end if;
2167
  end function cond_sel_stdulogic_f;
2168
 
2169 50 zero_gravi
  -- Function: Conditional select string ----------------------------------------------------
2170 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
2171 50 zero_gravi
  function cond_sel_string_f(cond : boolean; val_t : string; val_f : string) return string is
2172
  begin
2173
    if (cond = true) then
2174
      return val_t;
2175
    else
2176
      return val_f;
2177
    end if;
2178
  end function cond_sel_string_f;
2179
 
2180
  -- Function: Convert bool to std_ulogic ---------------------------------------------------
2181
  -- -------------------------------------------------------------------------------------------
2182 2 zero_gravi
  function bool_to_ulogic_f(cond : boolean) return std_ulogic is
2183
  begin
2184
    if (cond = true) then
2185
      return '1';
2186
    else
2187
      return '0';
2188
    end if;
2189
  end function bool_to_ulogic_f;
2190
 
2191 60 zero_gravi
  -- Function: OR-reduce all bits -----------------------------------------------------------
2192 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
2193 60 zero_gravi
  function or_reduce_f(a : std_ulogic_vector) return std_ulogic is
2194 2 zero_gravi
    variable tmp_v : std_ulogic;
2195
  begin
2196 56 zero_gravi
    tmp_v := '0';
2197 65 zero_gravi
    for i in a'range loop
2198
      tmp_v := tmp_v or a(i);
2199
    end loop; -- i
2200 2 zero_gravi
    return tmp_v;
2201 60 zero_gravi
  end function or_reduce_f;
2202 2 zero_gravi
 
2203 60 zero_gravi
  -- Function: AND-reduce all bits ----------------------------------------------------------
2204 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
2205 60 zero_gravi
  function and_reduce_f(a : std_ulogic_vector) return std_ulogic is
2206 2 zero_gravi
    variable tmp_v : std_ulogic;
2207
  begin
2208 56 zero_gravi
    tmp_v := '1';
2209 65 zero_gravi
    for i in a'range loop
2210
      tmp_v := tmp_v and a(i);
2211
    end loop; -- i
2212 2 zero_gravi
    return tmp_v;
2213 60 zero_gravi
  end function and_reduce_f;
2214 2 zero_gravi
 
2215 60 zero_gravi
  -- Function: XOR-reduce all bits ----------------------------------------------------------
2216 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
2217 60 zero_gravi
  function xor_reduce_f(a : std_ulogic_vector) return std_ulogic is
2218 2 zero_gravi
    variable tmp_v : std_ulogic;
2219
  begin
2220 56 zero_gravi
    tmp_v := '0';
2221 65 zero_gravi
    for i in a'range loop
2222
      tmp_v := tmp_v xor a(i);
2223
    end loop; -- i
2224 2 zero_gravi
    return tmp_v;
2225 60 zero_gravi
  end function xor_reduce_f;
2226 2 zero_gravi
 
2227 40 zero_gravi
  -- Function: Convert std_ulogic_vector to hex char ----------------------------------------
2228 6 zero_gravi
  -- -------------------------------------------------------------------------------------------
2229
  function to_hexchar_f(input : std_ulogic_vector(3 downto 0)) return character is
2230
    variable output_v : character;
2231
  begin
2232
    case input is
2233 7 zero_gravi
      when x"0"   => output_v := '0';
2234
      when x"1"   => output_v := '1';
2235
      when x"2"   => output_v := '2';
2236
      when x"3"   => output_v := '3';
2237
      when x"4"   => output_v := '4';
2238
      when x"5"   => output_v := '5';
2239
      when x"6"   => output_v := '6';
2240
      when x"7"   => output_v := '7';
2241
      when x"8"   => output_v := '8';
2242
      when x"9"   => output_v := '9';
2243
      when x"a"   => output_v := 'a';
2244
      when x"b"   => output_v := 'b';
2245
      when x"c"   => output_v := 'c';
2246
      when x"d"   => output_v := 'd';
2247
      when x"e"   => output_v := 'e';
2248
      when x"f"   => output_v := 'f';
2249 6 zero_gravi
      when others => output_v := '?';
2250
    end case;
2251
    return output_v;
2252
  end function to_hexchar_f;
2253
 
2254 40 zero_gravi
  -- Function: Convert hex char to std_ulogic_vector ----------------------------------------
2255
  -- -------------------------------------------------------------------------------------------
2256
  function hexchar_to_stdulogicvector_f(input : character) return std_ulogic_vector is
2257
    variable hex_value_v : std_ulogic_vector(3 downto 0);
2258
  begin
2259
    case input is
2260
      when '0'       => hex_value_v := x"0";
2261
      when '1'       => hex_value_v := x"1";
2262
      when '2'       => hex_value_v := x"2";
2263
      when '3'       => hex_value_v := x"3";
2264
      when '4'       => hex_value_v := x"4";
2265
      when '5'       => hex_value_v := x"5";
2266
      when '6'       => hex_value_v := x"6";
2267
      when '7'       => hex_value_v := x"7";
2268
      when '8'       => hex_value_v := x"8";
2269
      when '9'       => hex_value_v := x"9";
2270
      when 'a' | 'A' => hex_value_v := x"a";
2271
      when 'b' | 'B' => hex_value_v := x"b";
2272
      when 'c' | 'C' => hex_value_v := x"c";
2273
      when 'd' | 'D' => hex_value_v := x"d";
2274
      when 'e' | 'E' => hex_value_v := x"e";
2275
      when 'f' | 'F' => hex_value_v := x"f";
2276
      when others    => hex_value_v := (others => 'X');
2277
    end case;
2278
    return hex_value_v;
2279
  end function hexchar_to_stdulogicvector_f;
2280
 
2281 32 zero_gravi
  -- Function: Bit reversal -----------------------------------------------------------------
2282
  -- -------------------------------------------------------------------------------------------
2283
  function bit_rev_f(input : std_ulogic_vector) return std_ulogic_vector is
2284
    variable output_v : std_ulogic_vector(input'range);
2285
  begin
2286
    for i in 0 to input'length-1 loop
2287
      output_v(input'length-i-1) := input(i);
2288
    end loop; -- i
2289
    return output_v;
2290
  end function bit_rev_f;
2291
 
2292 36 zero_gravi
  -- Function: Test if input number is a power of two ---------------------------------------
2293
  -- -------------------------------------------------------------------------------------------
2294
  function is_power_of_two_f(input : natural) return boolean is
2295
  begin
2296 38 zero_gravi
    if (input = 1) then -- 2^0
2297 36 zero_gravi
      return true;
2298 38 zero_gravi
    elsif ((input / 2) /= 0) and ((input mod 2) = 0) then
2299
      return true;
2300 36 zero_gravi
    else
2301
      return false;
2302
    end if;
2303
  end function is_power_of_two_f;
2304
 
2305 40 zero_gravi
  -- Function: Swap all bytes of a 32-bit word (endianness conversion) ----------------------
2306
  -- -------------------------------------------------------------------------------------------
2307
  function bswap32_f(input : std_ulogic_vector) return std_ulogic_vector is
2308
    variable output_v : std_ulogic_vector(input'range);
2309
  begin
2310
    output_v(07 downto 00) := input(31 downto 24);
2311
    output_v(15 downto 08) := input(23 downto 16);
2312
    output_v(23 downto 16) := input(15 downto 08);
2313
    output_v(31 downto 24) := input(07 downto 00);
2314
    return output_v;
2315
  end function bswap32_f;
2316
 
2317 61 zero_gravi
  -- Function: Convert char to lowercase ----------------------------------------------------
2318
  -- -------------------------------------------------------------------------------------------
2319 62 zero_gravi
  function char_to_lower_f(ch : character) return character is
2320 61 zero_gravi
    variable res: character;
2321
   begin
2322
     case ch is
2323
       when 'A'    => res := 'a';
2324
       when 'B'    => res := 'b';
2325
       when 'C'    => res := 'c';
2326
       when 'D'    => res := 'd';
2327
       when 'E'    => res := 'e';
2328
       when 'F'    => res := 'f';
2329
       when 'G'    => res := 'g';
2330
       when 'H'    => res := 'h';
2331
       when 'I'    => res := 'i';
2332
       when 'J'    => res := 'j';
2333
       when 'K'    => res := 'k';
2334
       when 'L'    => res := 'l';
2335
       when 'M'    => res := 'm';
2336
       when 'N'    => res := 'n';
2337
       when 'O'    => res := 'o';
2338
       when 'P'    => res := 'p';
2339
       when 'Q'    => res := 'q';
2340
       when 'R'    => res := 'r';
2341
       when 'S'    => res := 's';
2342
       when 'T'    => res := 't';
2343
       when 'U'    => res := 'u';
2344
       when 'V'    => res := 'v';
2345
       when 'W'    => res := 'w';
2346
       when 'X'    => res := 'x';
2347
       when 'Y'    => res := 'y';
2348
       when 'Z'    => res := 'z';
2349
       when others => res := ch;
2350
      end case;
2351
    return res;
2352 62 zero_gravi
  end function char_to_lower_f;
2353 61 zero_gravi
 
2354
  -- Function: Compare strings (convert to lower case, check lengths) -----------------------
2355
  -- -------------------------------------------------------------------------------------------
2356
  function str_equal_f(str0 : string; str1 : string) return boolean is
2357
    variable tmp0_v : string(str0'range);
2358
    variable tmp1_v : string(str1'range);
2359
  begin
2360
    if (str0'length /= str1'length) then -- equal length?
2361
      return false;
2362
    else
2363
      -- convert to lower case --
2364
      for i in str0'range loop
2365 62 zero_gravi
        tmp0_v(i) := char_to_lower_f(str0(i));
2366 61 zero_gravi
      end loop;
2367
      for i in str1'range loop
2368 62 zero_gravi
        tmp1_v(i) := char_to_lower_f(str1(i));
2369 61 zero_gravi
      end loop;
2370
      -- compare lowercase strings --
2371
      if (tmp0_v = tmp1_v) then
2372
        return true;
2373
      else
2374
        return false;
2375
      end if;
2376
    end if;
2377
  end function str_equal_f;
2378
 
2379 63 zero_gravi
  -- Function: Population count (number of set bits) ----------------------------------------
2380
  -- -------------------------------------------------------------------------------------------
2381
  function popcount_f(input : std_ulogic_vector) return natural is
2382
    variable cnt_v : natural range 0 to input'length;
2383
  begin
2384
    cnt_v := 0;
2385
    for i in input'length-1 downto 0 loop
2386
      if (input(i) = '1') then
2387
        cnt_v := cnt_v + 1;
2388
      end if;
2389
    end loop; -- i
2390
    return cnt_v;
2391
  end function popcount_f;
2392
 
2393
  -- Function: Count leading zeros ----------------------------------------------------------
2394
  -- -------------------------------------------------------------------------------------------
2395
  function leading_zeros_f(input : std_ulogic_vector) return natural is
2396
    variable cnt_v : natural range 0 to input'length;
2397
  begin
2398
    cnt_v := 0;
2399
    for i in input'length-1 downto 0 loop
2400
      if (input(i) = '0') then
2401
        cnt_v := cnt_v + 1;
2402
      else
2403
        exit;
2404
      end if;
2405
    end loop; -- i
2406
    return cnt_v;
2407
  end function leading_zeros_f;
2408
 
2409 61 zero_gravi
  -- Function: Initialize mem32_t array from another mem32_t array --------------------------
2410
  -- -------------------------------------------------------------------------------------------
2411
  -- impure function: returns NOT the same result every time it is evaluated with the same arguments since the source file might have changed
2412
  impure function mem32_init_f(init : mem32_t; depth : natural) return mem32_t is
2413
    variable mem_v : mem32_t(0 to depth-1);
2414
  begin
2415 62 zero_gravi
    mem_v := (others => (others => '0')); -- make sure remaining memory entries are set to zero
2416
    if (init'length > depth) then
2417
      return mem_v;
2418
    end if;
2419
    for idx_v in 0 to init'length-1 loop -- init only in range of source data array
2420
      mem_v(idx_v) := init(idx_v);
2421
    end loop; -- idx_v
2422 61 zero_gravi
    return mem_v;
2423
  end function mem32_init_f;
2424
 
2425 62 zero_gravi
 
2426 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.