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