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

Subversion Repositories neorv32

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

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

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