You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1832 lines
91 KiB

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