shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 1 | /* |
| 2 | * PicoSoC - A simple example SoC using PicoRV32 |
| 3 | * |
| 4 | * Copyright (C) 2017 Clifford Wolf <clifford@clifford.at> |
| 5 | * |
| 6 | * Permission to use, copy, modify, and/or distribute this software for any |
| 7 | * purpose with or without fee is hereby granted, provided that the above |
| 8 | * copyright notice and this permission notice appear in all copies. |
| 9 | * |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | * |
| 18 | * Revision 1, July 2019: Added signals to drive flash_clk and flash_csb |
| 19 | * output enable (inverted), tied to reset so that the flash is completely |
| 20 | * isolated from the processor when the processor is in reset. |
| 21 | * |
| 22 | * Also: Made ram_wenb a 4-bit bus so that the memory access can be made |
| 23 | * byte-wide for byte-wide instructions. |
| 24 | */ |
| 25 | |
| 26 | `ifdef PICORV32_V |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 27 | `error "mgmt_soc.v must be read before picorv32.v!" |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 28 | `endif |
| 29 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 30 | `define PICORV32_REGS mgmt_soc_regs |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 31 | |
| 32 | `include "picorv32.v" |
| 33 | `include "spimemio.v" |
| 34 | `include "simpleuart.v" |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 35 | `include "simple_spi_master.v" |
Tim Edwards | 7be29a2 | 2020-10-25 21:50:19 -0400 | [diff] [blame] | 36 | `include "counter_timer_high.v" |
| 37 | `include "counter_timer_low.v" |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 38 | `include "wb_intercon.v" |
| 39 | `include "mem_wb.v" |
| 40 | `include "gpio_wb.v" |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 41 | `include "sysctrl.v" |
| 42 | `include "la_wb.v" |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 43 | `include "mprj_ctrl.v" |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 44 | `include "convert_gpio_sigs.v" |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 45 | |
Ahmed Ghazy | 22d29d6 | 2020-10-28 03:42:02 +0200 | [diff] [blame] | 46 | module mgmt_soc ( |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 47 | `ifdef LVS |
| 48 | inout vdd1v8, /* 1.8V domain */ |
| 49 | inout vss, |
| 50 | `endif |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 51 | input clk, |
| 52 | input resetn, |
| 53 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 54 | // Trap state from CPU |
| 55 | output trap, |
| 56 | |
| 57 | // GPIO (one pin) |
| 58 | output gpio_out_pad, // Connect to out on gpio pad |
| 59 | input gpio_in_pad, // Connect to in on gpio pad |
| 60 | output gpio_mode0_pad, // Connect to dm[0] on gpio pad |
| 61 | output gpio_mode1_pad, // Connect to dm[2] on gpio pad |
| 62 | output gpio_outenb_pad, // Connect to oe_n on gpio pad |
| 63 | output gpio_inenb_pad, // Connect to inp_dis on gpio pad |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 64 | |
| 65 | // LA signals |
Tim Edwards | 6d9739d | 2020-10-19 11:00:49 -0400 | [diff] [blame] | 66 | input [127:0] la_input, // From User Project to cpu |
| 67 | output [127:0] la_output, // From CPU to User Project |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 68 | output [127:0] la_oen, // LA output enable (active low) |
| 69 | |
Tim Edwards | 6d9739d | 2020-10-19 11:00:49 -0400 | [diff] [blame] | 70 | // User Project I/O Configuration (serial load) |
Tim Edwards | 05ad4fc | 2020-10-19 22:12:33 -0400 | [diff] [blame] | 71 | input mprj_vcc_pwrgood, |
| 72 | input mprj2_vcc_pwrgood, |
| 73 | input mprj_vdd_pwrgood, |
| 74 | input mprj2_vdd_pwrgood, |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 75 | output mprj_io_loader_resetn, |
| 76 | output mprj_io_loader_clock, |
| 77 | output mprj_io_loader_data, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 78 | |
Tim Edwards | 6d9739d | 2020-10-19 11:00:49 -0400 | [diff] [blame] | 79 | // User Project pad data (when management SoC controls the pad) |
Ahmed Ghazy | 22d29d6 | 2020-10-28 03:42:02 +0200 | [diff] [blame] | 80 | input [`MPRJ_IO_PADS-1:0] mgmt_in_data, |
| 81 | output [`MPRJ_IO_PADS-1:0] mgmt_out_data, |
| 82 | output [`MPRJ_PWR_PADS-1:0] pwr_ctrl_out, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 83 | |
| 84 | // IRQ |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 85 | input irq_spi, // IRQ from standalone SPI |
| 86 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 87 | // Flash memory control (SPI master) |
| 88 | output flash_csb, |
| 89 | output flash_clk, |
| 90 | |
| 91 | output flash_csb_oeb, |
| 92 | output flash_clk_oeb, |
| 93 | |
| 94 | output flash_io0_oeb, |
| 95 | output flash_io1_oeb, |
| 96 | output flash_io2_oeb, |
| 97 | output flash_io3_oeb, |
| 98 | |
| 99 | output flash_csb_ieb, |
| 100 | output flash_clk_ieb, |
| 101 | |
| 102 | output flash_io0_ieb, |
| 103 | output flash_io1_ieb, |
| 104 | output flash_io2_ieb, |
| 105 | output flash_io3_ieb, |
| 106 | |
| 107 | output flash_io0_do, |
| 108 | output flash_io1_do, |
| 109 | output flash_io2_do, |
| 110 | output flash_io3_do, |
| 111 | |
| 112 | input flash_io0_di, |
| 113 | input flash_io1_di, |
| 114 | input flash_io2_di, |
| 115 | input flash_io3_di, |
| 116 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 117 | // SPI pass-thru mode |
| 118 | input pass_thru_mgmt, |
| 119 | input pass_thru_mgmt_csb, |
| 120 | input pass_thru_mgmt_sck, |
| 121 | input pass_thru_mgmt_sdi, |
| 122 | output pass_thru_mgmt_sdo, |
| 123 | |
Tim Edwards | 496a08a | 2020-10-26 15:44:51 -0400 | [diff] [blame] | 124 | // State of JTAG and SDO pins (override for management output use) |
| 125 | output sdo_oenb_state, |
| 126 | output jtag_oenb_state, |
Tim Edwards | 8115320 | 2020-10-09 19:57:04 -0400 | [diff] [blame] | 127 | // SPI master->slave direct link |
| 128 | output hk_connect, |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 129 | // User clock monitoring |
| 130 | input user_clk, |
Tim Edwards | 8115320 | 2020-10-09 19:57:04 -0400 | [diff] [blame] | 131 | |
Tim Edwards | 6d9739d | 2020-10-19 11:00:49 -0400 | [diff] [blame] | 132 | // WB MI A (User project) |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 133 | input mprj_ack_i, |
Tim Edwards | ef8312e | 2020-09-22 17:20:06 -0400 | [diff] [blame] | 134 | input [31:0] mprj_dat_i, |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 135 | output mprj_cyc_o, |
Tim Edwards | ef8312e | 2020-09-22 17:20:06 -0400 | [diff] [blame] | 136 | output mprj_stb_o, |
| 137 | output mprj_we_o, |
| 138 | output [3:0] mprj_sel_o, |
| 139 | output [31:0] mprj_adr_o, |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 140 | output [31:0] mprj_dat_o, |
| 141 | |
| 142 | // MGMT area R/W interface for mgmt RAM |
| 143 | output [`MGMT_BLOCKS-1:0] mgmt_ena, |
| 144 | output [(`MGMT_BLOCKS*4)-1:0] mgmt_wen_mask, |
| 145 | output [`MGMT_BLOCKS-1:0] mgmt_wen, |
| 146 | output [7:0] mgmt_addr, |
| 147 | output [31:0] mgmt_wdata, |
| 148 | input [(`MGMT_BLOCKS*32)-1:0] mgmt_rdata, |
| 149 | |
| 150 | // MGMT area RO interface for user RAM |
| 151 | output [`USER_BLOCKS-1:0] user_ena, |
| 152 | output [7:0] user_addr, |
| 153 | input [(`USER_BLOCKS*32)-1:0] user_rdata |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 154 | ); |
| 155 | /* Memory reverted back to 256 words while memory has to be synthesized */ |
Manar | ec9b536 | 2020-10-28 22:24:06 +0200 | [diff] [blame] | 156 | parameter [31:0] STACKADDR = (4*(`MEM_WORDS)); // end of memory |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 157 | parameter [31:0] PROGADDR_RESET = 32'h 1000_0000; |
| 158 | parameter [31:0] PROGADDR_IRQ = 32'h 0000_0000; |
| 159 | |
| 160 | // Slaves Base Addresses |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 161 | parameter RAM_BASE_ADR = 32'h 0000_0000; |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 162 | parameter EXT_MRAM_BASE_ADR = 32'h 0100_0000; |
| 163 | parameter EXT_URAM_BASE_ADR = 32'h 0200_0000; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 164 | parameter FLASH_BASE_ADR = 32'h 1000_0000; |
| 165 | parameter UART_BASE_ADR = 32'h 2000_0000; |
| 166 | parameter GPIO_BASE_ADR = 32'h 2100_0000; |
Tim Edwards | 856b092 | 2020-10-09 16:30:22 -0400 | [diff] [blame] | 167 | parameter COUNTER_TIMER0_BASE_ADR = 32'h 2200_0000; |
| 168 | parameter COUNTER_TIMER1_BASE_ADR = 32'h 2300_0000; |
| 169 | parameter SPI_MASTER_BASE_ADR = 32'h 2400_0000; |
| 170 | parameter LA_BASE_ADR = 32'h 2500_0000; |
| 171 | parameter MPRJ_CTRL_ADR = 32'h 2600_0000; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 172 | parameter FLASH_CTRL_CFG = 32'h 2D00_0000; |
Tim Edwards | 856b092 | 2020-10-09 16:30:22 -0400 | [diff] [blame] | 173 | parameter SYS_BASE_ADR = 32'h 2F00_0000; |
| 174 | parameter MPRJ_BASE_ADR = 32'h 3000_0000; // WB MI A |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 175 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 176 | // UART |
| 177 | parameter UART_CLK_DIV = 8'h00; |
| 178 | parameter UART_DATA = 8'h04; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 179 | |
| 180 | // SPI Master |
| 181 | parameter SPI_MASTER_CONFIG = 8'h00; |
| 182 | parameter SPI_MASTER_DATA = 8'h04; |
| 183 | |
| 184 | // Counter-timer 0 |
| 185 | parameter COUNTER_TIMER0_CONFIG = 8'h00; |
| 186 | parameter COUNTER_TIMER0_VALUE = 8'h04; |
| 187 | parameter COUNTER_TIMER0_DATA = 8'h08; |
| 188 | |
| 189 | // Counter-timer 1 |
| 190 | parameter COUNTER_TIMER1_CONFIG = 8'h00; |
| 191 | parameter COUNTER_TIMER1_VALUE = 8'h04; |
| 192 | parameter COUNTER_TIMER1_DATA = 8'h08; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 193 | |
| 194 | // SOC GPIO |
| 195 | parameter GPIO_DATA = 8'h00; |
| 196 | parameter GPIO_ENA = 8'h04; |
| 197 | parameter GPIO_PU = 8'h08; |
| 198 | parameter GPIO_PD = 8'h0c; |
| 199 | |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 200 | // LA |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 201 | parameter LA_DATA_0 = 8'h00; |
| 202 | parameter LA_DATA_1 = 8'h04; |
| 203 | parameter LA_DATA_2 = 8'h08; |
| 204 | parameter LA_DATA_3 = 8'h0c; |
| 205 | parameter LA_ENA_0 = 8'h10; |
| 206 | parameter LA_ENA_1 = 8'h14; |
| 207 | parameter LA_ENA_2 = 8'h18; |
| 208 | parameter LA_ENA_3 = 8'h1c; |
| 209 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 210 | // System Control Registers |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 211 | parameter PWRGOOD = 8'h00; |
| 212 | parameter CLK_OUT = 8'h04; |
| 213 | parameter TRAP_OUT = 8'h08; |
| 214 | parameter IRQ_SRC = 8'h0c; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 215 | |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 216 | // Storage area RAM blocks |
| 217 | parameter [(`MGMT_BLOCKS*24)-1:0] MGMT_BLOCKS_ADR = { |
| 218 | {24'h 10_0000}, |
| 219 | {24'h 00_0000} |
| 220 | }; |
| 221 | |
| 222 | parameter [(`USER_BLOCKS*24)-1:0] USER_BLOCKS_ADR = { |
Manar | db08adb | 2020-11-02 17:13:25 +0200 | [diff] [blame] | 223 | {24'h 50_0000}, |
| 224 | {24'h 40_0000}, |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 225 | {24'h 30_0000}, |
| 226 | {24'h 20_0000}, |
| 227 | {24'h 10_0000}, |
| 228 | {24'h 00_0000} |
| 229 | }; |
| 230 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 231 | // Wishbone Interconnect |
| 232 | localparam ADR_WIDTH = 32; |
| 233 | localparam DAT_WIDTH = 32; |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 234 | localparam NUM_SLAVES = 14; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 235 | |
| 236 | parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = { |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 237 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 238 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 239 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 240 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 241 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 242 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 243 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 244 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 245 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 246 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 247 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 248 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 249 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 250 | {8'hFF, {ADR_WIDTH-8{1'b0}}} |
| 251 | }; |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 252 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 253 | parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = { |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 254 | {SYS_BASE_ADR}, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 255 | {FLASH_CTRL_CFG}, |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 256 | {MPRJ_BASE_ADR}, |
| 257 | {MPRJ_CTRL_ADR}, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 258 | {LA_BASE_ADR}, |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 259 | {SPI_MASTER_BASE_ADR}, |
| 260 | {COUNTER_TIMER1_BASE_ADR}, |
| 261 | {COUNTER_TIMER0_BASE_ADR}, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 262 | {GPIO_BASE_ADR}, |
| 263 | {UART_BASE_ADR}, |
| 264 | {FLASH_BASE_ADR}, |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 265 | {EXT_URAM_BASE_ADR}, |
| 266 | {EXT_MRAM_BASE_ADR}, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 267 | {RAM_BASE_ADR} |
| 268 | }; |
| 269 | |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 270 | // The following functions are connected to specific user project |
| 271 | // area pins, when under control of the management area (during |
| 272 | // startup, and when not otherwise programmed for the user project). |
| 273 | |
| 274 | // JTAG = jtag_out (inout) |
| 275 | // SDO = sdo_out (output) (shared with SPI master) |
| 276 | // SDI = mgmt_in_data[2] (input) (shared with SPI master) |
| 277 | // CSB = mgmt_in_data[3] (input) (shared with SPI master) |
| 278 | // SCK = mgmt_in_data[4] (input) (shared with SPI master) |
| 279 | // ser_rx = mgmt_in_data[5] (input) |
| 280 | // ser_tx = mgmt_out_data[6] (output) |
| 281 | // irq_pin = mgmt_in_data[7] (input) |
| 282 | // flash_csb = mgmt_out_data[8] (output) (user area flash) |
| 283 | // flash_sck = mgmt_out_data[9] (output) (user area flash) |
| 284 | // flash_io0 = mgmt_in/out_data[10] (input) (user area flash) |
| 285 | // flash_io1 = mgmt_in/out_data[11] (output) (user area flash) |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 286 | // irq2_pin = mgmt_in_data[12] (input) |
| 287 | // trap_mon = mgmt_in_data[13] (output) |
| 288 | // clk1_mon = mgmt_in_data[14] (output) |
| 289 | // clk2_mon = mgmt_in_data[15] (output) |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 290 | |
| 291 | // OEB lines for [0] and [1] are the only ones connected directly to |
| 292 | // the pad. All others have OEB controlled by the configuration bit |
| 293 | // in the control block. |
| 294 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 295 | // memory-mapped I/O control registers |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 296 | wire gpio_pullup; // Intermediate GPIO pullup |
| 297 | wire gpio_pulldown; // Intermediate GPIO pulldown |
| 298 | wire gpio_outenb; // Intermediate GPIO out enable (bar) |
| 299 | wire gpio_out; // Intermediate GPIO output |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 300 | |
Tim Edwards | ef8312e | 2020-09-22 17:20:06 -0400 | [diff] [blame] | 301 | wire trap_output_dest; // Trap signal output destination |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 302 | wire clk1_output_dest; // Core clock1 signal output destination |
| 303 | wire clk2_output_dest; // Core clock2 signal output destination |
Tim Edwards | ef8312e | 2020-09-22 17:20:06 -0400 | [diff] [blame] | 304 | wire irq_7_inputsrc; // IRQ 7 source |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 305 | wire irq_8_inputsrc; // IRQ 8 source |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 306 | |
Tim Edwards | ef8312e | 2020-09-22 17:20:06 -0400 | [diff] [blame] | 307 | // Convert GPIO signals to sky130_fd_io pad signals |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 308 | convert_gpio_sigs convert_gpio_bit ( |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 309 | .gpio_out(gpio_out), |
| 310 | .gpio_outenb(gpio_outenb), |
| 311 | .gpio_pu(gpio_pullup), |
| 312 | .gpio_pd(gpio_pulldown), |
| 313 | .gpio_out_pad(gpio_out_pad), |
| 314 | .gpio_outenb_pad(gpio_outenb_pad), |
| 315 | .gpio_inenb_pad(gpio_inenb_pad), |
| 316 | .gpio_mode1_pad(gpio_mode1_pad), |
| 317 | .gpio_mode0_pad(gpio_mode0_pad) |
| 318 | ); |
| 319 | |
| 320 | reg [31:0] irq; |
| 321 | wire irq_7; |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 322 | wire irq_8; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 323 | wire irq_stall; |
| 324 | wire irq_uart; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 325 | wire irq_spi_master; |
| 326 | wire irq_counter_timer0; |
| 327 | wire irq_counter_timer1; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 328 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 329 | assign irq_stall = 0; |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 330 | assign irq_7 = (irq_7_inputsrc == 1'b1) ? mgmt_in_data[7] : 1'b0; |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 331 | assign irq_8 = (irq_8_inputsrc == 1'b1) ? mgmt_in_data[12] : 1'b0; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 332 | |
| 333 | always @* begin |
| 334 | irq = 0; |
| 335 | irq[3] = irq_stall; |
| 336 | irq[4] = irq_uart; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 337 | irq[6] = irq_spi; |
| 338 | irq[7] = irq_7; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 339 | irq[9] = irq_spi_master; |
| 340 | irq[10] = irq_counter_timer0; |
| 341 | irq[11] = irq_counter_timer1; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 342 | end |
| 343 | |
Tim Edwards | 3245e2f | 2020-10-10 14:02:11 -0400 | [diff] [blame] | 344 | // Assumption : no syscon module and wb_clk is the clock coming from the |
| 345 | // caravel_clocking module |
| 346 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 347 | assign wb_clk_i = clk; |
| 348 | assign wb_rst_i = ~resetn; // Redundant |
| 349 | |
| 350 | // Wishbone Master |
| 351 | wire [31:0] cpu_adr_o; |
| 352 | wire [31:0] cpu_dat_i; |
| 353 | wire [3:0] cpu_sel_o; |
| 354 | wire cpu_we_o; |
| 355 | wire cpu_cyc_o; |
| 356 | wire cpu_stb_o; |
| 357 | wire [31:0] cpu_dat_o; |
| 358 | wire cpu_ack_i; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 359 | |
| 360 | picorv32_wb #( |
| 361 | .STACKADDR(STACKADDR), |
| 362 | .PROGADDR_RESET(PROGADDR_RESET), |
| 363 | .PROGADDR_IRQ(PROGADDR_IRQ), |
| 364 | .BARREL_SHIFTER(1), |
| 365 | .COMPRESSED_ISA(1), |
| 366 | .ENABLE_MUL(1), |
| 367 | .ENABLE_DIV(1), |
| 368 | .ENABLE_IRQ(1), |
| 369 | .ENABLE_IRQ_QREGS(0) |
| 370 | ) cpu ( |
| 371 | .wb_clk_i (wb_clk_i), |
| 372 | .wb_rst_i (wb_rst_i), |
| 373 | .trap (trap), |
| 374 | .irq (irq), |
| 375 | .mem_instr(mem_instr), |
| 376 | .wbm_adr_o(cpu_adr_o), |
| 377 | .wbm_dat_i(cpu_dat_i), |
| 378 | .wbm_stb_o(cpu_stb_o), |
| 379 | .wbm_ack_i(cpu_ack_i), |
| 380 | .wbm_cyc_o(cpu_cyc_o), |
| 381 | .wbm_dat_o(cpu_dat_o), |
| 382 | .wbm_we_o(cpu_we_o), |
| 383 | .wbm_sel_o(cpu_sel_o) |
| 384 | ); |
| 385 | |
| 386 | // Wishbone Slave SPIMEMIO |
| 387 | wire spimemio_flash_stb_i; |
| 388 | wire spimemio_flash_ack_o; |
| 389 | wire [31:0] spimemio_flash_dat_o; |
| 390 | |
| 391 | wire spimemio_cfg_stb_i; |
| 392 | wire spimemio_cfg_ack_o; |
| 393 | wire [31:0] spimemio_cfg_dat_o; |
| 394 | |
| 395 | spimemio_wb spimemio ( |
| 396 | .wb_clk_i(wb_clk_i), |
| 397 | .wb_rst_i(wb_rst_i), |
| 398 | |
| 399 | .wb_adr_i(cpu_adr_o), |
| 400 | .wb_dat_i(cpu_dat_o), |
| 401 | .wb_sel_i(cpu_sel_o), |
| 402 | .wb_we_i(cpu_we_o), |
| 403 | .wb_cyc_i(cpu_cyc_o), |
| 404 | |
| 405 | // FLash Slave |
| 406 | .wb_flash_stb_i(spimemio_flash_stb_i), |
| 407 | .wb_flash_ack_o(spimemio_flash_ack_o), |
| 408 | .wb_flash_dat_o(spimemio_flash_dat_o), |
| 409 | |
| 410 | // Config Register Slave |
| 411 | .wb_cfg_stb_i(spimemio_cfg_stb_i), |
| 412 | .wb_cfg_ack_o(spimemio_cfg_ack_o), |
| 413 | .wb_cfg_dat_o(spimemio_cfg_dat_o), |
| 414 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 415 | .pass_thru(pass_thru_mgmt), |
| 416 | .pass_thru_csb(pass_thru_mgmt_csb), |
| 417 | .pass_thru_sck(pass_thru_mgmt_sck), |
| 418 | .pass_thru_sdi(pass_thru_mgmt_sdi), |
| 419 | .pass_thru_sdo(pass_thru_mgmt_sdo), |
| 420 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 421 | .flash_csb (flash_csb), |
| 422 | .flash_clk (flash_clk), |
| 423 | |
| 424 | .flash_csb_oeb (flash_csb_oeb), |
| 425 | .flash_clk_oeb (flash_clk_oeb), |
| 426 | |
| 427 | .flash_io0_oeb (flash_io0_oeb), |
| 428 | .flash_io1_oeb (flash_io1_oeb), |
| 429 | .flash_io2_oeb (flash_io2_oeb), |
| 430 | .flash_io3_oeb (flash_io3_oeb), |
| 431 | |
| 432 | .flash_csb_ieb (flash_csb_ieb), |
| 433 | .flash_clk_ieb (flash_clk_ieb), |
| 434 | |
| 435 | .flash_io0_ieb (flash_io0_ieb), |
| 436 | .flash_io1_ieb (flash_io1_ieb), |
| 437 | .flash_io2_ieb (flash_io2_ieb), |
| 438 | .flash_io3_ieb (flash_io3_ieb), |
| 439 | |
| 440 | .flash_io0_do (flash_io0_do), |
| 441 | .flash_io1_do (flash_io1_do), |
| 442 | .flash_io2_do (flash_io2_do), |
| 443 | .flash_io3_do (flash_io3_do), |
| 444 | |
| 445 | .flash_io0_di (flash_io0_di), |
| 446 | .flash_io1_di (flash_io1_di), |
| 447 | .flash_io2_di (flash_io2_di), |
| 448 | .flash_io3_di (flash_io3_di) |
| 449 | ); |
| 450 | |
| 451 | // Wishbone Slave uart |
| 452 | wire uart_stb_i; |
| 453 | wire uart_ack_o; |
| 454 | wire [31:0] uart_dat_o; |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 455 | wire uart_enabled; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 456 | |
| 457 | simpleuart_wb #( |
| 458 | .BASE_ADR(UART_BASE_ADR), |
| 459 | .CLK_DIV(UART_CLK_DIV), |
| 460 | .DATA(UART_DATA) |
| 461 | ) simpleuart ( |
| 462 | // Wishbone Interface |
| 463 | .wb_clk_i(wb_clk_i), |
| 464 | .wb_rst_i(wb_rst_i), |
| 465 | |
| 466 | .wb_adr_i(cpu_adr_o), |
| 467 | .wb_dat_i(cpu_dat_o), |
| 468 | .wb_sel_i(cpu_sel_o), |
| 469 | .wb_we_i(cpu_we_o), |
| 470 | .wb_cyc_i(cpu_cyc_o), |
| 471 | |
| 472 | .wb_stb_i(uart_stb_i), |
| 473 | .wb_ack_o(uart_ack_o), |
| 474 | .wb_dat_o(uart_dat_o), |
| 475 | |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 476 | .uart_enabled(uart_enabled), |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 477 | .ser_tx(ser_tx), |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 478 | .ser_rx(mgmt_in_data[5]) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 479 | ); |
| 480 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 481 | // Wishbone SPI master |
| 482 | wire spi_master_stb_i; |
| 483 | wire spi_master_ack_o; |
| 484 | wire [31:0] spi_master_dat_o; |
| 485 | |
| 486 | simple_spi_master_wb #( |
| 487 | .BASE_ADR(SPI_MASTER_BASE_ADR), |
| 488 | .CONFIG(SPI_MASTER_CONFIG), |
| 489 | .DATA(SPI_MASTER_DATA) |
| 490 | ) simple_spi_master_inst ( |
| 491 | // Wishbone Interface |
| 492 | .wb_clk_i(wb_clk_i), |
| 493 | .wb_rst_i(wb_rst_i), |
| 494 | |
| 495 | .wb_adr_i(cpu_adr_o), |
| 496 | .wb_dat_i(cpu_dat_o), |
| 497 | .wb_sel_i(cpu_sel_o), |
| 498 | .wb_we_i(cpu_we_o), |
| 499 | .wb_cyc_i(cpu_cyc_o), |
| 500 | |
| 501 | .wb_stb_i(spi_master_stb_i), |
| 502 | .wb_ack_o(spi_master_ack_o), |
| 503 | .wb_dat_o(spi_master_dat_o), |
| 504 | |
Tim Edwards | 8115320 | 2020-10-09 19:57:04 -0400 | [diff] [blame] | 505 | .hk_connect(hk_connect), |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 506 | .csb(mgmt_out_pre[3]), |
| 507 | .sck(mgmt_out_pre[4]), |
| 508 | .sdi(mgmt_in_data[1]), |
| 509 | .sdo(mgmt_out_pre[2]), |
| 510 | .sdoenb(), |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 511 | .irq(irq_spi_master) |
| 512 | ); |
| 513 | |
Tim Edwards | 7be29a2 | 2020-10-25 21:50:19 -0400 | [diff] [blame] | 514 | wire counter_timer_strobe, counter_timer_offset; |
| 515 | wire counter_timer0_enable, counter_timer1_enable; |
| 516 | wire counter_timer0_stop, counter_timer1_stop; |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 517 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 518 | // Wishbone Counter-timer 0 |
| 519 | wire counter_timer0_stb_i; |
| 520 | wire counter_timer0_ack_o; |
| 521 | wire [31:0] counter_timer0_dat_o; |
| 522 | |
Tim Edwards | 7be29a2 | 2020-10-25 21:50:19 -0400 | [diff] [blame] | 523 | counter_timer_low_wb #( |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 524 | .BASE_ADR(COUNTER_TIMER0_BASE_ADR), |
| 525 | .CONFIG(COUNTER_TIMER0_CONFIG), |
| 526 | .VALUE(COUNTER_TIMER0_VALUE), |
| 527 | .DATA(COUNTER_TIMER0_DATA) |
| 528 | ) counter_timer_0 ( |
| 529 | // Wishbone Interface |
| 530 | .wb_clk_i(wb_clk_i), |
| 531 | .wb_rst_i(wb_rst_i), |
| 532 | |
| 533 | .wb_adr_i(cpu_adr_o), |
| 534 | .wb_dat_i(cpu_dat_o), |
| 535 | .wb_sel_i(cpu_sel_o), |
| 536 | .wb_we_i(cpu_we_o), |
| 537 | .wb_cyc_i(cpu_cyc_o), |
| 538 | |
| 539 | .wb_stb_i(counter_timer0_stb_i), |
| 540 | .wb_ack_o(counter_timer0_ack_o), |
| 541 | .wb_dat_o(counter_timer0_dat_o), |
Tim Edwards | 7be29a2 | 2020-10-25 21:50:19 -0400 | [diff] [blame] | 542 | |
| 543 | .enable_in(counter_timer1_enable), |
| 544 | .stop_in(counter_timer1_stop), |
| 545 | .strobe(counter_timer_strobe), |
| 546 | .is_offset(counter_timer_offset), |
| 547 | .enable_out(counter_timer0_enable), |
| 548 | .stop_out(counter_timer0_stop), |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 549 | .irq(irq_counter_timer0) |
| 550 | ); |
| 551 | |
| 552 | // Wishbone Counter-timer 1 |
| 553 | wire counter_timer1_stb_i; |
| 554 | wire counter_timer1_ack_o; |
| 555 | wire [31:0] counter_timer1_dat_o; |
| 556 | |
Tim Edwards | 7be29a2 | 2020-10-25 21:50:19 -0400 | [diff] [blame] | 557 | counter_timer_high_wb #( |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 558 | .BASE_ADR(COUNTER_TIMER1_BASE_ADR), |
| 559 | .CONFIG(COUNTER_TIMER1_CONFIG), |
| 560 | .VALUE(COUNTER_TIMER1_VALUE), |
| 561 | .DATA(COUNTER_TIMER1_DATA) |
| 562 | ) counter_timer_1 ( |
| 563 | // Wishbone Interface |
| 564 | .wb_clk_i(wb_clk_i), |
| 565 | .wb_rst_i(wb_rst_i), |
| 566 | |
| 567 | .wb_adr_i(cpu_adr_o), |
| 568 | .wb_dat_i(cpu_dat_o), |
| 569 | .wb_sel_i(cpu_sel_o), |
| 570 | .wb_we_i(cpu_we_o), |
| 571 | .wb_cyc_i(cpu_cyc_o), |
| 572 | |
| 573 | .wb_stb_i(counter_timer1_stb_i), |
| 574 | .wb_ack_o(counter_timer1_ack_o), |
| 575 | .wb_dat_o(counter_timer1_dat_o), |
Tim Edwards | 7be29a2 | 2020-10-25 21:50:19 -0400 | [diff] [blame] | 576 | |
| 577 | .enable_in(counter_timer0_enable), |
| 578 | .strobe(counter_timer_strobe), |
| 579 | .stop_in(counter_timer0_stop), |
| 580 | .is_offset(counter_timer_offset), |
| 581 | .enable_out(counter_timer1_enable), |
| 582 | .stop_out(counter_timer1_stop), |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 583 | .irq(irq_counter_timer1) |
| 584 | ); |
| 585 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 586 | // Wishbone Slave GPIO Registers |
| 587 | wire gpio_stb_i; |
| 588 | wire gpio_ack_o; |
| 589 | wire [31:0] gpio_dat_o; |
| 590 | |
| 591 | gpio_wb #( |
| 592 | .BASE_ADR(GPIO_BASE_ADR), |
| 593 | .GPIO_DATA(GPIO_DATA), |
| 594 | .GPIO_ENA(GPIO_ENA), |
| 595 | .GPIO_PD(GPIO_PD), |
| 596 | .GPIO_PU(GPIO_PU) |
| 597 | ) gpio_wb ( |
| 598 | .wb_clk_i(wb_clk_i), |
| 599 | .wb_rst_i(wb_rst_i), |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 600 | .wb_adr_i(cpu_adr_o), |
| 601 | .wb_dat_i(cpu_dat_o), |
| 602 | .wb_sel_i(cpu_sel_o), |
| 603 | .wb_we_i(cpu_we_o), |
| 604 | .wb_cyc_i(cpu_cyc_o), |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 605 | .wb_stb_i(gpio_stb_i), |
| 606 | .wb_ack_o(gpio_ack_o), |
| 607 | .wb_dat_o(gpio_dat_o), |
| 608 | .gpio_in_pad(gpio_in_pad), |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 609 | .gpio(gpio_out), |
| 610 | .gpio_oeb(gpio_outenb), |
| 611 | .gpio_pu(gpio_pullup), |
| 612 | .gpio_pd(gpio_pulldown) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 613 | ); |
| 614 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 615 | // Wishbone Slave System Control Register |
| 616 | wire sys_stb_i; |
| 617 | wire sys_ack_o; |
| 618 | wire [31:0] sys_dat_o; |
| 619 | |
| 620 | sysctrl_wb #( |
| 621 | .BASE_ADR(SYS_BASE_ADR), |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 622 | .PWRGOOD(PWRGOOD), |
| 623 | .CLK_OUT(CLK_OUT), |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 624 | .TRAP_OUT(TRAP_OUT), |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 625 | .IRQ_SRC(IRQ_SRC) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 626 | ) sysctrl ( |
| 627 | .wb_clk_i(wb_clk_i), |
| 628 | .wb_rst_i(wb_rst_i), |
| 629 | |
| 630 | .wb_adr_i(cpu_adr_o), |
| 631 | .wb_dat_i(cpu_dat_o), |
| 632 | .wb_sel_i(cpu_sel_o), |
| 633 | .wb_we_i(cpu_we_o), |
| 634 | .wb_cyc_i(cpu_cyc_o), |
| 635 | |
| 636 | .wb_stb_i(sys_stb_i), |
| 637 | .wb_ack_o(sys_ack_o), |
| 638 | .wb_dat_o(sys_dat_o), |
| 639 | |
Tim Edwards | 05ad4fc | 2020-10-19 22:12:33 -0400 | [diff] [blame] | 640 | .usr1_vcc_pwrgood(mprj_vcc_pwrgood), |
| 641 | .usr2_vcc_pwrgood(mprj2_vcc_pwrgood), |
| 642 | .usr1_vdd_pwrgood(mprj_vdd_pwrgood), |
| 643 | .usr2_vdd_pwrgood(mprj2_vdd_pwrgood), |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 644 | .trap_output_dest(trap_output_dest), |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 645 | .clk1_output_dest(clk1_output_dest), |
| 646 | .clk2_output_dest(clk2_output_dest), |
| 647 | .irq_7_inputsrc(irq_7_inputsrc), |
| 648 | .irq_8_inputsrc(irq_8_inputsrc) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 649 | ); |
| 650 | |
| 651 | // Logic Analyzer |
| 652 | wire la_stb_i; |
| 653 | wire la_ack_o; |
| 654 | wire [31:0] la_dat_o; |
| 655 | |
| 656 | la_wb #( |
| 657 | .BASE_ADR(LA_BASE_ADR), |
| 658 | .LA_DATA_0(LA_DATA_0), |
| 659 | .LA_DATA_1(LA_DATA_1), |
| 660 | .LA_DATA_3(LA_DATA_3), |
| 661 | .LA_ENA_0(LA_ENA_0), |
| 662 | .LA_ENA_1(LA_ENA_1), |
| 663 | .LA_ENA_2(LA_ENA_2), |
| 664 | .LA_ENA_3(LA_ENA_3) |
| 665 | ) la ( |
| 666 | .wb_clk_i(wb_clk_i), |
| 667 | .wb_rst_i(wb_rst_i), |
| 668 | |
| 669 | .wb_adr_i(cpu_adr_o), |
| 670 | .wb_dat_i(cpu_dat_o), |
| 671 | .wb_sel_i(cpu_sel_o), |
| 672 | .wb_we_i(cpu_we_o), |
| 673 | .wb_cyc_i(cpu_cyc_o), |
| 674 | |
| 675 | .wb_stb_i(la_stb_i), |
| 676 | .wb_ack_o(la_ack_o), |
| 677 | .wb_dat_o(la_dat_o), |
| 678 | |
| 679 | .la_data(la_output), |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 680 | .la_data_in(la_input), |
| 681 | .la_oen(la_oen) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 682 | ); |
| 683 | |
Manar | cd4cff7 | 2020-11-04 16:22:59 +0200 | [diff] [blame] | 684 | // User project WB MI A port |
| 685 | assign mprj_cyc_o = cpu_cyc_o; |
| 686 | assign mprj_we_o = cpu_we_o; |
| 687 | assign mprj_sel_o = cpu_sel_o; |
| 688 | assign mprj_adr_o = cpu_adr_o; |
| 689 | assign mprj_dat_o = cpu_dat_o; |
| 690 | |
Tim Edwards | 6d9739d | 2020-10-19 11:00:49 -0400 | [diff] [blame] | 691 | // WB Slave User Project Control |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 692 | wire mprj_ctrl_stb_i; |
| 693 | wire mprj_ctrl_ack_o; |
| 694 | wire [31:0] mprj_ctrl_dat_o; |
Ahmed Ghazy | 22d29d6 | 2020-10-28 03:42:02 +0200 | [diff] [blame] | 695 | wire [`MPRJ_IO_PADS-1:0] mgmt_out_pre; |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 696 | |
| 697 | // Bits assigned to specific functions as outputs prevent the |
| 698 | // mprj GPIO-as-output from applying data when that function |
| 699 | // is active |
| 700 | |
Ahmed Ghazy | 22d29d6 | 2020-10-28 03:42:02 +0200 | [diff] [blame] | 701 | assign mgmt_out_data[`MPRJ_IO_PADS-1:16] = mgmt_out_pre[`MPRJ_IO_PADS-1:16]; |
Tim Edwards | 32d0542 | 2020-10-19 19:43:52 -0400 | [diff] [blame] | 702 | |
| 703 | // Routing of output monitors (PLL, trap, clk1, clk2) |
| 704 | assign mgmt_out_data[15] = clk2_output_dest ? user_clk : mgmt_out_pre[15]; |
| 705 | assign mgmt_out_data[14] = clk1_output_dest ? clk : mgmt_out_pre[14]; |
| 706 | assign mgmt_out_data[13] = trap_output_dest ? trap : mgmt_out_pre[13]; |
| 707 | |
| 708 | assign mgmt_out_data[12:7] = mgmt_out_pre[12:7]; |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 709 | assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6]; |
| 710 | assign mgmt_out_data[5:0] = mgmt_out_pre[5:0]; |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 711 | |
| 712 | mprj_ctrl_wb #( |
Ahmed Ghazy | 22d29d6 | 2020-10-28 03:42:02 +0200 | [diff] [blame] | 713 | .BASE_ADR(MPRJ_CTRL_ADR) |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 714 | ) mprj_ctrl ( |
| 715 | .wb_clk_i(wb_clk_i), |
| 716 | .wb_rst_i(wb_rst_i), |
| 717 | |
| 718 | .wb_adr_i(cpu_adr_o), |
| 719 | .wb_dat_i(cpu_dat_o), |
| 720 | .wb_sel_i(cpu_sel_o), |
| 721 | .wb_we_i(cpu_we_o), |
| 722 | .wb_cyc_i(cpu_cyc_o), |
| 723 | .wb_stb_i(mprj_ctrl_stb_i), |
| 724 | .wb_ack_o(mprj_ctrl_ack_o), |
| 725 | .wb_dat_o(mprj_ctrl_dat_o), |
| 726 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 727 | .serial_clock(mprj_io_loader_clock), |
| 728 | .serial_resetn(mprj_io_loader_resetn), |
| 729 | .serial_data_out(mprj_io_loader_data), |
Tim Edwards | 496a08a | 2020-10-26 15:44:51 -0400 | [diff] [blame] | 730 | .sdo_oenb_state(sdo_oenb_state), |
| 731 | .jtag_oenb_state(jtag_oenb_state), |
Tim Edwards | ca2f318 | 2020-10-06 10:05:11 -0400 | [diff] [blame] | 732 | .mgmt_gpio_out(mgmt_out_pre), |
Tim Edwards | ba32890 | 2020-10-27 15:03:22 -0400 | [diff] [blame] | 733 | .mgmt_gpio_in(mgmt_in_data), |
| 734 | .pwr_ctrl_out(pwr_ctrl_out) |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 735 | ); |
| 736 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 737 | // Wishbone Slave RAM |
| 738 | wire mem_stb_i; |
| 739 | wire mem_ack_o; |
| 740 | wire [31:0] mem_dat_o; |
| 741 | |
Ahmed Ghazy | 22d29d6 | 2020-10-28 03:42:02 +0200 | [diff] [blame] | 742 | mem_wb soc_mem ( |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 743 | .wb_clk_i(wb_clk_i), |
| 744 | .wb_rst_i(wb_rst_i), |
| 745 | |
| 746 | .wb_adr_i(cpu_adr_o), |
| 747 | .wb_dat_i(cpu_dat_o), |
| 748 | .wb_sel_i(cpu_sel_o), |
| 749 | .wb_we_i(cpu_we_o), |
| 750 | .wb_cyc_i(cpu_cyc_o), |
| 751 | |
| 752 | .wb_stb_i(mem_stb_i), |
| 753 | .wb_ack_o(mem_ack_o), |
| 754 | .wb_dat_o(mem_dat_o) |
| 755 | ); |
| 756 | |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 757 | wire uram_stb_i; |
| 758 | wire mram_stb_i; |
| 759 | wire uram_ack_o; |
| 760 | wire mram_ack_o; |
| 761 | wire [31:0] mram_dat_o; |
| 762 | wire [31:0] uram_dat_o; |
| 763 | |
| 764 | // Storage area wishbone brige |
| 765 | storage_bridge_wb #( |
| 766 | .USER_BLOCKS(`USER_BLOCKS), |
| 767 | .MGMT_BLOCKS(`MGMT_BLOCKS), |
| 768 | .MGMT_BASE_ADR(EXT_MRAM_BASE_ADR), |
| 769 | .USER_BASE_ADR(EXT_URAM_BASE_ADR), |
| 770 | .MGMT_BLOCKS_ADR(MGMT_BLOCKS_ADR), |
| 771 | .USER_BLOCKS_ADR(USER_BLOCKS_ADR) |
| 772 | ) wb_bridge ( |
| 773 | .wb_clk_i(wb_clk_i), |
| 774 | .wb_rst_i(wb_rst_i), |
| 775 | |
| 776 | .wb_adr_i(cpu_adr_o), |
| 777 | .wb_dat_i(cpu_dat_o), |
| 778 | .wb_sel_i(cpu_sel_o), |
| 779 | .wb_we_i(cpu_we_o), |
| 780 | .wb_cyc_i(cpu_cyc_o), |
| 781 | .wb_stb_i({uram_stb_i, mram_stb_i}), |
| 782 | .wb_ack_o({uram_ack_o, mram_ack_o}), |
| 783 | .wb_mgmt_dat_o(mram_dat_o), |
| 784 | |
| 785 | // MGMT_AREA RO WB Interface |
| 786 | .wb_user_dat_o(uram_dat_o), |
| 787 | |
| 788 | // MGMT Area native memory interface |
| 789 | .mgmt_ena(mgmt_ena), |
| 790 | .mgmt_wen_mask(mgmt_wen_mask), |
| 791 | .mgmt_wen(mgmt_wen), |
| 792 | .mgmt_addr(mgmt_addr), |
| 793 | .mgmt_wdata(mgmt_wdata), |
| 794 | .mgmt_rdata(mgmt_rdata), |
| 795 | |
| 796 | // MGMT_AREA RO interface |
| 797 | .mgmt_user_ena(user_ena), |
| 798 | .mgmt_user_addr(user_addr), |
| 799 | .mgmt_user_rdata(user_rdata) |
| 800 | ); |
| 801 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 802 | // Wishbone intercon logic |
| 803 | wb_intercon #( |
| 804 | .AW(ADR_WIDTH), |
| 805 | .DW(DAT_WIDTH), |
| 806 | .NS(NUM_SLAVES), |
| 807 | .ADR_MASK(ADR_MASK), |
| 808 | .SLAVE_ADR(SLAVE_ADR) |
| 809 | ) intercon ( |
| 810 | // Master Interface |
| 811 | .wbm_adr_i(cpu_adr_o), |
| 812 | .wbm_stb_i(cpu_stb_o), |
| 813 | .wbm_dat_o(cpu_dat_i), |
| 814 | .wbm_ack_o(cpu_ack_i), |
| 815 | |
| 816 | // Slaves Interface |
Manar | 98a7adc | 2020-10-19 23:21:36 +0200 | [diff] [blame] | 817 | .wbs_stb_o({ sys_stb_i, spimemio_cfg_stb_i, |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 818 | mprj_stb_o, mprj_ctrl_stb_i, la_stb_i, |
| 819 | spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i, |
| 820 | gpio_stb_i, uart_stb_i, |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 821 | spimemio_flash_stb_i,uram_stb_i, mram_stb_i, mem_stb_i }), |
Manar | 98a7adc | 2020-10-19 23:21:36 +0200 | [diff] [blame] | 822 | .wbs_dat_i({ sys_dat_o, spimemio_cfg_dat_o, |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 823 | mprj_dat_i, mprj_ctrl_dat_o, la_dat_o, |
| 824 | spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o, |
| 825 | gpio_dat_o, uart_dat_o, |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 826 | spimemio_flash_dat_o, uram_dat_o, mram_dat_o, mem_dat_o }), |
Manar | 98a7adc | 2020-10-19 23:21:36 +0200 | [diff] [blame] | 827 | .wbs_ack_i({ sys_ack_o, spimemio_cfg_ack_o, |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 828 | mprj_ack_i, mprj_ctrl_ack_o, la_ack_o, |
| 829 | spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o, |
| 830 | gpio_ack_o, uart_ack_o, |
Manar | 55ec369 | 2020-10-30 16:32:18 +0200 | [diff] [blame] | 831 | spimemio_flash_ack_o, uram_ack_o, mram_ack_o, mem_ack_o }) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 832 | ); |
| 833 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 834 | endmodule |
| 835 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 836 | // Implementation note: |
| 837 | // Replace the following two modules with wrappers for your SRAM cells. |
Tim Edwards | ef8312e | 2020-09-22 17:20:06 -0400 | [diff] [blame] | 838 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 839 | module mgmt_soc_regs ( |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 840 | input clk, wen, |
| 841 | input [5:0] waddr, |
| 842 | input [5:0] raddr1, |
| 843 | input [5:0] raddr2, |
| 844 | input [31:0] wdata, |
| 845 | output [31:0] rdata1, |
| 846 | output [31:0] rdata2 |
| 847 | ); |
| 848 | reg [31:0] regs [0:31]; |
| 849 | |
| 850 | always @(posedge clk) |
| 851 | if (wen) regs[waddr[4:0]] <= wdata; |
| 852 | |
| 853 | assign rdata1 = regs[raddr1[4:0]]; |
| 854 | assign rdata2 = regs[raddr2[4:0]]; |
| 855 | endmodule |