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

Subversion Repositories neorv32

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

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

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