blob: f6cf0f6e22a44b6445b895854eeb8dfadb49df53 [file] [log] [blame]
shalanfd13eb52020-08-21 16:48:07 +02001/*
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 Edwards04ba17f2020-10-02 22:27:50 -040027`error "mgmt_soc.v must be read before picorv32.v!"
shalanfd13eb52020-08-21 16:48:07 +020028`endif
29
Tim Edwards04ba17f2020-10-02 22:27:50 -040030`define PICORV32_REGS mgmt_soc_regs
shalanfd13eb52020-08-21 16:48:07 +020031
32`include "picorv32.v"
33`include "spimemio.v"
34`include "simpleuart.v"
Tim Edwards04ba17f2020-10-02 22:27:50 -040035`include "simple_spi_master.v"
36`include "counter_timer.v"
shalanfd13eb52020-08-21 16:48:07 +020037`include "wb_intercon.v"
38`include "mem_wb.v"
39`include "gpio_wb.v"
shalanfd13eb52020-08-21 16:48:07 +020040`include "sysctrl.v"
41`include "la_wb.v"
shalan0d14e6e2020-08-31 16:50:48 +020042`include "mprj_ctrl.v"
Tim Edwards04ba17f2020-10-02 22:27:50 -040043`include "convert_gpio_sigs.v"
shalanfd13eb52020-08-21 16:48:07 +020044
Tim Edwards9eda80d2020-10-08 21:36:44 -040045module mgmt_soc #(
46 parameter MPRJ_IO_PADS = 32,
47 parameter MPRJ_PWR_PADS = 32
48) (
shalanfd13eb52020-08-21 16:48:07 +020049`ifdef LVS
50 inout vdd1v8, /* 1.8V domain */
51 inout vss,
52`endif
53 input pll_clk,
54 input ext_clk,
55 input ext_clk_sel,
56
57 input clk,
58 input resetn,
59
Tim Edwards04ba17f2020-10-02 22:27:50 -040060 // Trap state from CPU
61 output trap,
62
63 // GPIO (one pin)
64 output gpio_out_pad, // Connect to out on gpio pad
65 input gpio_in_pad, // Connect to in on gpio pad
66 output gpio_mode0_pad, // Connect to dm[0] on gpio pad
67 output gpio_mode1_pad, // Connect to dm[2] on gpio pad
68 output gpio_outenb_pad, // Connect to oe_n on gpio pad
69 output gpio_inenb_pad, // Connect to inp_dis on gpio pad
shalanfd13eb52020-08-21 16:48:07 +020070
71 // LA signals
72 input [127:0] la_input, // From Mega-Project to cpu
73 output [127:0] la_output, // From CPU to Mega-Project
shalan0d14e6e2020-08-31 16:50:48 +020074 output [127:0] la_oen, // LA output enable (active low)
75
Tim Edwards04ba17f2020-10-02 22:27:50 -040076 // Mega-Project I/O Configuration (serial load)
77 output mprj_io_loader_resetn,
78 output mprj_io_loader_clock,
79 output mprj_io_loader_data,
shalanfd13eb52020-08-21 16:48:07 +020080
Tim Edwards04ba17f2020-10-02 22:27:50 -040081 // Mega-Project pad data (when management SoC controls the pad)
Tim Edwards44bab472020-10-04 22:09:54 -040082 input [MPRJ_IO_PADS-1:0] mgmt_in_data,
83 output [MPRJ_IO_PADS-1:0] mgmt_out_data,
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
shalan0d14e6e2020-08-31 16:50:48 +0200125 // WB MI A (Mega project)
126 input mprj_ack_i,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400127 input [31:0] mprj_dat_i,
shalan0d14e6e2020-08-31 16:50:48 +0200128 output mprj_cyc_o,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400129 output mprj_stb_o,
130 output mprj_we_o,
131 output [3:0] mprj_sel_o,
132 output [31:0] mprj_adr_o,
133 output [31:0] mprj_dat_o,
shalan0d14e6e2020-08-31 16:50:48 +0200134
135 // WB MI B (xbar)
shalanfd13eb52020-08-21 16:48:07 +0200136 input [31:0] xbar_dat_i,
137 input xbar_ack_i,
138 output xbar_cyc_o,
139 output xbar_stb_o,
140 output xbar_we_o,
141 output [3:0] xbar_sel_o,
142 output [31:0] xbar_adr_o,
143 output [31:0] xbar_dat_o
144);
145 /* Memory reverted back to 256 words while memory has to be synthesized */
shalan0d14e6e2020-08-31 16:50:48 +0200146 parameter integer MEM_WORDS = 8192;
shalanfd13eb52020-08-21 16:48:07 +0200147 parameter [31:0] STACKADDR = (4*MEM_WORDS); // end of memory
148 parameter [31:0] PROGADDR_RESET = 32'h 1000_0000;
149 parameter [31:0] PROGADDR_IRQ = 32'h 0000_0000;
150
151 // Slaves Base Addresses
Tim Edwards04ba17f2020-10-02 22:27:50 -0400152 parameter RAM_BASE_ADR = 32'h 0000_0000;
153 parameter FLASH_BASE_ADR = 32'h 1000_0000;
154 parameter UART_BASE_ADR = 32'h 2000_0000;
155 parameter GPIO_BASE_ADR = 32'h 2100_0000;
156 parameter COUNTER_TIMER0_BASE_ADR = 32'h 2110_0000;
157 parameter COUNTER_TIMER1_BASE_ADR = 32'h 2120_0000;
158 parameter SPI_MASTER_BASE_ADR = 32'h 2130_0000;
159 parameter LA_BASE_ADR = 32'h 2200_0000;
160 parameter MPRJ_CTRL_ADR = 32'h 2300_0000;
161 parameter MPRJ_BASE_ADR = 32'h 3000_0000; // WB MI A
162 parameter SYS_BASE_ADR = 32'h 2F00_0000;
163 parameter FLASH_CTRL_CFG = 32'h 2D00_0000;
164 parameter XBAR_BASE_ADR = 32'h 8000_0000;
shalanfd13eb52020-08-21 16:48:07 +0200165
166 // UART
167 parameter UART_CLK_DIV = 8'h00;
168 parameter UART_DATA = 8'h04;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400169
170 // SPI Master
171 parameter SPI_MASTER_CONFIG = 8'h00;
172 parameter SPI_MASTER_DATA = 8'h04;
173
174 // Counter-timer 0
175 parameter COUNTER_TIMER0_CONFIG = 8'h00;
176 parameter COUNTER_TIMER0_VALUE = 8'h04;
177 parameter COUNTER_TIMER0_DATA = 8'h08;
178
179 // Counter-timer 1
180 parameter COUNTER_TIMER1_CONFIG = 8'h00;
181 parameter COUNTER_TIMER1_VALUE = 8'h04;
182 parameter COUNTER_TIMER1_DATA = 8'h08;
shalanfd13eb52020-08-21 16:48:07 +0200183
184 // SOC GPIO
185 parameter GPIO_DATA = 8'h00;
186 parameter GPIO_ENA = 8'h04;
187 parameter GPIO_PU = 8'h08;
188 parameter GPIO_PD = 8'h0c;
189
shalan0d14e6e2020-08-31 16:50:48 +0200190 // LA
shalanfd13eb52020-08-21 16:48:07 +0200191 parameter LA_DATA_0 = 8'h00;
192 parameter LA_DATA_1 = 8'h04;
193 parameter LA_DATA_2 = 8'h08;
194 parameter LA_DATA_3 = 8'h0c;
195 parameter LA_ENA_0 = 8'h10;
196 parameter LA_ENA_1 = 8'h14;
197 parameter LA_ENA_2 = 8'h18;
198 parameter LA_ENA_3 = 8'h1c;
199
shalanfd13eb52020-08-21 16:48:07 +0200200 // System Control Registers
Tim Edwards44bab472020-10-04 22:09:54 -0400201 parameter PLL_OUT = 8'h00;
202 parameter TRAP_OUT = 8'h04;
203 parameter IRQ7_SRC = 8'h08;
shalanfd13eb52020-08-21 16:48:07 +0200204
205 // Wishbone Interconnect
206 localparam ADR_WIDTH = 32;
207 localparam DAT_WIDTH = 32;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400208 localparam NUM_SLAVES = 13;
shalanfd13eb52020-08-21 16:48:07 +0200209
210 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = {
211 {8'h80, {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}}},
216 {8'hFF, {ADR_WIDTH-8{1'b0}}},
217 {8'hFF, {ADR_WIDTH-8{1'b0}}},
218 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalan0d14e6e2020-08-31 16:50:48 +0200219 {8'hFF, {ADR_WIDTH-8{1'b0}}},
220 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400221 {8'hFF, {ADR_WIDTH-8{1'b0}}},
222 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalanfd13eb52020-08-21 16:48:07 +0200223 {8'hFF, {ADR_WIDTH-8{1'b0}}}
224 };
shalan0d14e6e2020-08-31 16:50:48 +0200225
shalanfd13eb52020-08-21 16:48:07 +0200226 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = {
227 {XBAR_BASE_ADR},
228 {SYS_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200229 {FLASH_CTRL_CFG},
shalan0d14e6e2020-08-31 16:50:48 +0200230 {MPRJ_BASE_ADR},
231 {MPRJ_CTRL_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200232 {LA_BASE_ADR},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400233 {SPI_MASTER_BASE_ADR},
234 {COUNTER_TIMER1_BASE_ADR},
235 {COUNTER_TIMER0_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200236 {GPIO_BASE_ADR},
237 {UART_BASE_ADR},
238 {FLASH_BASE_ADR},
239 {RAM_BASE_ADR}
240 };
241
Tim Edwardsca2f3182020-10-06 10:05:11 -0400242 // The following functions are connected to specific user project
243 // area pins, when under control of the management area (during
244 // startup, and when not otherwise programmed for the user project).
245
246 // JTAG = jtag_out (inout)
247 // SDO = sdo_out (output) (shared with SPI master)
248 // SDI = mgmt_in_data[2] (input) (shared with SPI master)
249 // CSB = mgmt_in_data[3] (input) (shared with SPI master)
250 // SCK = mgmt_in_data[4] (input) (shared with SPI master)
251 // ser_rx = mgmt_in_data[5] (input)
252 // ser_tx = mgmt_out_data[6] (output)
253 // irq_pin = mgmt_in_data[7] (input)
254 // flash_csb = mgmt_out_data[8] (output) (user area flash)
255 // flash_sck = mgmt_out_data[9] (output) (user area flash)
256 // flash_io0 = mgmt_in/out_data[10] (input) (user area flash)
257 // flash_io1 = mgmt_in/out_data[11] (output) (user area flash)
258
259 // OEB lines for [0] and [1] are the only ones connected directly to
260 // the pad. All others have OEB controlled by the configuration bit
261 // in the control block.
262
shalanfd13eb52020-08-21 16:48:07 +0200263 // memory-mapped I/O control registers
Tim Edwards04ba17f2020-10-02 22:27:50 -0400264 wire gpio_pullup; // Intermediate GPIO pullup
265 wire gpio_pulldown; // Intermediate GPIO pulldown
266 wire gpio_outenb; // Intermediate GPIO out enable (bar)
267 wire gpio_out; // Intermediate GPIO output
shalanfd13eb52020-08-21 16:48:07 +0200268
Tim Edwards04ba17f2020-10-02 22:27:50 -0400269 wire gpio; // GPIO output data
270 wire gpio_pu; // GPIO pull-up enable
271 wire gpio_pd; // GPIO pull-down enable
272 wire gpio_oeb; // GPIO output enable (sense negative)
shalanfd13eb52020-08-21 16:48:07 +0200273
Tim Edwardsef8312e2020-09-22 17:20:06 -0400274 wire pll_output_dest; // PLL clock output destination
275 wire trap_output_dest; // Trap signal output destination
276 wire irq_7_inputsrc; // IRQ 7 source
shalanfd13eb52020-08-21 16:48:07 +0200277
278 // GPIO assignments
Tim Edwards04ba17f2020-10-02 22:27:50 -0400279 assign gpio_out = (trap_output_dest == 1'b1) ? trap : gpio;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400280 assign gpio_outenb = (trap_output_dest == 1'b0) ? gpio_oeb : 1'b0;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400281 assign gpio_pullup = (trap_output_dest == 1'b0) ? gpio_pu : 1'b0;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400282 assign gpio_pulldown = (trap_output_dest == 1'b0) ? gpio_pd : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200283
Tim Edwardsef8312e2020-09-22 17:20:06 -0400284 // Convert GPIO signals to sky130_fd_io pad signals
Tim Edwards04ba17f2020-10-02 22:27:50 -0400285 convert_gpio_sigs convert_gpio_bit (
shalanfd13eb52020-08-21 16:48:07 +0200286 .gpio_out(gpio_out),
287 .gpio_outenb(gpio_outenb),
288 .gpio_pu(gpio_pullup),
289 .gpio_pd(gpio_pulldown),
290 .gpio_out_pad(gpio_out_pad),
291 .gpio_outenb_pad(gpio_outenb_pad),
292 .gpio_inenb_pad(gpio_inenb_pad),
293 .gpio_mode1_pad(gpio_mode1_pad),
294 .gpio_mode0_pad(gpio_mode0_pad)
295 );
296
297 reg [31:0] irq;
298 wire irq_7;
shalanfd13eb52020-08-21 16:48:07 +0200299 wire irq_stall;
300 wire irq_uart;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400301 wire irq_spi_master;
302 wire irq_counter_timer0;
303 wire irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200304
shalanfd13eb52020-08-21 16:48:07 +0200305 assign irq_stall = 0;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400306 assign irq_7 = (irq_7_inputsrc == 1'b1) ? mgmt_in_data[7] : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200307
308 always @* begin
309 irq = 0;
310 irq[3] = irq_stall;
311 irq[4] = irq_uart;
shalanfd13eb52020-08-21 16:48:07 +0200312 irq[6] = irq_spi;
313 irq[7] = irq_7;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400314 irq[9] = irq_spi_master;
315 irq[10] = irq_counter_timer0;
316 irq[11] = irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200317 end
318
shalanfd13eb52020-08-21 16:48:07 +0200319 // Assumption : no syscon module and wb_clk is the clock coming from the chip pin ?
320 assign wb_clk_i = clk;
321 assign wb_rst_i = ~resetn; // Redundant
322
323 // Wishbone Master
324 wire [31:0] cpu_adr_o;
325 wire [31:0] cpu_dat_i;
326 wire [3:0] cpu_sel_o;
327 wire cpu_we_o;
328 wire cpu_cyc_o;
329 wire cpu_stb_o;
330 wire [31:0] cpu_dat_o;
331 wire cpu_ack_i;
332
333 assign xbar_cyc_o = cpu_cyc_o;
334 assign xbar_we_o = cpu_we_o;
335 assign xbar_sel_o = cpu_sel_o;
336 assign xbar_adr_o = cpu_adr_o;
337 assign xbar_dat_o = cpu_dat_o;
338
339 picorv32_wb #(
340 .STACKADDR(STACKADDR),
341 .PROGADDR_RESET(PROGADDR_RESET),
342 .PROGADDR_IRQ(PROGADDR_IRQ),
343 .BARREL_SHIFTER(1),
344 .COMPRESSED_ISA(1),
345 .ENABLE_MUL(1),
346 .ENABLE_DIV(1),
347 .ENABLE_IRQ(1),
348 .ENABLE_IRQ_QREGS(0)
349 ) cpu (
350 .wb_clk_i (wb_clk_i),
351 .wb_rst_i (wb_rst_i),
352 .trap (trap),
353 .irq (irq),
354 .mem_instr(mem_instr),
355 .wbm_adr_o(cpu_adr_o),
356 .wbm_dat_i(cpu_dat_i),
357 .wbm_stb_o(cpu_stb_o),
358 .wbm_ack_i(cpu_ack_i),
359 .wbm_cyc_o(cpu_cyc_o),
360 .wbm_dat_o(cpu_dat_o),
361 .wbm_we_o(cpu_we_o),
362 .wbm_sel_o(cpu_sel_o)
363 );
364
365 // Wishbone Slave SPIMEMIO
366 wire spimemio_flash_stb_i;
367 wire spimemio_flash_ack_o;
368 wire [31:0] spimemio_flash_dat_o;
369
370 wire spimemio_cfg_stb_i;
371 wire spimemio_cfg_ack_o;
372 wire [31:0] spimemio_cfg_dat_o;
373
374 spimemio_wb spimemio (
375 .wb_clk_i(wb_clk_i),
376 .wb_rst_i(wb_rst_i),
377
378 .wb_adr_i(cpu_adr_o),
379 .wb_dat_i(cpu_dat_o),
380 .wb_sel_i(cpu_sel_o),
381 .wb_we_i(cpu_we_o),
382 .wb_cyc_i(cpu_cyc_o),
383
384 // FLash Slave
385 .wb_flash_stb_i(spimemio_flash_stb_i),
386 .wb_flash_ack_o(spimemio_flash_ack_o),
387 .wb_flash_dat_o(spimemio_flash_dat_o),
388
389 // Config Register Slave
390 .wb_cfg_stb_i(spimemio_cfg_stb_i),
391 .wb_cfg_ack_o(spimemio_cfg_ack_o),
392 .wb_cfg_dat_o(spimemio_cfg_dat_o),
393
Tim Edwards04ba17f2020-10-02 22:27:50 -0400394 .pass_thru(pass_thru_mgmt),
395 .pass_thru_csb(pass_thru_mgmt_csb),
396 .pass_thru_sck(pass_thru_mgmt_sck),
397 .pass_thru_sdi(pass_thru_mgmt_sdi),
398 .pass_thru_sdo(pass_thru_mgmt_sdo),
399
shalanfd13eb52020-08-21 16:48:07 +0200400 .flash_csb (flash_csb),
401 .flash_clk (flash_clk),
402
403 .flash_csb_oeb (flash_csb_oeb),
404 .flash_clk_oeb (flash_clk_oeb),
405
406 .flash_io0_oeb (flash_io0_oeb),
407 .flash_io1_oeb (flash_io1_oeb),
408 .flash_io2_oeb (flash_io2_oeb),
409 .flash_io3_oeb (flash_io3_oeb),
410
411 .flash_csb_ieb (flash_csb_ieb),
412 .flash_clk_ieb (flash_clk_ieb),
413
414 .flash_io0_ieb (flash_io0_ieb),
415 .flash_io1_ieb (flash_io1_ieb),
416 .flash_io2_ieb (flash_io2_ieb),
417 .flash_io3_ieb (flash_io3_ieb),
418
419 .flash_io0_do (flash_io0_do),
420 .flash_io1_do (flash_io1_do),
421 .flash_io2_do (flash_io2_do),
422 .flash_io3_do (flash_io3_do),
423
424 .flash_io0_di (flash_io0_di),
425 .flash_io1_di (flash_io1_di),
426 .flash_io2_di (flash_io2_di),
427 .flash_io3_di (flash_io3_di)
428 );
429
430 // Wishbone Slave uart
431 wire uart_stb_i;
432 wire uart_ack_o;
433 wire [31:0] uart_dat_o;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400434 wire uart_enabled;
shalanfd13eb52020-08-21 16:48:07 +0200435
436 simpleuart_wb #(
437 .BASE_ADR(UART_BASE_ADR),
438 .CLK_DIV(UART_CLK_DIV),
439 .DATA(UART_DATA)
440 ) simpleuart (
441 // Wishbone Interface
442 .wb_clk_i(wb_clk_i),
443 .wb_rst_i(wb_rst_i),
444
445 .wb_adr_i(cpu_adr_o),
446 .wb_dat_i(cpu_dat_o),
447 .wb_sel_i(cpu_sel_o),
448 .wb_we_i(cpu_we_o),
449 .wb_cyc_i(cpu_cyc_o),
450
451 .wb_stb_i(uart_stb_i),
452 .wb_ack_o(uart_ack_o),
453 .wb_dat_o(uart_dat_o),
454
Tim Edwardsca2f3182020-10-06 10:05:11 -0400455 .uart_enabled(uart_enabled),
shalanfd13eb52020-08-21 16:48:07 +0200456 .ser_tx(ser_tx),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400457 .ser_rx(mgmt_in_data[5])
shalanfd13eb52020-08-21 16:48:07 +0200458 );
459
Tim Edwards04ba17f2020-10-02 22:27:50 -0400460 // Wishbone SPI master
461 wire spi_master_stb_i;
462 wire spi_master_ack_o;
463 wire [31:0] spi_master_dat_o;
464
465 simple_spi_master_wb #(
466 .BASE_ADR(SPI_MASTER_BASE_ADR),
467 .CONFIG(SPI_MASTER_CONFIG),
468 .DATA(SPI_MASTER_DATA)
469 ) simple_spi_master_inst (
470 // Wishbone Interface
471 .wb_clk_i(wb_clk_i),
472 .wb_rst_i(wb_rst_i),
473
474 .wb_adr_i(cpu_adr_o),
475 .wb_dat_i(cpu_dat_o),
476 .wb_sel_i(cpu_sel_o),
477 .wb_we_i(cpu_we_o),
478 .wb_cyc_i(cpu_cyc_o),
479
480 .wb_stb_i(spi_master_stb_i),
481 .wb_ack_o(spi_master_ack_o),
482 .wb_dat_o(spi_master_dat_o),
483
Tim Edwardsca2f3182020-10-06 10:05:11 -0400484 .csb(mgmt_out_pre[3]),
485 .sck(mgmt_out_pre[4]),
486 .sdi(mgmt_in_data[1]),
487 .sdo(mgmt_out_pre[2]),
488 .sdoenb(),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400489 .irq(irq_spi_master)
490 );
491
492 // Wishbone Counter-timer 0
493 wire counter_timer0_stb_i;
494 wire counter_timer0_ack_o;
495 wire [31:0] counter_timer0_dat_o;
496
497 counter_timer_wb #(
498 .BASE_ADR(COUNTER_TIMER0_BASE_ADR),
499 .CONFIG(COUNTER_TIMER0_CONFIG),
500 .VALUE(COUNTER_TIMER0_VALUE),
501 .DATA(COUNTER_TIMER0_DATA)
502 ) counter_timer_0 (
503 // Wishbone Interface
504 .wb_clk_i(wb_clk_i),
505 .wb_rst_i(wb_rst_i),
506
507 .wb_adr_i(cpu_adr_o),
508 .wb_dat_i(cpu_dat_o),
509 .wb_sel_i(cpu_sel_o),
510 .wb_we_i(cpu_we_o),
511 .wb_cyc_i(cpu_cyc_o),
512
513 .wb_stb_i(counter_timer0_stb_i),
514 .wb_ack_o(counter_timer0_ack_o),
515 .wb_dat_o(counter_timer0_dat_o),
516 .irq(irq_counter_timer0)
517 );
518
519 // Wishbone Counter-timer 1
520 wire counter_timer1_stb_i;
521 wire counter_timer1_ack_o;
522 wire [31:0] counter_timer1_dat_o;
523
524 counter_timer_wb #(
525 .BASE_ADR(COUNTER_TIMER1_BASE_ADR),
526 .CONFIG(COUNTER_TIMER1_CONFIG),
527 .VALUE(COUNTER_TIMER1_VALUE),
528 .DATA(COUNTER_TIMER1_DATA)
529 ) counter_timer_1 (
530 // Wishbone Interface
531 .wb_clk_i(wb_clk_i),
532 .wb_rst_i(wb_rst_i),
533
534 .wb_adr_i(cpu_adr_o),
535 .wb_dat_i(cpu_dat_o),
536 .wb_sel_i(cpu_sel_o),
537 .wb_we_i(cpu_we_o),
538 .wb_cyc_i(cpu_cyc_o),
539
540 .wb_stb_i(counter_timer1_stb_i),
541 .wb_ack_o(counter_timer1_ack_o),
542 .wb_dat_o(counter_timer1_dat_o),
543 .irq(irq_counter_timer1)
544 );
545
shalanfd13eb52020-08-21 16:48:07 +0200546 // Wishbone Slave GPIO Registers
547 wire gpio_stb_i;
548 wire gpio_ack_o;
549 wire [31:0] gpio_dat_o;
550
551 gpio_wb #(
552 .BASE_ADR(GPIO_BASE_ADR),
553 .GPIO_DATA(GPIO_DATA),
554 .GPIO_ENA(GPIO_ENA),
555 .GPIO_PD(GPIO_PD),
556 .GPIO_PU(GPIO_PU)
557 ) gpio_wb (
558 .wb_clk_i(wb_clk_i),
559 .wb_rst_i(wb_rst_i),
shalanfd13eb52020-08-21 16:48:07 +0200560 .wb_adr_i(cpu_adr_o),
561 .wb_dat_i(cpu_dat_o),
562 .wb_sel_i(cpu_sel_o),
563 .wb_we_i(cpu_we_o),
564 .wb_cyc_i(cpu_cyc_o),
shalanfd13eb52020-08-21 16:48:07 +0200565 .wb_stb_i(gpio_stb_i),
566 .wb_ack_o(gpio_ack_o),
567 .wb_dat_o(gpio_dat_o),
568 .gpio_in_pad(gpio_in_pad),
shalanfd13eb52020-08-21 16:48:07 +0200569 .gpio(gpio),
570 .gpio_oeb(gpio_oeb),
571 .gpio_pu(gpio_pu),
572 .gpio_pd(gpio_pd)
573 );
574
shalanfd13eb52020-08-21 16:48:07 +0200575 // Wishbone Slave System Control Register
576 wire sys_stb_i;
577 wire sys_ack_o;
578 wire [31:0] sys_dat_o;
579
580 sysctrl_wb #(
581 .BASE_ADR(SYS_BASE_ADR),
shalanfd13eb52020-08-21 16:48:07 +0200582 .PLL_OUT(PLL_OUT),
583 .TRAP_OUT(TRAP_OUT),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400584 .IRQ7_SRC(IRQ7_SRC)
shalanfd13eb52020-08-21 16:48:07 +0200585 ) sysctrl (
586 .wb_clk_i(wb_clk_i),
587 .wb_rst_i(wb_rst_i),
588
589 .wb_adr_i(cpu_adr_o),
590 .wb_dat_i(cpu_dat_o),
591 .wb_sel_i(cpu_sel_o),
592 .wb_we_i(cpu_we_o),
593 .wb_cyc_i(cpu_cyc_o),
594
595 .wb_stb_i(sys_stb_i),
596 .wb_ack_o(sys_ack_o),
597 .wb_dat_o(sys_dat_o),
598
shalanfd13eb52020-08-21 16:48:07 +0200599 .pll_output_dest(pll_output_dest),
600 .trap_output_dest(trap_output_dest),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400601 .irq_7_inputsrc(irq_7_inputsrc)
shalanfd13eb52020-08-21 16:48:07 +0200602 );
603
604 // Logic Analyzer
605 wire la_stb_i;
606 wire la_ack_o;
607 wire [31:0] la_dat_o;
608
609 la_wb #(
610 .BASE_ADR(LA_BASE_ADR),
611 .LA_DATA_0(LA_DATA_0),
612 .LA_DATA_1(LA_DATA_1),
613 .LA_DATA_3(LA_DATA_3),
614 .LA_ENA_0(LA_ENA_0),
615 .LA_ENA_1(LA_ENA_1),
616 .LA_ENA_2(LA_ENA_2),
617 .LA_ENA_3(LA_ENA_3)
618 ) la (
619 .wb_clk_i(wb_clk_i),
620 .wb_rst_i(wb_rst_i),
621
622 .wb_adr_i(cpu_adr_o),
623 .wb_dat_i(cpu_dat_o),
624 .wb_sel_i(cpu_sel_o),
625 .wb_we_i(cpu_we_o),
626 .wb_cyc_i(cpu_cyc_o),
627
628 .wb_stb_i(la_stb_i),
629 .wb_ack_o(la_ack_o),
630 .wb_dat_o(la_dat_o),
631
632 .la_data(la_output),
shalan0d14e6e2020-08-31 16:50:48 +0200633 .la_data_in(la_input),
634 .la_oen(la_oen)
shalanfd13eb52020-08-21 16:48:07 +0200635 );
636
shalan0d14e6e2020-08-31 16:50:48 +0200637 // WB Slave Mega-Project Control
638 wire mprj_ctrl_stb_i;
639 wire mprj_ctrl_ack_o;
640 wire [31:0] mprj_ctrl_dat_o;
Tim Edwards9eda80d2020-10-08 21:36:44 -0400641 wire [MPRJ_IO_PADS-1:0] mgmt_out_pre;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400642
643 // Bits assigned to specific functions as outputs prevent the
644 // mprj GPIO-as-output from applying data when that function
645 // is active
646
647 assign mgmt_out_data[MPRJ_IO_PADS-1:7] = mgmt_out_pre[MPRJ_IO_PADS-1:7];
648 assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6];
649 assign mgmt_out_data[5:0] = mgmt_out_pre[5:0];
shalan0d14e6e2020-08-31 16:50:48 +0200650
651 mprj_ctrl_wb #(
652 .BASE_ADR(MPRJ_CTRL_ADR),
653 .IO_PADS(MPRJ_IO_PADS),
Tim Edwardsc18c4742020-10-03 11:26:39 -0400654 .PWR_PADS(MPRJ_PWR_PADS)
shalan0d14e6e2020-08-31 16:50:48 +0200655 ) mprj_ctrl (
656 .wb_clk_i(wb_clk_i),
657 .wb_rst_i(wb_rst_i),
658
659 .wb_adr_i(cpu_adr_o),
660 .wb_dat_i(cpu_dat_o),
661 .wb_sel_i(cpu_sel_o),
662 .wb_we_i(cpu_we_o),
663 .wb_cyc_i(cpu_cyc_o),
664 .wb_stb_i(mprj_ctrl_stb_i),
665 .wb_ack_o(mprj_ctrl_ack_o),
666 .wb_dat_o(mprj_ctrl_dat_o),
667
Tim Edwards04ba17f2020-10-02 22:27:50 -0400668 .serial_clock(mprj_io_loader_clock),
669 .serial_resetn(mprj_io_loader_resetn),
670 .serial_data_out(mprj_io_loader_data),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400671 .mgmt_gpio_out(mgmt_out_pre),
672 .mgmt_gpio_in(mgmt_in_data)
shalan0d14e6e2020-08-31 16:50:48 +0200673 );
674
shalanfd13eb52020-08-21 16:48:07 +0200675 // Wishbone Slave RAM
676 wire mem_stb_i;
677 wire mem_ack_o;
678 wire [31:0] mem_dat_o;
679
680 mem_wb #(
681 .MEM_WORDS(MEM_WORDS)
682 ) soc_mem (
683 .wb_clk_i(wb_clk_i),
684 .wb_rst_i(wb_rst_i),
685
686 .wb_adr_i(cpu_adr_o),
687 .wb_dat_i(cpu_dat_o),
688 .wb_sel_i(cpu_sel_o),
689 .wb_we_i(cpu_we_o),
690 .wb_cyc_i(cpu_cyc_o),
691
692 .wb_stb_i(mem_stb_i),
693 .wb_ack_o(mem_ack_o),
694 .wb_dat_o(mem_dat_o)
695 );
696
697 // Wishbone intercon logic
698 wb_intercon #(
699 .AW(ADR_WIDTH),
700 .DW(DAT_WIDTH),
701 .NS(NUM_SLAVES),
702 .ADR_MASK(ADR_MASK),
703 .SLAVE_ADR(SLAVE_ADR)
704 ) intercon (
705 // Master Interface
706 .wbm_adr_i(cpu_adr_o),
707 .wbm_stb_i(cpu_stb_o),
708 .wbm_dat_o(cpu_dat_i),
709 .wbm_ack_o(cpu_ack_i),
710
711 // Slaves Interface
Tim Edwards04ba17f2020-10-02 22:27:50 -0400712 .wbs_stb_o({ xbar_stb_o, sys_stb_i, spimemio_cfg_stb_i,
713 mprj_stb_o, mprj_ctrl_stb_i, la_stb_i,
714 spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i,
715 gpio_stb_i, uart_stb_i,
716 spimemio_flash_stb_i, mem_stb_i }),
717 .wbs_dat_i({ xbar_dat_i, sys_dat_o, spimemio_cfg_dat_o,
718 mprj_dat_i, mprj_ctrl_dat_o, la_dat_o,
719 spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o,
720 gpio_dat_o, uart_dat_o,
721 spimemio_flash_dat_o, mem_dat_o }),
722 .wbs_ack_i({ xbar_ack_i, sys_ack_o, spimemio_cfg_ack_o,
723 mprj_ack_i, mprj_ctrl_ack_o, la_ack_o,
724 spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o,
725 gpio_ack_o, uart_ack_o,
726 spimemio_flash_ack_o, mem_ack_o })
shalanfd13eb52020-08-21 16:48:07 +0200727 );
728
shalanfd13eb52020-08-21 16:48:07 +0200729endmodule
730
shalanfd13eb52020-08-21 16:48:07 +0200731// Implementation note:
732// Replace the following two modules with wrappers for your SRAM cells.
Tim Edwardsef8312e2020-09-22 17:20:06 -0400733
Tim Edwards04ba17f2020-10-02 22:27:50 -0400734module mgmt_soc_regs (
shalanfd13eb52020-08-21 16:48:07 +0200735 input clk, wen,
736 input [5:0] waddr,
737 input [5:0] raddr1,
738 input [5:0] raddr2,
739 input [31:0] wdata,
740 output [31:0] rdata1,
741 output [31:0] rdata2
742);
743 reg [31:0] regs [0:31];
744
745 always @(posedge clk)
746 if (wen) regs[waddr[4:0]] <= wdata;
747
748 assign rdata1 = regs[raddr1[4:0]];
749 assign rdata2 = regs[raddr2[4:0]];
750endmodule