blob: 8d3e1f77974073c484f28234ecf30bfc7a005cfb [file] [log] [blame]
Matt Venn08cd6eb2020-11-16 12:01:14 +01001`default_nettype none
shalanfd13eb52020-08-21 16:48:07 +02002/*
3 * PicoSoC - A simple example SoC using PicoRV32
4 *
5 * Copyright (C) 2017 Clifford Wolf <clifford@clifford.at>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *
19 * Revision 1, July 2019: Added signals to drive flash_clk and flash_csb
20 * output enable (inverted), tied to reset so that the flash is completely
21 * isolated from the processor when the processor is in reset.
22 *
23 * Also: Made ram_wenb a 4-bit bus so that the memory access can be made
24 * byte-wide for byte-wide instructions.
25 */
26
27`ifdef PICORV32_V
Tim Edwards04ba17f2020-10-02 22:27:50 -040028`error "mgmt_soc.v must be read before picorv32.v!"
shalanfd13eb52020-08-21 16:48:07 +020029`endif
30
Tim Edwards04ba17f2020-10-02 22:27:50 -040031`define PICORV32_REGS mgmt_soc_regs
shalanfd13eb52020-08-21 16:48:07 +020032
33`include "picorv32.v"
34`include "spimemio.v"
35`include "simpleuart.v"
Tim Edwards04ba17f2020-10-02 22:27:50 -040036`include "simple_spi_master.v"
Tim Edwards7be29a22020-10-25 21:50:19 -040037`include "counter_timer_high.v"
38`include "counter_timer_low.v"
shalanfd13eb52020-08-21 16:48:07 +020039`include "wb_intercon.v"
40`include "mem_wb.v"
41`include "gpio_wb.v"
shalanfd13eb52020-08-21 16:48:07 +020042`include "sysctrl.v"
43`include "la_wb.v"
shalan0d14e6e2020-08-31 16:50:48 +020044`include "mprj_ctrl.v"
Tim Edwards04ba17f2020-10-02 22:27:50 -040045`include "convert_gpio_sigs.v"
shalanfd13eb52020-08-21 16:48:07 +020046
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020047module mgmt_soc (
Manar61dce922020-11-10 19:26:28 +020048`ifdef USE_POWER_PINS
shalanfd13eb52020-08-21 16:48:07 +020049 inout vdd1v8, /* 1.8V domain */
50 inout vss,
51`endif
shalanfd13eb52020-08-21 16:48:07 +020052 input clk,
53 input resetn,
54
Tim Edwards04ba17f2020-10-02 22:27:50 -040055 // 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
shalanfd13eb52020-08-21 16:48:07 +020065
66 // LA signals
Tim Edwards6d9739d2020-10-19 11:00:49 -040067 input [127:0] la_input, // From User Project to cpu
68 output [127:0] la_output, // From CPU to User Project
shalan0d14e6e2020-08-31 16:50:48 +020069 output [127:0] la_oen, // LA output enable (active low)
70
Tim Edwards6d9739d2020-10-19 11:00:49 -040071 // User Project I/O Configuration (serial load)
Tim Edwards05ad4fc2020-10-19 22:12:33 -040072 input mprj_vcc_pwrgood,
73 input mprj2_vcc_pwrgood,
74 input mprj_vdd_pwrgood,
75 input mprj2_vdd_pwrgood,
Tim Edwards04ba17f2020-10-02 22:27:50 -040076 output mprj_io_loader_resetn,
77 output mprj_io_loader_clock,
78 output mprj_io_loader_data,
shalanfd13eb52020-08-21 16:48:07 +020079
Tim Edwards6d9739d2020-10-19 11:00:49 -040080 // User Project pad data (when management SoC controls the pad)
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020081 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,
shalanfd13eb52020-08-21 16:48:07 +020084
85 // IRQ
shalanfd13eb52020-08-21 16:48:07 +020086 input irq_spi, // IRQ from standalone SPI
87
shalanfd13eb52020-08-21 16:48:07 +020088 // 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 Edwards04ba17f2020-10-02 22:27:50 -0400118 // 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 Edwards496a08a2020-10-26 15:44:51 -0400125 // State of JTAG and SDO pins (override for management output use)
126 output sdo_oenb_state,
127 output jtag_oenb_state,
Tim Edwards81153202020-10-09 19:57:04 -0400128 // SPI master->slave direct link
129 output hk_connect,
Tim Edwards32d05422020-10-19 19:43:52 -0400130 // User clock monitoring
131 input user_clk,
Tim Edwards81153202020-10-09 19:57:04 -0400132
Tim Edwards6d9739d2020-10-19 11:00:49 -0400133 // WB MI A (User project)
shalan0d14e6e2020-08-31 16:50:48 +0200134 input mprj_ack_i,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400135 input [31:0] mprj_dat_i,
shalan0d14e6e2020-08-31 16:50:48 +0200136 output mprj_cyc_o,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400137 output mprj_stb_o,
138 output mprj_we_o,
139 output [3:0] mprj_sel_o,
140 output [31:0] mprj_adr_o,
Manar55ec3692020-10-30 16:32:18 +0200141 output [31:0] mprj_dat_o,
142
143 // MGMT area R/W interface for mgmt RAM
Manarffe6cad2020-11-09 19:09:04 +0200144 output [`RAM_BLOCKS-1:0] mgmt_ena,
145 output [(`RAM_BLOCKS*4)-1:0] mgmt_wen_mask,
146 output [`RAM_BLOCKS-1:0] mgmt_wen,
Manar55ec3692020-10-30 16:32:18 +0200147 output [7:0] mgmt_addr,
148 output [31:0] mgmt_wdata,
Manarffe6cad2020-11-09 19:09:04 +0200149 input [(`RAM_BLOCKS*32)-1:0] mgmt_rdata,
Manar55ec3692020-10-30 16:32:18 +0200150
151 // MGMT area RO interface for user RAM
Manarffe6cad2020-11-09 19:09:04 +0200152 output mgmt_ena_ro,
153 output [7:0] mgmt_addr_ro,
154 input [31:0] mgmt_rdata_ro
shalanfd13eb52020-08-21 16:48:07 +0200155);
156 /* Memory reverted back to 256 words while memory has to be synthesized */
Manarec9b5362020-10-28 22:24:06 +0200157 parameter [31:0] STACKADDR = (4*(`MEM_WORDS)); // end of memory
shalanfd13eb52020-08-21 16:48:07 +0200158 parameter [31:0] PROGADDR_RESET = 32'h 1000_0000;
159 parameter [31:0] PROGADDR_IRQ = 32'h 0000_0000;
160
161 // Slaves Base Addresses
Tim Edwards04ba17f2020-10-02 22:27:50 -0400162 parameter RAM_BASE_ADR = 32'h 0000_0000;
Manarffe6cad2020-11-09 19:09:04 +0200163 parameter STORAGE_RW_ADR = 32'h 0100_0000;
164 parameter STORAGE_RO_ADR = 32'h 0200_0000;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400165 parameter FLASH_BASE_ADR = 32'h 1000_0000;
166 parameter UART_BASE_ADR = 32'h 2000_0000;
167 parameter GPIO_BASE_ADR = 32'h 2100_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400168 parameter COUNTER_TIMER0_BASE_ADR = 32'h 2200_0000;
169 parameter COUNTER_TIMER1_BASE_ADR = 32'h 2300_0000;
170 parameter SPI_MASTER_BASE_ADR = 32'h 2400_0000;
171 parameter LA_BASE_ADR = 32'h 2500_0000;
172 parameter MPRJ_CTRL_ADR = 32'h 2600_0000;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400173 parameter FLASH_CTRL_CFG = 32'h 2D00_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400174 parameter SYS_BASE_ADR = 32'h 2F00_0000;
175 parameter MPRJ_BASE_ADR = 32'h 3000_0000; // WB MI A
Manar55ec3692020-10-30 16:32:18 +0200176
shalanfd13eb52020-08-21 16:48:07 +0200177 // UART
178 parameter UART_CLK_DIV = 8'h00;
179 parameter UART_DATA = 8'h04;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400180
181 // SPI Master
182 parameter SPI_MASTER_CONFIG = 8'h00;
183 parameter SPI_MASTER_DATA = 8'h04;
184
185 // Counter-timer 0
186 parameter COUNTER_TIMER0_CONFIG = 8'h00;
187 parameter COUNTER_TIMER0_VALUE = 8'h04;
188 parameter COUNTER_TIMER0_DATA = 8'h08;
189
190 // Counter-timer 1
191 parameter COUNTER_TIMER1_CONFIG = 8'h00;
192 parameter COUNTER_TIMER1_VALUE = 8'h04;
193 parameter COUNTER_TIMER1_DATA = 8'h08;
shalanfd13eb52020-08-21 16:48:07 +0200194
195 // SOC GPIO
196 parameter GPIO_DATA = 8'h00;
197 parameter GPIO_ENA = 8'h04;
198 parameter GPIO_PU = 8'h08;
199 parameter GPIO_PD = 8'h0c;
200
shalan0d14e6e2020-08-31 16:50:48 +0200201 // LA
shalanfd13eb52020-08-21 16:48:07 +0200202 parameter LA_DATA_0 = 8'h00;
203 parameter LA_DATA_1 = 8'h04;
204 parameter LA_DATA_2 = 8'h08;
205 parameter LA_DATA_3 = 8'h0c;
206 parameter LA_ENA_0 = 8'h10;
207 parameter LA_ENA_1 = 8'h14;
208 parameter LA_ENA_2 = 8'h18;
209 parameter LA_ENA_3 = 8'h1c;
210
shalanfd13eb52020-08-21 16:48:07 +0200211 // System Control Registers
Tim Edwards32d05422020-10-19 19:43:52 -0400212 parameter PWRGOOD = 8'h00;
213 parameter CLK_OUT = 8'h04;
214 parameter TRAP_OUT = 8'h08;
215 parameter IRQ_SRC = 8'h0c;
shalanfd13eb52020-08-21 16:48:07 +0200216
Manar55ec3692020-10-30 16:32:18 +0200217 // Storage area RAM blocks
Manarffe6cad2020-11-09 19:09:04 +0200218 parameter [(`RAM_BLOCKS*24)-1:0] RW_BLOCKS_ADR = {
Manar55ec3692020-10-30 16:32:18 +0200219 {24'h 10_0000},
220 {24'h 00_0000}
221 };
222
Manarffe6cad2020-11-09 19:09:04 +0200223 parameter [23:0] RO_BLOCKS_ADR = {
Manar55ec3692020-10-30 16:32:18 +0200224 {24'h 00_0000}
225 };
226
shalanfd13eb52020-08-21 16:48:07 +0200227 // Wishbone Interconnect
228 localparam ADR_WIDTH = 32;
229 localparam DAT_WIDTH = 32;
Manar55ec3692020-10-30 16:32:18 +0200230 localparam NUM_SLAVES = 14;
shalanfd13eb52020-08-21 16:48:07 +0200231
232 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = {
shalanfd13eb52020-08-21 16:48:07 +0200233 {8'hFF, {ADR_WIDTH-8{1'b0}}},
234 {8'hFF, {ADR_WIDTH-8{1'b0}}},
235 {8'hFF, {ADR_WIDTH-8{1'b0}}},
236 {8'hFF, {ADR_WIDTH-8{1'b0}}},
237 {8'hFF, {ADR_WIDTH-8{1'b0}}},
238 {8'hFF, {ADR_WIDTH-8{1'b0}}},
239 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalan0d14e6e2020-08-31 16:50:48 +0200240 {8'hFF, {ADR_WIDTH-8{1'b0}}},
241 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400242 {8'hFF, {ADR_WIDTH-8{1'b0}}},
243 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Manar55ec3692020-10-30 16:32:18 +0200244 {8'hFF, {ADR_WIDTH-8{1'b0}}},
245 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalanfd13eb52020-08-21 16:48:07 +0200246 {8'hFF, {ADR_WIDTH-8{1'b0}}}
247 };
shalan0d14e6e2020-08-31 16:50:48 +0200248
shalanfd13eb52020-08-21 16:48:07 +0200249 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = {
shalanfd13eb52020-08-21 16:48:07 +0200250 {SYS_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200251 {FLASH_CTRL_CFG},
shalan0d14e6e2020-08-31 16:50:48 +0200252 {MPRJ_BASE_ADR},
253 {MPRJ_CTRL_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200254 {LA_BASE_ADR},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400255 {SPI_MASTER_BASE_ADR},
256 {COUNTER_TIMER1_BASE_ADR},
257 {COUNTER_TIMER0_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200258 {GPIO_BASE_ADR},
259 {UART_BASE_ADR},
260 {FLASH_BASE_ADR},
Manarffe6cad2020-11-09 19:09:04 +0200261 {STORAGE_RO_ADR},
262 {STORAGE_RW_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200263 {RAM_BASE_ADR}
264 };
265
Tim Edwardsca2f3182020-10-06 10:05:11 -0400266 // The following functions are connected to specific user project
267 // area pins, when under control of the management area (during
268 // startup, and when not otherwise programmed for the user project).
269
270 // JTAG = jtag_out (inout)
271 // SDO = sdo_out (output) (shared with SPI master)
272 // SDI = mgmt_in_data[2] (input) (shared with SPI master)
273 // CSB = mgmt_in_data[3] (input) (shared with SPI master)
274 // SCK = mgmt_in_data[4] (input) (shared with SPI master)
275 // ser_rx = mgmt_in_data[5] (input)
276 // ser_tx = mgmt_out_data[6] (output)
277 // irq_pin = mgmt_in_data[7] (input)
278 // flash_csb = mgmt_out_data[8] (output) (user area flash)
279 // flash_sck = mgmt_out_data[9] (output) (user area flash)
280 // flash_io0 = mgmt_in/out_data[10] (input) (user area flash)
281 // flash_io1 = mgmt_in/out_data[11] (output) (user area flash)
Tim Edwards32d05422020-10-19 19:43:52 -0400282 // irq2_pin = mgmt_in_data[12] (input)
283 // trap_mon = mgmt_in_data[13] (output)
284 // clk1_mon = mgmt_in_data[14] (output)
285 // clk2_mon = mgmt_in_data[15] (output)
Tim Edwardsca2f3182020-10-06 10:05:11 -0400286
287 // OEB lines for [0] and [1] are the only ones connected directly to
288 // the pad. All others have OEB controlled by the configuration bit
289 // in the control block.
290
shalanfd13eb52020-08-21 16:48:07 +0200291 // memory-mapped I/O control registers
Tim Edwards04ba17f2020-10-02 22:27:50 -0400292 wire gpio_pullup; // Intermediate GPIO pullup
293 wire gpio_pulldown; // Intermediate GPIO pulldown
294 wire gpio_outenb; // Intermediate GPIO out enable (bar)
295 wire gpio_out; // Intermediate GPIO output
shalanfd13eb52020-08-21 16:48:07 +0200296
Tim Edwardsef8312e2020-09-22 17:20:06 -0400297 wire trap_output_dest; // Trap signal output destination
Tim Edwards32d05422020-10-19 19:43:52 -0400298 wire clk1_output_dest; // Core clock1 signal output destination
299 wire clk2_output_dest; // Core clock2 signal output destination
Tim Edwardsef8312e2020-09-22 17:20:06 -0400300 wire irq_7_inputsrc; // IRQ 7 source
Tim Edwards32d05422020-10-19 19:43:52 -0400301 wire irq_8_inputsrc; // IRQ 8 source
shalanfd13eb52020-08-21 16:48:07 +0200302
Tim Edwardsef8312e2020-09-22 17:20:06 -0400303 // Convert GPIO signals to sky130_fd_io pad signals
Tim Edwards04ba17f2020-10-02 22:27:50 -0400304 convert_gpio_sigs convert_gpio_bit (
shalanfd13eb52020-08-21 16:48:07 +0200305 .gpio_out(gpio_out),
306 .gpio_outenb(gpio_outenb),
307 .gpio_pu(gpio_pullup),
308 .gpio_pd(gpio_pulldown),
309 .gpio_out_pad(gpio_out_pad),
310 .gpio_outenb_pad(gpio_outenb_pad),
311 .gpio_inenb_pad(gpio_inenb_pad),
312 .gpio_mode1_pad(gpio_mode1_pad),
313 .gpio_mode0_pad(gpio_mode0_pad)
314 );
315
316 reg [31:0] irq;
317 wire irq_7;
Tim Edwards32d05422020-10-19 19:43:52 -0400318 wire irq_8;
shalanfd13eb52020-08-21 16:48:07 +0200319 wire irq_stall;
320 wire irq_uart;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400321 wire irq_spi_master;
322 wire irq_counter_timer0;
323 wire irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200324
shalanfd13eb52020-08-21 16:48:07 +0200325 assign irq_stall = 0;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400326 assign irq_7 = (irq_7_inputsrc == 1'b1) ? mgmt_in_data[7] : 1'b0;
Tim Edwards32d05422020-10-19 19:43:52 -0400327 assign irq_8 = (irq_8_inputsrc == 1'b1) ? mgmt_in_data[12] : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200328
329 always @* begin
330 irq = 0;
331 irq[3] = irq_stall;
332 irq[4] = irq_uart;
shalanfd13eb52020-08-21 16:48:07 +0200333 irq[6] = irq_spi;
334 irq[7] = irq_7;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400335 irq[9] = irq_spi_master;
336 irq[10] = irq_counter_timer0;
337 irq[11] = irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200338 end
339
Tim Edwards3245e2f2020-10-10 14:02:11 -0400340 // Assumption : no syscon module and wb_clk is the clock coming from the
341 // caravel_clocking module
342
shalanfd13eb52020-08-21 16:48:07 +0200343 assign wb_clk_i = clk;
344 assign wb_rst_i = ~resetn; // Redundant
345
346 // Wishbone Master
347 wire [31:0] cpu_adr_o;
348 wire [31:0] cpu_dat_i;
349 wire [3:0] cpu_sel_o;
350 wire cpu_we_o;
351 wire cpu_cyc_o;
352 wire cpu_stb_o;
353 wire [31:0] cpu_dat_o;
354 wire cpu_ack_i;
shalanfd13eb52020-08-21 16:48:07 +0200355
356 picorv32_wb #(
357 .STACKADDR(STACKADDR),
358 .PROGADDR_RESET(PROGADDR_RESET),
359 .PROGADDR_IRQ(PROGADDR_IRQ),
360 .BARREL_SHIFTER(1),
361 .COMPRESSED_ISA(1),
362 .ENABLE_MUL(1),
363 .ENABLE_DIV(1),
364 .ENABLE_IRQ(1),
365 .ENABLE_IRQ_QREGS(0)
366 ) cpu (
367 .wb_clk_i (wb_clk_i),
368 .wb_rst_i (wb_rst_i),
369 .trap (trap),
370 .irq (irq),
371 .mem_instr(mem_instr),
372 .wbm_adr_o(cpu_adr_o),
373 .wbm_dat_i(cpu_dat_i),
374 .wbm_stb_o(cpu_stb_o),
375 .wbm_ack_i(cpu_ack_i),
376 .wbm_cyc_o(cpu_cyc_o),
377 .wbm_dat_o(cpu_dat_o),
378 .wbm_we_o(cpu_we_o),
379 .wbm_sel_o(cpu_sel_o)
380 );
381
382 // Wishbone Slave SPIMEMIO
383 wire spimemio_flash_stb_i;
384 wire spimemio_flash_ack_o;
385 wire [31:0] spimemio_flash_dat_o;
386
387 wire spimemio_cfg_stb_i;
388 wire spimemio_cfg_ack_o;
389 wire [31:0] spimemio_cfg_dat_o;
390
391 spimemio_wb spimemio (
392 .wb_clk_i(wb_clk_i),
393 .wb_rst_i(wb_rst_i),
394
395 .wb_adr_i(cpu_adr_o),
396 .wb_dat_i(cpu_dat_o),
397 .wb_sel_i(cpu_sel_o),
398 .wb_we_i(cpu_we_o),
399 .wb_cyc_i(cpu_cyc_o),
400
401 // FLash Slave
402 .wb_flash_stb_i(spimemio_flash_stb_i),
403 .wb_flash_ack_o(spimemio_flash_ack_o),
404 .wb_flash_dat_o(spimemio_flash_dat_o),
405
406 // Config Register Slave
407 .wb_cfg_stb_i(spimemio_cfg_stb_i),
408 .wb_cfg_ack_o(spimemio_cfg_ack_o),
409 .wb_cfg_dat_o(spimemio_cfg_dat_o),
410
Tim Edwards04ba17f2020-10-02 22:27:50 -0400411 .pass_thru(pass_thru_mgmt),
412 .pass_thru_csb(pass_thru_mgmt_csb),
413 .pass_thru_sck(pass_thru_mgmt_sck),
414 .pass_thru_sdi(pass_thru_mgmt_sdi),
415 .pass_thru_sdo(pass_thru_mgmt_sdo),
416
shalanfd13eb52020-08-21 16:48:07 +0200417 .flash_csb (flash_csb),
418 .flash_clk (flash_clk),
419
420 .flash_csb_oeb (flash_csb_oeb),
421 .flash_clk_oeb (flash_clk_oeb),
422
423 .flash_io0_oeb (flash_io0_oeb),
424 .flash_io1_oeb (flash_io1_oeb),
425 .flash_io2_oeb (flash_io2_oeb),
426 .flash_io3_oeb (flash_io3_oeb),
427
428 .flash_csb_ieb (flash_csb_ieb),
429 .flash_clk_ieb (flash_clk_ieb),
430
431 .flash_io0_ieb (flash_io0_ieb),
432 .flash_io1_ieb (flash_io1_ieb),
433 .flash_io2_ieb (flash_io2_ieb),
434 .flash_io3_ieb (flash_io3_ieb),
435
436 .flash_io0_do (flash_io0_do),
437 .flash_io1_do (flash_io1_do),
438 .flash_io2_do (flash_io2_do),
439 .flash_io3_do (flash_io3_do),
440
441 .flash_io0_di (flash_io0_di),
442 .flash_io1_di (flash_io1_di),
443 .flash_io2_di (flash_io2_di),
444 .flash_io3_di (flash_io3_di)
445 );
446
447 // Wishbone Slave uart
448 wire uart_stb_i;
449 wire uart_ack_o;
450 wire [31:0] uart_dat_o;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400451 wire uart_enabled;
shalanfd13eb52020-08-21 16:48:07 +0200452
453 simpleuart_wb #(
454 .BASE_ADR(UART_BASE_ADR),
455 .CLK_DIV(UART_CLK_DIV),
456 .DATA(UART_DATA)
457 ) simpleuart (
458 // Wishbone Interface
459 .wb_clk_i(wb_clk_i),
460 .wb_rst_i(wb_rst_i),
461
462 .wb_adr_i(cpu_adr_o),
463 .wb_dat_i(cpu_dat_o),
464 .wb_sel_i(cpu_sel_o),
465 .wb_we_i(cpu_we_o),
466 .wb_cyc_i(cpu_cyc_o),
467
468 .wb_stb_i(uart_stb_i),
469 .wb_ack_o(uart_ack_o),
470 .wb_dat_o(uart_dat_o),
471
Tim Edwardsca2f3182020-10-06 10:05:11 -0400472 .uart_enabled(uart_enabled),
shalanfd13eb52020-08-21 16:48:07 +0200473 .ser_tx(ser_tx),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400474 .ser_rx(mgmt_in_data[5])
shalanfd13eb52020-08-21 16:48:07 +0200475 );
476
Tim Edwards04ba17f2020-10-02 22:27:50 -0400477 // Wishbone SPI master
478 wire spi_master_stb_i;
479 wire spi_master_ack_o;
480 wire [31:0] spi_master_dat_o;
481
482 simple_spi_master_wb #(
483 .BASE_ADR(SPI_MASTER_BASE_ADR),
484 .CONFIG(SPI_MASTER_CONFIG),
485 .DATA(SPI_MASTER_DATA)
486 ) simple_spi_master_inst (
487 // Wishbone Interface
488 .wb_clk_i(wb_clk_i),
489 .wb_rst_i(wb_rst_i),
490
491 .wb_adr_i(cpu_adr_o),
492 .wb_dat_i(cpu_dat_o),
493 .wb_sel_i(cpu_sel_o),
494 .wb_we_i(cpu_we_o),
495 .wb_cyc_i(cpu_cyc_o),
496
497 .wb_stb_i(spi_master_stb_i),
498 .wb_ack_o(spi_master_ack_o),
499 .wb_dat_o(spi_master_dat_o),
500
Tim Edwards81153202020-10-09 19:57:04 -0400501 .hk_connect(hk_connect),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400502 .csb(mgmt_out_pre[3]),
503 .sck(mgmt_out_pre[4]),
504 .sdi(mgmt_in_data[1]),
505 .sdo(mgmt_out_pre[2]),
506 .sdoenb(),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400507 .irq(irq_spi_master)
508 );
509
Tim Edwards7be29a22020-10-25 21:50:19 -0400510 wire counter_timer_strobe, counter_timer_offset;
511 wire counter_timer0_enable, counter_timer1_enable;
512 wire counter_timer0_stop, counter_timer1_stop;
Tim Edwards32d05422020-10-19 19:43:52 -0400513
Tim Edwards04ba17f2020-10-02 22:27:50 -0400514 // Wishbone Counter-timer 0
515 wire counter_timer0_stb_i;
516 wire counter_timer0_ack_o;
517 wire [31:0] counter_timer0_dat_o;
518
Tim Edwards7be29a22020-10-25 21:50:19 -0400519 counter_timer_low_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400520 .BASE_ADR(COUNTER_TIMER0_BASE_ADR),
521 .CONFIG(COUNTER_TIMER0_CONFIG),
522 .VALUE(COUNTER_TIMER0_VALUE),
523 .DATA(COUNTER_TIMER0_DATA)
524 ) counter_timer_0 (
525 // Wishbone Interface
526 .wb_clk_i(wb_clk_i),
527 .wb_rst_i(wb_rst_i),
528
529 .wb_adr_i(cpu_adr_o),
530 .wb_dat_i(cpu_dat_o),
531 .wb_sel_i(cpu_sel_o),
532 .wb_we_i(cpu_we_o),
533 .wb_cyc_i(cpu_cyc_o),
534
535 .wb_stb_i(counter_timer0_stb_i),
536 .wb_ack_o(counter_timer0_ack_o),
537 .wb_dat_o(counter_timer0_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400538
539 .enable_in(counter_timer1_enable),
540 .stop_in(counter_timer1_stop),
541 .strobe(counter_timer_strobe),
542 .is_offset(counter_timer_offset),
543 .enable_out(counter_timer0_enable),
544 .stop_out(counter_timer0_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400545 .irq(irq_counter_timer0)
546 );
547
548 // Wishbone Counter-timer 1
549 wire counter_timer1_stb_i;
550 wire counter_timer1_ack_o;
551 wire [31:0] counter_timer1_dat_o;
552
Tim Edwards7be29a22020-10-25 21:50:19 -0400553 counter_timer_high_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400554 .BASE_ADR(COUNTER_TIMER1_BASE_ADR),
555 .CONFIG(COUNTER_TIMER1_CONFIG),
556 .VALUE(COUNTER_TIMER1_VALUE),
557 .DATA(COUNTER_TIMER1_DATA)
558 ) counter_timer_1 (
559 // Wishbone Interface
560 .wb_clk_i(wb_clk_i),
561 .wb_rst_i(wb_rst_i),
562
563 .wb_adr_i(cpu_adr_o),
564 .wb_dat_i(cpu_dat_o),
565 .wb_sel_i(cpu_sel_o),
566 .wb_we_i(cpu_we_o),
567 .wb_cyc_i(cpu_cyc_o),
568
569 .wb_stb_i(counter_timer1_stb_i),
570 .wb_ack_o(counter_timer1_ack_o),
571 .wb_dat_o(counter_timer1_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400572
573 .enable_in(counter_timer0_enable),
574 .strobe(counter_timer_strobe),
575 .stop_in(counter_timer0_stop),
576 .is_offset(counter_timer_offset),
577 .enable_out(counter_timer1_enable),
578 .stop_out(counter_timer1_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400579 .irq(irq_counter_timer1)
580 );
581
shalanfd13eb52020-08-21 16:48:07 +0200582 // Wishbone Slave GPIO Registers
583 wire gpio_stb_i;
584 wire gpio_ack_o;
585 wire [31:0] gpio_dat_o;
586
587 gpio_wb #(
588 .BASE_ADR(GPIO_BASE_ADR),
589 .GPIO_DATA(GPIO_DATA),
590 .GPIO_ENA(GPIO_ENA),
591 .GPIO_PD(GPIO_PD),
592 .GPIO_PU(GPIO_PU)
593 ) gpio_wb (
594 .wb_clk_i(wb_clk_i),
595 .wb_rst_i(wb_rst_i),
shalanfd13eb52020-08-21 16:48:07 +0200596 .wb_adr_i(cpu_adr_o),
597 .wb_dat_i(cpu_dat_o),
598 .wb_sel_i(cpu_sel_o),
599 .wb_we_i(cpu_we_o),
600 .wb_cyc_i(cpu_cyc_o),
shalanfd13eb52020-08-21 16:48:07 +0200601 .wb_stb_i(gpio_stb_i),
602 .wb_ack_o(gpio_ack_o),
603 .wb_dat_o(gpio_dat_o),
604 .gpio_in_pad(gpio_in_pad),
Tim Edwards32d05422020-10-19 19:43:52 -0400605 .gpio(gpio_out),
606 .gpio_oeb(gpio_outenb),
607 .gpio_pu(gpio_pullup),
608 .gpio_pd(gpio_pulldown)
shalanfd13eb52020-08-21 16:48:07 +0200609 );
610
shalanfd13eb52020-08-21 16:48:07 +0200611 // Wishbone Slave System Control Register
612 wire sys_stb_i;
613 wire sys_ack_o;
614 wire [31:0] sys_dat_o;
615
616 sysctrl_wb #(
617 .BASE_ADR(SYS_BASE_ADR),
Tim Edwards32d05422020-10-19 19:43:52 -0400618 .PWRGOOD(PWRGOOD),
619 .CLK_OUT(CLK_OUT),
shalanfd13eb52020-08-21 16:48:07 +0200620 .TRAP_OUT(TRAP_OUT),
Tim Edwards32d05422020-10-19 19:43:52 -0400621 .IRQ_SRC(IRQ_SRC)
shalanfd13eb52020-08-21 16:48:07 +0200622 ) sysctrl (
623 .wb_clk_i(wb_clk_i),
624 .wb_rst_i(wb_rst_i),
625
626 .wb_adr_i(cpu_adr_o),
627 .wb_dat_i(cpu_dat_o),
628 .wb_sel_i(cpu_sel_o),
629 .wb_we_i(cpu_we_o),
630 .wb_cyc_i(cpu_cyc_o),
631
632 .wb_stb_i(sys_stb_i),
633 .wb_ack_o(sys_ack_o),
634 .wb_dat_o(sys_dat_o),
635
Tim Edwards05ad4fc2020-10-19 22:12:33 -0400636 .usr1_vcc_pwrgood(mprj_vcc_pwrgood),
637 .usr2_vcc_pwrgood(mprj2_vcc_pwrgood),
638 .usr1_vdd_pwrgood(mprj_vdd_pwrgood),
639 .usr2_vdd_pwrgood(mprj2_vdd_pwrgood),
shalanfd13eb52020-08-21 16:48:07 +0200640 .trap_output_dest(trap_output_dest),
Tim Edwards32d05422020-10-19 19:43:52 -0400641 .clk1_output_dest(clk1_output_dest),
642 .clk2_output_dest(clk2_output_dest),
643 .irq_7_inputsrc(irq_7_inputsrc),
644 .irq_8_inputsrc(irq_8_inputsrc)
shalanfd13eb52020-08-21 16:48:07 +0200645 );
646
647 // Logic Analyzer
648 wire la_stb_i;
649 wire la_ack_o;
650 wire [31:0] la_dat_o;
651
652 la_wb #(
653 .BASE_ADR(LA_BASE_ADR),
654 .LA_DATA_0(LA_DATA_0),
655 .LA_DATA_1(LA_DATA_1),
656 .LA_DATA_3(LA_DATA_3),
657 .LA_ENA_0(LA_ENA_0),
658 .LA_ENA_1(LA_ENA_1),
659 .LA_ENA_2(LA_ENA_2),
660 .LA_ENA_3(LA_ENA_3)
661 ) la (
662 .wb_clk_i(wb_clk_i),
663 .wb_rst_i(wb_rst_i),
664
665 .wb_adr_i(cpu_adr_o),
666 .wb_dat_i(cpu_dat_o),
667 .wb_sel_i(cpu_sel_o),
668 .wb_we_i(cpu_we_o),
669 .wb_cyc_i(cpu_cyc_o),
670
671 .wb_stb_i(la_stb_i),
672 .wb_ack_o(la_ack_o),
673 .wb_dat_o(la_dat_o),
674
675 .la_data(la_output),
shalan0d14e6e2020-08-31 16:50:48 +0200676 .la_data_in(la_input),
677 .la_oen(la_oen)
shalanfd13eb52020-08-21 16:48:07 +0200678 );
679
Manarcd4cff72020-11-04 16:22:59 +0200680 // User project WB MI A port
681 assign mprj_cyc_o = cpu_cyc_o;
682 assign mprj_we_o = cpu_we_o;
683 assign mprj_sel_o = cpu_sel_o;
684 assign mprj_adr_o = cpu_adr_o;
685 assign mprj_dat_o = cpu_dat_o;
686
Tim Edwards6d9739d2020-10-19 11:00:49 -0400687 // WB Slave User Project Control
shalan0d14e6e2020-08-31 16:50:48 +0200688 wire mprj_ctrl_stb_i;
689 wire mprj_ctrl_ack_o;
690 wire [31:0] mprj_ctrl_dat_o;
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200691 wire [`MPRJ_IO_PADS-1:0] mgmt_out_pre;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400692
693 // Bits assigned to specific functions as outputs prevent the
694 // mprj GPIO-as-output from applying data when that function
695 // is active
696
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200697 assign mgmt_out_data[`MPRJ_IO_PADS-1:16] = mgmt_out_pre[`MPRJ_IO_PADS-1:16];
Tim Edwards32d05422020-10-19 19:43:52 -0400698
699 // Routing of output monitors (PLL, trap, clk1, clk2)
700 assign mgmt_out_data[15] = clk2_output_dest ? user_clk : mgmt_out_pre[15];
701 assign mgmt_out_data[14] = clk1_output_dest ? clk : mgmt_out_pre[14];
702 assign mgmt_out_data[13] = trap_output_dest ? trap : mgmt_out_pre[13];
703
704 assign mgmt_out_data[12:7] = mgmt_out_pre[12:7];
Tim Edwardsca2f3182020-10-06 10:05:11 -0400705 assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6];
706 assign mgmt_out_data[5:0] = mgmt_out_pre[5:0];
shalan0d14e6e2020-08-31 16:50:48 +0200707
708 mprj_ctrl_wb #(
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200709 .BASE_ADR(MPRJ_CTRL_ADR)
shalan0d14e6e2020-08-31 16:50:48 +0200710 ) mprj_ctrl (
711 .wb_clk_i(wb_clk_i),
712 .wb_rst_i(wb_rst_i),
713
714 .wb_adr_i(cpu_adr_o),
715 .wb_dat_i(cpu_dat_o),
716 .wb_sel_i(cpu_sel_o),
717 .wb_we_i(cpu_we_o),
718 .wb_cyc_i(cpu_cyc_o),
719 .wb_stb_i(mprj_ctrl_stb_i),
720 .wb_ack_o(mprj_ctrl_ack_o),
721 .wb_dat_o(mprj_ctrl_dat_o),
722
Tim Edwards04ba17f2020-10-02 22:27:50 -0400723 .serial_clock(mprj_io_loader_clock),
724 .serial_resetn(mprj_io_loader_resetn),
725 .serial_data_out(mprj_io_loader_data),
Tim Edwards496a08a2020-10-26 15:44:51 -0400726 .sdo_oenb_state(sdo_oenb_state),
727 .jtag_oenb_state(jtag_oenb_state),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400728 .mgmt_gpio_out(mgmt_out_pre),
Tim Edwardsba328902020-10-27 15:03:22 -0400729 .mgmt_gpio_in(mgmt_in_data),
730 .pwr_ctrl_out(pwr_ctrl_out)
shalan0d14e6e2020-08-31 16:50:48 +0200731 );
732
shalanfd13eb52020-08-21 16:48:07 +0200733 // Wishbone Slave RAM
734 wire mem_stb_i;
735 wire mem_ack_o;
736 wire [31:0] mem_dat_o;
737
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200738 mem_wb soc_mem (
Manar61dce922020-11-10 19:26:28 +0200739 `ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +0200740 .VPWR(vdd1v8),
741 .VGND(vss),
742 `endif
shalanfd13eb52020-08-21 16:48:07 +0200743 .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
Manarffe6cad2020-11-09 19:09:04 +0200757 wire stg_rw_stb_i;
758 wire stg_ro_stb_i;
759 wire stg_rw_ack_o;
760 wire stg_ro_ack_o;
761 wire [31:0] stg_rw_dat_o;
762 wire [31:0] stg_ro_dat_o;
Manar55ec3692020-10-30 16:32:18 +0200763
764 // Storage area wishbone brige
765 storage_bridge_wb #(
Manarffe6cad2020-11-09 19:09:04 +0200766 .RW_BLOCKS_ADR(RW_BLOCKS_ADR),
767 .RO_BLOCKS_ADR(RO_BLOCKS_ADR)
Manar55ec3692020-10-30 16:32:18 +0200768 ) wb_bridge (
769 .wb_clk_i(wb_clk_i),
770 .wb_rst_i(wb_rst_i),
Manar55ec3692020-10-30 16:32:18 +0200771 .wb_adr_i(cpu_adr_o),
772 .wb_dat_i(cpu_dat_o),
773 .wb_sel_i(cpu_sel_o),
774 .wb_we_i(cpu_we_o),
775 .wb_cyc_i(cpu_cyc_o),
Manarffe6cad2020-11-09 19:09:04 +0200776 .wb_stb_i({stg_ro_stb_i, stg_rw_stb_i}),
777 .wb_ack_o({stg_ro_ack_o, stg_rw_ack_o}),
778 .wb_rw_dat_o(stg_rw_dat_o),
Manar55ec3692020-10-30 16:32:18 +0200779 // MGMT_AREA RO WB Interface
Manarffe6cad2020-11-09 19:09:04 +0200780 .wb_ro_dat_o(stg_ro_dat_o),
Manar55ec3692020-10-30 16:32:18 +0200781 // MGMT Area native memory interface
782 .mgmt_ena(mgmt_ena),
783 .mgmt_wen_mask(mgmt_wen_mask),
784 .mgmt_wen(mgmt_wen),
785 .mgmt_addr(mgmt_addr),
786 .mgmt_wdata(mgmt_wdata),
787 .mgmt_rdata(mgmt_rdata),
Manar55ec3692020-10-30 16:32:18 +0200788 // MGMT_AREA RO interface
Manarffe6cad2020-11-09 19:09:04 +0200789 .mgmt_ena_ro(mgmt_ena_ro),
790 .mgmt_addr_ro(mgmt_addr_ro),
791 .mgmt_rdata_ro(mgmt_rdata_ro)
Manar55ec3692020-10-30 16:32:18 +0200792 );
793
shalanfd13eb52020-08-21 16:48:07 +0200794 // Wishbone intercon logic
795 wb_intercon #(
796 .AW(ADR_WIDTH),
797 .DW(DAT_WIDTH),
798 .NS(NUM_SLAVES),
799 .ADR_MASK(ADR_MASK),
800 .SLAVE_ADR(SLAVE_ADR)
801 ) intercon (
802 // Master Interface
803 .wbm_adr_i(cpu_adr_o),
804 .wbm_stb_i(cpu_stb_o),
805 .wbm_dat_o(cpu_dat_i),
806 .wbm_ack_o(cpu_ack_i),
807
808 // Slaves Interface
Manar98a7adc2020-10-19 23:21:36 +0200809 .wbs_stb_o({ sys_stb_i, spimemio_cfg_stb_i,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400810 mprj_stb_o, mprj_ctrl_stb_i, la_stb_i,
811 spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i,
812 gpio_stb_i, uart_stb_i,
Manarffe6cad2020-11-09 19:09:04 +0200813 spimemio_flash_stb_i, stg_ro_stb_i, stg_rw_stb_i, mem_stb_i }),
Manar98a7adc2020-10-19 23:21:36 +0200814 .wbs_dat_i({ sys_dat_o, spimemio_cfg_dat_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400815 mprj_dat_i, mprj_ctrl_dat_o, la_dat_o,
816 spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o,
817 gpio_dat_o, uart_dat_o,
Manarffe6cad2020-11-09 19:09:04 +0200818 spimemio_flash_dat_o, stg_ro_dat_o ,stg_rw_dat_o, mem_dat_o }),
Manar98a7adc2020-10-19 23:21:36 +0200819 .wbs_ack_i({ sys_ack_o, spimemio_cfg_ack_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400820 mprj_ack_i, mprj_ctrl_ack_o, la_ack_o,
821 spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o,
822 gpio_ack_o, uart_ack_o,
Manarffe6cad2020-11-09 19:09:04 +0200823 spimemio_flash_ack_o, stg_ro_ack_o, stg_rw_ack_o, mem_ack_o })
shalanfd13eb52020-08-21 16:48:07 +0200824 );
825
shalanfd13eb52020-08-21 16:48:07 +0200826endmodule
827
shalanfd13eb52020-08-21 16:48:07 +0200828// Implementation note:
829// Replace the following two modules with wrappers for your SRAM cells.
Tim Edwardsef8312e2020-09-22 17:20:06 -0400830
Tim Edwards04ba17f2020-10-02 22:27:50 -0400831module mgmt_soc_regs (
shalanfd13eb52020-08-21 16:48:07 +0200832 input clk, wen,
833 input [5:0] waddr,
834 input [5:0] raddr1,
835 input [5:0] raddr2,
836 input [31:0] wdata,
837 output [31:0] rdata1,
838 output [31:0] rdata2
839);
840 reg [31:0] regs [0:31];
841
842 always @(posedge clk)
843 if (wen) regs[waddr[4:0]] <= wdata;
844
845 assign rdata1 = regs[raddr1[4:0]];
846 assign rdata2 = regs[raddr2[4:0]];
847endmodule