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

Subversion Repositories neorv32

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

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

Line No. Rev Author Line
1 2 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - Processor Top Entity >>                                                          #
3
-- # ********************************************************************************************* #
4
-- # This is the top entity of the NEORV32 Processor. Instantiate this unit in your own project    #
5
-- # and define all the configuration generics according to your needs. Alternatively, you can use #
6
-- # one of the alternative top entities provided in the "rtl\top_templates" folder.               #
7
-- # Check the processor's documentary for more information: doc\NEORV32.pdf                       #
8
-- # ********************************************************************************************* #
9
-- # BSD 3-Clause License                                                                          #
10
-- #                                                                                               #
11
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
12
-- #                                                                                               #
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 12 zero_gravi
    CLOCK_FREQUENCY              : natural := 0;      -- clock frequency of clk_i in Hz
51 8 zero_gravi
    BOOTLOADER_USE               : boolean := true;   -- implement processor-internal bootloader?
52
    CSR_COUNTERS_USE             : boolean := true;   -- implement RISC-V perf. counters ([m]instret[h], [m]cycle[h], time[h])?
53 12 zero_gravi
    USER_CODE                    : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom user code
54 2 zero_gravi
    -- RISC-V CPU Extensions --
55 11 zero_gravi
    CPU_EXTENSION_RISCV_C        : boolean := false;  -- implement compressed extension?
56 8 zero_gravi
    CPU_EXTENSION_RISCV_E        : boolean := false;  -- implement embedded RF extension?
57 11 zero_gravi
    CPU_EXTENSION_RISCV_M        : boolean := false;  -- implement muld/div extension?
58 15 zero_gravi
    CPU_EXTENSION_RISCV_U        : boolean := false;  -- implement user mode extension?
59 8 zero_gravi
    CPU_EXTENSION_RISCV_Zicsr    : boolean := true;   -- implement CSR system?
60
    CPU_EXTENSION_RISCV_Zifencei : boolean := true;   -- implement instruction stream sync.?
61 15 zero_gravi
    -- Physical Memory Protection (PMP) --
62
    PMP_USE                      : boolean := false; -- implement PMP?
63 16 zero_gravi
    PMP_NUM_REGIONS              : natural := 4;     -- number of regions (max 8)
64
    PMP_GRANULARITY              : natural := 14;    -- minimal region granularity (1=8B, 2=16B, 3=32B, ...) default is 64k
65 2 zero_gravi
    -- Memory configuration: Instruction memory --
66 8 zero_gravi
    MEM_ISPACE_BASE              : std_ulogic_vector(31 downto 0) := x"00000000"; -- base address of instruction memory space
67
    MEM_ISPACE_SIZE              : natural := 16*1024; -- total size of instruction memory space in byte
68
    MEM_INT_IMEM_USE             : boolean := true;   -- implement processor-internal instruction memory
69
    MEM_INT_IMEM_SIZE            : natural := 16*1024; -- size of processor-internal instruction memory in bytes
70
    MEM_INT_IMEM_ROM             : boolean := false;  -- implement processor-internal instruction memory as ROM
71 2 zero_gravi
    -- Memory configuration: Data memory --
72 8 zero_gravi
    MEM_DSPACE_BASE              : std_ulogic_vector(31 downto 0) := x"80000000"; -- base address of data memory space
73
    MEM_DSPACE_SIZE              : natural := 8*1024; -- total size of data memory space in byte
74
    MEM_INT_DMEM_USE             : boolean := true;   -- implement processor-internal data memory
75
    MEM_INT_DMEM_SIZE            : natural := 8*1024; -- size of processor-internal data memory in bytes
76 2 zero_gravi
    -- Memory configuration: External memory interface --
77 8 zero_gravi
    MEM_EXT_USE                  : boolean := false;  -- implement external memory bus interface?
78
    MEM_EXT_REG_STAGES           : natural := 2;      -- number of interface register stages (0,1,2)
79
    MEM_EXT_TIMEOUT              : natural := 15;     -- cycles after which a valid bus access will timeout
80 2 zero_gravi
    -- Processor peripherals --
81 8 zero_gravi
    IO_GPIO_USE                  : boolean := true;   -- implement general purpose input/output port unit (GPIO)?
82
    IO_MTIME_USE                 : boolean := true;   -- implement machine system timer (MTIME)?
83
    IO_UART_USE                  : boolean := true;   -- implement universal asynchronous receiver/transmitter (UART)?
84
    IO_SPI_USE                   : boolean := true;   -- implement serial peripheral interface (SPI)?
85
    IO_TWI_USE                   : boolean := true;   -- implement two-wire interface (TWI)?
86
    IO_PWM_USE                   : boolean := true;   -- implement pulse-width modulation unit (PWM)?
87
    IO_WDT_USE                   : boolean := true;   -- implement watch dog timer (WDT)?
88
    IO_TRNG_USE                  : boolean := false;  -- implement true random number generator (TRNG)?
89
    IO_DEVNULL_USE               : boolean := true    -- implement dummy device (DEVNULL)?
90 2 zero_gravi
  );
91
  port (
92
    -- Global control --
93
    clk_i      : in  std_ulogic := '0'; -- global clock, rising edge
94
    rstn_i     : in  std_ulogic := '0'; -- global reset, low-active, async
95
    -- Wishbone bus interface (available if MEM_EXT_USE = true) --
96
    wb_adr_o   : out std_ulogic_vector(31 downto 0); -- address
97
    wb_dat_i   : in  std_ulogic_vector(31 downto 0) := (others => '0'); -- read data
98
    wb_dat_o   : out std_ulogic_vector(31 downto 0); -- write data
99
    wb_we_o    : out std_ulogic; -- read/write
100
    wb_sel_o   : out std_ulogic_vector(03 downto 0); -- byte enable
101
    wb_stb_o   : out std_ulogic; -- strobe
102
    wb_cyc_o   : out std_ulogic; -- valid cycle
103
    wb_ack_i   : in  std_ulogic := '0'; -- transfer acknowledge
104
    wb_err_i   : in  std_ulogic := '0'; -- transfer error
105 12 zero_gravi
    -- Advanced memory control signals (available if MEM_EXT_USE = true) --
106
    fence_o    : out std_ulogic; -- indicates an executed FENCE operation
107
    fencei_o   : out std_ulogic; -- indicates an executed FENCEI operation
108 2 zero_gravi
    -- GPIO (available if IO_GPIO_USE = true) --
109
    gpio_o     : out std_ulogic_vector(15 downto 0); -- parallel output
110
    gpio_i     : in  std_ulogic_vector(15 downto 0) := (others => '0'); -- parallel input
111
    -- UART (available if IO_UART_USE = true) --
112
    uart_txd_o : out std_ulogic; -- UART send data
113
    uart_rxd_i : in  std_ulogic := '0'; -- UART receive data
114
    -- SPI (available if IO_SPI_USE = true) --
115 6 zero_gravi
    spi_sck_o  : out std_ulogic; -- SPI serial clock
116
    spi_sdo_o  : out std_ulogic; -- controller data out, peripheral data in
117 14 zero_gravi
    spi_sdi_i  : in  std_ulogic := '0'; -- controller data in, peripheral data out
118 2 zero_gravi
    spi_csn_o  : out std_ulogic_vector(07 downto 0); -- SPI CS
119
    -- TWI (available if IO_TWI_USE = true) --
120
    twi_sda_io : inout std_logic := 'H'; -- twi serial data line
121
    twi_scl_io : inout std_logic := 'H'; -- twi serial clock line
122
    -- PWM (available if IO_PWM_USE = true) --
123 14 zero_gravi
    pwm_o      : out std_ulogic_vector(03 downto 0); -- pwm channels
124
    -- Interrupts --
125
    msw_irq_i  : in  std_ulogic := '0'; -- machine software interrupt
126
    mext_irq_i : in  std_ulogic := '0'  -- machine external interrupt
127 2 zero_gravi
  );
128
end neorv32_top;
129
 
130
architecture neorv32_top_rtl of neorv32_top is
131
 
132 12 zero_gravi
  -- CPU boot address --
133
  constant boot_addr_c : std_ulogic_vector(31 downto 0) := cond_sel_stdulogicvector_f(BOOTLOADER_USE, boot_base_c, MEM_ISPACE_BASE);
134
 
135 2 zero_gravi
  -- reset generator --
136
  signal rstn_i_sync0 : std_ulogic;
137
  signal rstn_i_sync1 : std_ulogic;
138
  signal rstn_i_sync2 : std_ulogic;
139
  signal rstn_gen     : std_ulogic_vector(3 downto 0);
140
  signal ext_rstn     : std_ulogic;
141
  signal sys_rstn     : std_ulogic;
142
  signal wdt_rstn     : std_ulogic;
143
 
144
  -- clock generator --
145
  signal clk_div    : std_ulogic_vector(11 downto 0);
146
  signal clk_div_ff : std_ulogic_vector(11 downto 0);
147
  signal clk_gen    : std_ulogic_vector(07 downto 0);
148
  signal wdt_cg_en  : std_ulogic;
149
  signal uart_cg_en : std_ulogic;
150
  signal spi_cg_en  : std_ulogic;
151
  signal twi_cg_en  : std_ulogic;
152
  signal pwm_cg_en  : std_ulogic;
153
 
154 12 zero_gravi
  -- bus interface --
155
  type bus_interface_t is record
156 11 zero_gravi
    addr   : std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
157
    rdata  : std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
158
    wdata  : std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
159
    ben    : std_ulogic_vector(03 downto 0); -- byte enable
160
    we     : std_ulogic; -- write enable
161
    re     : std_ulogic; -- read enable
162
    cancel : std_ulogic; -- cancel current transfer
163
    ack    : std_ulogic; -- bus transfer acknowledge
164
    err    : std_ulogic; -- bus transfer error
165 12 zero_gravi
    fence  : std_ulogic; -- fence(i) instruction executed
166 11 zero_gravi
  end record;
167 12 zero_gravi
  signal cpu_i, cpu_d, p_bus : bus_interface_t;
168 2 zero_gravi
 
169
  -- io space access --
170
  signal io_acc  : std_ulogic;
171
  signal io_rden : std_ulogic;
172
  signal io_wren : std_ulogic;
173
 
174
  -- read-back busses -
175
  signal imem_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
176
  signal imem_ack       : std_ulogic;
177
  signal dmem_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
178
  signal dmem_ack       : std_ulogic;
179
  signal bootrom_rdata  : std_ulogic_vector(data_width_c-1 downto 0);
180
  signal bootrom_ack    : std_ulogic;
181
  signal wishbone_rdata : std_ulogic_vector(data_width_c-1 downto 0);
182
  signal wishbone_ack   : std_ulogic;
183
  signal wishbone_err   : std_ulogic;
184
  signal gpio_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
185
  signal gpio_ack       : std_ulogic;
186
  signal mtime_rdata    : std_ulogic_vector(data_width_c-1 downto 0);
187
  signal mtime_ack      : std_ulogic;
188
  signal uart_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
189
  signal uart_ack       : std_ulogic;
190
  signal spi_rdata      : std_ulogic_vector(data_width_c-1 downto 0);
191
  signal spi_ack        : std_ulogic;
192
  signal twi_rdata      : std_ulogic_vector(data_width_c-1 downto 0);
193
  signal twi_ack        : std_ulogic;
194
  signal pwm_rdata      : std_ulogic_vector(data_width_c-1 downto 0);
195
  signal pwm_ack        : std_ulogic;
196
  signal wdt_rdata      : std_ulogic_vector(data_width_c-1 downto 0);
197
  signal wdt_ack        : std_ulogic;
198
  signal trng_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
199
  signal trng_ack       : std_ulogic;
200 3 zero_gravi
  signal devnull_rdata  : std_ulogic_vector(data_width_c-1 downto 0);
201
  signal devnull_ack    : std_ulogic;
202 12 zero_gravi
  signal sysinfo_rdata  : std_ulogic_vector(data_width_c-1 downto 0);
203
  signal sysinfo_ack    : std_ulogic;
204 2 zero_gravi
 
205
  -- IRQs --
206
  signal mtime_irq : std_ulogic;
207 14 zero_gravi
  signal fast_irq  : std_ulogic_vector(3 downto 0);
208 2 zero_gravi
  signal gpio_irq  : std_ulogic;
209
  signal wdt_irq   : std_ulogic;
210
  signal uart_irq  : std_ulogic;
211
  signal spi_irq   : std_ulogic;
212
  signal twi_irq   : std_ulogic;
213
 
214 11 zero_gravi
  -- misc --
215
  signal mtime_time : std_ulogic_vector(63 downto 0); -- current system time from MTIME
216
 
217 2 zero_gravi
begin
218
 
219
  -- Sanity Checks --------------------------------------------------------------------------
220
  -- -------------------------------------------------------------------------------------------
221
  sanity_check: process(clk_i)
222
  begin
223
    if rising_edge(clk_i) then
224
      -- internal bootloader memory --
225
      if (BOOTLOADER_USE = true) and (boot_size_c > boot_max_size_c) then
226
        assert false report "NEORV32 CONFIG ERROR! Boot ROM size out of range." severity error;
227
      end if;
228
 
229
      -- memory system - data/instruction fetch --
230
      if (MEM_EXT_USE = false) then
231
        if (MEM_INT_DMEM_USE = false) then
232
          assert false report "NEORV32 CONFIG ERROR! Core cannot fetch data without external memory interface and internal data memory." severity error;
233
        end if;
234
        if (MEM_INT_IMEM_USE = false) and (BOOTLOADER_USE = false) then
235
          assert false report "NEORV32 CONFIG ERROR! Core cannot fetch instructions without external memory interface, internal data memory and bootloader." severity error;
236
        end if;
237
      end if;
238
 
239 12 zero_gravi
      -- memory system --
240 2 zero_gravi
      if (MEM_INT_IMEM_USE = true) and (MEM_INT_IMEM_SIZE > MEM_ISPACE_SIZE) then
241
        assert false report "NEORV32 CONFIG ERROR! Internal instruction memory (IMEM) cannot be greater than total instruction address space." severity error;
242
      end if;
243
      if (MEM_INT_DMEM_USE = true) and (MEM_INT_DMEM_SIZE > MEM_DSPACE_SIZE) then
244
        assert false report "NEORV32 CONFIG ERROR! Internal data memory (DMEM) cannot be greater than total data address space." severity error;
245
      end if;
246 12 zero_gravi
      if (MEM_EXT_TIMEOUT < 1) then
247
        assert false report "NEORV32 CONFIG ERROR! Invalid bus timeout. Processor-internal components have 1 cycle delay." severity error;
248 2 zero_gravi
      end if;
249
 
250
      -- clock --
251
      if (CLOCK_FREQUENCY = 0) then
252
        assert false report "NEORV32 CONFIG ERROR! Core clock frequency (CLOCK_FREQUENCY) not specified." severity error;
253
      end if;
254
 
255
      -- memory layout notifier --
256
      if (MEM_ISPACE_BASE /= x"00000000") then
257 12 zero_gravi
        assert false report "NEORV32 CONFIG WARNING! Non-default base address for instruction address space. Make sure this is sync with the software framwork." severity warning;
258 2 zero_gravi
      end if;
259
      if (MEM_DSPACE_BASE /= x"80000000") then
260 12 zero_gravi
        assert false report "NEORV32 CONFIG WARNING! Non-default base address for data address space. Make sure this is sync with the software framwork." severity warning;
261 2 zero_gravi
      end if;
262
    end if;
263
  end process sanity_check;
264
 
265
 
266
  -- Reset Generator ------------------------------------------------------------------------
267
  -- -------------------------------------------------------------------------------------------
268
  reset_generator_sync: process(clk_i)
269
  begin
270
    -- make sure the external reset is free of metastability and has a minimal duration of 1 clock cycle
271
    if rising_edge(clk_i) then
272
      rstn_i_sync0 <= rstn_i;
273
      rstn_i_sync1 <= rstn_i_sync0;
274
      rstn_i_sync2 <= rstn_i_sync1;
275
    end if;
276
  end process reset_generator_sync;
277
 
278
  -- keep internal reset active for at least 4 clock cycles
279
  reset_generator: process(rstn_i_sync1, rstn_i_sync2, clk_i)
280
  begin
281
    if ((rstn_i_sync1 or rstn_i_sync2) = '0') then -- signal stable somehow?
282
      rstn_gen <= (others => '0');
283
    elsif rising_edge(clk_i) then
284
      rstn_gen <= rstn_gen(rstn_gen'left-1 downto 0) & '1';
285
    end if;
286
  end process reset_generator;
287
 
288
  ext_rstn <= rstn_gen(rstn_gen'left); -- the beautified external reset signal
289
  sys_rstn <= ext_rstn and wdt_rstn; -- system reset - can also be triggered by watchdog
290
 
291
 
292
  -- Clock Generator ------------------------------------------------------------------------
293
  -- -------------------------------------------------------------------------------------------
294
  clock_generator: process(sys_rstn, clk_i)
295
  begin
296
    if (sys_rstn = '0') then
297
      clk_div    <= (others => '0');
298
      clk_div_ff <= (others => '0');
299
    elsif rising_edge(clk_i) then
300
      -- anybody wanting some fresh clocks? --
301
      if ((wdt_cg_en or uart_cg_en or spi_cg_en or twi_cg_en or pwm_cg_en) = '1') then
302
        clk_div    <= std_ulogic_vector(unsigned(clk_div) + 1);
303
        clk_div_ff <= clk_div;
304
      end if;
305
    end if;
306
  end process clock_generator;
307
 
308
  -- clock enable select: rising edge detectors --
309
  clk_gen(clk_div2_c)    <= clk_div(0)  and (not clk_div_ff(0));  -- CLK/2
310
  clk_gen(clk_div4_c)    <= clk_div(1)  and (not clk_div_ff(1));  -- CLK/4
311
  clk_gen(clk_div8_c)    <= clk_div(2)  and (not clk_div_ff(2));  -- CLK/8
312
  clk_gen(clk_div64_c)   <= clk_div(5)  and (not clk_div_ff(5));  -- CLK/64
313
  clk_gen(clk_div128_c)  <= clk_div(6)  and (not clk_div_ff(6));  -- CLK/128
314
  clk_gen(clk_div1024_c) <= clk_div(9)  and (not clk_div_ff(9));  -- CLK/1024
315
  clk_gen(clk_div2048_c) <= clk_div(10) and (not clk_div_ff(10)); -- CLK/2048
316
  clk_gen(clk_div4096_c) <= clk_div(11) and (not clk_div_ff(11)); -- CLK/4096
317
 
318
 
319
  -- CPU ------------------------------------------------------------------------------------
320
  -- -------------------------------------------------------------------------------------------
321
  neorv32_cpu_inst: neorv32_cpu
322
  generic map (
323
    -- General --
324 12 zero_gravi
    CSR_COUNTERS_USE             => CSR_COUNTERS_USE, -- implement RISC-V perf. counters ([m]instret[h], [m]cycle[h], time[h])?
325
    HW_THREAD_ID                 => (others => '0'),  -- hardware thread id
326
    CPU_BOOT_ADDR                => boot_addr_c,      -- cpu boot address
327 2 zero_gravi
    -- RISC-V CPU Extensions --
328 8 zero_gravi
    CPU_EXTENSION_RISCV_C        => CPU_EXTENSION_RISCV_C,        -- implement compressed extension?
329
    CPU_EXTENSION_RISCV_E        => CPU_EXTENSION_RISCV_E,        -- implement embedded RF extension?
330
    CPU_EXTENSION_RISCV_M        => CPU_EXTENSION_RISCV_M,        -- implement muld/div extension?
331 15 zero_gravi
    CPU_EXTENSION_RISCV_U        => CPU_EXTENSION_RISCV_U,        -- implement user mode extension?
332 8 zero_gravi
    CPU_EXTENSION_RISCV_Zicsr    => CPU_EXTENSION_RISCV_Zicsr,    -- implement CSR system?
333
    CPU_EXTENSION_RISCV_Zifencei => CPU_EXTENSION_RISCV_Zifencei, -- implement instruction stream sync.?
334 15 zero_gravi
    -- Physical Memory Protection (PMP) --
335
    PMP_USE                      => PMP_USE,         -- implement PMP?
336 16 zero_gravi
    PMP_NUM_REGIONS              => PMP_NUM_REGIONS, -- number of regions (max 8)
337
    PMP_GRANULARITY              => PMP_GRANULARITY, -- minimal region granularity (1=8B, 2=16B, 3=32B, ...) default is 64k
338 14 zero_gravi
    -- Bus Interface --
339
    BUS_TIMEOUT                  => MEM_EXT_TIMEOUT   -- cycles after which a valid bus access will timeout
340 2 zero_gravi
  )
341
  port map (
342
    -- global control --
343 12 zero_gravi
    clk_i          => clk_i,        -- global clock, rising edge
344
    rstn_i         => sys_rstn,     -- global reset, low-active, async
345
    -- instruction bus interface --
346
    i_bus_addr_o   => cpu_i.addr,   -- bus access address
347
    i_bus_rdata_i  => cpu_i.rdata,  -- bus read data
348
    i_bus_wdata_o  => cpu_i.wdata,  -- bus write data
349
    i_bus_ben_o    => cpu_i.ben,    -- byte enable
350
    i_bus_we_o     => cpu_i.we,     -- write enable
351
    i_bus_re_o     => cpu_i.re,     -- read enable
352
    i_bus_cancel_o => cpu_i.cancel, -- cancel current bus transaction
353
    i_bus_ack_i    => cpu_i.ack,    -- bus transfer acknowledge
354
    i_bus_err_i    => cpu_i.err,    -- bus transfer error
355
    i_bus_fence_o  => cpu_i.fence,  -- executed FENCEI operation
356
    -- data bus interface --
357
    d_bus_addr_o   => cpu_d.addr,   -- bus access address
358
    d_bus_rdata_i  => cpu_d.rdata,  -- bus read data
359
    d_bus_wdata_o  => cpu_d.wdata,  -- bus write data
360
    d_bus_ben_o    => cpu_d.ben,    -- byte enable
361
    d_bus_we_o     => cpu_d.we,     -- write enable
362
    d_bus_re_o     => cpu_d.re,     -- read enable
363
    d_bus_cancel_o => cpu_d.cancel, -- cancel current bus transaction
364
    d_bus_ack_i    => cpu_d.ack,    -- bus transfer acknowledge
365
    d_bus_err_i    => cpu_d.err,    -- bus transfer error
366
    d_bus_fence_o  => cpu_d.fence,  -- executed FENCE operation
367 11 zero_gravi
    -- system time input from MTIME --
368 12 zero_gravi
    time_i         => mtime_time,   -- current system time
369 14 zero_gravi
    -- interrupts (risc-v compliant) --
370
    msw_irq_i      => msw_irq_i,    -- machine software interrupt
371
    mext_irq_i     => mext_irq_i,   -- machine external interrupt request
372
    mtime_irq_i    => mtime_irq,    -- machine timer interrupt
373
    -- fast interrupts (custom) --
374
    firq_i         => fast_irq
375 2 zero_gravi
  );
376
 
377 14 zero_gravi
  -- advanced memory control --
378
  fence_o  <= cpu_d.fence; -- indicates an executed FENCE operation
379
  fencei_o <= cpu_i.fence; -- indicates an executed FENCEI operation
380 2 zero_gravi
 
381 14 zero_gravi
  -- fast interrupts --
382
  fast_irq(0) <= wdt_irq; -- highest priority
383
  fast_irq(1) <= gpio_irq;
384
  fast_irq(2) <= uart_irq;
385
  fast_irq(3) <= spi_irq or twi_irq; -- lowest priority, can be triggered by SPI or TWI
386
 
387
 
388 12 zero_gravi
  -- CPU Crossbar Switch --------------------------------------------------------------------
389
  -- -------------------------------------------------------------------------------------------
390
  neorv32_busswitch_inst: neorv32_busswitch
391
  generic map (
392
    PORT_CA_READ_ONLY => false, -- set if controller port A is read-only
393
    PORT_CB_READ_ONLY => true   -- set if controller port B is read-only
394
  )
395
  port map (
396
    -- global control --
397
    clk_i           => clk_i,        -- global clock, rising edge
398
    rstn_i          => sys_rstn,     -- global reset, low-active, async
399
    -- controller interface a --
400
    ca_bus_addr_i   => cpu_d.addr,   -- bus access address
401
    ca_bus_rdata_o  => cpu_d.rdata,  -- bus read data
402
    ca_bus_wdata_i  => cpu_d.wdata,  -- bus write data
403
    ca_bus_ben_i    => cpu_d.ben,    -- byte enable
404
    ca_bus_we_i     => cpu_d.we,     -- write enable
405
    ca_bus_re_i     => cpu_d.re,     -- read enable
406
    ca_bus_cancel_i => cpu_d.cancel, -- cancel current bus transaction
407
    ca_bus_ack_o    => cpu_d.ack,    -- bus transfer acknowledge
408
    ca_bus_err_o    => cpu_d.err,    -- bus transfer error
409
    -- controller interface b --
410
    cb_bus_addr_i   => cpu_i.addr,   -- bus access address
411
    cb_bus_rdata_o  => cpu_i.rdata,  -- bus read data
412
    cb_bus_wdata_i  => cpu_i.wdata,  -- bus write data
413
    cb_bus_ben_i    => cpu_i.ben,    -- byte enable
414
    cb_bus_we_i     => cpu_i.we,     -- write enable
415
    cb_bus_re_i     => cpu_i.re,     -- read enable
416
    cb_bus_cancel_i => cpu_i.cancel, -- cancel current bus transaction
417
    cb_bus_ack_o    => cpu_i.ack,    -- bus transfer acknowledge
418
    cb_bus_err_o    => cpu_i.err,    -- bus transfer error
419
    -- peripheral bus --
420
    p_bus_addr_o    => p_bus.addr,   -- bus access address
421
    p_bus_rdata_i   => p_bus.rdata,  -- bus read data
422
    p_bus_wdata_o   => p_bus.wdata,  -- bus write data
423
    p_bus_ben_o     => p_bus.ben,    -- byte enable
424
    p_bus_we_o      => p_bus.we,     -- write enable
425
    p_bus_re_o      => p_bus.re,     -- read enable
426
    p_bus_cancel_o  => p_bus.cancel, -- cancel current bus transaction
427
    p_bus_ack_i     => p_bus.ack,    -- bus transfer acknowledge
428
    p_bus_err_i     => p_bus.err     -- bus transfer error
429
  );
430 2 zero_gravi
 
431 14 zero_gravi
  -- processor bus: CPU data input --
432 12 zero_gravi
  p_bus.rdata <= (imem_rdata or dmem_rdata or bootrom_rdata) or wishbone_rdata or (gpio_rdata or mtime_rdata or uart_rdata or
433 14 zero_gravi
                 spi_rdata or twi_rdata or pwm_rdata or wdt_rdata or trng_rdata or devnull_rdata or sysinfo_rdata);
434 2 zero_gravi
 
435 14 zero_gravi
  -- processor bus: CPU data ACK input --
436 12 zero_gravi
  p_bus.ack <= (imem_ack or dmem_ack or bootrom_ack) or wishbone_ack or (gpio_ack or mtime_ack or uart_ack or
437 14 zero_gravi
               spi_ack or twi_ack or pwm_ack or wdt_ack or trng_ack or devnull_ack or sysinfo_ack);
438 12 zero_gravi
 
439 14 zero_gravi
  -- processor bus: CPU data bus error input --
440 12 zero_gravi
  p_bus.err <= wishbone_err;
441
 
442
 
443 2 zero_gravi
  -- Processor-Internal Instruction Memory (IMEM) -------------------------------------------
444
  -- -------------------------------------------------------------------------------------------
445
  neorv32_int_imem_inst_true:
446
  if (MEM_INT_IMEM_USE = true) generate
447
    neorv32_int_imem_inst: neorv32_imem
448
    generic map (
449
      IMEM_BASE      => MEM_ISPACE_BASE,   -- memory base address
450
      IMEM_SIZE      => MEM_INT_IMEM_SIZE, -- processor-internal instruction memory size in bytes
451
      IMEM_AS_ROM    => MEM_INT_IMEM_ROM,  -- implement IMEM as read-only memory?
452
      BOOTLOADER_USE => BOOTLOADER_USE     -- implement and use bootloader?
453
    )
454
    port map (
455 12 zero_gravi
      clk_i  => clk_i,       -- global clock line
456
      rden_i => p_bus.re,    -- read enable
457
      wren_i => p_bus.we,    -- write enable
458
      ben_i  => p_bus.ben,   -- byte write enable
459
      upen_i => '1',         -- update enable
460
      addr_i => p_bus.addr,  -- address
461
      data_i => p_bus.wdata, -- data in
462
      data_o => imem_rdata,  -- data out
463
      ack_o  => imem_ack     -- transfer acknowledge
464 2 zero_gravi
    );
465
  end generate;
466
 
467
  neorv32_int_imem_inst_false:
468
  if (MEM_INT_IMEM_USE = false) generate
469
    imem_rdata <= (others => '0');
470
    imem_ack   <= '0';
471
  end generate;
472
 
473
 
474
  -- Processor-Internal Data Memory (DMEM) --------------------------------------------------
475
  -- -------------------------------------------------------------------------------------------
476
  neorv32_int_dmem_inst_true:
477
  if (MEM_INT_DMEM_USE = true) generate
478
    neorv32_int_dmem_inst: neorv32_dmem
479
    generic map (
480
      DMEM_BASE => MEM_DSPACE_BASE,  -- memory base address
481
      DMEM_SIZE => MEM_INT_DMEM_SIZE -- processor-internal data memory size in bytes
482
    )
483
    port map (
484 12 zero_gravi
      clk_i  => clk_i,       -- global clock line
485
      rden_i => p_bus.re,    -- read enable
486
      wren_i => p_bus.we,    -- write enable
487
      ben_i  => p_bus.ben,   -- byte write enable
488
      addr_i => p_bus.addr,  -- address
489
      data_i => p_bus.wdata, -- data in
490
      data_o => dmem_rdata,  -- data out
491
      ack_o  => dmem_ack     -- transfer acknowledge
492 2 zero_gravi
    );
493
  end generate;
494
 
495
  neorv32_int_dmem_inst_false:
496
  if (MEM_INT_DMEM_USE = false) generate
497
    dmem_rdata <= (others => '0');
498
    dmem_ack   <= '0';
499
  end generate;
500
 
501
 
502
  -- Processor-Internal Bootloader ROM (BOOTROM) --------------------------------------------
503
  -- -------------------------------------------------------------------------------------------
504
  neorv32_boot_rom_inst_true:
505
  if (BOOTLOADER_USE = true) generate
506
    neorv32_boot_rom_inst: neorv32_boot_rom
507
    port map (
508
      clk_i  => clk_i,         -- global clock line
509 12 zero_gravi
      rden_i => p_bus.re,      -- read enable
510
      addr_i => p_bus.addr,    -- address
511 2 zero_gravi
      data_o => bootrom_rdata, -- data out
512
      ack_o  => bootrom_ack    -- transfer acknowledge
513
    );
514
  end generate;
515
 
516
  neorv32_boot_rom_inst_false:
517
  if (BOOTLOADER_USE = false) generate
518
    bootrom_rdata <= (others => '0');
519
    bootrom_ack   <= '0';
520
  end generate;
521
 
522
 
523
  -- External Wishbone Gateway (WISHBONE) ---------------------------------------------------
524
  -- -------------------------------------------------------------------------------------------
525
  neorv32_wishbone_inst_true:
526
  if (MEM_EXT_USE = true) generate
527
    neorv32_wishbone_inst: neorv32_wishbone
528
    generic map (
529
      INTERFACE_REG_STAGES => MEM_EXT_REG_STAGES, -- number of interface register stages (0,1,2)
530
      -- Memory configuration: Instruction memory --
531 12 zero_gravi
      MEM_ISPACE_BASE      => MEM_ISPACE_BASE,    -- base address of instruction memory space
532
      MEM_ISPACE_SIZE      => MEM_ISPACE_SIZE,    -- total size of instruction memory space in byte
533
      MEM_INT_IMEM_USE     => MEM_INT_IMEM_USE,   -- implement processor-internal instruction memory
534
      MEM_INT_IMEM_SIZE    => MEM_INT_IMEM_SIZE,  -- size of processor-internal instruction memory in bytes
535 2 zero_gravi
      -- Memory configuration: Data memory --
536 12 zero_gravi
      MEM_DSPACE_BASE      => MEM_DSPACE_BASE,    -- base address of data memory space
537
      MEM_DSPACE_SIZE      => MEM_DSPACE_SIZE,    -- total size of data memory space in byte
538
      MEM_INT_DMEM_USE     => MEM_INT_DMEM_USE,   -- implement processor-internal data memory
539
      MEM_INT_DMEM_SIZE    => MEM_INT_DMEM_SIZE   -- size of processor-internal data memory in bytes
540 2 zero_gravi
    )
541
    port map (
542
      -- global control --
543
      clk_i    => clk_i,          -- global clock line
544
      rstn_i   => sys_rstn,       -- global reset line, low-active
545
      -- host access --
546 12 zero_gravi
      addr_i   => p_bus.addr,     -- address
547
      rden_i   => p_bus.re,       -- read enable
548
      wren_i   => p_bus.we,       -- write enable
549
      ben_i    => p_bus.ben,      -- byte write enable
550
      data_i   => p_bus.wdata,    -- data in
551 2 zero_gravi
      data_o   => wishbone_rdata, -- data out
552 12 zero_gravi
      cancel_i => p_bus.cancel,   -- cancel current transaction
553 2 zero_gravi
      ack_o    => wishbone_ack,   -- transfer acknowledge
554
      err_o    => wishbone_err,   -- transfer error
555
      -- wishbone interface --
556
      wb_adr_o => wb_adr_o,       -- address
557
      wb_dat_i => wb_dat_i,       -- read data
558
      wb_dat_o => wb_dat_o,       -- write data
559
      wb_we_o  => wb_we_o,        -- read/write
560
      wb_sel_o => wb_sel_o,       -- byte enable
561
      wb_stb_o => wb_stb_o,       -- strobe
562
      wb_cyc_o => wb_cyc_o,       -- valid cycle
563
      wb_ack_i => wb_ack_i,       -- transfer acknowledge
564
      wb_err_i => wb_err_i        -- transfer error
565
    );
566
  end generate;
567
 
568
  neorv32_wishbone_inst_false:
569
  if (MEM_EXT_USE = false) generate
570
    wishbone_rdata <= (others => '0');
571
    wishbone_ack   <= '0';
572
    wishbone_err   <= '0';
573
    --
574
    wb_adr_o <= (others => '0');
575
    wb_dat_o <= (others => '0');
576
    wb_we_o  <= '0';
577
    wb_sel_o <= (others => '0');
578
    wb_stb_o <= '0';
579
    wb_cyc_o <= '0';
580
  end generate;
581
 
582
 
583
  -- IO Access? -----------------------------------------------------------------------------
584
  -- -------------------------------------------------------------------------------------------
585 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';
586
  io_rden <= io_acc and p_bus.re;
587
  io_wren <= io_acc and p_bus.we;
588 2 zero_gravi
 
589
 
590
  -- General Purpose Input/Output Port (GPIO) -----------------------------------------------
591
  -- -------------------------------------------------------------------------------------------
592
  neorv32_gpio_inst_true:
593
  if (IO_GPIO_USE = true) generate
594
    neorv32_gpio_inst: neorv32_gpio
595
    port map (
596
      -- host access --
597 12 zero_gravi
      clk_i  => clk_i,       -- global clock line
598
      addr_i => p_bus.addr,  -- address
599
      rden_i => io_rden,     -- read enable
600
      wren_i => io_wren,     -- write enable
601
      ben_i  => p_bus.ben,   -- byte write enable
602
      data_i => p_bus.wdata, -- data in
603
      data_o => gpio_rdata,  -- data out
604
      ack_o  => gpio_ack,    -- transfer acknowledge
605 2 zero_gravi
      -- parallel io --
606
      gpio_o => gpio_o,
607
      gpio_i => gpio_i,
608
      -- interrupt --
609 12 zero_gravi
      irq_o  => gpio_irq     -- pin-change interrupt
610 2 zero_gravi
    );
611
  end generate;
612
 
613
  neorv32_gpio_inst_false:
614
  if (IO_GPIO_USE = false) generate
615
    gpio_rdata <= (others => '0');
616
    gpio_ack   <= '0';
617
    gpio_o     <= (others => '0');
618
    gpio_irq   <= '0';
619
  end generate;
620
 
621
 
622
  -- Watch Dog Timer (WDT) ------------------------------------------------------------------
623
  -- -------------------------------------------------------------------------------------------
624
  neorv32_wdt_inst_true:
625
  if (IO_WDT_USE = true) generate
626
    neorv32_wdt_inst: neorv32_wdt
627
    port map (
628
      -- host access --
629 12 zero_gravi
      clk_i       => clk_i,       -- global clock line
630
      rstn_i      => ext_rstn,    -- global reset line, low-active
631
      rden_i      => io_rden,     -- read enable
632
      wren_i      => io_wren,     -- write enable
633
      ben_i       => p_bus.ben,   -- byte write enable
634
      addr_i      => p_bus.addr,  -- address
635
      data_i      => p_bus.wdata, -- data in
636
      data_o      => wdt_rdata,   -- data out
637
      ack_o       => wdt_ack,     -- transfer acknowledge
638 2 zero_gravi
      -- clock generator --
639 12 zero_gravi
      clkgen_en_o => wdt_cg_en,   -- enable clock generator
640 2 zero_gravi
      clkgen_i    => clk_gen,
641
      -- timeout event --
642 12 zero_gravi
      irq_o       => wdt_irq,     -- timeout IRQ
643
      rstn_o      => wdt_rstn     -- timeout reset, low_active, use it as async!
644 2 zero_gravi
    );
645
  end generate;
646
 
647
  neorv32_wdt_inst_false:
648
  if (IO_WDT_USE = false) generate
649
    wdt_rdata <= (others => '0');
650
    wdt_ack   <= '0';
651
    wdt_irq   <= '0';
652
    wdt_rstn  <= '1';
653
    wdt_cg_en <= '0';
654
  end generate;
655
 
656
 
657
  -- Machine System Timer (MTIME) -----------------------------------------------------------
658
  -- -------------------------------------------------------------------------------------------
659
  neorv32_mtime_inst_true:
660
  if (IO_MTIME_USE = true) generate
661
    neorv32_mtime_inst: neorv32_mtime
662
    port map (
663
      -- host access --
664 12 zero_gravi
      clk_i     => clk_i,       -- global clock line
665
      rstn_i    => sys_rstn,    -- global reset, low-active, async
666
      addr_i    => p_bus.addr,  -- address
667
      rden_i    => io_rden,     -- read enable
668
      wren_i    => io_wren,     -- write enable
669
      ben_i     => p_bus.ben,   -- byte write enable
670
      data_i    => p_bus.wdata, -- data in
671
      data_o    => mtime_rdata, -- data out
672
      ack_o     => mtime_ack,   -- transfer acknowledge
673 11 zero_gravi
      -- time output for CPU --
674 12 zero_gravi
      time_o    => mtime_time,  -- current system time
675 2 zero_gravi
      -- interrupt --
676 12 zero_gravi
      irq_o     => mtime_irq    -- interrupt request
677 2 zero_gravi
    );
678
  end generate;
679
 
680
  neorv32_mtime_inst_false:
681
  if (IO_MTIME_USE = false) generate
682
    mtime_rdata <= (others => '0');
683 11 zero_gravi
    mtime_time  <= (others => '0');
684 2 zero_gravi
    mtime_ack   <= '0';
685
    mtime_irq   <= '0';
686
  end generate;
687
 
688
 
689
  -- Universal Asynchronous Receiver/Transmitter (UART) -------------------------------------
690
  -- -------------------------------------------------------------------------------------------
691
  neorv32_uart_inst_true:
692
  if (IO_UART_USE = true) generate
693
    neorv32_uart_inst: neorv32_uart
694
    port map (
695
      -- host access --
696 12 zero_gravi
      clk_i       => clk_i,       -- global clock line
697
      addr_i      => p_bus.addr,  -- address
698
      rden_i      => io_rden,     -- read enable
699
      wren_i      => io_wren,     -- write enable
700
      ben_i       => p_bus.ben,   -- byte write enable
701
      data_i      => p_bus.wdata, -- data in
702
      data_o      => uart_rdata,  -- data out
703
      ack_o       => uart_ack,    -- transfer acknowledge
704 2 zero_gravi
      -- clock generator --
705 12 zero_gravi
      clkgen_en_o => uart_cg_en,  -- enable clock generator
706 2 zero_gravi
      clkgen_i    => clk_gen,
707
      -- com lines --
708
      uart_txd_o  => uart_txd_o,
709
      uart_rxd_i  => uart_rxd_i,
710
      -- interrupts --
711 12 zero_gravi
      uart_irq_o  => uart_irq     -- uart rx/tx interrupt
712 2 zero_gravi
    );
713
  end generate;
714
 
715
  neorv32_uart_inst_false:
716
  if (IO_UART_USE = false) generate
717
    uart_rdata <= (others => '0');
718
    uart_ack   <= '0';
719
    uart_txd_o <= '0';
720
    uart_cg_en <= '0';
721
    uart_irq   <= '0';
722
  end generate;
723
 
724
 
725
  -- Serial Peripheral Interface (SPI) ------------------------------------------------------
726
  -- -------------------------------------------------------------------------------------------
727
  neorv32_spi_inst_true:
728
  if (IO_SPI_USE = true) generate
729
    neorv32_spi_inst: neorv32_spi
730
    port map (
731
      -- host access --
732 12 zero_gravi
      clk_i       => clk_i,       -- global clock line
733
      addr_i      => p_bus.addr,  -- address
734
      rden_i      => io_rden,     -- read enable
735
      wren_i      => io_wren,     -- write enable
736
      ben_i       => p_bus.ben,   -- byte write enable
737
      data_i      => p_bus.wdata, -- data in
738
      data_o      => spi_rdata,   -- data out
739
      ack_o       => spi_ack,     -- transfer acknowledge
740 2 zero_gravi
      -- clock generator --
741 12 zero_gravi
      clkgen_en_o => spi_cg_en,   -- enable clock generator
742 2 zero_gravi
      clkgen_i    => clk_gen,
743
      -- com lines --
744 12 zero_gravi
      spi_sck_o   => spi_sck_o,   -- SPI serial clock
745
      spi_sdo_o   => spi_sdo_o,   -- controller data out, peripheral data in
746
      spi_sdi_i   => spi_sdi_i,   -- controller data in, peripheral data out
747
      spi_csn_o   => spi_csn_o,   -- SPI CS
748 2 zero_gravi
      -- interrupt --
749 12 zero_gravi
      spi_irq_o   => spi_irq      -- transmission done interrupt
750 2 zero_gravi
    );
751
  end generate;
752
 
753
  neorv32_spi_inst_false:
754
  if (IO_SPI_USE = false) generate
755
    spi_rdata  <= (others => '0');
756
    spi_ack    <= '0';
757 6 zero_gravi
    spi_sck_o  <= '0';
758
    spi_sdo_o  <= '0';
759 2 zero_gravi
    spi_csn_o  <= (others => '1'); -- CSn lines are low-active
760
    spi_cg_en  <= '0';
761
    spi_irq    <= '0';
762
  end generate;
763
 
764
 
765
  -- Two-Wire Interface (TWI) ---------------------------------------------------------------
766
  -- -------------------------------------------------------------------------------------------
767
  neorv32_twi_inst_true:
768
  if (IO_TWI_USE = true) generate
769
    neorv32_twi_inst: neorv32_twi
770
    port map (
771
      -- host access --
772 12 zero_gravi
      clk_i       => clk_i,       -- global clock line
773
      addr_i      => p_bus.addr,  -- address
774
      rden_i      => io_rden,     -- read enable
775
      wren_i      => io_wren,     -- write enable
776
      ben_i       => p_bus.ben,   -- byte write enable
777
      data_i      => p_bus.wdata, -- data in
778
      data_o      => twi_rdata,   -- data out
779
      ack_o       => twi_ack,     -- transfer acknowledge
780 2 zero_gravi
      -- clock generator --
781 12 zero_gravi
      clkgen_en_o => twi_cg_en,   -- enable clock generator
782 2 zero_gravi
      clkgen_i    => clk_gen,
783
      -- com lines --
784 12 zero_gravi
      twi_sda_io  => twi_sda_io,  -- serial data line
785
      twi_scl_io  => twi_scl_io,  -- serial clock line
786 2 zero_gravi
      -- interrupt --
787 12 zero_gravi
      twi_irq_o   => twi_irq      -- transfer done IRQ
788 2 zero_gravi
    );
789
  end generate;
790
 
791
  neorv32_twi_inst_false:
792
  if (IO_TWI_USE = false) generate
793
    twi_rdata  <= (others => '0');
794
    twi_ack    <= '0';
795
--  twi_sda_io <= 'H';
796
--  twi_scl_io <= 'H';
797
    twi_cg_en  <= '0';
798
    twi_irq    <= '0';
799
  end generate;
800
 
801
 
802
  -- Pulse-Width Modulation Controller (PWM) ------------------------------------------------
803
  -- -------------------------------------------------------------------------------------------
804
  neorv32_pwm_inst_true:
805
  if (IO_PWM_USE = true) generate
806
    neorv32_pwm_inst: neorv32_pwm
807
    port map (
808
      -- host access --
809 12 zero_gravi
      clk_i       => clk_i,       -- global clock line
810
      addr_i      => p_bus.addr,  -- address
811
      rden_i      => io_rden,     -- read enable
812
      wren_i      => io_wren,     -- write enable
813
      ben_i       => p_bus.ben,   -- byte write enable
814
      data_i      => p_bus.wdata, -- data in
815
      data_o      => pwm_rdata,   -- data out
816
      ack_o       => pwm_ack,     -- transfer acknowledge
817 2 zero_gravi
      -- clock generator --
818 12 zero_gravi
      clkgen_en_o => pwm_cg_en,   -- enable clock generator
819 2 zero_gravi
      clkgen_i    => clk_gen,
820
      -- pwm output channels --
821
      pwm_o       => pwm_o
822
    );
823
  end generate;
824
 
825
  neorv32_pwm_inst_false:
826
  if (IO_PWM_USE = false) generate
827
    pwm_rdata <= (others => '0');
828
    pwm_ack   <= '0';
829
    pwm_cg_en <= '0';
830
    pwm_o     <= (others => '0');
831
  end generate;
832
 
833
 
834
  -- True Random Number Generator (TRNG) ----------------------------------------------------
835
  -- -------------------------------------------------------------------------------------------
836
  neorv32_trng_inst_true:
837
  if (IO_TRNG_USE = true) generate
838
    neorv32_trng_inst: neorv32_trng
839
    port map (
840
      -- host access --
841 12 zero_gravi
      clk_i  => clk_i,       -- global clock line
842
      addr_i => p_bus.addr,  -- address
843
      rden_i => io_rden,     -- read enable
844
      wren_i => io_wren,     -- write enable
845
      ben_i  => p_bus.ben,   -- byte write enable
846
      data_i => p_bus.wdata, -- data in
847
      data_o => trng_rdata,  -- data out
848
      ack_o  => trng_ack     -- transfer acknowledge
849 2 zero_gravi
    );
850
  end generate;
851
 
852
  neorv32_trng_inst_false:
853
  if (IO_TRNG_USE = false) generate
854
    trng_rdata <= (others => '0');
855
    trng_ack   <= '0';
856
  end generate;
857
 
858
 
859 3 zero_gravi
  -- Dummy Device (DEVNULL) -----------------------------------------------------------------
860
  -- -------------------------------------------------------------------------------------------
861
  neorv32_devnull_inst_true:
862
  if (IO_DEVNULL_USE = true) generate
863
    neorv32_devnull_inst: neorv32_devnull
864
    port map (
865
      -- host access --
866
      clk_i  => clk_i,         -- global clock line
867 12 zero_gravi
      addr_i => p_bus.addr,    -- address
868 3 zero_gravi
      rden_i => io_rden,       -- read enable
869
      wren_i => io_wren,       -- write enable
870 12 zero_gravi
      ben_i  => p_bus.ben,     -- byte write enable
871
      data_i => p_bus.wdata,   -- data in
872 3 zero_gravi
      data_o => devnull_rdata, -- data out
873
      ack_o  => devnull_ack    -- transfer acknowledge
874
    );
875
  end generate;
876 12 zero_gravi
 
877 3 zero_gravi
  neorv32_devnull_inst_false:
878
  if (IO_DEVNULL_USE = false) generate
879
    devnull_rdata <= (others => '0');
880
    devnull_ack   <= '0';
881
  end generate;
882
 
883
 
884 12 zero_gravi
  -- System Configuration Information Memory (SYSINFO) --------------------------------------
885
  -- -------------------------------------------------------------------------------------------
886
  neorv32_sysinfo_inst: neorv32_sysinfo
887
  generic map (
888
    -- General --
889
    CLOCK_FREQUENCY   => CLOCK_FREQUENCY,   -- clock frequency of clk_i in Hz
890
    BOOTLOADER_USE    => BOOTLOADER_USE,    -- implement processor-internal bootloader?
891
    USER_CODE         => USER_CODE,         -- custom user code
892
    -- Memory configuration: Instruction memory --
893
    MEM_ISPACE_BASE   => MEM_ISPACE_BASE,   -- base address of instruction memory space
894
    MEM_ISPACE_SIZE   => MEM_ISPACE_SIZE,   -- total size of instruction memory space in byte
895
    MEM_INT_IMEM_USE  => MEM_INT_IMEM_USE,  -- implement processor-internal instruction memory
896
    MEM_INT_IMEM_SIZE => MEM_INT_IMEM_SIZE, -- size of processor-internal instruction memory in bytes
897
    MEM_INT_IMEM_ROM  => MEM_INT_IMEM_ROM,  -- implement processor-internal instruction memory as ROM
898
    -- Memory configuration: Data memory --
899
    MEM_DSPACE_BASE   => MEM_DSPACE_BASE,   -- base address of data memory space
900
    MEM_DSPACE_SIZE   => MEM_DSPACE_SIZE,   -- total size of data memory space in byte
901
    MEM_INT_DMEM_USE  => MEM_INT_DMEM_USE,  -- implement processor-internal data memory
902
    MEM_INT_DMEM_SIZE => MEM_INT_DMEM_SIZE, -- size of processor-internal data memory in bytes
903
    -- Memory configuration: External memory interface --
904
    MEM_EXT_USE       => MEM_EXT_USE,       -- implement external memory bus interface?
905
    -- Processor peripherals --
906
    IO_GPIO_USE       => IO_GPIO_USE,       -- implement general purpose input/output port unit (GPIO)?
907
    IO_MTIME_USE      => IO_MTIME_USE,      -- implement machine system timer (MTIME)?
908
    IO_UART_USE       => IO_UART_USE,       -- implement universal asynchronous receiver/transmitter (UART)?
909
    IO_SPI_USE        => IO_SPI_USE,        -- implement serial peripheral interface (SPI)?
910
    IO_TWI_USE        => IO_TWI_USE,        -- implement two-wire interface (TWI)?
911
    IO_PWM_USE        => IO_PWM_USE,        -- implement pulse-width modulation unit (PWM)?
912
    IO_WDT_USE        => IO_WDT_USE,        -- implement watch dog timer (WDT)?
913
    IO_TRNG_USE       => IO_TRNG_USE,       -- implement true random number generator (TRNG)?
914
    IO_DEVNULL_USE    => IO_DEVNULL_USE     -- implement dummy device (DEVNULL)?
915
  )
916
  port map (
917
    -- host access --
918
    clk_i  => clk_i,         -- global clock line
919
    addr_i => p_bus.addr,    -- address
920
    rden_i => io_rden,       -- read enable
921
    data_o => sysinfo_rdata, -- data out
922
    ack_o  => sysinfo_ack    -- transfer acknowledge
923
  );
924
 
925
 
926 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.