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" |
| 36 | `include "counter_timer.v" |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 37 | `include "wb_intercon.v" |
| 38 | `include "mem_wb.v" |
| 39 | `include "gpio_wb.v" |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 40 | `include "sysctrl.v" |
| 41 | `include "la_wb.v" |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 42 | `include "mprj_ctrl.v" |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 43 | `include "convert_gpio_sigs.v" |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 44 | |
| 45 | module mgmt_soc ( |
| 46 | `ifdef LVS |
| 47 | inout vdd1v8, /* 1.8V domain */ |
| 48 | inout vss, |
| 49 | `endif |
| 50 | input pll_clk, |
| 51 | input ext_clk, |
| 52 | input ext_clk_sel, |
| 53 | |
| 54 | input clk, |
| 55 | input resetn, |
| 56 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 57 | // Trap state from CPU |
| 58 | output trap, |
| 59 | |
| 60 | // GPIO (one pin) |
| 61 | output gpio_out_pad, // Connect to out on gpio pad |
| 62 | input gpio_in_pad, // Connect to in on gpio pad |
| 63 | output gpio_mode0_pad, // Connect to dm[0] on gpio pad |
| 64 | output gpio_mode1_pad, // Connect to dm[2] on gpio pad |
| 65 | output gpio_outenb_pad, // Connect to oe_n on gpio pad |
| 66 | output gpio_inenb_pad, // Connect to inp_dis on gpio pad |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 67 | |
| 68 | // LA signals |
| 69 | input [127:0] la_input, // From Mega-Project to cpu |
| 70 | output [127:0] la_output, // From CPU to Mega-Project |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 71 | output [127:0] la_oen, // LA output enable (active low) |
| 72 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 73 | // Mega-Project I/O Configuration (serial load) |
| 74 | output mprj_io_loader_resetn, |
| 75 | output mprj_io_loader_clock, |
| 76 | output mprj_io_loader_data, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 77 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 78 | // Mega-Project pad data (when management SoC controls the pad) |
| 79 | inout [MPRJ_IO_PADS-1:0] mgmt_io_data, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 80 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 81 | // SPI master |
| 82 | output spi_csb, |
| 83 | output spi_sck, |
| 84 | output spi_sdo, |
| 85 | input spi_sdi, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 86 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 87 | // UART |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 88 | output ser_tx, |
| 89 | input ser_rx, |
| 90 | |
| 91 | // IRQ |
| 92 | input irq_pin, // dedicated IRQ pin |
| 93 | input irq_spi, // IRQ from standalone SPI |
| 94 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 95 | // Flash memory control (SPI master) |
| 96 | output flash_csb, |
| 97 | output flash_clk, |
| 98 | |
| 99 | output flash_csb_oeb, |
| 100 | output flash_clk_oeb, |
| 101 | |
| 102 | output flash_io0_oeb, |
| 103 | output flash_io1_oeb, |
| 104 | output flash_io2_oeb, |
| 105 | output flash_io3_oeb, |
| 106 | |
| 107 | output flash_csb_ieb, |
| 108 | output flash_clk_ieb, |
| 109 | |
| 110 | output flash_io0_ieb, |
| 111 | output flash_io1_ieb, |
| 112 | output flash_io2_ieb, |
| 113 | output flash_io3_ieb, |
| 114 | |
| 115 | output flash_io0_do, |
| 116 | output flash_io1_do, |
| 117 | output flash_io2_do, |
| 118 | output flash_io3_do, |
| 119 | |
| 120 | input flash_io0_di, |
| 121 | input flash_io1_di, |
| 122 | input flash_io2_di, |
| 123 | input flash_io3_di, |
| 124 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 125 | // SPI pass-thru mode |
| 126 | input pass_thru_mgmt, |
| 127 | input pass_thru_mgmt_csb, |
| 128 | input pass_thru_mgmt_sck, |
| 129 | input pass_thru_mgmt_sdi, |
| 130 | output pass_thru_mgmt_sdo, |
| 131 | |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 132 | // WB MI A (Mega project) |
| 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, |
| 140 | output [31:0] mprj_dat_o, |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 141 | |
| 142 | // WB MI B (xbar) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 143 | input [31:0] xbar_dat_i, |
| 144 | input xbar_ack_i, |
| 145 | output xbar_cyc_o, |
| 146 | output xbar_stb_o, |
| 147 | output xbar_we_o, |
| 148 | output [3:0] xbar_sel_o, |
| 149 | output [31:0] xbar_adr_o, |
| 150 | output [31:0] xbar_dat_o |
| 151 | ); |
| 152 | /* Memory reverted back to 256 words while memory has to be synthesized */ |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 153 | parameter integer MEM_WORDS = 8192; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 154 | parameter [31:0] STACKADDR = (4*MEM_WORDS); // end of memory |
| 155 | parameter [31:0] PROGADDR_RESET = 32'h 1000_0000; |
| 156 | parameter [31:0] PROGADDR_IRQ = 32'h 0000_0000; |
| 157 | |
| 158 | // Slaves Base Addresses |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 159 | parameter RAM_BASE_ADR = 32'h 0000_0000; |
| 160 | parameter FLASH_BASE_ADR = 32'h 1000_0000; |
| 161 | parameter UART_BASE_ADR = 32'h 2000_0000; |
| 162 | parameter GPIO_BASE_ADR = 32'h 2100_0000; |
| 163 | parameter COUNTER_TIMER0_BASE_ADR = 32'h 2110_0000; |
| 164 | parameter COUNTER_TIMER1_BASE_ADR = 32'h 2120_0000; |
| 165 | parameter SPI_MASTER_BASE_ADR = 32'h 2130_0000; |
| 166 | parameter LA_BASE_ADR = 32'h 2200_0000; |
| 167 | parameter MPRJ_CTRL_ADR = 32'h 2300_0000; |
| 168 | parameter MPRJ_BASE_ADR = 32'h 3000_0000; // WB MI A |
| 169 | parameter SYS_BASE_ADR = 32'h 2F00_0000; |
| 170 | parameter FLASH_CTRL_CFG = 32'h 2D00_0000; |
| 171 | parameter XBAR_BASE_ADR = 32'h 8000_0000; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 172 | |
| 173 | // UART |
| 174 | parameter UART_CLK_DIV = 8'h00; |
| 175 | parameter UART_DATA = 8'h04; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 176 | |
| 177 | // SPI Master |
| 178 | parameter SPI_MASTER_CONFIG = 8'h00; |
| 179 | parameter SPI_MASTER_DATA = 8'h04; |
| 180 | |
| 181 | // Counter-timer 0 |
| 182 | parameter COUNTER_TIMER0_CONFIG = 8'h00; |
| 183 | parameter COUNTER_TIMER0_VALUE = 8'h04; |
| 184 | parameter COUNTER_TIMER0_DATA = 8'h08; |
| 185 | |
| 186 | // Counter-timer 1 |
| 187 | parameter COUNTER_TIMER1_CONFIG = 8'h00; |
| 188 | parameter COUNTER_TIMER1_VALUE = 8'h04; |
| 189 | parameter COUNTER_TIMER1_DATA = 8'h08; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 190 | |
| 191 | // SOC GPIO |
| 192 | parameter GPIO_DATA = 8'h00; |
| 193 | parameter GPIO_ENA = 8'h04; |
| 194 | parameter GPIO_PU = 8'h08; |
| 195 | parameter GPIO_PD = 8'h0c; |
| 196 | |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 197 | // LA |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 198 | parameter LA_DATA_0 = 8'h00; |
| 199 | parameter LA_DATA_1 = 8'h04; |
| 200 | parameter LA_DATA_2 = 8'h08; |
| 201 | parameter LA_DATA_3 = 8'h0c; |
| 202 | parameter LA_ENA_0 = 8'h10; |
| 203 | parameter LA_ENA_1 = 8'h14; |
| 204 | parameter LA_ENA_2 = 8'h18; |
| 205 | parameter LA_ENA_3 = 8'h1c; |
| 206 | |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 207 | // Mega-Project Control |
| 208 | parameter MPRJ_IO_PADS = 32; |
Tim Edwards | c18c474 | 2020-10-03 11:26:39 -0400 | [diff] [blame] | 209 | parameter MPRJ_PWR_PADS = 32; |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 210 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 211 | // System Control Registers |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 212 | parameter PLL_OUT = 8'h0c; |
| 213 | parameter TRAP_OUT = 8'h10; |
| 214 | parameter IRQ7_SRC = 8'h14; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 215 | |
| 216 | // Wishbone Interconnect |
| 217 | localparam ADR_WIDTH = 32; |
| 218 | localparam DAT_WIDTH = 32; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 219 | localparam NUM_SLAVES = 13; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 220 | |
| 221 | parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = { |
| 222 | {8'h80, {ADR_WIDTH-8{1'b0}}}, |
| 223 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 224 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 225 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 226 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 227 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 228 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 229 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 230 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 231 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 232 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
| 233 | {8'hFF, {ADR_WIDTH-8{1'b0}}}, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 234 | {8'hFF, {ADR_WIDTH-8{1'b0}}} |
| 235 | }; |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 236 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 237 | parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = { |
| 238 | {XBAR_BASE_ADR}, |
| 239 | {SYS_BASE_ADR}, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 240 | {FLASH_CTRL_CFG}, |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 241 | {MPRJ_BASE_ADR}, |
| 242 | {MPRJ_CTRL_ADR}, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 243 | {LA_BASE_ADR}, |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 244 | {SPI_MASTER_BASE_ADR}, |
| 245 | {COUNTER_TIMER1_BASE_ADR}, |
| 246 | {COUNTER_TIMER0_BASE_ADR}, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 247 | {GPIO_BASE_ADR}, |
| 248 | {UART_BASE_ADR}, |
| 249 | {FLASH_BASE_ADR}, |
| 250 | {RAM_BASE_ADR} |
| 251 | }; |
| 252 | |
| 253 | // memory-mapped I/O control registers |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 254 | wire gpio_pullup; // Intermediate GPIO pullup |
| 255 | wire gpio_pulldown; // Intermediate GPIO pulldown |
| 256 | wire gpio_outenb; // Intermediate GPIO out enable (bar) |
| 257 | wire gpio_out; // Intermediate GPIO output |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 258 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 259 | wire gpio; // GPIO output data |
| 260 | wire gpio_pu; // GPIO pull-up enable |
| 261 | wire gpio_pd; // GPIO pull-down enable |
| 262 | wire gpio_oeb; // GPIO output enable (sense negative) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 263 | |
Tim Edwards | ef8312e | 2020-09-22 17:20:06 -0400 | [diff] [blame] | 264 | wire pll_output_dest; // PLL clock output destination |
| 265 | wire trap_output_dest; // Trap signal output destination |
| 266 | wire irq_7_inputsrc; // IRQ 7 source |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 267 | |
| 268 | // GPIO assignments |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 269 | assign gpio_out = (trap_output_dest == 1'b1) ? trap : gpio; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 270 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 271 | assign gpio_outenb = (trap_output_dest == 1'b0) ? gpio_oeb : 1'b0; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 272 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 273 | assign gpio_pullup = (trap_output_dest == 1'b0) ? gpio_pu : 1'b0; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 274 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 275 | assign gpio_pulldown = (trap_output_dest == 1'b0) ? gpio_pd : 1'b0; |
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; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 292 | wire irq_stall; |
| 293 | wire irq_uart; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 294 | wire irq_spi_master; |
| 295 | wire irq_counter_timer0; |
| 296 | wire irq_counter_timer1; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 297 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 298 | assign irq_stall = 0; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 299 | assign irq_7 = (irq_7_inputsrc == 1'b1) ? gpio_in_pad : 1'b0; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 300 | |
| 301 | always @* begin |
| 302 | irq = 0; |
| 303 | irq[3] = irq_stall; |
| 304 | irq[4] = irq_uart; |
| 305 | irq[5] = irq_pin; |
| 306 | irq[6] = irq_spi; |
| 307 | irq[7] = irq_7; |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 308 | irq[9] = irq_spi_master; |
| 309 | irq[10] = irq_counter_timer0; |
| 310 | irq[11] = irq_counter_timer1; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 311 | end |
| 312 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 313 | // Assumption : no syscon module and wb_clk is the clock coming from the chip pin ? |
| 314 | assign wb_clk_i = clk; |
| 315 | assign wb_rst_i = ~resetn; // Redundant |
| 316 | |
| 317 | // Wishbone Master |
| 318 | wire [31:0] cpu_adr_o; |
| 319 | wire [31:0] cpu_dat_i; |
| 320 | wire [3:0] cpu_sel_o; |
| 321 | wire cpu_we_o; |
| 322 | wire cpu_cyc_o; |
| 323 | wire cpu_stb_o; |
| 324 | wire [31:0] cpu_dat_o; |
| 325 | wire cpu_ack_i; |
| 326 | |
| 327 | assign xbar_cyc_o = cpu_cyc_o; |
| 328 | assign xbar_we_o = cpu_we_o; |
| 329 | assign xbar_sel_o = cpu_sel_o; |
| 330 | assign xbar_adr_o = cpu_adr_o; |
| 331 | assign xbar_dat_o = cpu_dat_o; |
| 332 | |
| 333 | picorv32_wb #( |
| 334 | .STACKADDR(STACKADDR), |
| 335 | .PROGADDR_RESET(PROGADDR_RESET), |
| 336 | .PROGADDR_IRQ(PROGADDR_IRQ), |
| 337 | .BARREL_SHIFTER(1), |
| 338 | .COMPRESSED_ISA(1), |
| 339 | .ENABLE_MUL(1), |
| 340 | .ENABLE_DIV(1), |
| 341 | .ENABLE_IRQ(1), |
| 342 | .ENABLE_IRQ_QREGS(0) |
| 343 | ) cpu ( |
| 344 | .wb_clk_i (wb_clk_i), |
| 345 | .wb_rst_i (wb_rst_i), |
| 346 | .trap (trap), |
| 347 | .irq (irq), |
| 348 | .mem_instr(mem_instr), |
| 349 | .wbm_adr_o(cpu_adr_o), |
| 350 | .wbm_dat_i(cpu_dat_i), |
| 351 | .wbm_stb_o(cpu_stb_o), |
| 352 | .wbm_ack_i(cpu_ack_i), |
| 353 | .wbm_cyc_o(cpu_cyc_o), |
| 354 | .wbm_dat_o(cpu_dat_o), |
| 355 | .wbm_we_o(cpu_we_o), |
| 356 | .wbm_sel_o(cpu_sel_o) |
| 357 | ); |
| 358 | |
| 359 | // Wishbone Slave SPIMEMIO |
| 360 | wire spimemio_flash_stb_i; |
| 361 | wire spimemio_flash_ack_o; |
| 362 | wire [31:0] spimemio_flash_dat_o; |
| 363 | |
| 364 | wire spimemio_cfg_stb_i; |
| 365 | wire spimemio_cfg_ack_o; |
| 366 | wire [31:0] spimemio_cfg_dat_o; |
| 367 | |
| 368 | spimemio_wb spimemio ( |
| 369 | .wb_clk_i(wb_clk_i), |
| 370 | .wb_rst_i(wb_rst_i), |
| 371 | |
| 372 | .wb_adr_i(cpu_adr_o), |
| 373 | .wb_dat_i(cpu_dat_o), |
| 374 | .wb_sel_i(cpu_sel_o), |
| 375 | .wb_we_i(cpu_we_o), |
| 376 | .wb_cyc_i(cpu_cyc_o), |
| 377 | |
| 378 | // FLash Slave |
| 379 | .wb_flash_stb_i(spimemio_flash_stb_i), |
| 380 | .wb_flash_ack_o(spimemio_flash_ack_o), |
| 381 | .wb_flash_dat_o(spimemio_flash_dat_o), |
| 382 | |
| 383 | // Config Register Slave |
| 384 | .wb_cfg_stb_i(spimemio_cfg_stb_i), |
| 385 | .wb_cfg_ack_o(spimemio_cfg_ack_o), |
| 386 | .wb_cfg_dat_o(spimemio_cfg_dat_o), |
| 387 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 388 | .pass_thru(pass_thru_mgmt), |
| 389 | .pass_thru_csb(pass_thru_mgmt_csb), |
| 390 | .pass_thru_sck(pass_thru_mgmt_sck), |
| 391 | .pass_thru_sdi(pass_thru_mgmt_sdi), |
| 392 | .pass_thru_sdo(pass_thru_mgmt_sdo), |
| 393 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 394 | .flash_csb (flash_csb), |
| 395 | .flash_clk (flash_clk), |
| 396 | |
| 397 | .flash_csb_oeb (flash_csb_oeb), |
| 398 | .flash_clk_oeb (flash_clk_oeb), |
| 399 | |
| 400 | .flash_io0_oeb (flash_io0_oeb), |
| 401 | .flash_io1_oeb (flash_io1_oeb), |
| 402 | .flash_io2_oeb (flash_io2_oeb), |
| 403 | .flash_io3_oeb (flash_io3_oeb), |
| 404 | |
| 405 | .flash_csb_ieb (flash_csb_ieb), |
| 406 | .flash_clk_ieb (flash_clk_ieb), |
| 407 | |
| 408 | .flash_io0_ieb (flash_io0_ieb), |
| 409 | .flash_io1_ieb (flash_io1_ieb), |
| 410 | .flash_io2_ieb (flash_io2_ieb), |
| 411 | .flash_io3_ieb (flash_io3_ieb), |
| 412 | |
| 413 | .flash_io0_do (flash_io0_do), |
| 414 | .flash_io1_do (flash_io1_do), |
| 415 | .flash_io2_do (flash_io2_do), |
| 416 | .flash_io3_do (flash_io3_do), |
| 417 | |
| 418 | .flash_io0_di (flash_io0_di), |
| 419 | .flash_io1_di (flash_io1_di), |
| 420 | .flash_io2_di (flash_io2_di), |
| 421 | .flash_io3_di (flash_io3_di) |
| 422 | ); |
| 423 | |
| 424 | // Wishbone Slave uart |
| 425 | wire uart_stb_i; |
| 426 | wire uart_ack_o; |
| 427 | wire [31:0] uart_dat_o; |
| 428 | |
| 429 | simpleuart_wb #( |
| 430 | .BASE_ADR(UART_BASE_ADR), |
| 431 | .CLK_DIV(UART_CLK_DIV), |
| 432 | .DATA(UART_DATA) |
| 433 | ) simpleuart ( |
| 434 | // Wishbone Interface |
| 435 | .wb_clk_i(wb_clk_i), |
| 436 | .wb_rst_i(wb_rst_i), |
| 437 | |
| 438 | .wb_adr_i(cpu_adr_o), |
| 439 | .wb_dat_i(cpu_dat_o), |
| 440 | .wb_sel_i(cpu_sel_o), |
| 441 | .wb_we_i(cpu_we_o), |
| 442 | .wb_cyc_i(cpu_cyc_o), |
| 443 | |
| 444 | .wb_stb_i(uart_stb_i), |
| 445 | .wb_ack_o(uart_ack_o), |
| 446 | .wb_dat_o(uart_dat_o), |
| 447 | |
| 448 | .ser_tx(ser_tx), |
| 449 | .ser_rx(ser_rx) |
| 450 | ); |
| 451 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 452 | // Wishbone SPI master |
| 453 | wire spi_master_stb_i; |
| 454 | wire spi_master_ack_o; |
| 455 | wire [31:0] spi_master_dat_o; |
| 456 | |
| 457 | simple_spi_master_wb #( |
| 458 | .BASE_ADR(SPI_MASTER_BASE_ADR), |
| 459 | .CONFIG(SPI_MASTER_CONFIG), |
| 460 | .DATA(SPI_MASTER_DATA) |
| 461 | ) simple_spi_master_inst ( |
| 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(spi_master_stb_i), |
| 473 | .wb_ack_o(spi_master_ack_o), |
| 474 | .wb_dat_o(spi_master_dat_o), |
| 475 | |
| 476 | .csb(spi_csb), |
| 477 | .sck(spi_sck), |
| 478 | .sdi(spi_sdi), |
| 479 | .sdo(spi_sdo), |
| 480 | .irq(irq_spi_master) |
| 481 | ); |
| 482 | |
| 483 | // Wishbone Counter-timer 0 |
| 484 | wire counter_timer0_stb_i; |
| 485 | wire counter_timer0_ack_o; |
| 486 | wire [31:0] counter_timer0_dat_o; |
| 487 | |
| 488 | counter_timer_wb #( |
| 489 | .BASE_ADR(COUNTER_TIMER0_BASE_ADR), |
| 490 | .CONFIG(COUNTER_TIMER0_CONFIG), |
| 491 | .VALUE(COUNTER_TIMER0_VALUE), |
| 492 | .DATA(COUNTER_TIMER0_DATA) |
| 493 | ) counter_timer_0 ( |
| 494 | // Wishbone Interface |
| 495 | .wb_clk_i(wb_clk_i), |
| 496 | .wb_rst_i(wb_rst_i), |
| 497 | |
| 498 | .wb_adr_i(cpu_adr_o), |
| 499 | .wb_dat_i(cpu_dat_o), |
| 500 | .wb_sel_i(cpu_sel_o), |
| 501 | .wb_we_i(cpu_we_o), |
| 502 | .wb_cyc_i(cpu_cyc_o), |
| 503 | |
| 504 | .wb_stb_i(counter_timer0_stb_i), |
| 505 | .wb_ack_o(counter_timer0_ack_o), |
| 506 | .wb_dat_o(counter_timer0_dat_o), |
| 507 | .irq(irq_counter_timer0) |
| 508 | ); |
| 509 | |
| 510 | // Wishbone Counter-timer 1 |
| 511 | wire counter_timer1_stb_i; |
| 512 | wire counter_timer1_ack_o; |
| 513 | wire [31:0] counter_timer1_dat_o; |
| 514 | |
| 515 | counter_timer_wb #( |
| 516 | .BASE_ADR(COUNTER_TIMER1_BASE_ADR), |
| 517 | .CONFIG(COUNTER_TIMER1_CONFIG), |
| 518 | .VALUE(COUNTER_TIMER1_VALUE), |
| 519 | .DATA(COUNTER_TIMER1_DATA) |
| 520 | ) counter_timer_1 ( |
| 521 | // Wishbone Interface |
| 522 | .wb_clk_i(wb_clk_i), |
| 523 | .wb_rst_i(wb_rst_i), |
| 524 | |
| 525 | .wb_adr_i(cpu_adr_o), |
| 526 | .wb_dat_i(cpu_dat_o), |
| 527 | .wb_sel_i(cpu_sel_o), |
| 528 | .wb_we_i(cpu_we_o), |
| 529 | .wb_cyc_i(cpu_cyc_o), |
| 530 | |
| 531 | .wb_stb_i(counter_timer1_stb_i), |
| 532 | .wb_ack_o(counter_timer1_ack_o), |
| 533 | .wb_dat_o(counter_timer1_dat_o), |
| 534 | .irq(irq_counter_timer1) |
| 535 | ); |
| 536 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 537 | // Wishbone Slave GPIO Registers |
| 538 | wire gpio_stb_i; |
| 539 | wire gpio_ack_o; |
| 540 | wire [31:0] gpio_dat_o; |
| 541 | |
| 542 | gpio_wb #( |
| 543 | .BASE_ADR(GPIO_BASE_ADR), |
| 544 | .GPIO_DATA(GPIO_DATA), |
| 545 | .GPIO_ENA(GPIO_ENA), |
| 546 | .GPIO_PD(GPIO_PD), |
| 547 | .GPIO_PU(GPIO_PU) |
| 548 | ) gpio_wb ( |
| 549 | .wb_clk_i(wb_clk_i), |
| 550 | .wb_rst_i(wb_rst_i), |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 551 | .wb_adr_i(cpu_adr_o), |
| 552 | .wb_dat_i(cpu_dat_o), |
| 553 | .wb_sel_i(cpu_sel_o), |
| 554 | .wb_we_i(cpu_we_o), |
| 555 | .wb_cyc_i(cpu_cyc_o), |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 556 | .wb_stb_i(gpio_stb_i), |
| 557 | .wb_ack_o(gpio_ack_o), |
| 558 | .wb_dat_o(gpio_dat_o), |
| 559 | .gpio_in_pad(gpio_in_pad), |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 560 | .gpio(gpio), |
| 561 | .gpio_oeb(gpio_oeb), |
| 562 | .gpio_pu(gpio_pu), |
| 563 | .gpio_pd(gpio_pd) |
| 564 | ); |
| 565 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 566 | // Wishbone Slave System Control Register |
| 567 | wire sys_stb_i; |
| 568 | wire sys_ack_o; |
| 569 | wire [31:0] sys_dat_o; |
| 570 | |
| 571 | sysctrl_wb #( |
| 572 | .BASE_ADR(SYS_BASE_ADR), |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 573 | .PLL_OUT(PLL_OUT), |
| 574 | .TRAP_OUT(TRAP_OUT), |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 575 | .IRQ7_SRC(IRQ7_SRC) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 576 | ) sysctrl ( |
| 577 | .wb_clk_i(wb_clk_i), |
| 578 | .wb_rst_i(wb_rst_i), |
| 579 | |
| 580 | .wb_adr_i(cpu_adr_o), |
| 581 | .wb_dat_i(cpu_dat_o), |
| 582 | .wb_sel_i(cpu_sel_o), |
| 583 | .wb_we_i(cpu_we_o), |
| 584 | .wb_cyc_i(cpu_cyc_o), |
| 585 | |
| 586 | .wb_stb_i(sys_stb_i), |
| 587 | .wb_ack_o(sys_ack_o), |
| 588 | .wb_dat_o(sys_dat_o), |
| 589 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 590 | .pll_output_dest(pll_output_dest), |
| 591 | .trap_output_dest(trap_output_dest), |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 592 | .irq_7_inputsrc(irq_7_inputsrc) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 593 | ); |
| 594 | |
| 595 | // Logic Analyzer |
| 596 | wire la_stb_i; |
| 597 | wire la_ack_o; |
| 598 | wire [31:0] la_dat_o; |
| 599 | |
| 600 | la_wb #( |
| 601 | .BASE_ADR(LA_BASE_ADR), |
| 602 | .LA_DATA_0(LA_DATA_0), |
| 603 | .LA_DATA_1(LA_DATA_1), |
| 604 | .LA_DATA_3(LA_DATA_3), |
| 605 | .LA_ENA_0(LA_ENA_0), |
| 606 | .LA_ENA_1(LA_ENA_1), |
| 607 | .LA_ENA_2(LA_ENA_2), |
| 608 | .LA_ENA_3(LA_ENA_3) |
| 609 | ) la ( |
| 610 | .wb_clk_i(wb_clk_i), |
| 611 | .wb_rst_i(wb_rst_i), |
| 612 | |
| 613 | .wb_adr_i(cpu_adr_o), |
| 614 | .wb_dat_i(cpu_dat_o), |
| 615 | .wb_sel_i(cpu_sel_o), |
| 616 | .wb_we_i(cpu_we_o), |
| 617 | .wb_cyc_i(cpu_cyc_o), |
| 618 | |
| 619 | .wb_stb_i(la_stb_i), |
| 620 | .wb_ack_o(la_ack_o), |
| 621 | .wb_dat_o(la_dat_o), |
| 622 | |
| 623 | .la_data(la_output), |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 624 | .la_data_in(la_input), |
| 625 | .la_oen(la_oen) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 626 | ); |
| 627 | |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 628 | // WB Slave Mega-Project Control |
| 629 | wire mprj_ctrl_stb_i; |
| 630 | wire mprj_ctrl_ack_o; |
| 631 | wire [31:0] mprj_ctrl_dat_o; |
| 632 | |
| 633 | mprj_ctrl_wb #( |
| 634 | .BASE_ADR(MPRJ_CTRL_ADR), |
| 635 | .IO_PADS(MPRJ_IO_PADS), |
Tim Edwards | c18c474 | 2020-10-03 11:26:39 -0400 | [diff] [blame] | 636 | .PWR_PADS(MPRJ_PWR_PADS) |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 637 | ) mprj_ctrl ( |
| 638 | .wb_clk_i(wb_clk_i), |
| 639 | .wb_rst_i(wb_rst_i), |
| 640 | |
| 641 | .wb_adr_i(cpu_adr_o), |
| 642 | .wb_dat_i(cpu_dat_o), |
| 643 | .wb_sel_i(cpu_sel_o), |
| 644 | .wb_we_i(cpu_we_o), |
| 645 | .wb_cyc_i(cpu_cyc_o), |
| 646 | .wb_stb_i(mprj_ctrl_stb_i), |
| 647 | .wb_ack_o(mprj_ctrl_ack_o), |
| 648 | .wb_dat_o(mprj_ctrl_dat_o), |
| 649 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 650 | .serial_clock(mprj_io_loader_clock), |
| 651 | .serial_resetn(mprj_io_loader_resetn), |
| 652 | .serial_data_out(mprj_io_loader_data), |
| 653 | .mgmt_gpio_io(mgmt_io_data) |
shalan | 0d14e6e | 2020-08-31 16:50:48 +0200 | [diff] [blame] | 654 | ); |
| 655 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 656 | // Wishbone Slave RAM |
| 657 | wire mem_stb_i; |
| 658 | wire mem_ack_o; |
| 659 | wire [31:0] mem_dat_o; |
| 660 | |
| 661 | mem_wb #( |
| 662 | .MEM_WORDS(MEM_WORDS) |
| 663 | ) soc_mem ( |
| 664 | .wb_clk_i(wb_clk_i), |
| 665 | .wb_rst_i(wb_rst_i), |
| 666 | |
| 667 | .wb_adr_i(cpu_adr_o), |
| 668 | .wb_dat_i(cpu_dat_o), |
| 669 | .wb_sel_i(cpu_sel_o), |
| 670 | .wb_we_i(cpu_we_o), |
| 671 | .wb_cyc_i(cpu_cyc_o), |
| 672 | |
| 673 | .wb_stb_i(mem_stb_i), |
| 674 | .wb_ack_o(mem_ack_o), |
| 675 | .wb_dat_o(mem_dat_o) |
| 676 | ); |
| 677 | |
| 678 | // Wishbone intercon logic |
| 679 | wb_intercon #( |
| 680 | .AW(ADR_WIDTH), |
| 681 | .DW(DAT_WIDTH), |
| 682 | .NS(NUM_SLAVES), |
| 683 | .ADR_MASK(ADR_MASK), |
| 684 | .SLAVE_ADR(SLAVE_ADR) |
| 685 | ) intercon ( |
| 686 | // Master Interface |
| 687 | .wbm_adr_i(cpu_adr_o), |
| 688 | .wbm_stb_i(cpu_stb_o), |
| 689 | .wbm_dat_o(cpu_dat_i), |
| 690 | .wbm_ack_o(cpu_ack_i), |
| 691 | |
| 692 | // Slaves Interface |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 693 | .wbs_stb_o({ xbar_stb_o, sys_stb_i, spimemio_cfg_stb_i, |
| 694 | mprj_stb_o, mprj_ctrl_stb_i, la_stb_i, |
| 695 | spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i, |
| 696 | gpio_stb_i, uart_stb_i, |
| 697 | spimemio_flash_stb_i, mem_stb_i }), |
| 698 | .wbs_dat_i({ xbar_dat_i, sys_dat_o, spimemio_cfg_dat_o, |
| 699 | mprj_dat_i, mprj_ctrl_dat_o, la_dat_o, |
| 700 | spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o, |
| 701 | gpio_dat_o, uart_dat_o, |
| 702 | spimemio_flash_dat_o, mem_dat_o }), |
| 703 | .wbs_ack_i({ xbar_ack_i, sys_ack_o, spimemio_cfg_ack_o, |
| 704 | mprj_ack_i, mprj_ctrl_ack_o, la_ack_o, |
| 705 | spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o, |
| 706 | gpio_ack_o, uart_ack_o, |
| 707 | spimemio_flash_ack_o, mem_ack_o }) |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 708 | ); |
| 709 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 710 | endmodule |
| 711 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 712 | // Implementation note: |
| 713 | // Replace the following two modules with wrappers for your SRAM cells. |
Tim Edwards | ef8312e | 2020-09-22 17:20:06 -0400 | [diff] [blame] | 714 | |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 715 | module mgmt_soc_regs ( |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 716 | input clk, wen, |
| 717 | input [5:0] waddr, |
| 718 | input [5:0] raddr1, |
| 719 | input [5:0] raddr2, |
| 720 | input [31:0] wdata, |
| 721 | output [31:0] rdata1, |
| 722 | output [31:0] rdata2 |
| 723 | ); |
| 724 | reg [31:0] regs [0:31]; |
| 725 | |
| 726 | always @(posedge clk) |
| 727 | if (wen) regs[waddr[4:0]] <= wdata; |
| 728 | |
| 729 | assign rdata1 = regs[raddr1[4:0]]; |
| 730 | assign rdata2 = regs[raddr2[4:0]]; |
| 731 | endmodule |