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

Subversion Repositories neorv32

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

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