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

Subversion Repositories neorv32

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

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
    CLOCK_FREQUENCY           : natural := 0; -- clock frequency of clk_i in Hz
51
    HART_ID                   : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom hardware thread ID
52
    BOOTLOADER_USE            : boolean := true;   -- implement processor-internal bootloader?
53
    -- RISC-V CPU Extensions --
54
    CPU_EXTENSION_RISCV_C     : boolean := false;  -- implement compressed extension?
55
    CPU_EXTENSION_RISCV_E     : boolean := false;  -- implement embedded RF extension?
56
    CPU_EXTENSION_RISCV_M     : boolean := false;  -- implement muld/div extension?
57
    CPU_EXTENSION_RISCV_Zicsr : boolean := true;   -- implement CSR system?
58
    -- Memory configuration: Instruction memory --
59
    MEM_ISPACE_BASE           : std_ulogic_vector(31 downto 0) := x"00000000"; -- base address of instruction memory space
60
    MEM_ISPACE_SIZE           : natural := 16*1024; -- total size of instruction memory space in byte
61
    MEM_INT_IMEM_USE          : boolean := true;   -- implement processor-internal instruction memory
62
    MEM_INT_IMEM_SIZE         : natural := 16*1024; -- size of processor-internal instruction memory in bytes
63
    MEM_INT_IMEM_ROM          : boolean := false;  -- implement processor-internal instruction memory as ROM
64
    -- Memory configuration: Data memory --
65
    MEM_DSPACE_BASE           : std_ulogic_vector(31 downto 0) := x"80000000"; -- base address of data memory space
66
    MEM_DSPACE_SIZE           : natural := 8*1024; -- total size of data memory space in byte
67
    MEM_INT_DMEM_USE          : boolean := true;   -- implement processor-internal data memory
68
    MEM_INT_DMEM_SIZE         : natural := 8*1024; -- size of processor-internal data memory in bytes
69
    -- Memory configuration: External memory interface --
70
    MEM_EXT_USE               : boolean := false;  -- implement external memory bus interface?
71
    MEM_EXT_REG_STAGES        : natural := 2;      -- number of interface register stages (0,1,2)
72
    MEM_EXT_TIMEOUT           : natural := 15;     -- cycles after which a valid bus access will timeout
73
    -- Processor peripherals --
74
    IO_GPIO_USE               : boolean := true;   -- implement general purpose input/output port unit (GPIO)?
75
    IO_MTIME_USE              : boolean := true;   -- implement machine system timer (MTIME)?
76
    IO_UART_USE               : boolean := true;   -- implement universal asynchronous receiver/transmitter (UART)?
77
    IO_SPI_USE                : boolean := true;   -- implement serial peripheral interface (SPI)?
78
    IO_TWI_USE                : boolean := true;   -- implement two-wire interface (TWI)?
79
    IO_PWM_USE                : boolean := true;   -- implement pulse-width modulation unit (PWM)?
80
    IO_WDT_USE                : boolean := true;   -- implement watch dog timer (WDT)?
81
    IO_CLIC_USE               : boolean := true;   -- implement core local interrupt controller (CLIC)?
82
    IO_TRNG_USE               : boolean := false   -- implement true random number generator (TRNG)?
83
  );
84
  port (
85
    -- Global control --
86
    clk_i      : in  std_ulogic := '0'; -- global clock, rising edge
87
    rstn_i     : in  std_ulogic := '0'; -- global reset, low-active, async
88
    -- Wishbone bus interface (available if MEM_EXT_USE = true) --
89
    wb_adr_o   : out std_ulogic_vector(31 downto 0); -- address
90
    wb_dat_i   : in  std_ulogic_vector(31 downto 0) := (others => '0'); -- read data
91
    wb_dat_o   : out std_ulogic_vector(31 downto 0); -- write data
92
    wb_we_o    : out std_ulogic; -- read/write
93
    wb_sel_o   : out std_ulogic_vector(03 downto 0); -- byte enable
94
    wb_stb_o   : out std_ulogic; -- strobe
95
    wb_cyc_o   : out std_ulogic; -- valid cycle
96
    wb_ack_i   : in  std_ulogic := '0'; -- transfer acknowledge
97
    wb_err_i   : in  std_ulogic := '0'; -- transfer error
98
    -- GPIO (available if IO_GPIO_USE = true) --
99
    gpio_o     : out std_ulogic_vector(15 downto 0); -- parallel output
100
    gpio_i     : in  std_ulogic_vector(15 downto 0) := (others => '0'); -- parallel input
101
    -- UART (available if IO_UART_USE = true) --
102
    uart_txd_o : out std_ulogic; -- UART send data
103
    uart_rxd_i : in  std_ulogic := '0'; -- UART receive data
104
    -- SPI (available if IO_SPI_USE = true) --
105
    spi_sclk_o : out std_ulogic; -- serial clock line
106
    spi_mosi_o : out std_ulogic; -- serial data line out
107
    spi_miso_i : in  std_ulogic := '0'; -- serial data line in
108
    spi_csn_o  : out std_ulogic_vector(07 downto 0); -- SPI CS
109
    -- TWI (available if IO_TWI_USE = true) --
110
    twi_sda_io : inout std_logic := 'H'; -- twi serial data line
111
    twi_scl_io : inout std_logic := 'H'; -- twi serial clock line
112
    -- PWM (available if IO_PWM_USE = true) --
113
    pwm_o      : out std_ulogic_vector(03 downto 0);  -- pwm channels
114
    -- Interrupts (available if IO_CLIC_USE = true) --
115
    ext_irq_i  : in  std_ulogic_vector(01 downto 0) := (others => '0'); -- external interrupt request
116
    ext_ack_o  : out std_ulogic_vector(01 downto 0)  -- external interrupt request acknowledge
117
  );
118
end neorv32_top;
119
 
120
architecture neorv32_top_rtl of neorv32_top is
121
 
122
  -- reset generator --
123
  signal rstn_i_sync0 : std_ulogic;
124
  signal rstn_i_sync1 : std_ulogic;
125
  signal rstn_i_sync2 : std_ulogic;
126
  signal rstn_gen     : std_ulogic_vector(3 downto 0);
127
  signal ext_rstn     : std_ulogic;
128
  signal sys_rstn     : std_ulogic;
129
  signal wdt_rstn     : std_ulogic;
130
 
131
  -- clock generator --
132
  signal clk_div    : std_ulogic_vector(11 downto 0);
133
  signal clk_div_ff : std_ulogic_vector(11 downto 0);
134
  signal clk_gen    : std_ulogic_vector(07 downto 0);
135
  signal wdt_cg_en  : std_ulogic;
136
  signal uart_cg_en : std_ulogic;
137
  signal spi_cg_en  : std_ulogic;
138
  signal twi_cg_en  : std_ulogic;
139
  signal pwm_cg_en  : std_ulogic;
140
 
141
  -- cpu bus --
142
  signal cpu_addr  : std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
143
  signal cpu_rdata : std_ulogic_vector(data_width_c-1 downto 0); -- bus read data
144
  signal cpu_wdata : std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
145
  signal cpu_ben   : std_ulogic_vector(03 downto 0); -- byte enable
146
  signal cpu_we    : std_ulogic; -- write enable
147
  signal cpu_re    : std_ulogic; -- read enable
148
  signal cpu_ack   : std_ulogic; -- bus transfer acknowledge
149
  signal cpu_err   : std_ulogic; -- bus transfer error
150
 
151
  -- io space access --
152
  signal io_acc  : std_ulogic;
153
  signal io_rden : std_ulogic;
154
  signal io_wren : std_ulogic;
155
 
156
  -- read-back busses -
157
  signal imem_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
158
  signal imem_ack       : std_ulogic;
159
  signal dmem_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
160
  signal dmem_ack       : std_ulogic;
161
  signal bootrom_rdata  : std_ulogic_vector(data_width_c-1 downto 0);
162
  signal bootrom_ack    : std_ulogic;
163
  signal wishbone_rdata : std_ulogic_vector(data_width_c-1 downto 0);
164
  signal wishbone_ack   : std_ulogic;
165
  signal wishbone_err   : std_ulogic;
166
  signal gpio_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
167
  signal gpio_ack       : std_ulogic;
168
  signal mtime_rdata    : std_ulogic_vector(data_width_c-1 downto 0);
169
  signal mtime_ack      : std_ulogic;
170
  signal uart_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
171
  signal uart_ack       : std_ulogic;
172
  signal spi_rdata      : std_ulogic_vector(data_width_c-1 downto 0);
173
  signal spi_ack        : std_ulogic;
174
  signal twi_rdata      : std_ulogic_vector(data_width_c-1 downto 0);
175
  signal twi_ack        : std_ulogic;
176
  signal pwm_rdata      : std_ulogic_vector(data_width_c-1 downto 0);
177
  signal pwm_ack        : std_ulogic;
178
  signal wdt_rdata      : std_ulogic_vector(data_width_c-1 downto 0);
179
  signal wdt_ack        : std_ulogic;
180
  signal clic_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
181
  signal clic_ack       : std_ulogic;
182
  signal trng_rdata     : std_ulogic_vector(data_width_c-1 downto 0);
183
  signal trng_ack       : std_ulogic;
184
 
185
  -- IRQs --
186
  signal mtime_irq : std_ulogic;
187
  signal clic_irq  : std_ulogic;
188
  signal clic_xirq : std_ulogic_vector(7 downto 0);
189
  signal clic_xack : std_ulogic_vector(7 downto 0);
190
  signal gpio_irq  : std_ulogic;
191
  signal wdt_irq   : std_ulogic;
192
  signal uart_irq  : std_ulogic;
193
  signal spi_irq   : std_ulogic;
194
  signal twi_irq   : std_ulogic;
195
 
196
begin
197
 
198
  -- Sanity Checks --------------------------------------------------------------------------
199
  -- -------------------------------------------------------------------------------------------
200
  sanity_check: process(clk_i)
201
  begin
202
    if rising_edge(clk_i) then
203
      -- internal bootloader memory --
204
      if (BOOTLOADER_USE = true) and (boot_size_c > boot_max_size_c) then
205
        assert false report "NEORV32 CONFIG ERROR! Boot ROM size out of range." severity error;
206
      end if;
207
 
208
      -- memory system - data/instruction fetch --
209
      if (MEM_EXT_USE = false) then
210
        if (MEM_INT_DMEM_USE = false) then
211
          assert false report "NEORV32 CONFIG ERROR! Core cannot fetch data without external memory interface and internal data memory." severity error;
212
        end if;
213
        if (MEM_INT_IMEM_USE = false) and (BOOTLOADER_USE = false) then
214
          assert false report "NEORV32 CONFIG ERROR! Core cannot fetch instructions without external memory interface, internal data memory and bootloader." severity error;
215
        end if;
216
      end if;
217
 
218
      -- memory system - address space --
219
      if (MEM_INT_IMEM_USE = true) and (MEM_INT_IMEM_SIZE > MEM_ISPACE_SIZE) then
220
        assert false report "NEORV32 CONFIG ERROR! Internal instruction memory (IMEM) cannot be greater than total instruction address space." severity error;
221
      end if;
222
      if (MEM_INT_DMEM_USE = true) and (MEM_INT_DMEM_SIZE > MEM_DSPACE_SIZE) then
223
        assert false report "NEORV32 CONFIG ERROR! Internal data memory (DMEM) cannot be greater than total data address space." severity error;
224
      end if;
225
      if (MEM_EXT_TIMEOUT <= 1) then
226
        assert false report "NEORV32 CONFIG ERROR! Invalid bus timeout. Internal components require 1 cycle delay." severity error;
227
      end if;
228
 
229
      -- clock --
230
      if (CLOCK_FREQUENCY = 0) then
231
        assert false report "NEORV32 CONFIG ERROR! Core clock frequency (CLOCK_FREQUENCY) not specified." severity error;
232
      end if;
233
 
234
      -- CSR system not implemented --
235
      if (CPU_EXTENSION_RISCV_Zicsr = false) then
236
        assert false report "NEORV32 CONFIG WARNING! No exception/interrupt/machine status features available when CPU_EXTENSION_RISCV_Zicsr = false." severity warning;
237
      end if;
238
      -- core local interrupt controller --
239
      if (CPU_EXTENSION_RISCV_Zicsr = false) and (IO_CLIC_USE = true) then
240
        assert false report "NEORV32 CONFIG ERROR! Core local interrupt controller (CLIC) cannot be used without >Zicsr< CPU extension." severity error;
241
      end if;
242
 
243
      -- memory layout notifier --
244
      if (MEM_ISPACE_BASE /= x"00000000") then
245
        assert false report "NEORV32 CONFIG WARNING! Non-default base address for instruction address space. Make sure this is sync with the linker script." severity warning;
246
      end if;
247
      if (MEM_DSPACE_BASE /= x"80000000") then
248
        assert false report "NEORV32 CONFIG WARNING! Non-default base address for data address space. Make sure this is sync with the linker script." severity warning;
249
      end if;
250
    end if;
251
  end process sanity_check;
252
 
253
 
254
  -- Reset Generator ------------------------------------------------------------------------
255
  -- -------------------------------------------------------------------------------------------
256
  reset_generator_sync: process(clk_i)
257
  begin
258
    -- make sure the external reset is free of metastability and has a minimal duration of 1 clock cycle
259
    if rising_edge(clk_i) then
260
      rstn_i_sync0 <= rstn_i;
261
      rstn_i_sync1 <= rstn_i_sync0;
262
      rstn_i_sync2 <= rstn_i_sync1;
263
    end if;
264
  end process reset_generator_sync;
265
 
266
  -- keep internal reset active for at least 4 clock cycles
267
  reset_generator: process(rstn_i_sync1, rstn_i_sync2, clk_i)
268
  begin
269
    if ((rstn_i_sync1 or rstn_i_sync2) = '0') then -- signal stable somehow?
270
      rstn_gen <= (others => '0');
271
    elsif rising_edge(clk_i) then
272
      rstn_gen <= rstn_gen(rstn_gen'left-1 downto 0) & '1';
273
    end if;
274
  end process reset_generator;
275
 
276
  ext_rstn <= rstn_gen(rstn_gen'left); -- the beautified external reset signal
277
  sys_rstn <= ext_rstn and wdt_rstn; -- system reset - can also be triggered by watchdog
278
 
279
 
280
  -- Clock Generator ------------------------------------------------------------------------
281
  -- -------------------------------------------------------------------------------------------
282
  clock_generator: process(sys_rstn, clk_i)
283
  begin
284
    if (sys_rstn = '0') then
285
      clk_div    <= (others => '0');
286
      clk_div_ff <= (others => '0');
287
    elsif rising_edge(clk_i) then
288
      -- anybody wanting some fresh clocks? --
289
      if ((wdt_cg_en or uart_cg_en or spi_cg_en or twi_cg_en or pwm_cg_en) = '1') then
290
        clk_div    <= std_ulogic_vector(unsigned(clk_div) + 1);
291
        clk_div_ff <= clk_div;
292
      end if;
293
    end if;
294
  end process clock_generator;
295
 
296
  -- clock enable select: rising edge detectors --
297
  clk_gen(clk_div2_c)    <= clk_div(0)  and (not clk_div_ff(0));  -- CLK/2
298
  clk_gen(clk_div4_c)    <= clk_div(1)  and (not clk_div_ff(1));  -- CLK/4
299
  clk_gen(clk_div8_c)    <= clk_div(2)  and (not clk_div_ff(2));  -- CLK/8
300
  clk_gen(clk_div64_c)   <= clk_div(5)  and (not clk_div_ff(5));  -- CLK/64
301
  clk_gen(clk_div128_c)  <= clk_div(6)  and (not clk_div_ff(6));  -- CLK/128
302
  clk_gen(clk_div1024_c) <= clk_div(9)  and (not clk_div_ff(9));  -- CLK/1024
303
  clk_gen(clk_div2048_c) <= clk_div(10) and (not clk_div_ff(10)); -- CLK/2048
304
  clk_gen(clk_div4096_c) <= clk_div(11) and (not clk_div_ff(11)); -- CLK/4096
305
 
306
 
307
  -- CPU ------------------------------------------------------------------------------------
308
  -- -------------------------------------------------------------------------------------------
309
  neorv32_cpu_inst: neorv32_cpu
310
  generic map (
311
    -- General --
312
    CLOCK_FREQUENCY           => CLOCK_FREQUENCY,   -- clock frequency of clk_i in Hz
313
    HART_ID                   => HART_ID,           -- custom hardware thread ID
314
    BOOTLOADER_USE            => BOOTLOADER_USE,    -- implement processor-internal bootloader?
315
    -- RISC-V CPU Extensions --
316
    CPU_EXTENSION_RISCV_C     => CPU_EXTENSION_RISCV_C,     -- implement compressed extension?
317
    CPU_EXTENSION_RISCV_E     => CPU_EXTENSION_RISCV_E,     -- implement embedded RF extension?
318
    CPU_EXTENSION_RISCV_M     => CPU_EXTENSION_RISCV_M,     -- implement muld/div extension?
319
    CPU_EXTENSION_RISCV_Zicsr => CPU_EXTENSION_RISCV_Zicsr, -- implement CSR system?
320
    -- Memory configuration: Instruction memory --
321
    MEM_ISPACE_BASE           => MEM_ISPACE_BASE,   -- base address of instruction memory space
322
    MEM_ISPACE_SIZE           => MEM_ISPACE_SIZE,   -- total size of instruction memory space in byte
323
    MEM_INT_IMEM_USE          => MEM_INT_IMEM_USE,  -- implement processor-internal instruction memory
324
    MEM_INT_IMEM_SIZE         => MEM_INT_IMEM_SIZE, -- size of processor-internal instruction memory in bytes
325
    MEM_INT_IMEM_ROM          => MEM_INT_IMEM_ROM,  -- implement processor-internal instruction memory as ROM
326
    -- Memory configuration: Data memory --
327
    MEM_DSPACE_BASE           => MEM_DSPACE_BASE,   -- base address of data memory space
328
    MEM_DSPACE_SIZE           => MEM_DSPACE_SIZE,   -- total size of data memory space in byte
329
    MEM_INT_DMEM_USE          => MEM_INT_DMEM_USE,  -- implement processor-internal data memory
330
    MEM_INT_DMEM_SIZE         => MEM_INT_DMEM_SIZE, -- size of processor-internal data memory in bytes
331
    -- Memory configuration: External memory interface --
332
    MEM_EXT_USE               => MEM_EXT_USE,       -- implement external memory bus interface?
333
    MEM_EXT_TIMEOUT           => MEM_EXT_TIMEOUT,   -- cycles after which a valid bus access will timeout
334
    -- Processor peripherals --
335
    IO_GPIO_USE               => IO_GPIO_USE,       -- implement general purpose input/output port unit (GPIO)?
336
    IO_MTIME_USE              => IO_MTIME_USE,      -- implement machine system timer (MTIME)?
337
    IO_UART_USE               => IO_UART_USE,       -- implement universal asynchronous receiver/transmitter (UART)?
338
    IO_SPI_USE                => IO_SPI_USE,        -- implement serial peripheral interface (SPI)?
339
    IO_TWI_USE                => IO_TWI_USE,        -- implement two-wire interface (TWI)?
340
    IO_PWM_USE                => IO_PWM_USE,        -- implement pulse-width modulation unit (PWM)?
341
    IO_WDT_USE                => IO_WDT_USE,        -- implement watch dog timer (WDT)?
342
    IO_CLIC_USE               => IO_CLIC_USE,       -- implement core local interrupt controller (CLIC)?
343
    IO_TRNG_USE               => IO_TRNG_USE        -- implement true random number generator (TRNG)?
344
  )
345
  port map (
346
    -- global control --
347
    clk_i       => clk_i,        -- global clock, rising edge
348
    rstn_i      => sys_rstn,     -- global reset, low-active, async
349
    -- bus interface --
350
    bus_addr_o  => cpu_addr,     -- bus access address
351
    bus_rdata_i => cpu_rdata,    -- bus read data
352
    bus_wdata_o => cpu_wdata,    -- bus write data
353
    bus_ben_o   => cpu_ben,      -- byte enable
354
    bus_we_o    => cpu_we,       -- write enable
355
    bus_re_o    => cpu_re,       -- read enable
356
    bus_ack_i   => cpu_ack,      -- bus transfer acknowledge
357
    bus_err_i   => cpu_err,      -- bus transfer error
358
    -- external interrupts --
359
    clic_irq_i  => clic_irq,     -- CLIC interrupt request
360
    mtime_irq_i => mtime_irq     -- machine timer interrupt
361
  );
362
 
363
  -- CPU data input --
364
  cpu_rdata <= (imem_rdata or dmem_rdata or bootrom_rdata) or wishbone_rdata or (gpio_rdata or mtime_rdata or
365
               uart_rdata or spi_rdata or twi_rdata or pwm_rdata or wdt_rdata or clic_rdata or trng_rdata);
366
 
367
  -- CPU ACK input --
368
  cpu_ack <= (imem_ack or dmem_ack or bootrom_ack) or wishbone_ack or (gpio_ack or mtime_ack or
369
              uart_ack or spi_ack or twi_ack or pwm_ack or wdt_ack or clic_ack or trng_ack);
370
 
371
  -- CPU bus error input --
372
  cpu_err <= wishbone_err;
373
 
374
 
375
  -- Processor-Internal Instruction Memory (IMEM) -------------------------------------------
376
  -- -------------------------------------------------------------------------------------------
377
  neorv32_int_imem_inst_true:
378
  if (MEM_INT_IMEM_USE = true) generate
379
    neorv32_int_imem_inst: neorv32_imem
380
    generic map (
381
      IMEM_BASE      => MEM_ISPACE_BASE,   -- memory base address
382
      IMEM_SIZE      => MEM_INT_IMEM_SIZE, -- processor-internal instruction memory size in bytes
383
      IMEM_AS_ROM    => MEM_INT_IMEM_ROM,  -- implement IMEM as read-only memory?
384
      BOOTLOADER_USE => BOOTLOADER_USE     -- implement and use bootloader?
385
    )
386
    port map (
387
      clk_i  => clk_i,      -- global clock line
388
      rden_i => cpu_re,     -- read enable
389
      wren_i => cpu_we,     -- write enable
390
      ben_i  => cpu_ben,    -- byte write enable
391
      upen_i => '1',        -- update enable
392
      addr_i => cpu_addr,   -- address
393
      data_i => cpu_wdata,  -- data in
394
      data_o => imem_rdata, -- data out
395
      ack_o  => imem_ack    -- transfer acknowledge
396
    );
397
  end generate;
398
 
399
  neorv32_int_imem_inst_false:
400
  if (MEM_INT_IMEM_USE = false) generate
401
    imem_rdata <= (others => '0');
402
    imem_ack   <= '0';
403
  end generate;
404
 
405
 
406
  -- Processor-Internal Data Memory (DMEM) --------------------------------------------------
407
  -- -------------------------------------------------------------------------------------------
408
  neorv32_int_dmem_inst_true:
409
  if (MEM_INT_DMEM_USE = true) generate
410
    neorv32_int_dmem_inst: neorv32_dmem
411
    generic map (
412
      DMEM_BASE => MEM_DSPACE_BASE,  -- memory base address
413
      DMEM_SIZE => MEM_INT_DMEM_SIZE -- processor-internal data memory size in bytes
414
    )
415
    port map (
416
      clk_i  => clk_i,      -- global clock line
417
      rden_i => cpu_re,     -- read enable
418
      wren_i => cpu_we,     -- write enable
419
      ben_i  => cpu_ben,    -- byte write enable
420
      addr_i => cpu_addr,   -- address
421
      data_i => cpu_wdata,  -- data in
422
      data_o => dmem_rdata, -- data out
423
      ack_o  => dmem_ack    -- transfer acknowledge
424
    );
425
  end generate;
426
 
427
  neorv32_int_dmem_inst_false:
428
  if (MEM_INT_DMEM_USE = false) generate
429
    dmem_rdata <= (others => '0');
430
    dmem_ack   <= '0';
431
  end generate;
432
 
433
 
434
  -- Processor-Internal Bootloader ROM (BOOTROM) --------------------------------------------
435
  -- -------------------------------------------------------------------------------------------
436
  neorv32_boot_rom_inst_true:
437
  if (BOOTLOADER_USE = true) generate
438
    neorv32_boot_rom_inst: neorv32_boot_rom
439
    port map (
440
      clk_i  => clk_i,         -- global clock line
441
      rden_i => cpu_re,        -- read enable
442
      addr_i => cpu_addr,      -- address
443
      data_o => bootrom_rdata, -- data out
444
      ack_o  => bootrom_ack    -- transfer acknowledge
445
    );
446
  end generate;
447
 
448
  neorv32_boot_rom_inst_false:
449
  if (BOOTLOADER_USE = false) generate
450
    bootrom_rdata <= (others => '0');
451
    bootrom_ack   <= '0';
452
  end generate;
453
 
454
 
455
  -- External Wishbone Gateway (WISHBONE) ---------------------------------------------------
456
  -- -------------------------------------------------------------------------------------------
457
  neorv32_wishbone_inst_true:
458
  if (MEM_EXT_USE = true) generate
459
    neorv32_wishbone_inst: neorv32_wishbone
460
    generic map (
461
      INTERFACE_REG_STAGES => MEM_EXT_REG_STAGES, -- number of interface register stages (0,1,2)
462
      -- Memory configuration: Instruction memory --
463
      MEM_ISPACE_BASE      => MEM_ISPACE_BASE,   -- base address of instruction memory space
464
      MEM_ISPACE_SIZE      => MEM_ISPACE_SIZE,   -- total size of instruction memory space in byte
465
      MEM_INT_IMEM_USE     => MEM_INT_IMEM_USE,  -- implement processor-internal instruction memory
466
      MEM_INT_IMEM_SIZE    => MEM_INT_IMEM_SIZE, -- size of processor-internal instruction memory in bytes
467
      -- Memory configuration: Data memory --
468
      MEM_DSPACE_BASE      => MEM_DSPACE_BASE,   -- base address of data memory space
469
      MEM_DSPACE_SIZE      => MEM_DSPACE_SIZE,   -- total size of data memory space in byte
470
      MEM_INT_DMEM_USE     => MEM_INT_DMEM_USE,  -- implement processor-internal data memory
471
      MEM_INT_DMEM_SIZE    => MEM_INT_DMEM_SIZE  -- size of processor-internal data memory in bytes
472
    )
473
    port map (
474
      -- global control --
475
      clk_i    => clk_i,          -- global clock line
476
      rstn_i   => sys_rstn,       -- global reset line, low-active
477
      -- host access --
478
      addr_i   => cpu_addr,       -- address
479
      rden_i   => cpu_re,         -- read enable
480
      wren_i   => cpu_we,         -- write enable
481
      ben_i    => cpu_ben,        -- byte write enable
482
      data_i   => cpu_wdata,      -- data in
483
      data_o   => wishbone_rdata, -- data out
484
      ack_o    => wishbone_ack,   -- transfer acknowledge
485
      err_o    => wishbone_err,   -- transfer error
486
      -- wishbone interface --
487
      wb_adr_o => wb_adr_o,       -- address
488
      wb_dat_i => wb_dat_i,       -- read data
489
      wb_dat_o => wb_dat_o,       -- write data
490
      wb_we_o  => wb_we_o,        -- read/write
491
      wb_sel_o => wb_sel_o,       -- byte enable
492
      wb_stb_o => wb_stb_o,       -- strobe
493
      wb_cyc_o => wb_cyc_o,       -- valid cycle
494
      wb_ack_i => wb_ack_i,       -- transfer acknowledge
495
      wb_err_i => wb_err_i        -- transfer error
496
    );
497
  end generate;
498
 
499
  neorv32_wishbone_inst_false:
500
  if (MEM_EXT_USE = false) generate
501
    wishbone_rdata <= (others => '0');
502
    wishbone_ack   <= '0';
503
    wishbone_err   <= '0';
504
    --
505
    wb_adr_o <= (others => '0');
506
    wb_dat_o <= (others => '0');
507
    wb_we_o  <= '0';
508
    wb_sel_o <= (others => '0');
509
    wb_stb_o <= '0';
510
    wb_cyc_o <= '0';
511
  end generate;
512
 
513
 
514
  -- IO Access? -----------------------------------------------------------------------------
515
  -- -------------------------------------------------------------------------------------------
516
  io_acc  <= '1' when (cpu_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';
517
  io_rden <= io_acc and cpu_re;
518
  io_wren <= io_acc and cpu_we;
519
 
520
 
521
  -- General Purpose Input/Output Port (GPIO) -----------------------------------------------
522
  -- -------------------------------------------------------------------------------------------
523
  neorv32_gpio_inst_true:
524
  if (IO_GPIO_USE = true) generate
525
    neorv32_gpio_inst: neorv32_gpio
526
    port map (
527
      -- host access --
528
      clk_i  => clk_i,      -- global clock line
529
      addr_i => cpu_addr,   -- address
530
      rden_i => io_rden,    -- read enable
531
      wren_i => io_wren,    -- write enable
532
      ben_i  => cpu_ben,    -- byte write enable
533
      data_i => cpu_wdata,  -- data in
534
      data_o => gpio_rdata, -- data out
535
      ack_o  => gpio_ack,   -- transfer acknowledge
536
      -- parallel io --
537
      gpio_o => gpio_o,
538
      gpio_i => gpio_i,
539
      -- interrupt --
540
      irq_o  => gpio_irq    -- pin-change interrupt
541
    );
542
  end generate;
543
 
544
  neorv32_gpio_inst_false:
545
  if (IO_GPIO_USE = false) generate
546
    gpio_rdata <= (others => '0');
547
    gpio_ack   <= '0';
548
    gpio_o     <= (others => '0');
549
    gpio_irq   <= '0';
550
  end generate;
551
 
552
 
553
  -- Core-Local Interrupt Controller (CLIC) -------------------------------------------------
554
  -- -------------------------------------------------------------------------------------------
555
  neorv32_clic_inst_true:
556
  if (IO_CLIC_USE = true) generate
557
    neorv32_clic_inst: neorv32_clic
558
    port map (
559
      -- host access --
560
      clk_i     => clk_i,      -- global clock line
561
      rden_i    => io_rden,    -- read enable
562
      wren_i    => io_wren,    -- write enable
563
      ben_i     => cpu_ben,    -- byte write enable
564
      addr_i    => cpu_addr,   -- address
565
      data_i    => cpu_wdata,  -- data in
566
      data_o    => clic_rdata, -- data out
567
      ack_o     => clic_ack,   -- transfer acknowledge
568
      -- cpu interrupt --
569
      cpu_irq_o => clic_irq,   -- trigger CPU's external IRQ
570
      -- external interrupt lines --
571
      ext_irq_i => clic_xirq,  -- IRQ, triggering on HIGH level
572
      ext_ack_o => clic_xack   -- acknowledge
573
    );
574
  end generate;
575
 
576
  -- CLIC interrupt channels and priority --
577
  clic_xirq(0) <= wdt_irq; -- highest priority
578
  clic_xirq(1) <= '0'; -- reserved
579
  clic_xirq(2) <= gpio_irq;
580
  clic_xirq(3) <= uart_irq;
581
  clic_xirq(4) <= spi_irq;
582
  clic_xirq(5) <= twi_irq;
583
  clic_xirq(6) <= ext_irq_i(0);
584
  clic_xirq(7) <= ext_irq_i(1); -- lowest priority
585
 
586
  ext_ack_o <= clic_xirq(7 downto 6); -- external interrupt request acknowledge
587
 
588
  neorv32_clic_inst_false:
589
  if (IO_CLIC_USE = false) generate
590
    clic_rdata <= (others => '0');
591
    clic_ack   <= '0';
592
    clic_irq   <= '0';
593
    clic_xack  <= (others => '0');
594
  end generate;
595
 
596
 
597
  -- Watch Dog Timer (WDT) ------------------------------------------------------------------
598
  -- -------------------------------------------------------------------------------------------
599
  neorv32_wdt_inst_true:
600
  if (IO_WDT_USE = true) generate
601
    neorv32_wdt_inst: neorv32_wdt
602
    port map (
603
      -- host access --
604
      clk_i       => clk_i,      -- global clock line
605
      rstn_i      => ext_rstn,   -- global reset line, low-active
606
      rden_i      => io_rden,    -- read enable
607
      wren_i      => io_wren,    -- write enable
608
      ben_i       => cpu_ben,    -- byte write enable
609
      addr_i      => cpu_addr,   -- address
610
      data_i      => cpu_wdata,  -- data in
611
      data_o      => wdt_rdata,  -- data out
612
      ack_o       => wdt_ack,    -- transfer acknowledge
613
      -- clock generator --
614
      clkgen_en_o => wdt_cg_en,  -- enable clock generator
615
      clkgen_i    => clk_gen,
616
      -- timeout event --
617
      irq_o       => wdt_irq,    -- timeout IRQ
618
      rstn_o      => wdt_rstn    -- timeout reset, low_active, use it as async!
619
    );
620
  end generate;
621
 
622
  neorv32_wdt_inst_false:
623
  if (IO_WDT_USE = false) generate
624
    wdt_rdata <= (others => '0');
625
    wdt_ack   <= '0';
626
    wdt_irq   <= '0';
627
    wdt_rstn  <= '1';
628
    wdt_cg_en <= '0';
629
  end generate;
630
 
631
 
632
  -- Machine System Timer (MTIME) -----------------------------------------------------------
633
  -- -------------------------------------------------------------------------------------------
634
  neorv32_mtime_inst_true:
635
  if (IO_MTIME_USE = true) generate
636
    neorv32_mtime_inst: neorv32_mtime
637
    port map (
638
      -- host access --
639
      clk_i     => clk_i,        -- global clock line
640
      addr_i    => cpu_addr,     -- address
641
      rden_i    => io_rden,      -- read enable
642
      wren_i    => io_wren,      -- write enable
643
      ben_i     => cpu_ben,      -- byte write enable
644
      data_i    => cpu_wdata,    -- data in
645
      data_o    => mtime_rdata,  -- data out
646
      ack_o     => mtime_ack,    -- transfer acknowledge
647
      -- interrupt --
648
      irq_o     => mtime_irq     -- interrupt request
649
    );
650
  end generate;
651
 
652
  neorv32_mtime_inst_false:
653
  if (IO_MTIME_USE = false) generate
654
    mtime_rdata <= (others => '0');
655
    mtime_ack   <= '0';
656
    mtime_irq   <= '0';
657
  end generate;
658
 
659
 
660
  -- Universal Asynchronous Receiver/Transmitter (UART) -------------------------------------
661
  -- -------------------------------------------------------------------------------------------
662
  neorv32_uart_inst_true:
663
  if (IO_UART_USE = true) generate
664
    neorv32_uart_inst: neorv32_uart
665
    port map (
666
      -- host access --
667
      clk_i       => clk_i,      -- global clock line
668
      addr_i      => cpu_addr,   -- address
669
      rden_i      => io_rden,    -- read enable
670
      wren_i      => io_wren,    -- write enable
671
      ben_i       => cpu_ben,    -- byte write enable
672
      data_i      => cpu_wdata,  -- data in
673
      data_o      => uart_rdata, -- data out
674
      ack_o       => uart_ack,   -- transfer acknowledge
675
      -- clock generator --
676
      clkgen_en_o => uart_cg_en, -- enable clock generator
677
      clkgen_i    => clk_gen,
678
      -- com lines --
679
      uart_txd_o  => uart_txd_o,
680
      uart_rxd_i  => uart_rxd_i,
681
      -- interrupts --
682
      uart_irq_o  => uart_irq    -- uart rx/tx interrupt
683
    );
684
  end generate;
685
 
686
  neorv32_uart_inst_false:
687
  if (IO_UART_USE = false) generate
688
    uart_rdata <= (others => '0');
689
    uart_ack   <= '0';
690
    uart_txd_o <= '0';
691
    uart_cg_en <= '0';
692
    uart_irq   <= '0';
693
  end generate;
694
 
695
 
696
  -- Serial Peripheral Interface (SPI) ------------------------------------------------------
697
  -- -------------------------------------------------------------------------------------------
698
  neorv32_spi_inst_true:
699
  if (IO_SPI_USE = true) generate
700
    neorv32_spi_inst: neorv32_spi
701
    port map (
702
      -- host access --
703
      clk_i       => clk_i,      -- global clock line
704
      addr_i      => cpu_addr,   -- address
705
      rden_i      => io_rden,    -- read enable
706
      wren_i      => io_wren,    -- write enable
707
      ben_i       => cpu_ben,    -- byte write enable
708
      data_i      => cpu_wdata,  -- data in
709
      data_o      => spi_rdata,  -- data out
710
      ack_o       => spi_ack,    -- transfer acknowledge
711
      -- clock generator --
712
      clkgen_en_o => spi_cg_en,  -- enable clock generator
713
      clkgen_i    => clk_gen,
714
      -- com lines --
715
      spi_sclk_o  => spi_sclk_o, -- SPI serial clock
716
      spi_mosi_o  => spi_mosi_o, -- SPI master out, slave in
717
      spi_miso_i  => spi_miso_i, -- SPI master in, slave out
718
      spi_csn_o   => spi_csn_o,  -- SPI CS
719
      -- interrupt --
720
      spi_irq_o   => spi_irq     -- transmission done interrupt
721
    );
722
  end generate;
723
 
724
  neorv32_spi_inst_false:
725
  if (IO_SPI_USE = false) generate
726
    spi_rdata  <= (others => '0');
727
    spi_ack    <= '0';
728
    spi_sclk_o <= '0';
729
    spi_mosi_o <= '0';
730
    spi_csn_o  <= (others => '1'); -- CSn lines are low-active
731
    spi_cg_en  <= '0';
732
    spi_irq    <= '0';
733
  end generate;
734
 
735
 
736
  -- Two-Wire Interface (TWI) ---------------------------------------------------------------
737
  -- -------------------------------------------------------------------------------------------
738
  neorv32_twi_inst_true:
739
  if (IO_TWI_USE = true) generate
740
    neorv32_twi_inst: neorv32_twi
741
    port map (
742
      -- host access --
743
      clk_i       => clk_i,      -- global clock line
744
      addr_i      => cpu_addr,   -- address
745
      rden_i      => io_rden,    -- read enable
746
      wren_i      => io_wren,    -- write enable
747
      ben_i       => cpu_ben,    -- byte write enable
748
      data_i      => cpu_wdata,  -- data in
749
      data_o      => twi_rdata,  -- data out
750
      ack_o       => twi_ack,    -- transfer acknowledge
751
      -- clock generator --
752
      clkgen_en_o => twi_cg_en,  -- enable clock generator
753
      clkgen_i    => clk_gen,
754
      -- com lines --
755
      twi_sda_io  => twi_sda_io, -- serial data line
756
      twi_scl_io  => twi_scl_io, -- serial clock line
757
      -- interrupt --
758
      twi_irq_o   => twi_irq     -- transfer done IRQ
759
    );
760
  end generate;
761
 
762
  neorv32_twi_inst_false:
763
  if (IO_TWI_USE = false) generate
764
    twi_rdata  <= (others => '0');
765
    twi_ack    <= '0';
766
--  twi_sda_io <= 'H';
767
--  twi_scl_io <= 'H';
768
    twi_cg_en  <= '0';
769
    twi_irq    <= '0';
770
  end generate;
771
 
772
 
773
  -- Pulse-Width Modulation Controller (PWM) ------------------------------------------------
774
  -- -------------------------------------------------------------------------------------------
775
  neorv32_pwm_inst_true:
776
  if (IO_PWM_USE = true) generate
777
    neorv32_pwm_inst: neorv32_pwm
778
    port map (
779
      -- host access --
780
      clk_i       => clk_i,      -- global clock line
781
      addr_i      => cpu_addr,   -- address
782
      rden_i      => io_rden,    -- read enable
783
      wren_i      => io_wren,    -- write enable
784
      ben_i       => cpu_ben,    -- byte write enable
785
      data_i      => cpu_wdata,  -- data in
786
      data_o      => pwm_rdata,  -- data out
787
      ack_o       => pwm_ack,    -- transfer acknowledge
788
      -- clock generator --
789
      clkgen_en_o => pwm_cg_en,  -- enable clock generator
790
      clkgen_i    => clk_gen,
791
      -- pwm output channels --
792
      pwm_o       => pwm_o
793
    );
794
  end generate;
795
 
796
  neorv32_pwm_inst_false:
797
  if (IO_PWM_USE = false) generate
798
    pwm_rdata <= (others => '0');
799
    pwm_ack   <= '0';
800
    pwm_cg_en <= '0';
801
    pwm_o     <= (others => '0');
802
  end generate;
803
 
804
 
805
  -- True Random Number Generator (TRNG) ----------------------------------------------------
806
  -- -------------------------------------------------------------------------------------------
807
  neorv32_trng_inst_true:
808
  if (IO_TRNG_USE = true) generate
809
    neorv32_trng_inst: neorv32_trng
810
    port map (
811
      -- host access --
812
      clk_i  => clk_i,      -- global clock line
813
      addr_i => cpu_addr,   -- address
814
      rden_i => io_rden,    -- read enable
815
      wren_i => io_wren,    -- write enable
816
      ben_i  => cpu_ben,    -- byte write enable
817
      data_i => cpu_wdata,  -- data in
818
      data_o => trng_rdata, -- data out
819
      ack_o  => trng_ack    -- transfer acknowledge
820
    );
821
  end generate;
822
 
823
  neorv32_trng_inst_false:
824
  if (IO_TRNG_USE = false) generate
825
    trng_rdata <= (others => '0');
826
    trng_ack   <= '0';
827
  end generate;
828
 
829
 
830
end neorv32_top_rtl;

powered by: WebSVN 2.1.0

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