lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | // Copyright lowRISC contributors. |
| 2 | // Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | |
Timothy Chen | 7ff5312 | 2019-09-19 15:20:43 -0700 | [diff] [blame] | 5 | module top_earlgrey #( |
| 6 | parameter bit IbexPipeLine = 0 |
| 7 | ) ( |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 8 | // Clock and Reset |
| 9 | input clk_i, |
| 10 | input rst_ni, |
| 11 | |
| 12 | // JTAG interface |
| 13 | input jtag_tck_i, |
| 14 | input jtag_tms_i, |
| 15 | input jtag_trst_ni, |
| 16 | input jtag_td_i, |
| 17 | output jtag_td_o, |
| 18 | |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 19 | // Multiplexed I/O |
| 20 | input [31:0] mio_in_i, |
| 21 | output logic [31:0] mio_out_o, |
| 22 | output logic [31:0] mio_oe_o, |
| 23 | |
| 24 | // Dedicated I/O |
| 25 | input dio_spi_device_sck_i, |
| 26 | input dio_spi_device_csb_i, |
| 27 | input dio_spi_device_mosi_i, |
| 28 | output logic dio_spi_device_miso_o, |
| 29 | output logic dio_spi_device_miso_en_o, |
| 30 | input dio_uart_rx_i, |
| 31 | output logic dio_uart_tx_o, |
| 32 | output logic dio_uart_tx_en_o, |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 33 | |
| 34 | input scanmode_i // 1 for Scan |
| 35 | ); |
| 36 | |
Philipp Wagner | 086b703 | 2019-10-25 17:06:15 +0100 | [diff] [blame] | 37 | // JTAG IDCODE for development versions of this code. |
| 38 | // Manufacturers of OpenTitan chips must replace this code with one of their |
| 39 | // own IDs. |
| 40 | // Field structure as defined in the IEEE 1149.1 (JTAG) specification, |
| 41 | // section 12.1.1. |
| 42 | localparam JTAG_IDCODE = { |
| 43 | 4'h0, // Version |
| 44 | 16'h4F54, // Part Number: "OT" |
Philipp Wagner | f57964e | 2019-11-04 17:57:06 +0000 | [diff] [blame^] | 45 | 11'h426, // Manufacturer Identity: Google |
Philipp Wagner | 086b703 | 2019-10-25 17:06:15 +0100 | [diff] [blame] | 46 | 1'b1 // (fixed) |
| 47 | }; |
| 48 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 49 | import tlul_pkg::*; |
| 50 | import top_pkg::*; |
| 51 | import tl_main_pkg::*; |
| 52 | import flash_ctrl_pkg::*; |
| 53 | |
| 54 | tl_h2d_t tl_corei_h_h2d; |
| 55 | tl_d2h_t tl_corei_h_d2h; |
| 56 | |
| 57 | tl_h2d_t tl_cored_h_h2d; |
| 58 | tl_d2h_t tl_cored_h_d2h; |
| 59 | |
| 60 | tl_h2d_t tl_dm_sba_h_h2d; |
| 61 | tl_d2h_t tl_dm_sba_h_d2h; |
| 62 | |
| 63 | tl_h2d_t tl_debug_mem_d_h2d; |
| 64 | tl_d2h_t tl_debug_mem_d_d2h; |
| 65 | |
| 66 | tl_h2d_t tl_uart_d_h2d; |
| 67 | tl_d2h_t tl_uart_d_d2h; |
| 68 | tl_h2d_t tl_gpio_d_h2d; |
| 69 | tl_d2h_t tl_gpio_d_d2h; |
| 70 | tl_h2d_t tl_spi_device_d_h2d; |
| 71 | tl_d2h_t tl_spi_device_d_d2h; |
| 72 | tl_h2d_t tl_flash_ctrl_d_h2d; |
| 73 | tl_d2h_t tl_flash_ctrl_d_d2h; |
| 74 | tl_h2d_t tl_rv_timer_d_h2d; |
| 75 | tl_d2h_t tl_rv_timer_d_d2h; |
Pirmin Vogel | d453438 | 2019-10-17 13:18:31 +0100 | [diff] [blame] | 76 | tl_h2d_t tl_aes_d_h2d; |
| 77 | tl_d2h_t tl_aes_d_d2h; |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 78 | tl_h2d_t tl_hmac_d_h2d; |
| 79 | tl_d2h_t tl_hmac_d_d2h; |
| 80 | tl_h2d_t tl_rv_plic_d_h2d; |
| 81 | tl_d2h_t tl_rv_plic_d_d2h; |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 82 | tl_h2d_t tl_pinmux_d_h2d; |
| 83 | tl_d2h_t tl_pinmux_d_d2h; |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 84 | |
| 85 | tl_h2d_t tl_rom_d_h2d; |
| 86 | tl_d2h_t tl_rom_d_d2h; |
| 87 | tl_h2d_t tl_ram_main_d_h2d; |
| 88 | tl_d2h_t tl_ram_main_d_d2h; |
| 89 | tl_h2d_t tl_eflash_d_h2d; |
| 90 | tl_d2h_t tl_eflash_d_d2h; |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 91 | |
| 92 | //reset wires declaration |
| 93 | logic lc_rst_n; |
| 94 | logic sys_rst_n; |
| 95 | logic spi_device_rst_n; |
| 96 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 97 | //clock wires declaration |
| 98 | logic main_clk; |
| 99 | |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 100 | // Signals |
| 101 | logic [31:0] m2p; |
| 102 | logic [31:0] p2m; |
| 103 | logic [31:0] p2m_en; |
| 104 | // uart |
| 105 | logic cio_uart_rx_p2d; |
| 106 | logic cio_uart_tx_d2p; |
| 107 | logic cio_uart_tx_en_d2p; |
| 108 | // gpio |
| 109 | logic [31:0] cio_gpio_gpio_p2d; |
| 110 | logic [31:0] cio_gpio_gpio_d2p; |
| 111 | logic [31:0] cio_gpio_gpio_en_d2p; |
| 112 | // spi_device |
| 113 | logic cio_spi_device_sck_p2d; |
| 114 | logic cio_spi_device_csb_p2d; |
| 115 | logic cio_spi_device_mosi_p2d; |
| 116 | logic cio_spi_device_miso_d2p; |
| 117 | logic cio_spi_device_miso_en_d2p; |
| 118 | // flash_ctrl |
| 119 | // rv_timer |
| 120 | // aes |
| 121 | // hmac |
| 122 | // rv_plic |
| 123 | // pinmux |
| 124 | |
| 125 | |
Eunchan Kim | 226eab6 | 2019-10-18 14:11:29 -0700 | [diff] [blame] | 126 | logic [54:0] intr_vector; |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 127 | // Interrupt source list |
| 128 | logic intr_uart_tx_watermark; |
| 129 | logic intr_uart_rx_watermark; |
| 130 | logic intr_uart_tx_overflow; |
| 131 | logic intr_uart_rx_overflow; |
| 132 | logic intr_uart_rx_frame_err; |
| 133 | logic intr_uart_rx_break_err; |
| 134 | logic intr_uart_rx_timeout; |
| 135 | logic intr_uart_rx_parity_err; |
| 136 | logic [31:0] intr_gpio_gpio; |
Eunchan Kim | 8c57fe3 | 2019-09-02 21:14:24 -0700 | [diff] [blame] | 137 | logic intr_spi_device_rxf; |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 138 | logic intr_spi_device_rxlvl; |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 139 | logic intr_spi_device_txlvl; |
| 140 | logic intr_spi_device_rxerr; |
Eunchan Kim | 546c0d4 | 2019-09-24 15:07:06 -0700 | [diff] [blame] | 141 | logic intr_spi_device_rxoverflow; |
| 142 | logic intr_spi_device_txunderflow; |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 143 | logic intr_flash_ctrl_prog_empty; |
| 144 | logic intr_flash_ctrl_prog_lvl; |
| 145 | logic intr_flash_ctrl_rd_full; |
| 146 | logic intr_flash_ctrl_rd_lvl; |
| 147 | logic intr_flash_ctrl_op_done; |
| 148 | logic intr_flash_ctrl_op_error; |
| 149 | logic intr_rv_timer_timer_expired_0_0; |
| 150 | logic intr_hmac_hmac_done; |
| 151 | logic intr_hmac_fifo_full; |
Eunchan Kim | 226eab6 | 2019-10-18 14:11:29 -0700 | [diff] [blame] | 152 | logic intr_hmac_hmac_err; |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 153 | |
| 154 | |
| 155 | logic [0:0] irq_plic; |
| 156 | logic [5:0] irq_id[1]; |
| 157 | logic [0:0] msip; |
| 158 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 159 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 160 | // clock assignments |
| 161 | assign main_clk = clk_i; |
| 162 | |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 163 | // Non-debug module reset == reset for everything except for the debug module |
| 164 | logic ndmreset_req; |
| 165 | |
| 166 | // root resets |
| 167 | // TODO: lc_rst_n is not the true root reset. It will be differentiated once the |
| 168 | // the reset controller logic is present |
| 169 | assign lc_rst_n = rst_ni; |
| 170 | assign sys_rst_n = (scanmode_i) ? lc_rst_n : ~ndmreset_req & lc_rst_n; |
| 171 | |
| 172 | //non-root reset assignments |
| 173 | assign spi_device_rst_n = sys_rst_n; |
| 174 | |
| 175 | // debug request from rv_dm to core |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 176 | logic debug_req; |
| 177 | |
| 178 | // processor core |
| 179 | rv_core_ibex #( |
Philipp Wagner | a3ec3ba | 2019-10-16 14:15:50 +0100 | [diff] [blame] | 180 | .PMPEnable (0), |
| 181 | .PMPGranularity (0), |
| 182 | .PMPNumRegions (4), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 183 | .MHPMCounterNum (8), |
| 184 | .MHPMCounterWidth (40), |
| 185 | .RV32E (0), |
| 186 | .RV32M (1), |
| 187 | .DmHaltAddr (ADDR_SPACE_DEBUG_MEM + dm::HaltAddress), |
Timothy Chen | 7ff5312 | 2019-09-19 15:20:43 -0700 | [diff] [blame] | 188 | .DmExceptionAddr (ADDR_SPACE_DEBUG_MEM + dm::ExceptionAddress), |
| 189 | .PipeLine (IbexPipeLine) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 190 | ) core ( |
| 191 | // clock and reset |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 192 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 193 | .rst_ni (sys_rst_n), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 194 | .test_en_i (1'b0), |
| 195 | // static pinning |
Greg Chadwick | 53ef2ec | 2019-09-03 14:53:54 +0100 | [diff] [blame] | 196 | .hart_id_i (32'b0), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 197 | .boot_addr_i (ADDR_SPACE_ROM), |
| 198 | // TL-UL buses |
| 199 | .tl_i_o (tl_corei_h_h2d), |
| 200 | .tl_i_i (tl_corei_h_d2h), |
| 201 | .tl_d_o (tl_cored_h_h2d), |
| 202 | .tl_d_i (tl_cored_h_d2h), |
| 203 | // interrupts |
| 204 | .irq_software_i (msip), |
| 205 | .irq_timer_i (intr_rv_timer_timer_expired_0_0), |
| 206 | .irq_external_i (irq_plic), |
| 207 | .irq_fast_i (15'b0),// PLIC handles all peripheral interrupts |
| 208 | .irq_nm_i (1'b0),// TODO - add and connect alert responder |
| 209 | // debug interface |
| 210 | .debug_req_i (debug_req), |
| 211 | // CPU control signals |
Pirmin Vogel | ffc9e83 | 2019-09-13 16:16:05 +0100 | [diff] [blame] | 212 | .fetch_enable_i (1'b1), |
| 213 | .core_sleep_o () |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 214 | ); |
| 215 | |
| 216 | // Debug Module (RISC-V Debug Spec 0.13) |
| 217 | // |
| 218 | |
| 219 | rv_dm #( |
Philipp Wagner | 086b703 | 2019-10-25 17:06:15 +0100 | [diff] [blame] | 220 | .NrHarts (1), |
| 221 | .IdcodeValue (JTAG_IDCODE) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 222 | ) u_dm_top ( |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 223 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 224 | .rst_ni (lc_rst_n), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 225 | .testmode_i (1'b0), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 226 | .ndmreset_o (ndmreset_req), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 227 | .dmactive_o (), |
| 228 | .debug_req_o (debug_req), |
| 229 | .unavailable_i (1'b0), |
| 230 | |
| 231 | // bus device with debug memory (for execution-based debug) |
| 232 | .tl_d_i (tl_debug_mem_d_h2d), |
| 233 | .tl_d_o (tl_debug_mem_d_d2h), |
| 234 | |
| 235 | // bus host (for system bus accesses, SBA) |
| 236 | .tl_h_o (tl_dm_sba_h_h2d), |
| 237 | .tl_h_i (tl_dm_sba_h_d2h), |
| 238 | |
| 239 | //JTAG |
| 240 | .tck_i (jtag_tck_i), |
| 241 | .tms_i (jtag_tms_i), |
| 242 | .trst_ni (jtag_trst_ni), |
| 243 | .td_i (jtag_td_i), |
| 244 | .td_o (jtag_td_o), |
| 245 | .tdo_oe_o ( ) |
| 246 | ); |
| 247 | |
Timothy Chen | 4446103 | 2019-09-20 15:35:20 -0700 | [diff] [blame] | 248 | // ROM device |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 249 | logic rom_req; |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 250 | logic [10:0] rom_addr; |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 251 | logic [31:0] rom_rdata; |
| 252 | logic rom_rvalid; |
| 253 | |
| 254 | tlul_adapter_sram #( |
| 255 | .SramAw(11), |
| 256 | .SramDw(32), |
Timothy Chen | 4446103 | 2019-09-20 15:35:20 -0700 | [diff] [blame] | 257 | .Outstanding(1), |
| 258 | .ErrOnWrite(1) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 259 | ) tl_adapter_rom ( |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 260 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 261 | .rst_ni (sys_rst_n), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 262 | |
| 263 | .tl_i (tl_rom_d_h2d), |
| 264 | .tl_o (tl_rom_d_d2h), |
| 265 | |
| 266 | .req_o (rom_req), |
| 267 | .gnt_i (1'b1), // Always grant as only one requester exists |
Timothy Chen | 4446103 | 2019-09-20 15:35:20 -0700 | [diff] [blame] | 268 | .we_o (), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 269 | .addr_o (rom_addr), |
Timothy Chen | 4446103 | 2019-09-20 15:35:20 -0700 | [diff] [blame] | 270 | .wdata_o (), |
| 271 | .wmask_o (), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 272 | .rdata_i (rom_rdata), |
| 273 | .rvalid_i (rom_rvalid), |
| 274 | .rerror_i (2'b00) |
| 275 | ); |
| 276 | |
Timothy Chen | 4446103 | 2019-09-20 15:35:20 -0700 | [diff] [blame] | 277 | prim_rom #( |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 278 | .Width(32), |
Timothy Chen | 4446103 | 2019-09-20 15:35:20 -0700 | [diff] [blame] | 279 | .Depth(2048) |
| 280 | ) u_rom_rom ( |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 281 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 282 | .rst_ni (sys_rst_n), |
Timothy Chen | 4446103 | 2019-09-20 15:35:20 -0700 | [diff] [blame] | 283 | .cs_i (rom_req), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 284 | .addr_i (rom_addr), |
Timothy Chen | 4446103 | 2019-09-20 15:35:20 -0700 | [diff] [blame] | 285 | .dout_o (rom_rdata), |
| 286 | .dvalid_o (rom_rvalid) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 287 | ); |
Timothy Chen | 4446103 | 2019-09-20 15:35:20 -0700 | [diff] [blame] | 288 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 289 | // sram device |
| 290 | logic ram_main_req; |
| 291 | logic ram_main_we; |
| 292 | logic [13:0] ram_main_addr; |
| 293 | logic [31:0] ram_main_wdata; |
| 294 | logic [31:0] ram_main_wmask; |
| 295 | logic [31:0] ram_main_rdata; |
| 296 | logic ram_main_rvalid; |
| 297 | |
| 298 | tlul_adapter_sram #( |
| 299 | .SramAw(14), |
| 300 | .SramDw(32), |
| 301 | .Outstanding(1) |
| 302 | ) tl_adapter_ram_main ( |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 303 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 304 | .rst_ni (sys_rst_n), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 305 | .tl_i (tl_ram_main_d_h2d), |
| 306 | .tl_o (tl_ram_main_d_d2h), |
| 307 | |
| 308 | .req_o (ram_main_req), |
| 309 | .gnt_i (1'b1), // Always grant as only one requester exists |
| 310 | .we_o (ram_main_we), |
| 311 | .addr_o (ram_main_addr), |
| 312 | .wdata_o (ram_main_wdata), |
| 313 | .wmask_o (ram_main_wmask), |
| 314 | .rdata_i (ram_main_rdata), |
| 315 | .rvalid_i (ram_main_rvalid), |
| 316 | .rerror_i (2'b00) |
| 317 | ); |
| 318 | |
| 319 | prim_ram_1p #( |
| 320 | .Width(32), |
| 321 | .Depth(16384), |
| 322 | .DataBitsPerMask(8) |
| 323 | ) u_ram1p_ram_main ( |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 324 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 325 | .rst_ni (sys_rst_n), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 326 | |
| 327 | .req_i (ram_main_req), |
| 328 | .write_i (ram_main_we), |
| 329 | .addr_i (ram_main_addr), |
| 330 | .wdata_i (ram_main_wdata), |
| 331 | .wmask_i (ram_main_wmask), |
| 332 | .rvalid_o (ram_main_rvalid), |
| 333 | .rdata_o (ram_main_rdata) |
| 334 | ); |
| 335 | |
| 336 | // flash controller to eflash communication |
| 337 | flash_c2m_t flash_c2m; |
| 338 | flash_m2c_t flash_m2c; |
| 339 | |
| 340 | // host to flash communication |
| 341 | logic flash_host_req; |
| 342 | logic flash_host_req_rdy; |
| 343 | logic flash_host_req_done; |
| 344 | logic [FLASH_DW-1:0] flash_host_rdata; |
| 345 | logic [FLASH_AW-1:0] flash_host_addr; |
| 346 | |
Timothy Chen | 5aec528 | 2019-09-10 21:10:56 -0700 | [diff] [blame] | 347 | tlul_adapter_sram #( |
| 348 | .SramAw(FLASH_AW), |
| 349 | .SramDw(FLASH_DW), |
| 350 | .Outstanding(1), |
| 351 | .ByteAccess(0), |
| 352 | .ErrOnWrite(1) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 353 | ) tl_adapter_eflash ( |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 354 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 355 | .rst_ni (lc_rst_n), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 356 | |
| 357 | .tl_i (tl_eflash_d_h2d), |
| 358 | .tl_o (tl_eflash_d_d2h), |
| 359 | |
Timothy Chen | 5aec528 | 2019-09-10 21:10:56 -0700 | [diff] [blame] | 360 | .req_o (flash_host_req), |
| 361 | .gnt_i (flash_host_req_rdy), |
| 362 | .we_o (), |
| 363 | .addr_o (flash_host_addr), |
| 364 | .wdata_o (), |
| 365 | .wmask_o (), |
| 366 | .rdata_i (flash_host_rdata), |
| 367 | .rvalid_i (flash_host_req_done), |
| 368 | .rerror_i (2'b00) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 369 | ); |
| 370 | |
| 371 | flash_phy #( |
| 372 | .NumBanks(FLASH_BANKS), |
| 373 | .PagesPerBank(FLASH_PAGES_PER_BANK), |
| 374 | .WordsPerPage(FLASH_WORDS_PER_PAGE), |
| 375 | .DataWidth(32) |
| 376 | ) u_flash_eflash ( |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 377 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 378 | .rst_ni (lc_rst_n), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 379 | .host_req_i (flash_host_req), |
| 380 | .host_addr_i (flash_host_addr), |
| 381 | .host_req_rdy_o (flash_host_req_rdy), |
| 382 | .host_req_done_o (flash_host_req_done), |
| 383 | .host_rdata_o (flash_host_rdata), |
| 384 | .flash_ctrl_i (flash_c2m), |
| 385 | .flash_ctrl_o (flash_m2c) |
| 386 | ); |
| 387 | |
| 388 | |
| 389 | uart uart ( |
| 390 | .tl_i (tl_uart_d_h2d), |
| 391 | .tl_o (tl_uart_d_d2h), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 392 | |
| 393 | // Input |
| 394 | .cio_rx_i (cio_uart_rx_p2d), |
| 395 | |
| 396 | // Output |
| 397 | .cio_tx_o (cio_uart_tx_d2p), |
| 398 | .cio_tx_en_o (cio_uart_tx_en_d2p), |
| 399 | |
| 400 | // Interrupt |
| 401 | .intr_tx_watermark_o (intr_uart_tx_watermark), |
| 402 | .intr_rx_watermark_o (intr_uart_rx_watermark), |
| 403 | .intr_tx_overflow_o (intr_uart_tx_overflow), |
| 404 | .intr_rx_overflow_o (intr_uart_rx_overflow), |
| 405 | .intr_rx_frame_err_o (intr_uart_rx_frame_err), |
| 406 | .intr_rx_break_err_o (intr_uart_rx_break_err), |
| 407 | .intr_rx_timeout_o (intr_uart_rx_timeout), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 408 | .intr_rx_parity_err_o (intr_uart_rx_parity_err), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 409 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 410 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 411 | .rst_ni (sys_rst_n) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 412 | ); |
| 413 | |
| 414 | gpio gpio ( |
| 415 | .tl_i (tl_gpio_d_h2d), |
| 416 | .tl_o (tl_gpio_d_d2h), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 417 | |
| 418 | // Input |
| 419 | .cio_gpio_i (cio_gpio_gpio_p2d), |
| 420 | |
| 421 | // Output |
| 422 | .cio_gpio_o (cio_gpio_gpio_d2p), |
| 423 | .cio_gpio_en_o (cio_gpio_gpio_en_d2p), |
| 424 | |
| 425 | // Interrupt |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 426 | .intr_gpio_o (intr_gpio_gpio), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 427 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 428 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 429 | .rst_ni (sys_rst_n) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 430 | ); |
| 431 | |
| 432 | spi_device spi_device ( |
| 433 | .tl_i (tl_spi_device_d_h2d), |
| 434 | .tl_o (tl_spi_device_d_d2h), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 435 | |
| 436 | // Input |
| 437 | .cio_sck_i (cio_spi_device_sck_p2d), |
| 438 | .cio_csb_i (cio_spi_device_csb_p2d), |
| 439 | .cio_mosi_i (cio_spi_device_mosi_p2d), |
| 440 | |
| 441 | // Output |
| 442 | .cio_miso_o (cio_spi_device_miso_d2p), |
| 443 | .cio_miso_en_o (cio_spi_device_miso_en_d2p), |
| 444 | |
| 445 | // Interrupt |
| 446 | .intr_rxf_o (intr_spi_device_rxf), |
| 447 | .intr_rxlvl_o (intr_spi_device_rxlvl), |
| 448 | .intr_txlvl_o (intr_spi_device_txlvl), |
| 449 | .intr_rxerr_o (intr_spi_device_rxerr), |
| 450 | .intr_rxoverflow_o (intr_spi_device_rxoverflow), |
Eunchan Kim | 546c0d4 | 2019-09-24 15:07:06 -0700 | [diff] [blame] | 451 | .intr_txunderflow_o (intr_spi_device_txunderflow), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 452 | |
Eunchan Kim | 2cfadab | 2019-10-02 12:41:11 -0700 | [diff] [blame] | 453 | .scanmode_i (scanmode_i), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 454 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 455 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 456 | .rst_ni (spi_device_rst_n) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 457 | ); |
| 458 | |
| 459 | flash_ctrl flash_ctrl ( |
| 460 | .tl_i (tl_flash_ctrl_d_h2d), |
| 461 | .tl_o (tl_flash_ctrl_d_d2h), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 462 | |
| 463 | // Interrupt |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 464 | .intr_prog_empty_o (intr_flash_ctrl_prog_empty), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 465 | .intr_prog_lvl_o (intr_flash_ctrl_prog_lvl), |
| 466 | .intr_rd_full_o (intr_flash_ctrl_rd_full), |
| 467 | .intr_rd_lvl_o (intr_flash_ctrl_rd_lvl), |
| 468 | .intr_op_done_o (intr_flash_ctrl_op_done), |
| 469 | .intr_op_error_o (intr_flash_ctrl_op_error), |
| 470 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 471 | .flash_o(flash_c2m), |
| 472 | .flash_i(flash_m2c), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 473 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 474 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 475 | .rst_ni (lc_rst_n) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 476 | ); |
| 477 | |
| 478 | rv_timer rv_timer ( |
| 479 | .tl_i (tl_rv_timer_d_h2d), |
| 480 | .tl_o (tl_rv_timer_d_d2h), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 481 | |
| 482 | // Interrupt |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 483 | .intr_timer_expired_0_0_o (intr_rv_timer_timer_expired_0_0), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 484 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 485 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 486 | .rst_ni (sys_rst_n) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 487 | ); |
| 488 | |
Pirmin Vogel | d453438 | 2019-10-17 13:18:31 +0100 | [diff] [blame] | 489 | aes aes ( |
| 490 | .tl_i (tl_aes_d_h2d), |
| 491 | .tl_o (tl_aes_d_d2h), |
| 492 | |
| 493 | .clk_i (main_clk), |
| 494 | .rst_ni (sys_rst_n) |
| 495 | ); |
| 496 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 497 | hmac hmac ( |
| 498 | .tl_i (tl_hmac_d_h2d), |
| 499 | .tl_o (tl_hmac_d_d2h), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 500 | |
| 501 | // Interrupt |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 502 | .intr_hmac_done_o (intr_hmac_hmac_done), |
| 503 | .intr_fifo_full_o (intr_hmac_fifo_full), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 504 | .intr_hmac_err_o (intr_hmac_hmac_err), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 505 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 506 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 507 | .rst_ni (sys_rst_n) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 508 | ); |
| 509 | |
| 510 | rv_plic #( |
| 511 | .FIND_MAX("MATRIX") |
| 512 | ) rv_plic ( |
| 513 | .tl_i (tl_rv_plic_d_h2d), |
| 514 | .tl_o (tl_rv_plic_d_d2h), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 515 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 516 | .intr_src_i (intr_vector), |
| 517 | .irq_o (irq_plic), |
| 518 | .irq_id_o (irq_id), |
| 519 | .msip_o (msip), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 520 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 521 | .clk_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 522 | .rst_ni (sys_rst_n) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 523 | ); |
| 524 | |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 525 | pinmux pinmux ( |
| 526 | .tl_i (tl_pinmux_d_h2d), |
| 527 | .tl_o (tl_pinmux_d_d2h), |
| 528 | |
| 529 | .periph_to_mio_i (p2m ), |
| 530 | .periph_to_mio_oe_i (p2m_en ), |
| 531 | .mio_to_periph_o (m2p ), |
| 532 | |
| 533 | .mio_out_o (mio_out_o), |
| 534 | .mio_oe_o (mio_oe_o ), |
| 535 | .mio_in_i (mio_in_i ), |
| 536 | |
| 537 | .clk_i (main_clk), |
| 538 | .rst_ni (sys_rst_n) |
| 539 | ); |
| 540 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 541 | // interrupt assignments |
| 542 | assign intr_vector = { |
Eunchan Kim | 226eab6 | 2019-10-18 14:11:29 -0700 | [diff] [blame] | 543 | intr_hmac_hmac_err, |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 544 | intr_hmac_fifo_full, |
| 545 | intr_hmac_hmac_done, |
| 546 | intr_flash_ctrl_op_error, |
| 547 | intr_flash_ctrl_op_done, |
| 548 | intr_flash_ctrl_rd_lvl, |
| 549 | intr_flash_ctrl_rd_full, |
| 550 | intr_flash_ctrl_prog_lvl, |
| 551 | intr_flash_ctrl_prog_empty, |
Eunchan Kim | 546c0d4 | 2019-09-24 15:07:06 -0700 | [diff] [blame] | 552 | intr_spi_device_txunderflow, |
| 553 | intr_spi_device_rxoverflow, |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 554 | intr_spi_device_rxerr, |
| 555 | intr_spi_device_txlvl, |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 556 | intr_spi_device_rxlvl, |
Eunchan Kim | 8c57fe3 | 2019-09-02 21:14:24 -0700 | [diff] [blame] | 557 | intr_spi_device_rxf, |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 558 | intr_uart_rx_parity_err, |
| 559 | intr_uart_rx_timeout, |
| 560 | intr_uart_rx_break_err, |
| 561 | intr_uart_rx_frame_err, |
| 562 | intr_uart_rx_overflow, |
| 563 | intr_uart_tx_overflow, |
| 564 | intr_uart_rx_watermark, |
| 565 | intr_uart_tx_watermark, |
| 566 | intr_gpio_gpio |
| 567 | }; |
| 568 | |
| 569 | // TL-UL Crossbar |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 570 | xbar_main u_xbar_main ( |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 571 | .clk_main_i (main_clk), |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 572 | .rst_main_ni (sys_rst_n), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 573 | .tl_corei_i (tl_corei_h_h2d), |
| 574 | .tl_corei_o (tl_corei_h_d2h), |
| 575 | .tl_cored_i (tl_cored_h_h2d), |
| 576 | .tl_cored_o (tl_cored_h_d2h), |
| 577 | .tl_dm_sba_i (tl_dm_sba_h_h2d), |
| 578 | .tl_dm_sba_o (tl_dm_sba_h_d2h), |
| 579 | .tl_rom_o (tl_rom_d_h2d), |
| 580 | .tl_rom_i (tl_rom_d_d2h), |
| 581 | .tl_debug_mem_o (tl_debug_mem_d_h2d), |
| 582 | .tl_debug_mem_i (tl_debug_mem_d_d2h), |
| 583 | .tl_ram_main_o (tl_ram_main_d_h2d), |
| 584 | .tl_ram_main_i (tl_ram_main_d_d2h), |
| 585 | .tl_eflash_o (tl_eflash_d_h2d), |
| 586 | .tl_eflash_i (tl_eflash_d_d2h), |
| 587 | .tl_uart_o (tl_uart_d_h2d), |
| 588 | .tl_uart_i (tl_uart_d_d2h), |
| 589 | .tl_gpio_o (tl_gpio_d_h2d), |
| 590 | .tl_gpio_i (tl_gpio_d_d2h), |
| 591 | .tl_spi_device_o (tl_spi_device_d_h2d), |
| 592 | .tl_spi_device_i (tl_spi_device_d_d2h), |
| 593 | .tl_flash_ctrl_o (tl_flash_ctrl_d_h2d), |
| 594 | .tl_flash_ctrl_i (tl_flash_ctrl_d_d2h), |
| 595 | .tl_rv_timer_o (tl_rv_timer_d_h2d), |
| 596 | .tl_rv_timer_i (tl_rv_timer_d_d2h), |
| 597 | .tl_hmac_o (tl_hmac_d_h2d), |
| 598 | .tl_hmac_i (tl_hmac_d_d2h), |
Pirmin Vogel | d453438 | 2019-10-17 13:18:31 +0100 | [diff] [blame] | 599 | .tl_aes_o (tl_aes_d_h2d), |
| 600 | .tl_aes_i (tl_aes_d_d2h), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 601 | .tl_rv_plic_o (tl_rv_plic_d_h2d), |
| 602 | .tl_rv_plic_i (tl_rv_plic_d_d2h), |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 603 | .tl_pinmux_o (tl_pinmux_d_h2d), |
| 604 | .tl_pinmux_i (tl_pinmux_d_d2h), |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 605 | |
| 606 | .scanmode_i |
| 607 | ); |
| 608 | |
Eunchan Kim | 769065e | 2019-10-29 17:29:26 -0700 | [diff] [blame] | 609 | // Pinmux connections |
| 610 | assign p2m = { |
| 611 | cio_gpio_gpio_d2p |
| 612 | }; |
| 613 | assign p2m_en = { |
| 614 | cio_gpio_gpio_en_d2p |
| 615 | }; |
| 616 | assign { |
| 617 | cio_gpio_gpio_p2d |
| 618 | } = m2p; |
| 619 | |
| 620 | assign cio_spi_device_sck_p2d = dio_spi_device_sck_i; |
| 621 | assign cio_spi_device_csb_p2d = dio_spi_device_csb_i; |
| 622 | assign cio_spi_device_mosi_p2d = dio_spi_device_mosi_i; |
| 623 | assign dio_spi_device_miso_o = cio_spi_device_miso_d2p; |
| 624 | assign dio_spi_device_miso_en_o = cio_spi_device_miso_en_d2p; |
| 625 | assign cio_uart_rx_p2d = dio_uart_rx_i; |
| 626 | assign dio_uart_tx_o = cio_uart_tx_d2p; |
| 627 | assign dio_uart_tx_en_o = cio_uart_tx_en_d2p; |
| 628 | |
Nils Graf | 78607aa | 2019-09-16 15:47:23 -0700 | [diff] [blame] | 629 | // make sure scanmode_i is never X (including during reset) |
| 630 | `ASSERT_KNOWN(scanmodeKnown, scanmode_i, clk_i, 0) |
| 631 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 632 | endmodule |