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