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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_top.vhd] - Blame information for rev 64

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - Processor Top Entity >>                                                          #
3
-- # ********************************************************************************************* #
4 18 zero_gravi
-- # This is the top entity of the NEORV32 PROCESSOR. Instantiate this unit in your own project    #
5 63 zero_gravi
-- # and define all the configuration generics according to your needs or use one of the           #
6
-- # pre-defined template wrappers.                                                                #
7 18 zero_gravi
-- #                                                                                               #
8 63 zero_gravi
-- # Check out the processor's online documentation for more information:                          #
9
-- #  HQ:         https://github.com/stnolting/neorv32                                             #
10
-- #  Data Sheet: https://stnolting.github.io/neorv32                                              #
11
-- #  User Guide: https://stnolting.github.io/neorv32/ug                                           #
12 2 zero_gravi
-- # ********************************************************************************************* #
13
-- # BSD 3-Clause License                                                                          #
14
-- #                                                                                               #
15 42 zero_gravi
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
16 2 zero_gravi
-- #                                                                                               #
17
-- # Redistribution and use in source and binary forms, with or without modification, are          #
18
-- # permitted provided that the following conditions are met:                                     #
19
-- #                                                                                               #
20
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
21
-- #    conditions and the following disclaimer.                                                   #
22
-- #                                                                                               #
23
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
24
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
25
-- #    provided with the distribution.                                                            #
26
-- #                                                                                               #
27
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
28
-- #    endorse or promote products derived from this software without specific prior written      #
29
-- #    permission.                                                                                #
30
-- #                                                                                               #
31
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
32
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
33
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
34
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
35
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
36
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
37
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
38
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
39
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
40
-- # ********************************************************************************************* #
41
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
42
-- #################################################################################################
43
 
44
library ieee;
45
use ieee.std_logic_1164.all;
46
use ieee.numeric_std.all;
47
 
48
library neorv32;
49
use neorv32.neorv32_package.all;
50
 
51
entity neorv32_top is
52
  generic (
53
    -- General --
54 62 zero_gravi
    CLOCK_FREQUENCY              : natural;           -- clock frequency of clk_i in Hz
55 49 zero_gravi
    HW_THREAD_ID                 : natural := 0;      -- hardware thread id (32-bit)
56 62 zero_gravi
    INT_BOOTLOADER_EN            : boolean := false;  -- boot configuration: true = boot explicit bootloader; false = boot from int/ext (I)MEM
57 50 zero_gravi
 
58 59 zero_gravi
    -- On-Chip Debugger (OCD) --
59
    ON_CHIP_DEBUGGER_EN          : boolean := false;  -- implement on-chip debugger
60
 
61 2 zero_gravi
    -- RISC-V CPU Extensions --
62 39 zero_gravi
    CPU_EXTENSION_RISCV_A        : boolean := false;  -- implement atomic extension?
63 11 zero_gravi
    CPU_EXTENSION_RISCV_C        : boolean := false;  -- implement compressed extension?
64 8 zero_gravi
    CPU_EXTENSION_RISCV_E        : boolean := false;  -- implement embedded RF extension?
65 61 zero_gravi
    CPU_EXTENSION_RISCV_M        : boolean := false;  -- implement mul/div extension?
66 15 zero_gravi
    CPU_EXTENSION_RISCV_U        : boolean := false;  -- implement user mode extension?
67 63 zero_gravi
    CPU_EXTENSION_RISCV_Zbb      : boolean := false;  -- implement basic bit-manipulation sub-extension?
68 57 zero_gravi
    CPU_EXTENSION_RISCV_Zfinx    : boolean := false;  -- implement 32-bit floating-point extension (using INT regs!)
69 8 zero_gravi
    CPU_EXTENSION_RISCV_Zicsr    : boolean := true;   -- implement CSR system?
70 39 zero_gravi
    CPU_EXTENSION_RISCV_Zifencei : boolean := false;  -- implement instruction stream sync.?
71 61 zero_gravi
    CPU_EXTENSION_RISCV_Zmmul    : boolean := false;  -- implement multiply-only M sub-extension?
72 50 zero_gravi
 
73 19 zero_gravi
    -- Extension Options --
74 23 zero_gravi
    FAST_MUL_EN                  : boolean := false;  -- use DSPs for M extension's multiplier
75 39 zero_gravi
    FAST_SHIFT_EN                : boolean := false;  -- use barrel shifter for shift operations
76 56 zero_gravi
    CPU_CNT_WIDTH                : natural := 64;     -- total width of CPU cycle and instret counters (0..64)
77 62 zero_gravi
    CPU_IPB_ENTRIES              : natural := 2;      -- entries is instruction prefetch buffer, has to be a power of 2
78 50 zero_gravi
 
79 15 zero_gravi
    -- Physical Memory Protection (PMP) --
80 42 zero_gravi
    PMP_NUM_REGIONS              : natural := 0;      -- number of regions (0..64)
81
    PMP_MIN_GRANULARITY          : natural := 64*1024; -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
82 50 zero_gravi
 
83 42 zero_gravi
    -- Hardware Performance Monitors (HPM) --
84 47 zero_gravi
    HPM_NUM_CNTS                 : natural := 0;      -- number of implemented HPM counters (0..29)
85 60 zero_gravi
    HPM_CNT_WIDTH                : natural := 40;     -- total size of HPM counters (0..64)
86 50 zero_gravi
 
87 61 zero_gravi
    -- Internal Instruction memory (IMEM) --
88 62 zero_gravi
    MEM_INT_IMEM_EN              : boolean := false;  -- implement processor-internal instruction memory
89 8 zero_gravi
    MEM_INT_IMEM_SIZE            : natural := 16*1024; -- size of processor-internal instruction memory in bytes
90 50 zero_gravi
 
91 61 zero_gravi
    -- Internal Data memory (DMEM) --
92 62 zero_gravi
    MEM_INT_DMEM_EN              : boolean := false;  -- implement processor-internal data memory
93 8 zero_gravi
    MEM_INT_DMEM_SIZE            : natural := 8*1024; -- size of processor-internal data memory in bytes
94 50 zero_gravi
 
95 61 zero_gravi
    -- Internal Cache memory (iCACHE) --
96 44 zero_gravi
    ICACHE_EN                    : boolean := false;  -- implement instruction cache
97 41 zero_gravi
    ICACHE_NUM_BLOCKS            : natural := 4;      -- i-cache: number of blocks (min 1), has to be a power of 2
98
    ICACHE_BLOCK_SIZE            : natural := 64;     -- i-cache: block size in bytes (min 4), has to be a power of 2
99 45 zero_gravi
    ICACHE_ASSOCIATIVITY         : natural := 1;      -- i-cache: associativity / number of sets (1=direct_mapped), has to be a power of 2
100 50 zero_gravi
 
101 61 zero_gravi
    -- External memory interface (WISHBONE) --
102 44 zero_gravi
    MEM_EXT_EN                   : boolean := false;  -- implement external memory bus interface?
103 57 zero_gravi
    MEM_EXT_TIMEOUT              : natural := 255;    -- cycles after a pending bus access auto-terminates (0 = disabled)
104 62 zero_gravi
    MEM_EXT_PIPE_MODE            : boolean := false;  -- protocol: false=classic/standard wishbone mode, true=pipelined wishbone mode
105
    MEM_EXT_BIG_ENDIAN           : boolean := false;  -- byte order: true=big-endian, false=little-endian
106
    MEM_EXT_ASYNC_RX             : boolean := false;  -- use register buffer for RX data when false
107 50 zero_gravi
 
108 61 zero_gravi
    -- Stream link interface (SLINK) --
109
    SLINK_NUM_TX                 : natural := 0;      -- number of TX links (0..8)
110
    SLINK_NUM_RX                 : natural := 0;      -- number of TX links (0..8)
111
    SLINK_TX_FIFO                : natural := 1;      -- TX fifo depth, has to be a power of two
112
    SLINK_RX_FIFO                : natural := 1;      -- RX fifo depth, has to be a power of two
113
 
114
    -- External Interrupts Controller (XIRQ) --
115
    XIRQ_NUM_CH                  : natural := 0;      -- number of external IRQ channels (0..32)
116 63 zero_gravi
    XIRQ_TRIGGER_TYPE            : std_ulogic_vector(31 downto 0) := x"ffffffff"; -- trigger type: 0=level, 1=edge
117
    XIRQ_TRIGGER_POLARITY        : std_ulogic_vector(31 downto 0) := x"ffffffff"; -- trigger polarity: 0=low-level/falling-edge, 1=high-level/rising-edge
118 61 zero_gravi
 
119 2 zero_gravi
    -- Processor peripherals --
120 62 zero_gravi
    IO_GPIO_EN                   : boolean := false;  -- implement general purpose input/output port unit (GPIO)?
121
    IO_MTIME_EN                  : boolean := false;  -- implement machine system timer (MTIME)?
122
    IO_UART0_EN                  : boolean := false;  -- implement primary universal asynchronous receiver/transmitter (UART0)?
123
    IO_UART1_EN                  : boolean := false;  -- implement secondary universal asynchronous receiver/transmitter (UART1)?
124
    IO_SPI_EN                    : boolean := false;  -- implement serial peripheral interface (SPI)?
125
    IO_TWI_EN                    : boolean := false;  -- implement two-wire interface (TWI)?
126
    IO_PWM_NUM_CH                : natural := 0;      -- number of PWM channels to implement (0..60); 0 = disabled
127
    IO_WDT_EN                    : boolean := false;  -- implement watch dog timer (WDT)?
128 44 zero_gravi
    IO_TRNG_EN                   : boolean := false;  -- implement true random number generator (TRNG)?
129 47 zero_gravi
    IO_CFS_EN                    : boolean := false;  -- implement custom functions subsystem (CFS)?
130 56 zero_gravi
    IO_CFS_CONFIG                : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom CFS configuration generic
131 52 zero_gravi
    IO_CFS_IN_SIZE               : positive := 32;    -- size of CFS input conduit in bits
132
    IO_CFS_OUT_SIZE              : positive := 32;    -- size of CFS output conduit in bits
133 62 zero_gravi
    IO_NEOLED_EN                 : boolean := false;  -- implement NeoPixel-compatible smart LED interface (NEOLED)?
134
    IO_NEOLED_TX_FIFO            : natural := 1       -- NEOLED TX FIFO depth, 1..32k, has to be a power of two
135 2 zero_gravi
  );
136
  port (
137
    -- Global control --
138 62 zero_gravi
    clk_i          : in  std_ulogic; -- global clock, rising edge
139
    rstn_i         : in  std_ulogic; -- global reset, low-active, async
140 50 zero_gravi
 
141 59 zero_gravi
    -- JTAG on-chip debugger interface (available if ON_CHIP_DEBUGGER_EN = true) --
142 62 zero_gravi
    jtag_trst_i    : in  std_ulogic := 'U'; -- low-active TAP reset (optional)
143
    jtag_tck_i     : in  std_ulogic := 'U'; -- serial clock
144
    jtag_tdi_i     : in  std_ulogic := 'U'; -- serial data input
145 61 zero_gravi
    jtag_tdo_o     : out std_ulogic;        -- serial data output
146 62 zero_gravi
    jtag_tms_i     : in  std_ulogic := 'U'; -- mode select
147 59 zero_gravi
 
148 44 zero_gravi
    -- Wishbone bus interface (available if MEM_EXT_EN = true) --
149 61 zero_gravi
    wb_tag_o       : out std_ulogic_vector(02 downto 0); -- request tag
150
    wb_adr_o       : out std_ulogic_vector(31 downto 0); -- address
151 62 zero_gravi
    wb_dat_i       : in  std_ulogic_vector(31 downto 0) := (others => 'U'); -- read data
152 61 zero_gravi
    wb_dat_o       : out std_ulogic_vector(31 downto 0); -- write data
153
    wb_we_o        : out std_ulogic; -- read/write
154
    wb_sel_o       : out std_ulogic_vector(03 downto 0); -- byte enable
155
    wb_stb_o       : out std_ulogic; -- strobe
156
    wb_cyc_o       : out std_ulogic; -- valid cycle
157
    wb_lock_o      : out std_ulogic; -- exclusive access request
158 62 zero_gravi
    wb_ack_i       : in  std_ulogic := 'L'; -- transfer acknowledge
159
    wb_err_i       : in  std_ulogic := 'L'; -- transfer error
160 50 zero_gravi
 
161 44 zero_gravi
    -- Advanced memory control signals (available if MEM_EXT_EN = true) --
162 61 zero_gravi
    fence_o        : out std_ulogic; -- indicates an executed FENCE operation
163
    fencei_o       : out std_ulogic; -- indicates an executed FENCEI operation
164 50 zero_gravi
 
165 61 zero_gravi
    -- TX stream interfaces (available if SLINK_NUM_TX > 0) --
166
    slink_tx_dat_o : out sdata_8x32_t; -- output data
167
    slink_tx_val_o : out std_ulogic_vector(7 downto 0); -- valid output
168 62 zero_gravi
    slink_tx_rdy_i : in  std_ulogic_vector(7 downto 0) := (others => 'L'); -- ready to send
169 61 zero_gravi
 
170
    -- RX stream interfaces (available if SLINK_NUM_RX > 0) --
171 62 zero_gravi
    slink_rx_dat_i : in  sdata_8x32_t := (others => (others => 'U')); -- input data
172
    slink_rx_val_i : in  std_ulogic_vector(7 downto 0) := (others => 'L'); -- valid input
173 61 zero_gravi
    slink_rx_rdy_o : out std_ulogic_vector(7 downto 0); -- ready to receive
174
 
175 44 zero_gravi
    -- GPIO (available if IO_GPIO_EN = true) --
176 61 zero_gravi
    gpio_o         : out std_ulogic_vector(63 downto 0); -- parallel output
177 62 zero_gravi
    gpio_i         : in  std_ulogic_vector(63 downto 0) := (others => 'U'); -- parallel input
178 50 zero_gravi
 
179
    -- primary UART0 (available if IO_UART0_EN = true) --
180 61 zero_gravi
    uart0_txd_o    : out std_ulogic; -- UART0 send data
181 62 zero_gravi
    uart0_rxd_i    : in  std_ulogic := 'U'; -- UART0 receive data
182 61 zero_gravi
    uart0_rts_o    : out std_ulogic; -- hw flow control: UART0.RX ready to receive ("RTR"), low-active, optional
183 62 zero_gravi
    uart0_cts_i    : in  std_ulogic := 'L'; -- hw flow control: UART0.TX allowed to transmit, low-active, optional
184 50 zero_gravi
 
185
    -- secondary UART1 (available if IO_UART1_EN = true) --
186 61 zero_gravi
    uart1_txd_o    : out std_ulogic; -- UART1 send data
187 62 zero_gravi
    uart1_rxd_i    : in  std_ulogic := 'U'; -- UART1 receive data
188 61 zero_gravi
    uart1_rts_o    : out std_ulogic; -- hw flow control: UART1.RX ready to receive ("RTR"), low-active, optional
189 62 zero_gravi
    uart1_cts_i    : in  std_ulogic := 'L'; -- hw flow control: UART1.TX allowed to transmit, low-active, optional
190 50 zero_gravi
 
191 44 zero_gravi
    -- SPI (available if IO_SPI_EN = true) --
192 61 zero_gravi
    spi_sck_o      : out std_ulogic; -- SPI serial clock
193
    spi_sdo_o      : out std_ulogic; -- controller data out, peripheral data in
194 62 zero_gravi
    spi_sdi_i      : in  std_ulogic := 'U'; -- controller data in, peripheral data out
195 61 zero_gravi
    spi_csn_o      : out std_ulogic_vector(07 downto 0); -- chip-select
196 50 zero_gravi
 
197 44 zero_gravi
    -- TWI (available if IO_TWI_EN = true) --
198 62 zero_gravi
    twi_sda_io     : inout std_logic := 'U'; -- twi serial data line
199
    twi_scl_io     : inout std_logic := 'U'; -- twi serial clock line
200 50 zero_gravi
 
201 60 zero_gravi
    -- PWM (available if IO_PWM_NUM_CH > 0) --
202 61 zero_gravi
    pwm_o          : out std_ulogic_vector(IO_PWM_NUM_CH-1 downto 0); -- pwm channels
203 50 zero_gravi
 
204 47 zero_gravi
    -- Custom Functions Subsystem IO (available if IO_CFS_EN = true) --
205 62 zero_gravi
    cfs_in_i       : in  std_ulogic_vector(IO_CFS_IN_SIZE-1  downto 0) := (others => 'U'); -- custom CFS inputs conduit
206 61 zero_gravi
    cfs_out_o      : out std_ulogic_vector(IO_CFS_OUT_SIZE-1 downto 0); -- custom CFS outputs conduit
207 50 zero_gravi
 
208 52 zero_gravi
    -- NeoPixel-compatible smart LED interface (available if IO_NEOLED_EN = true) --
209 61 zero_gravi
    neoled_o       : out std_ulogic; -- async serial data line
210 52 zero_gravi
 
211 59 zero_gravi
    -- System time --
212 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)
213 61 zero_gravi
    mtime_o        : out std_ulogic_vector(63 downto 0); -- current system time from int. MTIME (if IO_MTIME_EN = true)
214 50 zero_gravi
 
215 61 zero_gravi
    -- External platform interrupts (available if XIRQ_NUM_CH > 0) --
216 62 zero_gravi
    xirq_i         : in  std_ulogic_vector(XIRQ_NUM_CH-1 downto 0) := (others => 'L'); -- IRQ channels
217 61 zero_gravi
 
218
    -- CPU interrupts --
219 62 zero_gravi
    mtime_irq_i    : in  std_ulogic := 'L'; -- machine timer interrupt, available if IO_MTIME_EN = false
220
    msw_irq_i      : in  std_ulogic := 'L'; -- machine software interrupt
221
    mext_irq_i     : in  std_ulogic := 'L'  -- machine external interrupt
222 2 zero_gravi
  );
223
end neorv32_top;
224
 
225
architecture neorv32_top_rtl of neorv32_top is
226
 
227 61 zero_gravi
  -- CPU boot configuration --
228
  constant cpu_boot_addr_c : std_ulogic_vector(31 downto 0) := cond_sel_stdulogicvector_f(INT_BOOTLOADER_EN, boot_rom_base_c, ispace_base_c);
229 12 zero_gravi
 
230 29 zero_gravi
  -- alignment check for internal memories --
231
  constant imem_align_check_c : std_ulogic_vector(index_size_f(MEM_INT_IMEM_SIZE)-1 downto 0) := (others => '0');
232
  constant dmem_align_check_c : std_ulogic_vector(index_size_f(MEM_INT_DMEM_SIZE)-1 downto 0) := (others => '0');
233
 
234 61 zero_gravi
  -- helpers --
235
  constant io_slink_en_c : boolean := boolean(SLINK_NUM_RX > 0) or boolean(SLINK_NUM_TX > 0); -- implement slink at all?
236
 
237 2 zero_gravi
  -- reset generator --
238 63 zero_gravi
  signal rstn_gen : std_ulogic_vector(7 downto 0) := (others => '0'); -- initialize (=reset) via  (for FPGAs only)
239 60 zero_gravi
  signal ext_rstn : std_ulogic;
240
  signal sys_rstn : std_ulogic;
241
  signal wdt_rstn : std_ulogic;
242 2 zero_gravi
 
243
  -- clock generator --
244
  signal clk_div    : std_ulogic_vector(11 downto 0);
245
  signal clk_div_ff : std_ulogic_vector(11 downto 0);
246
  signal clk_gen    : std_ulogic_vector(07 downto 0);
247 61 zero_gravi
  signal clk_gen_en : std_ulogic_vector(07 downto 0);
248 47 zero_gravi
  --
249 52 zero_gravi
  signal wdt_cg_en    : std_ulogic;
250
  signal uart0_cg_en  : std_ulogic;
251
  signal uart1_cg_en  : std_ulogic;
252
  signal spi_cg_en    : std_ulogic;
253
  signal twi_cg_en    : std_ulogic;
254
  signal pwm_cg_en    : std_ulogic;
255
  signal cfs_cg_en    : std_ulogic;
256
  signal neoled_cg_en : std_ulogic;
257 2 zero_gravi
 
258 12 zero_gravi
  -- bus interface --
259
  type bus_interface_t is record
260 11 zero_gravi
    addr   : std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
261
    rdata  : std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
262
    wdata  : std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
263
    ben    : std_ulogic_vector(03 downto 0); -- byte enable
264
    we     : std_ulogic; -- write enable
265
    re     : std_ulogic; -- read enable
266
    ack    : std_ulogic; -- bus transfer acknowledge
267
    err    : std_ulogic; -- bus transfer error
268 12 zero_gravi
    fence  : std_ulogic; -- fence(i) instruction executed
269 35 zero_gravi
    priv   : std_ulogic_vector(1 downto 0); -- current privilege level
270 40 zero_gravi
    src    : std_ulogic; -- access source (1=instruction fetch, 0=data access)
271 57 zero_gravi
    lock   : std_ulogic; -- exclusive access request
272 11 zero_gravi
  end record;
273 41 zero_gravi
  signal cpu_i, i_cache, cpu_d, p_bus : bus_interface_t;
274 2 zero_gravi
 
275 59 zero_gravi
  -- debug core interface (DCI) --
276
  signal dci_ndmrstn  : std_ulogic;
277
  signal dci_halt_req : std_ulogic;
278
 
279
  -- debug module interface (DMI) --
280
  type dmi_t is record
281
    rstn       : std_ulogic;
282
    req_valid  : std_ulogic;
283
    req_ready  : std_ulogic; -- DMI is allowed to make new requests when set
284
    req_addr   : std_ulogic_vector(06 downto 0);
285
    req_op     : std_ulogic; -- 0=read, 1=write
286
    req_data   : std_ulogic_vector(31 downto 0);
287
    resp_valid : std_ulogic; -- response valid when set
288
    resp_ready : std_ulogic; -- ready to receive respond
289
    resp_data  : std_ulogic_vector(31 downto 0);
290
    resp_err   : std_ulogic; -- 0=ok, 1=error
291
  end record;
292
  signal dmi : dmi_t;
293
 
294 2 zero_gravi
  -- io space access --
295
  signal io_acc  : std_ulogic;
296
  signal io_rden : std_ulogic;
297
  signal io_wren : std_ulogic;
298
 
299 60 zero_gravi
  -- module response bus - entry type --
300
  type resp_bus_entry_t is record
301
    rdata : std_ulogic_vector(data_width_c-1 downto 0);
302
    ack   : std_ulogic;
303
    err   : std_ulogic;
304
  end record;
305
  constant resp_bus_entry_terminate_c : resp_bus_entry_t := (rdata => (others => '0'), ack => '0', err => '0');
306 2 zero_gravi
 
307 60 zero_gravi
  -- module response bus - device ID --
308
  type resp_bus_id_t is (RESP_IMEM, RESP_DMEM, RESP_BOOTROM, RESP_WISHBONE, RESP_GPIO, RESP_MTIME, RESP_UART0, RESP_UART1, RESP_SPI,
309 61 zero_gravi
                         RESP_TWI, RESP_PWM, RESP_WDT, RESP_TRNG, RESP_CFS, RESP_NEOLED, RESP_SYSINFO, RESP_OCD, RESP_SLINK, RESP_XIRQ);
310 60 zero_gravi
 
311
  -- module response bus --
312
  type resp_bus_t is array (resp_bus_id_t) of resp_bus_entry_t;
313
  signal resp_bus : resp_bus_t := (others => resp_bus_entry_terminate_c);
314
 
315 2 zero_gravi
  -- IRQs --
316 59 zero_gravi
  signal fast_irq      : std_ulogic_vector(15 downto 0);
317 60 zero_gravi
  signal mtime_irq     : std_ulogic;
318 50 zero_gravi
  signal wdt_irq       : std_ulogic;
319
  signal uart0_rxd_irq : std_ulogic;
320
  signal uart0_txd_irq : std_ulogic;
321
  signal uart1_rxd_irq : std_ulogic;
322
  signal uart1_txd_irq : std_ulogic;
323
  signal spi_irq       : std_ulogic;
324
  signal twi_irq       : std_ulogic;
325
  signal cfs_irq       : std_ulogic;
326 52 zero_gravi
  signal neoled_irq    : std_ulogic;
327 61 zero_gravi
  signal slink_tx_irq  : std_ulogic;
328
  signal slink_rx_irq  : std_ulogic;
329
  signal xirq_irq      : std_ulogic;
330 2 zero_gravi
 
331 11 zero_gravi
  -- misc --
332 60 zero_gravi
  signal mtime_time     : std_ulogic_vector(63 downto 0); -- current system time from MTIME
333
  signal cpu_sleep      : std_ulogic; -- CPU is in sleep mode when set
334
  signal bus_keeper_err : std_ulogic; -- bus keeper: bus access timeout
335 11 zero_gravi
 
336 2 zero_gravi
begin
337
 
338 61 zero_gravi
  -- Processor IO/Peripherals Configuration -------------------------------------------------
339
  -- -------------------------------------------------------------------------------------------
340
  assert false report
341
  "NEORV32 PROCESSOR IO Configuration: " &
342
  cond_sel_string_f(IO_GPIO_EN, "GPIO ", "") &
343
  cond_sel_string_f(IO_MTIME_EN, "MTIME ", "") &
344
  cond_sel_string_f(IO_UART0_EN, "UART0 ", "") &
345
  cond_sel_string_f(IO_UART1_EN, "UART1 ", "") &
346
  cond_sel_string_f(IO_SPI_EN, "SPI ", "") &
347
  cond_sel_string_f(IO_TWI_EN, "TWI ", "") &
348
  cond_sel_string_f(boolean(IO_PWM_NUM_CH > 0), "PWM ", "") &
349
  cond_sel_string_f(IO_WDT_EN, "WDT ", "") &
350
  cond_sel_string_f(IO_TRNG_EN, "TRNG ", "") &
351
  cond_sel_string_f(IO_CFS_EN, "CFS ", "") &
352
  cond_sel_string_f(io_slink_en_c, "SLINK ", "") &
353
  cond_sel_string_f(IO_NEOLED_EN, "NEOLED ", "") &
354
  cond_sel_string_f(boolean(XIRQ_NUM_CH > 0), "XIRQ ", "") &
355
  ""
356
  severity note;
357
 
358
 
359 2 zero_gravi
  -- Sanity Checks --------------------------------------------------------------------------
360
  -- -------------------------------------------------------------------------------------------
361 61 zero_gravi
  -- boot configuration --
362
  assert not (INT_BOOTLOADER_EN = true) report "NEORV32 PROCESSOR CONFIG NOTE: Boot configuration: Indirect boot via bootloader (processor-internal BOOTROM)." severity note;
363
  assert not ((INT_BOOTLOADER_EN = false) and (MEM_INT_IMEM_EN = true)) report "NEORV32 PROCESSOR CONFIG NOTE: Boot configuration: Direct boot from memory (processor-internal IMEM)." severity note;
364
  assert not ((INT_BOOTLOADER_EN = false) and (MEM_INT_IMEM_EN = false)) report "NEORV32 PROCESSOR CONFIG NOTE: Boot configuration: Direct boot from memory (processor-external (I)MEM)." severity note;
365
  --
366
  assert not ((MEM_EXT_EN = false) and (MEM_INT_DMEM_EN = false)) report "NEORV32 PROCESSOR CONFIG ERROR! Core cannot fetch data without external memory interface and internal IMEM." severity error;
367
  assert not ((MEM_EXT_EN = false) and (MEM_INT_IMEM_EN = false) and (INT_BOOTLOADER_EN = false)) report "NEORV32 PROCESSOR CONFIG ERROR! Core cannot fetch instructions without external memory interface, internal IMEM and bootloader." severity error;
368
 
369 36 zero_gravi
  -- memory system - size --
370 44 zero_gravi
  assert not ((MEM_INT_DMEM_EN = true) and (is_power_of_two_f(MEM_INT_IMEM_SIZE) = false)) report "NEORV32 PROCESSOR CONFIG WARNING! MEM_INT_IMEM_SIZE should be a power of 2 to allow optimal hardware mapping." severity warning;
371
  assert not ((MEM_INT_IMEM_EN = true) and (is_power_of_two_f(MEM_INT_DMEM_SIZE) = false)) report "NEORV32 PROCESSOR CONFIG WARNING! MEM_INT_DMEM_SIZE should be a power of 2 to allow optimal hardware mapping." severity warning;
372 61 zero_gravi
 
373 29 zero_gravi
  -- memory system - alignment --
374
  assert not (ispace_base_c(1 downto 0) /= "00") report "NEORV32 PROCESSOR CONFIG ERROR! Instruction memory space base address must be 4-byte-aligned." severity error;
375
  assert not (dspace_base_c(1 downto 0) /= "00") report "NEORV32 PROCESSOR CONFIG ERROR! Data memory space base address must be 4-byte-aligned." severity error;
376 44 zero_gravi
  assert not ((ispace_base_c(index_size_f(MEM_INT_IMEM_SIZE)-1 downto 0) /= imem_align_check_c) and (MEM_INT_IMEM_EN = true)) report "NEORV32 PROCESSOR CONFIG ERROR! Instruction memory space base address has to be aligned to IMEM size." severity error;
377
  assert not ((dspace_base_c(index_size_f(MEM_INT_DMEM_SIZE)-1 downto 0) /= dmem_align_check_c) and (MEM_INT_DMEM_EN = true)) report "NEORV32 PROCESSOR CONFIG ERROR! Data memory space base address has to be aligned to DMEM size." severity error;
378 61 zero_gravi
 
379 36 zero_gravi
  -- memory system - layout warning --
380 29 zero_gravi
  assert not (ispace_base_c /= x"00000000") report "NEORV32 PROCESSOR CONFIG WARNING! Non-default base address for instruction address space. Make sure this is sync with the software framework." severity warning;
381
  assert not (dspace_base_c /= x"80000000") report "NEORV32 PROCESSOR CONFIG WARNING! Non-default base address for data address space. Make sure this is sync with the software framework." severity warning;
382 61 zero_gravi
 
383 41 zero_gravi
  -- memory system - the i-cache is intended to accelerate instruction fetch via the external memory interface only --
384 44 zero_gravi
  assert not ((ICACHE_EN = true) and (MEM_EXT_EN = false)) report "NEORV32 PROCESSOR CONFIG NOTE. Implementing i-cache without having the external memory interface implemented. The i-cache is intended to accelerate instruction fetch via the external memory interface." severity note;
385 61 zero_gravi
 
386 59 zero_gravi
  -- on-chip debugger --
387 61 zero_gravi
  assert not (ON_CHIP_DEBUGGER_EN = true) report "NEORV32 PROCESSOR CONFIG NOTE: Implementing on-chip debugger (OCD)." severity note;
388 2 zero_gravi
 
389 59 zero_gravi
 
390 2 zero_gravi
  -- Reset Generator ------------------------------------------------------------------------
391
  -- -------------------------------------------------------------------------------------------
392 60 zero_gravi
  reset_generator: process(rstn_i, clk_i)
393 2 zero_gravi
  begin
394 60 zero_gravi
    if (rstn_i = '0') then
395 2 zero_gravi
      rstn_gen <= (others => '0');
396 60 zero_gravi
      sys_rstn <= '0';
397 2 zero_gravi
    elsif rising_edge(clk_i) then
398 60 zero_gravi
      -- keep internal reset active for at least <rstn_gen'size> clock cycles --
399 2 zero_gravi
      rstn_gen <= rstn_gen(rstn_gen'left-1 downto 0) & '1';
400 60 zero_gravi
      -- system reset: can also be triggered by watchdog and debug module --
401
      sys_rstn <= ext_rstn and wdt_rstn and dci_ndmrstn;
402 2 zero_gravi
    end if;
403
  end process reset_generator;
404
 
405 60 zero_gravi
  -- beautified external reset signal --
406
  ext_rstn <= rstn_gen(rstn_gen'left);
407 2 zero_gravi
 
408
 
409
  -- Clock Generator ------------------------------------------------------------------------
410
  -- -------------------------------------------------------------------------------------------
411
  clock_generator: process(sys_rstn, clk_i)
412
  begin
413
    if (sys_rstn = '0') then
414 60 zero_gravi
      clk_gen_en <= (others => '-');
415 2 zero_gravi
      clk_div    <= (others => '0');
416 60 zero_gravi
      clk_div_ff <= (others => '-');
417
      clk_gen    <= (others => '-');
418 2 zero_gravi
    elsif rising_edge(clk_i) then
419 23 zero_gravi
      -- fresh clocks anyone? --
420 50 zero_gravi
      clk_gen_en(0) <= wdt_cg_en;
421
      clk_gen_en(1) <= uart0_cg_en;
422
      clk_gen_en(2) <= uart1_cg_en;
423
      clk_gen_en(3) <= spi_cg_en;
424
      clk_gen_en(4) <= twi_cg_en;
425
      clk_gen_en(5) <= pwm_cg_en;
426
      clk_gen_en(6) <= cfs_cg_en;
427 61 zero_gravi
      clk_gen_en(7) <= neoled_cg_en;
428 60 zero_gravi
      -- actual clock generator --
429
      if (or_reduce_f(clk_gen_en) = '1') then
430 23 zero_gravi
        clk_div <= std_ulogic_vector(unsigned(clk_div) + 1);
431 2 zero_gravi
      end if;
432 60 zero_gravi
      -- clock enables: rising edge detectors --
433 23 zero_gravi
      clk_div_ff <= clk_div;
434
      clk_gen(clk_div2_c)    <= clk_div(0)  and (not clk_div_ff(0));  -- CLK/2
435
      clk_gen(clk_div4_c)    <= clk_div(1)  and (not clk_div_ff(1));  -- CLK/4
436
      clk_gen(clk_div8_c)    <= clk_div(2)  and (not clk_div_ff(2));  -- CLK/8
437
      clk_gen(clk_div64_c)   <= clk_div(5)  and (not clk_div_ff(5));  -- CLK/64
438
      clk_gen(clk_div128_c)  <= clk_div(6)  and (not clk_div_ff(6));  -- CLK/128
439
      clk_gen(clk_div1024_c) <= clk_div(9)  and (not clk_div_ff(9));  -- CLK/1024
440
      clk_gen(clk_div2048_c) <= clk_div(10) and (not clk_div_ff(10)); -- CLK/2048
441
      clk_gen(clk_div4096_c) <= clk_div(11) and (not clk_div_ff(11)); -- CLK/4096
442
    end if;
443 60 zero_gravi
  end process clock_generator;
444 2 zero_gravi
 
445
 
446 45 zero_gravi
  -- CPU Core -------------------------------------------------------------------------------
447 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
448
  neorv32_cpu_inst: neorv32_cpu
449
  generic map (
450
    -- General --
451 41 zero_gravi
    HW_THREAD_ID                 => HW_THREAD_ID,        -- hardware thread id
452
    CPU_BOOT_ADDR                => cpu_boot_addr_c,     -- cpu boot address
453 59 zero_gravi
    CPU_DEBUG_ADDR               => dm_base_c,           -- cpu debug mode start address
454 2 zero_gravi
    -- RISC-V CPU Extensions --
455 39 zero_gravi
    CPU_EXTENSION_RISCV_A        => CPU_EXTENSION_RISCV_A,        -- implement atomic extension?
456 8 zero_gravi
    CPU_EXTENSION_RISCV_C        => CPU_EXTENSION_RISCV_C,        -- implement compressed extension?
457
    CPU_EXTENSION_RISCV_E        => CPU_EXTENSION_RISCV_E,        -- implement embedded RF extension?
458
    CPU_EXTENSION_RISCV_M        => CPU_EXTENSION_RISCV_M,        -- implement muld/div extension?
459 15 zero_gravi
    CPU_EXTENSION_RISCV_U        => CPU_EXTENSION_RISCV_U,        -- implement user mode extension?
460 63 zero_gravi
    CPU_EXTENSION_RISCV_Zbb      => CPU_EXTENSION_RISCV_Zbb,      -- implement basic bit-manipulation sub-extension?
461 55 zero_gravi
    CPU_EXTENSION_RISCV_Zfinx    => CPU_EXTENSION_RISCV_Zfinx,    -- implement 32-bit floating-point extension (using INT reg!)
462 8 zero_gravi
    CPU_EXTENSION_RISCV_Zicsr    => CPU_EXTENSION_RISCV_Zicsr,    -- implement CSR system?
463
    CPU_EXTENSION_RISCV_Zifencei => CPU_EXTENSION_RISCV_Zifencei, -- implement instruction stream sync.?
464 61 zero_gravi
    CPU_EXTENSION_RISCV_Zmmul    => CPU_EXTENSION_RISCV_Zmmul,    -- implement multiply-only M sub-extension?
465 59 zero_gravi
    CPU_EXTENSION_RISCV_DEBUG    => ON_CHIP_DEBUGGER_EN,          -- implement CPU debug mode?
466 19 zero_gravi
    -- Extension Options --
467 41 zero_gravi
    FAST_MUL_EN                  => FAST_MUL_EN,         -- use DSPs for M extension's multiplier
468
    FAST_SHIFT_EN                => FAST_SHIFT_EN,       -- use barrel shifter for shift operations
469 56 zero_gravi
    CPU_CNT_WIDTH                => CPU_CNT_WIDTH,       -- total width of CPU cycle and instret counters (0..64)
470 62 zero_gravi
    CPU_IPB_ENTRIES              => CPU_IPB_ENTRIES,     -- entries is instruction prefetch buffer, has to be a power of 2
471 15 zero_gravi
    -- Physical Memory Protection (PMP) --
472 42 zero_gravi
    PMP_NUM_REGIONS              => PMP_NUM_REGIONS,     -- number of regions (0..64)
473
    PMP_MIN_GRANULARITY          => PMP_MIN_GRANULARITY, -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
474
    -- Hardware Performance Monitors (HPM) --
475 56 zero_gravi
    HPM_NUM_CNTS                 => HPM_NUM_CNTS,        -- number of implemented HPM counters (0..29)
476 60 zero_gravi
    HPM_CNT_WIDTH                => HPM_CNT_WIDTH        -- total size of HPM counters (0..64)
477 2 zero_gravi
  )
478
  port map (
479
    -- global control --
480 12 zero_gravi
    clk_i          => clk_i,        -- global clock, rising edge
481
    rstn_i         => sys_rstn,     -- global reset, low-active, async
482 47 zero_gravi
    sleep_o        => cpu_sleep,    -- cpu is in sleep mode when set
483 12 zero_gravi
    -- instruction bus interface --
484
    i_bus_addr_o   => cpu_i.addr,   -- bus access address
485
    i_bus_rdata_i  => cpu_i.rdata,  -- bus read data
486
    i_bus_wdata_o  => cpu_i.wdata,  -- bus write data
487
    i_bus_ben_o    => cpu_i.ben,    -- byte enable
488
    i_bus_we_o     => cpu_i.we,     -- write enable
489
    i_bus_re_o     => cpu_i.re,     -- read enable
490 57 zero_gravi
    i_bus_lock_o   => cpu_i.lock,   -- exclusive access request
491 12 zero_gravi
    i_bus_ack_i    => cpu_i.ack,    -- bus transfer acknowledge
492
    i_bus_err_i    => cpu_i.err,    -- bus transfer error
493
    i_bus_fence_o  => cpu_i.fence,  -- executed FENCEI operation
494 35 zero_gravi
    i_bus_priv_o   => cpu_i.priv,   -- privilege level
495 12 zero_gravi
    -- data bus interface --
496
    d_bus_addr_o   => cpu_d.addr,   -- bus access address
497
    d_bus_rdata_i  => cpu_d.rdata,  -- bus read data
498
    d_bus_wdata_o  => cpu_d.wdata,  -- bus write data
499
    d_bus_ben_o    => cpu_d.ben,    -- byte enable
500
    d_bus_we_o     => cpu_d.we,     -- write enable
501
    d_bus_re_o     => cpu_d.re,     -- read enable
502 57 zero_gravi
    d_bus_lock_o   => cpu_d.lock,   -- exclusive access request
503 12 zero_gravi
    d_bus_ack_i    => cpu_d.ack,    -- bus transfer acknowledge
504
    d_bus_err_i    => cpu_d.err,    -- bus transfer error
505
    d_bus_fence_o  => cpu_d.fence,  -- executed FENCE operation
506 35 zero_gravi
    d_bus_priv_o   => cpu_d.priv,   -- privilege level
507 11 zero_gravi
    -- system time input from MTIME --
508 12 zero_gravi
    time_i         => mtime_time,   -- current system time
509 58 zero_gravi
    -- non-maskable interrupt --
510 64 zero_gravi
    msw_irq_i      => msw_irq_i,    -- machine software interrupt
511
    mext_irq_i     => mext_irq_i,   -- machine external interrupt request
512 14 zero_gravi
    mtime_irq_i    => mtime_irq,    -- machine timer interrupt
513
    -- fast interrupts (custom) --
514 47 zero_gravi
    firq_i         => fast_irq,     -- fast interrupt trigger
515 59 zero_gravi
    -- debug mode (halt) request --
516
    db_halt_req_i  => dci_halt_req
517 2 zero_gravi
  );
518
 
519 36 zero_gravi
  -- misc --
520 57 zero_gravi
  cpu_i.src <= '1'; -- initialized but unused
521
  cpu_d.src <= '0'; -- initialized but unused
522 36 zero_gravi
 
523 14 zero_gravi
  -- advanced memory control --
524
  fence_o  <= cpu_d.fence; -- indicates an executed FENCE operation
525
  fencei_o <= cpu_i.fence; -- indicates an executed FENCEI operation
526 2 zero_gravi
 
527 61 zero_gravi
  -- fast interrupts --
528 50 zero_gravi
  fast_irq(00) <= wdt_irq;       -- HIGHEST PRIORITY - watchdog timeout
529
  fast_irq(01) <= cfs_irq;       -- custom functions subsystem
530
  fast_irq(02) <= uart0_rxd_irq; -- primary UART (UART0) data received
531
  fast_irq(03) <= uart0_txd_irq; -- primary UART (UART0) sending done
532
  fast_irq(04) <= uart1_rxd_irq; -- secondary UART (UART1) data received
533
  fast_irq(05) <= uart1_txd_irq; -- secondary UART (UART1) sending done
534
  fast_irq(06) <= spi_irq;       -- SPI transmission done
535
  fast_irq(07) <= twi_irq;       -- TWI transmission done
536 61 zero_gravi
  fast_irq(08) <= xirq_irq;      -- external interrupt controller
537 52 zero_gravi
  fast_irq(09) <= neoled_irq;    -- NEOLED buffer free
538 61 zero_gravi
  fast_irq(10) <= slink_rx_irq;  -- SLINK data received
539
  fast_irq(11) <= slink_tx_irq;  -- SLINK data send
540
  --
541 62 zero_gravi
  fast_irq(12) <= '0'; -- reserved
542
  fast_irq(13) <= '0'; -- reserved
543
  fast_irq(14) <= '0'; -- reserved
544
  fast_irq(15) <= '0'; -- reserved
545 14 zero_gravi
 
546
 
547 41 zero_gravi
  -- CPU Instruction Cache ------------------------------------------------------------------
548
  -- -------------------------------------------------------------------------------------------
549
  neorv32_icache_inst_true:
550 44 zero_gravi
  if (ICACHE_EN = true) generate
551 45 zero_gravi
    neorv32_icache_inst: neorv32_icache
552 41 zero_gravi
    generic map (
553 47 zero_gravi
      ICACHE_NUM_BLOCKS => ICACHE_NUM_BLOCKS,   -- number of blocks (min 2), has to be a power of 2
554
      ICACHE_BLOCK_SIZE => ICACHE_BLOCK_SIZE,   -- block size in bytes (min 4), has to be a power of 2
555
      ICACHE_NUM_SETS   => ICACHE_ASSOCIATIVITY -- associativity / number of sets (1=direct_mapped), has to be a power of 2
556 41 zero_gravi
    )
557
    port map (
558
      -- global control --
559
      clk_i         => clk_i,          -- global clock, rising edge
560
      rstn_i        => sys_rstn,       -- global reset, low-active, async
561
      clear_i       => cpu_i.fence,    -- cache clear
562
      -- host controller interface --
563
      host_addr_i   => cpu_i.addr,     -- bus access address
564
      host_rdata_o  => cpu_i.rdata,    -- bus read data
565
      host_wdata_i  => cpu_i.wdata,    -- bus write data
566
      host_ben_i    => cpu_i.ben,      -- byte enable
567
      host_we_i     => cpu_i.we,       -- write enable
568
      host_re_i     => cpu_i.re,       -- read enable
569
      host_ack_o    => cpu_i.ack,      -- bus transfer acknowledge
570
      host_err_o    => cpu_i.err,      -- bus transfer error
571
      -- peripheral bus interface --
572
      bus_addr_o    => i_cache.addr,   -- bus access address
573
      bus_rdata_i   => i_cache.rdata,  -- bus read data
574
      bus_wdata_o   => i_cache.wdata,  -- bus write data
575
      bus_ben_o     => i_cache.ben,    -- byte enable
576
      bus_we_o      => i_cache.we,     -- write enable
577
      bus_re_o      => i_cache.re,     -- read enable
578
      bus_ack_i     => i_cache.ack,    -- bus transfer acknowledge
579
      bus_err_i     => i_cache.err     -- bus transfer error
580
    );
581
  end generate;
582
 
583 57 zero_gravi
  -- TODO: do not use LOCKED instruction fetch --
584
  i_cache.lock <= '0';
585
 
586 41 zero_gravi
  neorv32_icache_inst_false:
587 44 zero_gravi
  if (ICACHE_EN = false) generate
588 57 zero_gravi
    i_cache.addr  <= cpu_i.addr;
589
    cpu_i.rdata   <= i_cache.rdata;
590
    i_cache.wdata <= cpu_i.wdata;
591
    i_cache.ben   <= cpu_i.ben;
592
    i_cache.we    <= cpu_i.we;
593
    i_cache.re    <= cpu_i.re;
594
    cpu_i.ack     <= i_cache.ack;
595
    cpu_i.err     <= i_cache.err;
596 41 zero_gravi
  end generate;
597
 
598
 
599 45 zero_gravi
  -- CPU Bus Switch -------------------------------------------------------------------------
600 12 zero_gravi
  -- -------------------------------------------------------------------------------------------
601
  neorv32_busswitch_inst: neorv32_busswitch
602
  generic map (
603
    PORT_CA_READ_ONLY => false, -- set if controller port A is read-only
604
    PORT_CB_READ_ONLY => true   -- set if controller port B is read-only
605
  )
606
  port map (
607
    -- global control --
608 41 zero_gravi
    clk_i           => clk_i,          -- global clock, rising edge
609
    rstn_i          => sys_rstn,       -- global reset, low-active, async
610 12 zero_gravi
    -- controller interface a --
611 41 zero_gravi
    ca_bus_addr_i   => cpu_d.addr,     -- bus access address
612
    ca_bus_rdata_o  => cpu_d.rdata,    -- bus read data
613
    ca_bus_wdata_i  => cpu_d.wdata,    -- bus write data
614
    ca_bus_ben_i    => cpu_d.ben,      -- byte enable
615
    ca_bus_we_i     => cpu_d.we,       -- write enable
616
    ca_bus_re_i     => cpu_d.re,       -- read enable
617 57 zero_gravi
    ca_bus_lock_i   => cpu_d.lock,     -- exclusive access request
618 41 zero_gravi
    ca_bus_ack_o    => cpu_d.ack,      -- bus transfer acknowledge
619
    ca_bus_err_o    => cpu_d.err,      -- bus transfer error
620 12 zero_gravi
    -- controller interface b --
621 41 zero_gravi
    cb_bus_addr_i   => i_cache.addr,   -- bus access address
622
    cb_bus_rdata_o  => i_cache.rdata,  -- bus read data
623
    cb_bus_wdata_i  => i_cache.wdata,  -- bus write data
624
    cb_bus_ben_i    => i_cache.ben,    -- byte enable
625
    cb_bus_we_i     => i_cache.we,     -- write enable
626
    cb_bus_re_i     => i_cache.re,     -- read enable
627 57 zero_gravi
    cb_bus_lock_i   => i_cache.lock,   -- exclusive access request
628 41 zero_gravi
    cb_bus_ack_o    => i_cache.ack,    -- bus transfer acknowledge
629
    cb_bus_err_o    => i_cache.err,    -- bus transfer error
630 12 zero_gravi
    -- peripheral bus --
631 41 zero_gravi
    p_bus_src_o     => p_bus.src,      -- access source: 0 = A (data), 1 = B (instructions)
632
    p_bus_addr_o    => p_bus.addr,     -- bus access address
633
    p_bus_rdata_i   => p_bus.rdata,    -- bus read data
634
    p_bus_wdata_o   => p_bus.wdata,    -- bus write data
635
    p_bus_ben_o     => p_bus.ben,      -- byte enable
636
    p_bus_we_o      => p_bus.we,       -- write enable
637
    p_bus_re_o      => p_bus.re,       -- read enable
638 57 zero_gravi
    p_bus_lock_o    => p_bus.lock,     -- exclusive access request
639 41 zero_gravi
    p_bus_ack_i     => p_bus.ack,      -- bus transfer acknowledge
640
    p_bus_err_i     => p_bus.err       -- bus transfer error
641 12 zero_gravi
  );
642 2 zero_gravi
 
643 60 zero_gravi
  -- current CPU privilege level --
644
  p_bus.priv <= cpu_i.priv; -- note: cpu_i.priv == cpu_d.priv
645 53 zero_gravi
 
646 60 zero_gravi
  -- fence operation (unused) --
647
  p_bus.fence <= cpu_d.fence or cpu_i.fence;
648 2 zero_gravi
 
649 60 zero_gravi
  -- bus response --
650
  bus_response: process(resp_bus, bus_keeper_err)
651
    variable rdata_v : std_ulogic_vector(data_width_c-1 downto 0);
652
    variable ack_v   : std_ulogic;
653
    variable err_v   : std_ulogic;
654
  begin
655
    rdata_v := (others => '0');
656
    ack_v   := '0';
657
    err_v   := '0';
658
    for i in resp_bus'range loop
659
      rdata_v := rdata_v or resp_bus(i).rdata; -- read data
660
      ack_v   := ack_v   or resp_bus(i).ack;   -- acknowledge
661
      err_v   := err_v   or resp_bus(i).err;   -- error
662
    end loop; -- i
663
    p_bus.rdata <= rdata_v; -- processor bus: CPU transfer data input
664
    p_bus.ack   <= ack_v;   -- processor bus: CPU transfer ACK input
665
    p_bus.err   <= err_v or bus_keeper_err; -- processor bus: CPU transfer data bus error input
666
  end process;
667 12 zero_gravi
 
668
 
669 59 zero_gravi
  -- Processor-Internal Bus Keeper (BUS_KEEPER) ---------------------------------------------
670 57 zero_gravi
  -- -------------------------------------------------------------------------------------------
671
  neorv32_bus_keeper_inst: neorv32_bus_keeper
672
  generic map (
673 59 zero_gravi
    -- External memory interface --
674
    MEM_EXT_EN        => MEM_EXT_EN,        -- implement external memory bus interface?
675 57 zero_gravi
    -- Internal instruction memory --
676
    MEM_INT_IMEM_EN   => MEM_INT_IMEM_EN,   -- implement processor-internal instruction memory
677
    MEM_INT_IMEM_SIZE => MEM_INT_IMEM_SIZE, -- size of processor-internal instruction memory in bytes
678
    -- Internal data memory --
679
    MEM_INT_DMEM_EN   => MEM_INT_DMEM_EN,   -- implement processor-internal data memory
680
    MEM_INT_DMEM_SIZE => MEM_INT_DMEM_SIZE  -- size of processor-internal data memory in bytes
681
  )
682
  port map (
683
    -- host access --
684
    clk_i  => clk_i,         -- global clock line
685
    rstn_i => sys_rstn,      -- global reset line, low-active
686
    addr_i => p_bus.addr,    -- address
687
    rden_i => p_bus.re,      -- read enable
688
    wren_i => p_bus.we,      -- write enable
689
    ack_i  => p_bus.ack,     -- transfer acknowledge from bus system
690
    err_i  => p_bus.err,     -- transfer error from bus system
691
    err_o  => bus_keeper_err -- bus error
692
  );
693 36 zero_gravi
 
694 57 zero_gravi
 
695 2 zero_gravi
  -- Processor-Internal Instruction Memory (IMEM) -------------------------------------------
696
  -- -------------------------------------------------------------------------------------------
697
  neorv32_int_imem_inst_true:
698 44 zero_gravi
  if (MEM_INT_IMEM_EN = true) generate
699 2 zero_gravi
    neorv32_int_imem_inst: neorv32_imem
700
    generic map (
701 61 zero_gravi
      IMEM_BASE    => imem_base_c,          -- memory base address
702
      IMEM_SIZE    => MEM_INT_IMEM_SIZE,    -- processor-internal instruction memory size in bytes
703
      IMEM_AS_IROM => not INT_BOOTLOADER_EN -- implement IMEM as pre-initialized read-only memory?
704 2 zero_gravi
    )
705
    port map (
706 60 zero_gravi
      clk_i  => clk_i,                     -- global clock line
707
      rden_i => p_bus.re,                  -- read enable
708
      wren_i => p_bus.we,                  -- write enable
709
      ben_i  => p_bus.ben,                 -- byte write enable
710
      addr_i => p_bus.addr,                -- address
711
      data_i => p_bus.wdata,               -- data in
712
      data_o => resp_bus(RESP_IMEM).rdata, -- data out
713
      ack_o  => resp_bus(RESP_IMEM).ack    -- transfer acknowledge
714 2 zero_gravi
    );
715 60 zero_gravi
    resp_bus(RESP_IMEM).err <= '0'; -- no access error possible
716 2 zero_gravi
  end generate;
717
 
718
  neorv32_int_imem_inst_false:
719 44 zero_gravi
  if (MEM_INT_IMEM_EN = false) generate
720 60 zero_gravi
    resp_bus(RESP_IMEM) <= resp_bus_entry_terminate_c;
721 2 zero_gravi
  end generate;
722
 
723
 
724
  -- Processor-Internal Data Memory (DMEM) --------------------------------------------------
725
  -- -------------------------------------------------------------------------------------------
726
  neorv32_int_dmem_inst_true:
727 44 zero_gravi
  if (MEM_INT_DMEM_EN = true) generate
728 2 zero_gravi
    neorv32_int_dmem_inst: neorv32_dmem
729
    generic map (
730 23 zero_gravi
      DMEM_BASE => dmem_base_c,      -- memory base address
731 2 zero_gravi
      DMEM_SIZE => MEM_INT_DMEM_SIZE -- processor-internal data memory size in bytes
732
    )
733
    port map (
734 60 zero_gravi
      clk_i  => clk_i,                     -- global clock line
735
      rden_i => p_bus.re,                  -- read enable
736
      wren_i => p_bus.we,                  -- write enable
737
      ben_i  => p_bus.ben,                 -- byte write enable
738
      addr_i => p_bus.addr,                -- address
739
      data_i => p_bus.wdata,               -- data in
740
      data_o => resp_bus(RESP_DMEM).rdata, -- data out
741
      ack_o  => resp_bus(RESP_DMEM).ack    -- transfer acknowledge
742 2 zero_gravi
    );
743 60 zero_gravi
    resp_bus(RESP_DMEM).err <= '0'; -- no access error possible
744 2 zero_gravi
  end generate;
745
 
746
  neorv32_int_dmem_inst_false:
747 44 zero_gravi
  if (MEM_INT_DMEM_EN = false) generate
748 60 zero_gravi
    resp_bus(RESP_DMEM) <= resp_bus_entry_terminate_c;
749 2 zero_gravi
  end generate;
750
 
751
 
752
  -- Processor-Internal Bootloader ROM (BOOTROM) --------------------------------------------
753
  -- -------------------------------------------------------------------------------------------
754
  neorv32_boot_rom_inst_true:
755 61 zero_gravi
  if (INT_BOOTLOADER_EN = true) generate
756 2 zero_gravi
    neorv32_boot_rom_inst: neorv32_boot_rom
757 23 zero_gravi
    generic map (
758 61 zero_gravi
      BOOTROM_BASE => boot_rom_base_c -- boot ROM base address
759 23 zero_gravi
    )
760 2 zero_gravi
    port map (
761 60 zero_gravi
      clk_i  => clk_i,                        -- global clock line
762
      rden_i => p_bus.re,                     -- read enable
763
      addr_i => p_bus.addr,                   -- address
764
      data_o => resp_bus(RESP_BOOTROM).rdata, -- data out
765
      ack_o  => resp_bus(RESP_BOOTROM).ack    -- transfer acknowledge
766 2 zero_gravi
    );
767 60 zero_gravi
    resp_bus(RESP_BOOTROM).err <= '0'; -- no access error possible
768 2 zero_gravi
  end generate;
769
 
770
  neorv32_boot_rom_inst_false:
771 61 zero_gravi
  if (INT_BOOTLOADER_EN = false) generate
772 60 zero_gravi
    resp_bus(RESP_BOOTROM) <= resp_bus_entry_terminate_c;
773 2 zero_gravi
  end generate;
774
 
775
 
776
  -- External Wishbone Gateway (WISHBONE) ---------------------------------------------------
777
  -- -------------------------------------------------------------------------------------------
778
  neorv32_wishbone_inst_true:
779 44 zero_gravi
  if (MEM_EXT_EN = true) generate
780 2 zero_gravi
    neorv32_wishbone_inst: neorv32_wishbone
781
    generic map (
782 23 zero_gravi
      -- Internal instruction memory --
783 62 zero_gravi
      MEM_INT_IMEM_EN   => MEM_INT_IMEM_EN,    -- implement processor-internal instruction memory
784
      MEM_INT_IMEM_SIZE => MEM_INT_IMEM_SIZE,  -- size of processor-internal instruction memory in bytes
785 23 zero_gravi
      -- Internal data memory --
786 62 zero_gravi
      MEM_INT_DMEM_EN   => MEM_INT_DMEM_EN,    -- implement processor-internal data memory
787
      MEM_INT_DMEM_SIZE => MEM_INT_DMEM_SIZE,  -- size of processor-internal data memory in bytes
788
      -- Interface Configuration --
789
      BUS_TIMEOUT       => MEM_EXT_TIMEOUT,    -- cycles after an UNACKNOWLEDGED bus access triggers a bus fault exception
790
      PIPE_MODE         => MEM_EXT_PIPE_MODE,  -- protocol: false=classic/standard wishbone mode, true=pipelined wishbone mode
791
      BIG_ENDIAN        => MEM_EXT_BIG_ENDIAN, -- byte order: true=big-endian, false=little-endian
792
      ASYNC_RX          => MEM_EXT_ASYNC_RX    -- use register buffer for RX data when false
793 2 zero_gravi
    )
794
    port map (
795
      -- global control --
796 60 zero_gravi
      clk_i     => clk_i,                         -- global clock line
797
      rstn_i    => sys_rstn,                      -- global reset line, low-active
798 2 zero_gravi
      -- host access --
799 60 zero_gravi
      src_i     => p_bus.src,                     -- access type (0: data, 1:instruction)
800
      addr_i    => p_bus.addr,                    -- address
801
      rden_i    => p_bus.re,                      -- read enable
802
      wren_i    => p_bus.we,                      -- write enable
803
      ben_i     => p_bus.ben,                     -- byte write enable
804
      data_i    => p_bus.wdata,                   -- data in
805
      data_o    => resp_bus(RESP_WISHBONE).rdata, -- data out
806
      lock_i    => p_bus.lock,                    -- exclusive access request
807
      ack_o     => resp_bus(RESP_WISHBONE).ack,   -- transfer acknowledge
808
      err_o     => resp_bus(RESP_WISHBONE).err,   -- transfer error
809
      priv_i    => p_bus.priv,                    -- current CPU privilege level
810 2 zero_gravi
      -- wishbone interface --
811 60 zero_gravi
      wb_tag_o  => wb_tag_o,                      -- request tag
812
      wb_adr_o  => wb_adr_o,                      -- address
813
      wb_dat_i  => wb_dat_i,                      -- read data
814
      wb_dat_o  => wb_dat_o,                      -- write data
815
      wb_we_o   => wb_we_o,                       -- read/write
816
      wb_sel_o  => wb_sel_o,                      -- byte enable
817
      wb_stb_o  => wb_stb_o,                      -- strobe
818
      wb_cyc_o  => wb_cyc_o,                      -- valid cycle
819
      wb_lock_o => wb_lock_o,                     -- exclusive access request
820
      wb_ack_i  => wb_ack_i,                      -- transfer acknowledge
821
      wb_err_i  => wb_err_i                       -- transfer error
822 2 zero_gravi
    );
823
  end generate;
824
 
825
  neorv32_wishbone_inst_false:
826 44 zero_gravi
  if (MEM_EXT_EN = false) generate
827 60 zero_gravi
    resp_bus(RESP_WISHBONE) <= resp_bus_entry_terminate_c;
828 2 zero_gravi
    --
829 60 zero_gravi
    wb_adr_o  <= (others => '0');
830
    wb_dat_o  <= (others => '0');
831
    wb_we_o   <= '0';
832
    wb_sel_o  <= (others => '0');
833
    wb_stb_o  <= '0';
834
    wb_cyc_o  <= '0';
835
    wb_lock_o <= '0';
836
    wb_tag_o  <= (others => '0');
837 2 zero_gravi
  end generate;
838
 
839
 
840
  -- IO Access? -----------------------------------------------------------------------------
841
  -- -------------------------------------------------------------------------------------------
842 12 zero_gravi
  io_acc  <= '1' when (p_bus.addr(data_width_c-1 downto index_size_f(io_size_c)) = io_base_c(data_width_c-1 downto index_size_f(io_size_c))) else '0';
843 40 zero_gravi
  io_rden <= io_acc and p_bus.re and (not p_bus.src); -- PMA: no_execute for IO region
844 47 zero_gravi
  -- the default NEORV32 peripheral/IO devices in the IO area can only be written in word mode (reduces HW complexity)
845 60 zero_gravi
  io_wren <= io_acc and p_bus.we and and_reduce_f(p_bus.ben) and (not p_bus.src); -- PMA: write32 only, no_execute for IO region
846 2 zero_gravi
 
847
 
848 47 zero_gravi
  -- Custom Functions Subsystem (CFS) -------------------------------------------------------
849
  -- -------------------------------------------------------------------------------------------
850
  neorv32_cfs_inst_true:
851
  if (IO_CFS_EN = true) generate
852
    neorv32_cfs_inst: neorv32_cfs
853
    generic map (
854 61 zero_gravi
      CFS_CONFIG   => IO_CFS_CONFIG,  -- custom CFS configuration generic
855 52 zero_gravi
      CFS_IN_SIZE  => IO_CFS_IN_SIZE, -- size of CFS input conduit in bits
856
      CFS_OUT_SIZE => IO_CFS_OUT_SIZE -- size of CFS output conduit in bits
857 47 zero_gravi
    )
858
    port map (
859
      -- host access --
860 60 zero_gravi
      clk_i       => clk_i,                    -- global clock line
861
      rstn_i      => sys_rstn,                 -- global reset line, low-active, use as async
862
      addr_i      => p_bus.addr,               -- address
863
      rden_i      => io_rden,                  -- read enable
864
      wren_i      => io_wren,                  -- byte write enable
865
      data_i      => p_bus.wdata,              -- data in
866
      data_o      => resp_bus(RESP_CFS).rdata, -- data out
867
      ack_o       => resp_bus(RESP_CFS).ack,   -- transfer acknowledge
868 47 zero_gravi
      -- clock generator --
869 60 zero_gravi
      clkgen_en_o => cfs_cg_en,                -- enable clock generator
870
      clkgen_i    => clk_gen,                  -- "clock" inputs
871 47 zero_gravi
      -- CPU state --
872 60 zero_gravi
      sleep_i     => cpu_sleep,                -- set if cpu is in sleep mode
873 47 zero_gravi
      -- interrupt --
874 60 zero_gravi
      irq_o       => cfs_irq,                  -- interrupt request
875 47 zero_gravi
      -- custom io (conduit) --
876 60 zero_gravi
      cfs_in_i    => cfs_in_i,                 -- custom inputs
877
      cfs_out_o   => cfs_out_o                 -- custom outputs
878 47 zero_gravi
    );
879 60 zero_gravi
    resp_bus(RESP_CFS).err <= '0'; -- no access error possible
880 47 zero_gravi
  end generate;
881
 
882
  neorv32_cfs_inst_false:
883
  if (IO_CFS_EN = false) generate
884 60 zero_gravi
    resp_bus(RESP_CFS) <= resp_bus_entry_terminate_c;
885 47 zero_gravi
    cfs_cg_en <= '0';
886
    cfs_irq   <= '0';
887
    cfs_out_o <= (others => '0');
888
  end generate;
889
 
890
 
891 2 zero_gravi
  -- General Purpose Input/Output Port (GPIO) -----------------------------------------------
892
  -- -------------------------------------------------------------------------------------------
893
  neorv32_gpio_inst_true:
894 44 zero_gravi
  if (IO_GPIO_EN = true) generate
895 2 zero_gravi
    neorv32_gpio_inst: neorv32_gpio
896
    port map (
897
      -- host access --
898 60 zero_gravi
      clk_i  => clk_i,                     -- global clock line
899
      addr_i => p_bus.addr,                -- address
900
      rden_i => io_rden,                   -- read enable
901
      wren_i => io_wren,                   -- write enable
902
      data_i => p_bus.wdata,               -- data in
903
      data_o => resp_bus(RESP_GPIO).rdata, -- data out
904
      ack_o  => resp_bus(RESP_GPIO).ack,   -- transfer acknowledge
905 2 zero_gravi
      -- parallel io --
906
      gpio_o => gpio_o,
907 61 zero_gravi
      gpio_i => gpio_i
908 2 zero_gravi
    );
909 60 zero_gravi
    resp_bus(RESP_GPIO).err <= '0'; -- no access error possible
910 2 zero_gravi
  end generate;
911
 
912
  neorv32_gpio_inst_false:
913 44 zero_gravi
  if (IO_GPIO_EN = false) generate
914 60 zero_gravi
    resp_bus(RESP_GPIO) <= resp_bus_entry_terminate_c;
915 61 zero_gravi
    gpio_o <= (others => '0');
916 2 zero_gravi
  end generate;
917
 
918
 
919
  -- Watch Dog Timer (WDT) ------------------------------------------------------------------
920
  -- -------------------------------------------------------------------------------------------
921
  neorv32_wdt_inst_true:
922 44 zero_gravi
  if (IO_WDT_EN = true) generate
923 2 zero_gravi
    neorv32_wdt_inst: neorv32_wdt
924
    port map (
925
      -- host access --
926 60 zero_gravi
      clk_i       => clk_i,                    -- global clock line
927
      rstn_i      => ext_rstn,                 -- global reset line, low-active
928
      rden_i      => io_rden,                  -- read enable
929
      wren_i      => io_wren,                  -- write enable
930
      addr_i      => p_bus.addr,               -- address
931
      data_i      => p_bus.wdata,              -- data in
932
      data_o      => resp_bus(RESP_WDT).rdata, -- data out
933
      ack_o       => resp_bus(RESP_WDT).ack,   -- transfer acknowledge
934 2 zero_gravi
      -- clock generator --
935 60 zero_gravi
      clkgen_en_o => wdt_cg_en,                -- enable clock generator
936 2 zero_gravi
      clkgen_i    => clk_gen,
937
      -- timeout event --
938 60 zero_gravi
      irq_o       => wdt_irq,                  -- timeout IRQ
939
      rstn_o      => wdt_rstn                  -- timeout reset, low_active, use it as async!
940 2 zero_gravi
    );
941 60 zero_gravi
    resp_bus(RESP_WDT).err <= '0'; -- no access error possible
942 2 zero_gravi
  end generate;
943
 
944
  neorv32_wdt_inst_false:
945 44 zero_gravi
  if (IO_WDT_EN = false) generate
946 60 zero_gravi
    resp_bus(RESP_WDT) <= resp_bus_entry_terminate_c;
947 2 zero_gravi
    wdt_irq   <= '0';
948
    wdt_rstn  <= '1';
949
    wdt_cg_en <= '0';
950
  end generate;
951
 
952
 
953
  -- Machine System Timer (MTIME) -----------------------------------------------------------
954
  -- -------------------------------------------------------------------------------------------
955
  neorv32_mtime_inst_true:
956 44 zero_gravi
  if (IO_MTIME_EN = true) generate
957 2 zero_gravi
    neorv32_mtime_inst: neorv32_mtime
958
    port map (
959
      -- host access --
960 60 zero_gravi
      clk_i  => clk_i,                      -- global clock line
961
      addr_i => p_bus.addr,                 -- address
962
      rden_i => io_rden,                    -- read enable
963
      wren_i => io_wren,                    -- write enable
964
      data_i => p_bus.wdata,                -- data in
965
      data_o => resp_bus(RESP_MTIME).rdata, -- data out
966
      ack_o  => resp_bus(RESP_MTIME).ack,   -- transfer acknowledge
967 11 zero_gravi
      -- time output for CPU --
968 60 zero_gravi
      time_o => mtime_time,                 -- current system time
969 2 zero_gravi
      -- interrupt --
970 60 zero_gravi
      irq_o  => mtime_irq                   -- interrupt request
971 2 zero_gravi
    );
972 60 zero_gravi
    resp_bus(RESP_MTIME).err <= '0'; -- no access error possible
973 2 zero_gravi
  end generate;
974
 
975
  neorv32_mtime_inst_false:
976 44 zero_gravi
  if (IO_MTIME_EN = false) generate
977 60 zero_gravi
    resp_bus(RESP_MTIME) <= resp_bus_entry_terminate_c;
978
    mtime_time <= mtime_i; -- use external machine timer time signal
979 64 zero_gravi
    mtime_irq  <= mtime_irq_i; -- use external machine timer interrupt
980 2 zero_gravi
  end generate;
981
 
982
 
983 60 zero_gravi
  -- system time output LO --
984
  mtime_sync: process(clk_i)
985
  begin
986
    if rising_edge(clk_i) then
987
      -- buffer low word one clock cycle to compensate for MTIME's 1-cycle delay
988
      -- when overflowing from low-word to high-word -> only relevant for processor-external devices
989
      -- processor-internal devices (= the CPU) do not care about this delay offset as 64-bit MTIME.TIME
990
      -- cannot be accessed within a single cycle
991
      if (IO_MTIME_EN = true) then
992
        mtime_o(31 downto 0) <= mtime_time(31 downto 0);
993
      else
994
        mtime_o(31 downto 0) <= (others => '0');
995
      end if;
996
    end if;
997
  end process mtime_sync;
998 59 zero_gravi
 
999 60 zero_gravi
  -- system time output HI --
1000
  mtime_o(63 downto 32) <= mtime_time(63 downto 32) when (IO_MTIME_EN = true) else (others => '0');
1001
 
1002
 
1003 51 zero_gravi
  -- Primary Universal Asynchronous Receiver/Transmitter (UART0) ----------------------------
1004 2 zero_gravi
  -- -------------------------------------------------------------------------------------------
1005 50 zero_gravi
  neorv32_uart0_inst_true:
1006
  if (IO_UART0_EN = true) generate
1007
    neorv32_uart0_inst: neorv32_uart
1008
    generic map (
1009
      UART_PRIMARY => true -- true = primary UART (UART0), false = secondary UART (UART1)
1010
    )
1011 2 zero_gravi
    port map (
1012
      -- host access --
1013 60 zero_gravi
      clk_i       => clk_i,                      -- global clock line
1014
      addr_i      => p_bus.addr,                 -- address
1015
      rden_i      => io_rden,                    -- read enable
1016
      wren_i      => io_wren,                    -- write enable
1017
      data_i      => p_bus.wdata,                -- data in
1018
      data_o      => resp_bus(RESP_UART0).rdata, -- data out
1019
      ack_o       => resp_bus(RESP_UART0).ack,   -- transfer acknowledge
1020 2 zero_gravi
      -- clock generator --
1021 60 zero_gravi
      clkgen_en_o => uart0_cg_en,                -- enable clock generator
1022 2 zero_gravi
      clkgen_i    => clk_gen,
1023
      -- com lines --
1024 50 zero_gravi
      uart_txd_o  => uart0_txd_o,
1025
      uart_rxd_i  => uart0_rxd_i,
1026 51 zero_gravi
      -- hardware flow control --
1027 60 zero_gravi
      uart_rts_o  => uart0_rts_o,                -- UART.RX ready to receive ("RTR"), low-active, optional
1028
      uart_cts_i  => uart0_cts_i,                -- UART.TX allowed to transmit, low-active, optional
1029 2 zero_gravi
      -- interrupts --
1030 60 zero_gravi
      irq_rxd_o   => uart0_rxd_irq,              -- uart data received interrupt
1031
      irq_txd_o   => uart0_txd_irq               -- uart transmission done interrupt
1032 2 zero_gravi
    );
1033 60 zero_gravi
    resp_bus(RESP_UART0).err <= '0'; -- no access error possible
1034 2 zero_gravi
  end generate;
1035
 
1036 50 zero_gravi
  neorv32_uart0_inst_false:
1037
  if (IO_UART0_EN = false) generate
1038 60 zero_gravi
    resp_bus(RESP_UART0) <= resp_bus_entry_terminate_c;
1039 50 zero_gravi
    uart0_txd_o   <= '0';
1040 51 zero_gravi
    uart0_rts_o   <= '0';
1041 50 zero_gravi
    uart0_cg_en   <= '0';
1042
    uart0_rxd_irq <= '0';
1043
    uart0_txd_irq <= '0';
1044 2 zero_gravi
  end generate;
1045
 
1046
 
1047 51 zero_gravi
  -- Secondary Universal Asynchronous Receiver/Transmitter (UART1) --------------------------
1048 50 zero_gravi
  -- -------------------------------------------------------------------------------------------
1049
  neorv32_uart1_inst_true:
1050
  if (IO_UART1_EN = true) generate
1051
    neorv32_uart1_inst: neorv32_uart
1052
    generic map (
1053
      UART_PRIMARY => false -- true = primary UART (UART0), false = secondary UART (UART1)
1054
    )
1055
    port map (
1056
      -- host access --
1057 60 zero_gravi
      clk_i       => clk_i,                      -- global clock line
1058
      addr_i      => p_bus.addr,                 -- address
1059
      rden_i      => io_rden,                    -- read enable
1060
      wren_i      => io_wren,                    -- write enable
1061
      data_i      => p_bus.wdata,                -- data in
1062
      data_o      => resp_bus(RESP_UART1).rdata, -- data out
1063
      ack_o       => resp_bus(RESP_UART1).ack,   -- transfer acknowledge
1064 50 zero_gravi
      -- clock generator --
1065 60 zero_gravi
      clkgen_en_o => uart1_cg_en,                -- enable clock generator
1066 50 zero_gravi
      clkgen_i    => clk_gen,
1067
      -- com lines --
1068
      uart_txd_o  => uart1_txd_o,
1069
      uart_rxd_i  => uart1_rxd_i,
1070 51 zero_gravi
      -- hardware flow control --
1071 60 zero_gravi
      uart_rts_o  => uart1_rts_o,                -- UART.RX ready to receive ("RTR"), low-active, optional
1072
      uart_cts_i  => uart1_cts_i,                -- UART.TX allowed to transmit, low-active, optional
1073 50 zero_gravi
      -- interrupts --
1074 60 zero_gravi
      irq_rxd_o   => uart1_rxd_irq,              -- uart data received interrupt
1075
      irq_txd_o   => uart1_txd_irq               -- uart transmission done interrupt
1076 50 zero_gravi
    );
1077 60 zero_gravi
    resp_bus(RESP_UART1).err <= '0'; -- no access error possible
1078 50 zero_gravi
  end generate;
1079
 
1080
  neorv32_uart1_inst_false:
1081
  if (IO_UART1_EN = false) generate
1082 60 zero_gravi
    resp_bus(RESP_UART1) <= resp_bus_entry_terminate_c;
1083 50 zero_gravi
    uart1_txd_o   <= '0';
1084 51 zero_gravi
    uart1_rts_o   <= '0';
1085 50 zero_gravi
    uart1_cg_en   <= '0';
1086
    uart1_rxd_irq <= '0';
1087
    uart1_txd_irq <= '0';
1088
  end generate;
1089
 
1090
 
1091 2 zero_gravi
  -- Serial Peripheral Interface (SPI) ------------------------------------------------------
1092
  -- -------------------------------------------------------------------------------------------
1093
  neorv32_spi_inst_true:
1094 44 zero_gravi
  if (IO_SPI_EN = true) generate
1095 2 zero_gravi
    neorv32_spi_inst: neorv32_spi
1096
    port map (
1097
      -- host access --
1098 60 zero_gravi
      clk_i       => clk_i,                    -- global clock line
1099
      addr_i      => p_bus.addr,               -- address
1100
      rden_i      => io_rden,                  -- read enable
1101
      wren_i      => io_wren,                  -- write enable
1102
      data_i      => p_bus.wdata,              -- data in
1103
      data_o      => resp_bus(RESP_SPI).rdata, -- data out
1104
      ack_o       => resp_bus(RESP_SPI).ack,   -- transfer acknowledge
1105 2 zero_gravi
      -- clock generator --
1106 60 zero_gravi
      clkgen_en_o => spi_cg_en,                -- enable clock generator
1107 2 zero_gravi
      clkgen_i    => clk_gen,
1108
      -- com lines --
1109 60 zero_gravi
      spi_sck_o   => spi_sck_o,                -- SPI serial clock
1110
      spi_sdo_o   => spi_sdo_o,                -- controller data out, peripheral data in
1111
      spi_sdi_i   => spi_sdi_i,                -- controller data in, peripheral data out
1112
      spi_csn_o   => spi_csn_o,                -- SPI CS
1113 2 zero_gravi
      -- interrupt --
1114 60 zero_gravi
      irq_o       => spi_irq                   -- transmission done interrupt
1115 2 zero_gravi
    );
1116 60 zero_gravi
    resp_bus(RESP_SPI).err <= '0'; -- no access error possible
1117 2 zero_gravi
  end generate;
1118
 
1119
  neorv32_spi_inst_false:
1120 44 zero_gravi
  if (IO_SPI_EN = false) generate
1121 60 zero_gravi
    resp_bus(RESP_SPI) <= resp_bus_entry_terminate_c;
1122
    spi_sck_o <= '0';
1123
    spi_sdo_o <= '0';
1124
    spi_csn_o <= (others => '1'); -- CSn lines are low-active
1125
    spi_cg_en <= '0';
1126
    spi_irq   <= '0';
1127 2 zero_gravi
  end generate;
1128
 
1129
 
1130
  -- Two-Wire Interface (TWI) ---------------------------------------------------------------
1131
  -- -------------------------------------------------------------------------------------------
1132
  neorv32_twi_inst_true:
1133 44 zero_gravi
  if (IO_TWI_EN = true) generate
1134 2 zero_gravi
    neorv32_twi_inst: neorv32_twi
1135
    port map (
1136
      -- host access --
1137 60 zero_gravi
      clk_i       => clk_i,                    -- global clock line
1138
      addr_i      => p_bus.addr,               -- address
1139
      rden_i      => io_rden,                  -- read enable
1140
      wren_i      => io_wren,                  -- write enable
1141
      data_i      => p_bus.wdata,              -- data in
1142
      data_o      => resp_bus(RESP_TWI).rdata, -- data out
1143
      ack_o       => resp_bus(RESP_TWI).ack,   -- transfer acknowledge
1144 2 zero_gravi
      -- clock generator --
1145 60 zero_gravi
      clkgen_en_o => twi_cg_en,                -- enable clock generator
1146 2 zero_gravi
      clkgen_i    => clk_gen,
1147
      -- com lines --
1148 60 zero_gravi
      twi_sda_io  => twi_sda_io,               -- serial data line
1149
      twi_scl_io  => twi_scl_io,               -- serial clock line
1150 2 zero_gravi
      -- interrupt --
1151 60 zero_gravi
      irq_o       => twi_irq                   -- transfer done IRQ
1152 2 zero_gravi
    );
1153 60 zero_gravi
    resp_bus(RESP_TWI).err <= '0'; -- no access error possible
1154 2 zero_gravi
  end generate;
1155
 
1156
  neorv32_twi_inst_false:
1157 44 zero_gravi
  if (IO_TWI_EN = false) generate
1158 60 zero_gravi
    resp_bus(RESP_TWI) <= resp_bus_entry_terminate_c;
1159 51 zero_gravi
--  twi_sda_io <= 'Z'; -- FIXME?
1160
--  twi_scl_io <= 'Z'; -- FIXME?
1161 2 zero_gravi
    twi_cg_en  <= '0';
1162
    twi_irq    <= '0';
1163
  end generate;
1164
 
1165
 
1166
  -- Pulse-Width Modulation Controller (PWM) ------------------------------------------------
1167
  -- -------------------------------------------------------------------------------------------
1168
  neorv32_pwm_inst_true:
1169 60 zero_gravi
  if (IO_PWM_NUM_CH > 0) generate
1170 2 zero_gravi
    neorv32_pwm_inst: neorv32_pwm
1171 60 zero_gravi
    generic map (
1172
      NUM_CHANNELS => IO_PWM_NUM_CH -- number of PWM channels (0..60)
1173
    )
1174 2 zero_gravi
    port map (
1175
      -- host access --
1176 60 zero_gravi
      clk_i       => clk_i,                    -- global clock line
1177
      addr_i      => p_bus.addr,               -- address
1178
      rden_i      => io_rden,                  -- read enable
1179
      wren_i      => io_wren,                  -- write enable
1180
      data_i      => p_bus.wdata,              -- data in
1181
      data_o      => resp_bus(RESP_PWM).rdata, -- data out
1182
      ack_o       => resp_bus(RESP_PWM).ack,   -- transfer acknowledge
1183 2 zero_gravi
      -- clock generator --
1184 60 zero_gravi
      clkgen_en_o => pwm_cg_en,                -- enable clock generator
1185 2 zero_gravi
      clkgen_i    => clk_gen,
1186
      -- pwm output channels --
1187
      pwm_o       => pwm_o
1188
    );
1189 60 zero_gravi
    resp_bus(RESP_PWM).err <= '0'; -- no access error possible
1190 2 zero_gravi
  end generate;
1191
 
1192
  neorv32_pwm_inst_false:
1193 60 zero_gravi
  if (IO_PWM_NUM_CH = 0) generate
1194
    resp_bus(RESP_PWM) <= resp_bus_entry_terminate_c;
1195 2 zero_gravi
    pwm_cg_en <= '0';
1196
    pwm_o     <= (others => '0');
1197
  end generate;
1198
 
1199
 
1200
  -- True Random Number Generator (TRNG) ----------------------------------------------------
1201
  -- -------------------------------------------------------------------------------------------
1202
  neorv32_trng_inst_true:
1203 44 zero_gravi
  if (IO_TRNG_EN = true) generate
1204 2 zero_gravi
    neorv32_trng_inst: neorv32_trng
1205
    port map (
1206
      -- host access --
1207 60 zero_gravi
      clk_i  => clk_i,                     -- global clock line
1208
      addr_i => p_bus.addr,                -- address
1209
      rden_i => io_rden,                   -- read enable
1210
      wren_i => io_wren,                   -- write enable
1211
      data_i => p_bus.wdata,               -- data in
1212
      data_o => resp_bus(RESP_TRNG).rdata, -- data out
1213
      ack_o  => resp_bus(RESP_TRNG).ack    -- transfer acknowledge
1214 2 zero_gravi
    );
1215 60 zero_gravi
    resp_bus(RESP_TRNG).err <= '0'; -- no access error possible
1216 2 zero_gravi
  end generate;
1217
 
1218
  neorv32_trng_inst_false:
1219 44 zero_gravi
  if (IO_TRNG_EN = false) generate
1220 60 zero_gravi
    resp_bus(RESP_TRNG) <= resp_bus_entry_terminate_c;
1221 2 zero_gravi
  end generate;
1222
 
1223
 
1224 52 zero_gravi
  -- Smart LED (WS2811/WS2812) Interface (NEOLED) -------------------------------------------
1225
  -- -------------------------------------------------------------------------------------------
1226
  neorv32_neoled_inst_true:
1227
  if (IO_NEOLED_EN = true) generate
1228
    neorv32_neoled_inst: neorv32_neoled
1229 62 zero_gravi
    generic map (
1230
      FIFO_DEPTH => IO_NEOLED_TX_FIFO -- TX FIFO depth (1..32k, power of two)
1231
    )
1232 52 zero_gravi
    port map (
1233
      -- host access --
1234 60 zero_gravi
      clk_i       => clk_i,                       -- global clock line
1235
      addr_i      => p_bus.addr,                  -- address
1236
      rden_i      => io_rden,                     -- read enable
1237
      wren_i      => io_wren,                     -- write enable
1238
      data_i      => p_bus.wdata,                 -- data in
1239
      data_o      => resp_bus(RESP_NEOLED).rdata, -- data out
1240
      ack_o       => resp_bus(RESP_NEOLED).ack,   -- transfer acknowledge
1241 52 zero_gravi
      -- clock generator --
1242 60 zero_gravi
      clkgen_en_o => neoled_cg_en,                -- enable clock generator
1243 52 zero_gravi
      clkgen_i    => clk_gen,
1244
      -- interrupt --
1245 60 zero_gravi
      irq_o       => neoled_irq,                  -- interrupt request
1246 52 zero_gravi
      -- NEOLED output --
1247 60 zero_gravi
      neoled_o    => neoled_o                     -- serial async data line
1248 52 zero_gravi
    );
1249 60 zero_gravi
    resp_bus(RESP_NEOLED).err <= '0'; -- no access error possible
1250 52 zero_gravi
  end generate;
1251
 
1252
  neorv32_neoled_inst_false:
1253
  if (IO_NEOLED_EN = false) generate
1254 60 zero_gravi
    resp_bus(RESP_NEOLED) <= resp_bus_entry_terminate_c;
1255 52 zero_gravi
    neoled_cg_en <= '0';
1256
    neoled_irq   <= '0';
1257
    neoled_o     <= '0';
1258
  end generate;
1259
 
1260
 
1261 61 zero_gravi
  -- Stream Link Interface (SLINK) ----------------------------------------------------------
1262
  -- -------------------------------------------------------------------------------------------
1263
  neorv32_slink_inst_true:
1264
  if (io_slink_en_c = true) generate
1265
    neorv32_slink_inst: neorv32_slink
1266
    generic map (
1267
      SLINK_NUM_TX  => SLINK_NUM_TX,  -- number of TX links (0..8)
1268
      SLINK_NUM_RX  => SLINK_NUM_RX,  -- number of TX links (0..8)
1269
      SLINK_TX_FIFO => SLINK_TX_FIFO, -- TX fifo depth, has to be a power of two
1270
      SLINK_RX_FIFO => SLINK_RX_FIFO  -- RX fifo depth, has to be a power of two
1271
    )
1272
    port map (
1273
      -- host access --
1274
      clk_i          => clk_i,                      -- global clock line
1275
      addr_i         => p_bus.addr,                 -- address
1276
      rden_i         => io_rden,                    -- read enable
1277
      wren_i         => io_wren,                    -- write enable
1278
      data_i         => p_bus.wdata,                -- data in
1279
      data_o         => resp_bus(RESP_SLINK).rdata, -- data out
1280
      ack_o          => resp_bus(RESP_SLINK).ack,   -- transfer acknowledge
1281
      -- interrupt --
1282
      irq_tx_o       => slink_tx_irq,               -- transmission done
1283
      irq_rx_o       => slink_rx_irq,               -- data received
1284
      -- TX stream interfaces --
1285
      slink_tx_dat_o => slink_tx_dat_o,             -- output data
1286
      slink_tx_val_o => slink_tx_val_o,             -- valid output
1287
      slink_tx_rdy_i => slink_tx_rdy_i,             -- ready to send
1288
      -- RX stream interfaces --
1289
      slink_rx_dat_i => slink_rx_dat_i,             -- input data
1290
      slink_rx_val_i => slink_rx_val_i,             -- valid input
1291
      slink_rx_rdy_o => slink_rx_rdy_o              -- ready to receive
1292
    );
1293
    resp_bus(RESP_SLINK).err <= '0'; -- no access error possible
1294
  end generate;
1295
 
1296
  neorv32_slink_inst_false:
1297
  if (io_slink_en_c = false) generate
1298
    resp_bus(RESP_SLINK) <= resp_bus_entry_terminate_c;
1299
    slink_tx_irq   <= '0';
1300
    slink_rx_irq   <= '0';
1301
    slink_tx_dat_o <= (others => (others => '0'));
1302
    slink_tx_val_o <= (others => '0');
1303
    slink_rx_rdy_o <= (others => '0');
1304
  end generate;
1305
 
1306
 
1307
  -- External Interrupt Controller (XIRQ) ---------------------------------------------------
1308
  -- -------------------------------------------------------------------------------------------
1309
  neorv32_xirq_inst_true:
1310
  if (XIRQ_NUM_CH > 0) generate
1311
    neorv32_slink_inst: neorv32_xirq
1312
    generic map (
1313
      XIRQ_NUM_CH           => XIRQ_NUM_CH,          -- number of external IRQ channels (0..32)
1314
      XIRQ_TRIGGER_TYPE     => XIRQ_TRIGGER_TYPE,    -- trigger type: 0=level, 1=edge
1315
      XIRQ_TRIGGER_POLARITY => XIRQ_TRIGGER_POLARITY -- trigger polarity: 0=low-level/falling-edge, 1=high-level/rising-edge
1316
    )
1317
    port map (
1318
      -- host access --
1319
      clk_i     => clk_i,                     -- global clock line
1320
      addr_i    => p_bus.addr,                -- address
1321
      rden_i    => io_rden,                   -- read enable
1322
      wren_i    => io_wren,                   -- write enable
1323
      data_i    => p_bus.wdata,               -- data in
1324
      data_o    => resp_bus(RESP_XIRQ).rdata, -- data out
1325
      ack_o     => resp_bus(RESP_XIRQ).ack,   -- transfer acknowledge
1326
      -- external interrupt lines --
1327
      xirq_i    => xirq_i,
1328
      -- CPU interrupt --
1329
      cpu_irq_o => xirq_irq
1330
    );
1331
    resp_bus(RESP_XIRQ).err <= '0'; -- no access error possible
1332
  end generate;
1333
 
1334
  neorv32_xirq_inst_false:
1335
  if (XIRQ_NUM_CH = 0) generate
1336
    resp_bus(RESP_XIRQ) <= resp_bus_entry_terminate_c;
1337
    xirq_irq <= '0';
1338
  end generate;
1339
 
1340
 
1341 12 zero_gravi
  -- System Configuration Information Memory (SYSINFO) --------------------------------------
1342
  -- -------------------------------------------------------------------------------------------
1343
  neorv32_sysinfo_inst: neorv32_sysinfo
1344
  generic map (
1345
    -- General --
1346 63 zero_gravi
    CLOCK_FREQUENCY              => CLOCK_FREQUENCY,      -- clock frequency of clk_i in Hz
1347
    INT_BOOTLOADER_EN            => INT_BOOTLOADER_EN,    -- implement processor-internal bootloader?
1348
    -- RISC-V CPU Extensions --
1349
    CPU_EXTENSION_RISCV_Zbb      => CPU_EXTENSION_RISCV_Zbb,      -- implement basic bit-manipulation sub-extension?
1350
    CPU_EXTENSION_RISCV_Zfinx    => CPU_EXTENSION_RISCV_Zfinx,    -- implement 32-bit floating-point extension (using INT reg!)
1351
    CPU_EXTENSION_RISCV_Zicsr    => CPU_EXTENSION_RISCV_Zicsr,    -- implement CSR system?
1352
    CPU_EXTENSION_RISCV_Zifencei => CPU_EXTENSION_RISCV_Zifencei, -- implement instruction stream sync.?
1353
    CPU_EXTENSION_RISCV_Zmmul    => CPU_EXTENSION_RISCV_Zmmul,    -- implement multiply-only M sub-extension?
1354
    CPU_EXTENSION_RISCV_DEBUG    => ON_CHIP_DEBUGGER_EN,          -- implement CPU debug mode?
1355
    -- Extension Options --
1356
    FAST_MUL_EN                  => FAST_MUL_EN,          -- use DSPs for M extension's multiplier
1357
    FAST_SHIFT_EN                => FAST_SHIFT_EN,        -- use barrel shifter for shift operations
1358
    CPU_CNT_WIDTH                => CPU_CNT_WIDTH,        -- total width of CPU cycle and instret counters (0..64)
1359
    -- Physical memory protection (PMP) --
1360
    PMP_NUM_REGIONS              => PMP_NUM_REGIONS,      -- number of regions (0..64)
1361
    -- Hardware Performance Monitors (HPM) --
1362
    HPM_NUM_CNTS                 => HPM_NUM_CNTS,         -- number of implemented HPM counters (0..29)
1363 23 zero_gravi
    -- internal Instruction memory --
1364 63 zero_gravi
    MEM_INT_IMEM_EN              => MEM_INT_IMEM_EN,      -- implement processor-internal instruction memory
1365
    MEM_INT_IMEM_SIZE            => MEM_INT_IMEM_SIZE,    -- size of processor-internal instruction memory in bytes
1366 23 zero_gravi
    -- Internal Data memory --
1367 63 zero_gravi
    MEM_INT_DMEM_EN              => MEM_INT_DMEM_EN,      -- implement processor-internal data memory
1368
    MEM_INT_DMEM_SIZE            => MEM_INT_DMEM_SIZE,    -- size of processor-internal data memory in bytes
1369 41 zero_gravi
    -- Internal Cache memory --
1370 63 zero_gravi
    ICACHE_EN                    => ICACHE_EN,            -- implement instruction cache
1371
    ICACHE_NUM_BLOCKS            => ICACHE_NUM_BLOCKS,    -- i-cache: number of blocks (min 2), has to be a power of 2
1372
    ICACHE_BLOCK_SIZE            => ICACHE_BLOCK_SIZE,    -- i-cache: block size in bytes (min 4), has to be a power of 2
1373
    ICACHE_ASSOCIATIVITY         => ICACHE_ASSOCIATIVITY, -- i-cache: associativity (min 1), has to be a power 2
1374 23 zero_gravi
    -- External memory interface --
1375 63 zero_gravi
    MEM_EXT_EN                   => MEM_EXT_EN,           -- implement external memory bus interface?
1376
    MEM_EXT_BIG_ENDIAN           => MEM_EXT_BIG_ENDIAN,   -- byte order: true=big-endian, false=little-endian
1377 59 zero_gravi
    -- On-Chip Debugger --
1378 63 zero_gravi
    ON_CHIP_DEBUGGER_EN          => ON_CHIP_DEBUGGER_EN,  -- implement OCD?
1379 12 zero_gravi
    -- Processor peripherals --
1380 63 zero_gravi
    IO_GPIO_EN                   => IO_GPIO_EN,           -- implement general purpose input/output port unit (GPIO)?
1381
    IO_MTIME_EN                  => IO_MTIME_EN,          -- implement machine system timer (MTIME)?
1382
    IO_UART0_EN                  => IO_UART0_EN,          -- implement primary universal asynchronous receiver/transmitter (UART0)?
1383
    IO_UART1_EN                  => IO_UART1_EN,          -- implement secondary universal asynchronous receiver/transmitter (UART1)?
1384
    IO_SPI_EN                    => IO_SPI_EN,            -- implement serial peripheral interface (SPI)?
1385
    IO_TWI_EN                    => IO_TWI_EN,            -- implement two-wire interface (TWI)?
1386
    IO_PWM_NUM_CH                => IO_PWM_NUM_CH,        -- number of PWM channels to implement
1387
    IO_WDT_EN                    => IO_WDT_EN,            -- implement watch dog timer (WDT)?
1388
    IO_TRNG_EN                   => IO_TRNG_EN,           -- implement true random number generator (TRNG)?
1389
    IO_CFS_EN                    => IO_CFS_EN,            -- implement custom functions subsystem (CFS)?
1390
    IO_SLINK_EN                  => io_slink_en_c,        -- implement stream link interface?
1391
    IO_NEOLED_EN                 => IO_NEOLED_EN,         -- implement NeoPixel-compatible smart LED interface (NEOLED)?
1392
    IO_XIRQ_NUM_CH               => XIRQ_NUM_CH           -- number of external interrupt (XIRQ) channels to implement
1393 12 zero_gravi
  )
1394
  port map (
1395
    -- host access --
1396 60 zero_gravi
    clk_i  => clk_i,                        -- global clock line
1397
    addr_i => p_bus.addr,                   -- address
1398
    rden_i => io_rden,                      -- read enable
1399
    data_o => resp_bus(RESP_SYSINFO).rdata, -- data out
1400
    ack_o  => resp_bus(RESP_SYSINFO).ack    -- transfer acknowledge
1401 12 zero_gravi
  );
1402
 
1403 60 zero_gravi
  resp_bus(RESP_SYSINFO).err <= '0'; -- no access error possible
1404 12 zero_gravi
 
1405 60 zero_gravi
 
1406 59 zero_gravi
  -- **************************************************************************************************************************
1407
  -- On-Chip Debugger Complex
1408
  -- **************************************************************************************************************************
1409
 
1410
 
1411
  -- On-Chip Debugger - Debug Module (DM) ---------------------------------------------------
1412
  -- -------------------------------------------------------------------------------------------
1413
  neorv32_neorv32_debug_dm_true:
1414
  if (ON_CHIP_DEBUGGER_EN = true) generate
1415
    neorv32_debug_dm_inst: neorv32_debug_dm
1416
    port map (
1417
      -- global control --
1418 60 zero_gravi
      clk_i            => clk_i,                    -- global clock line
1419
      rstn_i           => ext_rstn,                 -- external reset, low-active
1420 59 zero_gravi
      -- debug module interface (DMI) --
1421
      dmi_rstn_i       => dmi.rstn,
1422
      dmi_req_valid_i  => dmi.req_valid,
1423
      dmi_req_ready_o  => dmi.req_ready,
1424
      dmi_req_addr_i   => dmi.req_addr,
1425
      dmi_req_op_i     => dmi.req_op,
1426
      dmi_req_data_i   => dmi.req_data,
1427 60 zero_gravi
      dmi_resp_valid_o => dmi.resp_valid,           -- response valid when set
1428
      dmi_resp_ready_i => dmi.resp_ready,           -- ready to receive respond
1429 59 zero_gravi
      dmi_resp_data_o  => dmi.resp_data,
1430 60 zero_gravi
      dmi_resp_err_o   => dmi.resp_err,             -- 0=ok, 1=error
1431 59 zero_gravi
      -- CPU bus access --
1432 60 zero_gravi
      cpu_addr_i       => p_bus.addr,               -- address
1433
      cpu_rden_i       => p_bus.re,                 -- read enable
1434
      cpu_wren_i       => p_bus.we,                 -- write enable
1435
      cpu_data_i       => p_bus.wdata,              -- data in
1436
      cpu_data_o       => resp_bus(RESP_OCD).rdata, -- data out
1437
      cpu_ack_o        => resp_bus(RESP_OCD).ack,   -- transfer acknowledge
1438 59 zero_gravi
      -- CPU control --
1439 60 zero_gravi
      cpu_ndmrstn_o    => dci_ndmrstn,              -- soc reset
1440
      cpu_halt_req_o   => dci_halt_req              -- request hart to halt (enter debug mode)
1441 59 zero_gravi
    );
1442 60 zero_gravi
    resp_bus(RESP_OCD).err <= '0'; -- no access error possible
1443 59 zero_gravi
  end generate;
1444
 
1445
  neorv32_debug_dm_false:
1446
  if (ON_CHIP_DEBUGGER_EN = false) generate
1447
    dmi.req_ready  <= '0';
1448
    dmi.resp_valid <= '0';
1449
    dmi.resp_data  <= (others => '0');
1450
    dmi.resp_err   <= '0';
1451
    --
1452 60 zero_gravi
    resp_bus(RESP_OCD) <= resp_bus_entry_terminate_c;
1453
    dci_ndmrstn  <= '1';
1454
    dci_halt_req <= '0';
1455 59 zero_gravi
  end generate;
1456
 
1457
 
1458
  -- On-Chip Debugger - Debug Transport Module (DTM) ----------------------------------------
1459
  -- -------------------------------------------------------------------------------------------
1460
  neorv32_neorv32_debug_dtm_true:
1461
  if (ON_CHIP_DEBUGGER_EN = true) generate
1462
    neorv32_debug_dtm_inst: neorv32_debug_dtm
1463
    generic map (
1464
      IDCODE_VERSION => jtag_tap_idcode_version_c, -- version
1465
      IDCODE_PARTID  => jtag_tap_idcode_partid_c,  -- part number
1466
      IDCODE_MANID   => jtag_tap_idcode_manid_c    -- manufacturer id
1467
    )
1468
    port map (
1469
      -- global control --
1470
      clk_i            => clk_i,          -- global clock line
1471
      rstn_i           => ext_rstn,       -- external reset, low-active
1472
      -- jtag connection --
1473
      jtag_trst_i      => jtag_trst_i,
1474
      jtag_tck_i       => jtag_tck_i,
1475
      jtag_tdi_i       => jtag_tdi_i,
1476
      jtag_tdo_o       => jtag_tdo_o,
1477
      jtag_tms_i       => jtag_tms_i,
1478
      -- debug module interface (DMI) --
1479
      dmi_rstn_o       => dmi.rstn,
1480
      dmi_req_valid_o  => dmi.req_valid,
1481
      dmi_req_ready_i  => dmi.req_ready,  -- DMI is allowed to make new requests when set
1482
      dmi_req_addr_o   => dmi.req_addr,
1483
      dmi_req_op_o     => dmi.req_op,     -- 0=read, 1=write
1484
      dmi_req_data_o   => dmi.req_data,
1485
      dmi_resp_valid_i => dmi.resp_valid, -- response valid when set
1486
      dmi_resp_ready_o => dmi.resp_ready, -- ready to receive respond
1487
      dmi_resp_data_i  => dmi.resp_data,
1488
      dmi_resp_err_i   => dmi.resp_err    -- 0=ok, 1=error
1489
    );
1490
  end generate;
1491
 
1492
  neorv32_debug_dtm_false:
1493
  if (ON_CHIP_DEBUGGER_EN = false) generate
1494
    jtag_tdo_o <= jtag_tdi_i; -- feed-through
1495
    --
1496
    dmi.rstn       <= '0';
1497
    dmi.req_valid  <= '0';
1498
    dmi.req_addr   <= (others => '0');
1499
    dmi.req_op     <= '0';
1500
    dmi.req_data   <= (others => '0');
1501
    dmi.resp_ready <= '0';
1502
  end generate;
1503
 
1504
 
1505 2 zero_gravi
end neorv32_top_rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.