blob: 6778da07cab7448f583f6c2cdde1eccd8118f9ec [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
shalanfd13eb52020-08-21 16:48:07 +020053 input clk,
54 input resetn,
55
Tim Edwards04ba17f2020-10-02 22:27:50 -040056 // Trap state from CPU
57 output trap,
58
59 // GPIO (one pin)
60 output gpio_out_pad, // Connect to out on gpio pad
61 input gpio_in_pad, // Connect to in on gpio pad
62 output gpio_mode0_pad, // Connect to dm[0] on gpio pad
63 output gpio_mode1_pad, // Connect to dm[2] on gpio pad
64 output gpio_outenb_pad, // Connect to oe_n on gpio pad
65 output gpio_inenb_pad, // Connect to inp_dis on gpio pad
shalanfd13eb52020-08-21 16:48:07 +020066
67 // LA signals
Tim Edwards6d9739d2020-10-19 11:00:49 -040068 input [127:0] la_input, // From User Project to cpu
69 output [127:0] la_output, // From CPU to User Project
shalan0d14e6e2020-08-31 16:50:48 +020070 output [127:0] la_oen, // LA output enable (active low)
71
Tim Edwards6d9739d2020-10-19 11:00:49 -040072 // User Project I/O Configuration (serial load)
Tim Edwards04ba17f2020-10-02 22:27:50 -040073 output mprj_io_loader_resetn,
74 output mprj_io_loader_clock,
75 output mprj_io_loader_data,
shalanfd13eb52020-08-21 16:48:07 +020076
Tim Edwards6d9739d2020-10-19 11:00:49 -040077 // User Project pad data (when management SoC controls the pad)
Tim Edwards44bab472020-10-04 22:09:54 -040078 input [MPRJ_IO_PADS-1:0] mgmt_in_data,
79 output [MPRJ_IO_PADS-1:0] mgmt_out_data,
shalanfd13eb52020-08-21 16:48:07 +020080
81 // IRQ
shalanfd13eb52020-08-21 16:48:07 +020082 input irq_spi, // IRQ from standalone SPI
83
shalanfd13eb52020-08-21 16:48:07 +020084 // Flash memory control (SPI master)
85 output flash_csb,
86 output flash_clk,
87
88 output flash_csb_oeb,
89 output flash_clk_oeb,
90
91 output flash_io0_oeb,
92 output flash_io1_oeb,
93 output flash_io2_oeb,
94 output flash_io3_oeb,
95
96 output flash_csb_ieb,
97 output flash_clk_ieb,
98
99 output flash_io0_ieb,
100 output flash_io1_ieb,
101 output flash_io2_ieb,
102 output flash_io3_ieb,
103
104 output flash_io0_do,
105 output flash_io1_do,
106 output flash_io2_do,
107 output flash_io3_do,
108
109 input flash_io0_di,
110 input flash_io1_di,
111 input flash_io2_di,
112 input flash_io3_di,
113
Tim Edwards04ba17f2020-10-02 22:27:50 -0400114 // SPI pass-thru mode
115 input pass_thru_mgmt,
116 input pass_thru_mgmt_csb,
117 input pass_thru_mgmt_sck,
118 input pass_thru_mgmt_sdi,
119 output pass_thru_mgmt_sdo,
120
Tim Edwards81153202020-10-09 19:57:04 -0400121 // SPI master->slave direct link
122 output hk_connect,
123
Tim Edwards6d9739d2020-10-19 11:00:49 -0400124 // WB MI A (User project)
shalan0d14e6e2020-08-31 16:50:48 +0200125 input mprj_ack_i,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400126 input [31:0] mprj_dat_i,
shalan0d14e6e2020-08-31 16:50:48 +0200127 output mprj_cyc_o,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400128 output mprj_stb_o,
129 output mprj_we_o,
130 output [3:0] mprj_sel_o,
131 output [31:0] mprj_adr_o,
132 output [31:0] mprj_dat_o,
shalan0d14e6e2020-08-31 16:50:48 +0200133
134 // WB MI B (xbar)
shalanfd13eb52020-08-21 16:48:07 +0200135 input [31:0] xbar_dat_i,
136 input xbar_ack_i,
137 output xbar_cyc_o,
138 output xbar_stb_o,
139 output xbar_we_o,
140 output [3:0] xbar_sel_o,
141 output [31:0] xbar_adr_o,
142 output [31:0] xbar_dat_o
143);
144 /* Memory reverted back to 256 words while memory has to be synthesized */
shalan0d14e6e2020-08-31 16:50:48 +0200145 parameter integer MEM_WORDS = 8192;
shalanfd13eb52020-08-21 16:48:07 +0200146 parameter [31:0] STACKADDR = (4*MEM_WORDS); // end of memory
147 parameter [31:0] PROGADDR_RESET = 32'h 1000_0000;
148 parameter [31:0] PROGADDR_IRQ = 32'h 0000_0000;
149
150 // Slaves Base Addresses
Tim Edwards04ba17f2020-10-02 22:27:50 -0400151 parameter RAM_BASE_ADR = 32'h 0000_0000;
152 parameter FLASH_BASE_ADR = 32'h 1000_0000;
153 parameter UART_BASE_ADR = 32'h 2000_0000;
154 parameter GPIO_BASE_ADR = 32'h 2100_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400155 parameter COUNTER_TIMER0_BASE_ADR = 32'h 2200_0000;
156 parameter COUNTER_TIMER1_BASE_ADR = 32'h 2300_0000;
157 parameter SPI_MASTER_BASE_ADR = 32'h 2400_0000;
158 parameter LA_BASE_ADR = 32'h 2500_0000;
159 parameter MPRJ_CTRL_ADR = 32'h 2600_0000;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400160 parameter FLASH_CTRL_CFG = 32'h 2D00_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400161 parameter SYS_BASE_ADR = 32'h 2F00_0000;
162 parameter MPRJ_BASE_ADR = 32'h 3000_0000; // WB MI A
Tim Edwards04ba17f2020-10-02 22:27:50 -0400163 parameter XBAR_BASE_ADR = 32'h 8000_0000;
shalanfd13eb52020-08-21 16:48:07 +0200164
165 // UART
166 parameter UART_CLK_DIV = 8'h00;
167 parameter UART_DATA = 8'h04;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400168
169 // SPI Master
170 parameter SPI_MASTER_CONFIG = 8'h00;
171 parameter SPI_MASTER_DATA = 8'h04;
172
173 // Counter-timer 0
174 parameter COUNTER_TIMER0_CONFIG = 8'h00;
175 parameter COUNTER_TIMER0_VALUE = 8'h04;
176 parameter COUNTER_TIMER0_DATA = 8'h08;
177
178 // Counter-timer 1
179 parameter COUNTER_TIMER1_CONFIG = 8'h00;
180 parameter COUNTER_TIMER1_VALUE = 8'h04;
181 parameter COUNTER_TIMER1_DATA = 8'h08;
shalanfd13eb52020-08-21 16:48:07 +0200182
183 // SOC GPIO
184 parameter GPIO_DATA = 8'h00;
185 parameter GPIO_ENA = 8'h04;
186 parameter GPIO_PU = 8'h08;
187 parameter GPIO_PD = 8'h0c;
188
shalan0d14e6e2020-08-31 16:50:48 +0200189 // LA
shalanfd13eb52020-08-21 16:48:07 +0200190 parameter LA_DATA_0 = 8'h00;
191 parameter LA_DATA_1 = 8'h04;
192 parameter LA_DATA_2 = 8'h08;
193 parameter LA_DATA_3 = 8'h0c;
194 parameter LA_ENA_0 = 8'h10;
195 parameter LA_ENA_1 = 8'h14;
196 parameter LA_ENA_2 = 8'h18;
197 parameter LA_ENA_3 = 8'h1c;
198
shalanfd13eb52020-08-21 16:48:07 +0200199 // System Control Registers
Tim Edwards44bab472020-10-04 22:09:54 -0400200 parameter PLL_OUT = 8'h00;
201 parameter TRAP_OUT = 8'h04;
202 parameter IRQ7_SRC = 8'h08;
shalanfd13eb52020-08-21 16:48:07 +0200203
204 // Wishbone Interconnect
205 localparam ADR_WIDTH = 32;
206 localparam DAT_WIDTH = 32;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400207 localparam NUM_SLAVES = 13;
shalanfd13eb52020-08-21 16:48:07 +0200208
209 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = {
210 {8'h80, {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}}},
216 {8'hFF, {ADR_WIDTH-8{1'b0}}},
217 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalan0d14e6e2020-08-31 16:50:48 +0200218 {8'hFF, {ADR_WIDTH-8{1'b0}}},
219 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400220 {8'hFF, {ADR_WIDTH-8{1'b0}}},
221 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalanfd13eb52020-08-21 16:48:07 +0200222 {8'hFF, {ADR_WIDTH-8{1'b0}}}
223 };
shalan0d14e6e2020-08-31 16:50:48 +0200224
shalanfd13eb52020-08-21 16:48:07 +0200225 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = {
226 {XBAR_BASE_ADR},
227 {SYS_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200228 {FLASH_CTRL_CFG},
shalan0d14e6e2020-08-31 16:50:48 +0200229 {MPRJ_BASE_ADR},
230 {MPRJ_CTRL_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200231 {LA_BASE_ADR},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400232 {SPI_MASTER_BASE_ADR},
233 {COUNTER_TIMER1_BASE_ADR},
234 {COUNTER_TIMER0_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200235 {GPIO_BASE_ADR},
236 {UART_BASE_ADR},
237 {FLASH_BASE_ADR},
238 {RAM_BASE_ADR}
239 };
240
Tim Edwardsca2f3182020-10-06 10:05:11 -0400241 // The following functions are connected to specific user project
242 // area pins, when under control of the management area (during
243 // startup, and when not otherwise programmed for the user project).
244
245 // JTAG = jtag_out (inout)
246 // SDO = sdo_out (output) (shared with SPI master)
247 // SDI = mgmt_in_data[2] (input) (shared with SPI master)
248 // CSB = mgmt_in_data[3] (input) (shared with SPI master)
249 // SCK = mgmt_in_data[4] (input) (shared with SPI master)
250 // ser_rx = mgmt_in_data[5] (input)
251 // ser_tx = mgmt_out_data[6] (output)
252 // irq_pin = mgmt_in_data[7] (input)
253 // flash_csb = mgmt_out_data[8] (output) (user area flash)
254 // flash_sck = mgmt_out_data[9] (output) (user area flash)
255 // flash_io0 = mgmt_in/out_data[10] (input) (user area flash)
256 // flash_io1 = mgmt_in/out_data[11] (output) (user area flash)
257
258 // OEB lines for [0] and [1] are the only ones connected directly to
259 // the pad. All others have OEB controlled by the configuration bit
260 // in the control block.
261
shalanfd13eb52020-08-21 16:48:07 +0200262 // memory-mapped I/O control registers
Tim Edwards04ba17f2020-10-02 22:27:50 -0400263 wire gpio_pullup; // Intermediate GPIO pullup
264 wire gpio_pulldown; // Intermediate GPIO pulldown
265 wire gpio_outenb; // Intermediate GPIO out enable (bar)
266 wire gpio_out; // Intermediate GPIO output
shalanfd13eb52020-08-21 16:48:07 +0200267
Tim Edwards04ba17f2020-10-02 22:27:50 -0400268 wire gpio; // GPIO output data
269 wire gpio_pu; // GPIO pull-up enable
270 wire gpio_pd; // GPIO pull-down enable
271 wire gpio_oeb; // GPIO output enable (sense negative)
shalanfd13eb52020-08-21 16:48:07 +0200272
Tim Edwardsef8312e2020-09-22 17:20:06 -0400273 wire pll_output_dest; // PLL clock output destination
274 wire trap_output_dest; // Trap signal output destination
275 wire irq_7_inputsrc; // IRQ 7 source
shalanfd13eb52020-08-21 16:48:07 +0200276
277 // GPIO assignments
Tim Edwards04ba17f2020-10-02 22:27:50 -0400278 assign gpio_out = (trap_output_dest == 1'b1) ? trap : gpio;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400279 assign gpio_outenb = (trap_output_dest == 1'b0) ? gpio_oeb : 1'b0;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400280 assign gpio_pullup = (trap_output_dest == 1'b0) ? gpio_pu : 1'b0;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400281 assign gpio_pulldown = (trap_output_dest == 1'b0) ? gpio_pd : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200282
Tim Edwardsef8312e2020-09-22 17:20:06 -0400283 // Convert GPIO signals to sky130_fd_io pad signals
Tim Edwards04ba17f2020-10-02 22:27:50 -0400284 convert_gpio_sigs convert_gpio_bit (
shalanfd13eb52020-08-21 16:48:07 +0200285 .gpio_out(gpio_out),
286 .gpio_outenb(gpio_outenb),
287 .gpio_pu(gpio_pullup),
288 .gpio_pd(gpio_pulldown),
289 .gpio_out_pad(gpio_out_pad),
290 .gpio_outenb_pad(gpio_outenb_pad),
291 .gpio_inenb_pad(gpio_inenb_pad),
292 .gpio_mode1_pad(gpio_mode1_pad),
293 .gpio_mode0_pad(gpio_mode0_pad)
294 );
295
296 reg [31:0] irq;
297 wire irq_7;
shalanfd13eb52020-08-21 16:48:07 +0200298 wire irq_stall;
299 wire irq_uart;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400300 wire irq_spi_master;
301 wire irq_counter_timer0;
302 wire irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200303
shalanfd13eb52020-08-21 16:48:07 +0200304 assign irq_stall = 0;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400305 assign irq_7 = (irq_7_inputsrc == 1'b1) ? mgmt_in_data[7] : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200306
307 always @* begin
308 irq = 0;
309 irq[3] = irq_stall;
310 irq[4] = irq_uart;
shalanfd13eb52020-08-21 16:48:07 +0200311 irq[6] = irq_spi;
312 irq[7] = irq_7;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400313 irq[9] = irq_spi_master;
314 irq[10] = irq_counter_timer0;
315 irq[11] = irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200316 end
317
Tim Edwards3245e2f2020-10-10 14:02:11 -0400318 // Assumption : no syscon module and wb_clk is the clock coming from the
319 // caravel_clocking module
320
shalanfd13eb52020-08-21 16:48:07 +0200321 assign wb_clk_i = clk;
322 assign wb_rst_i = ~resetn; // Redundant
323
324 // Wishbone Master
325 wire [31:0] cpu_adr_o;
326 wire [31:0] cpu_dat_i;
327 wire [3:0] cpu_sel_o;
328 wire cpu_we_o;
329 wire cpu_cyc_o;
330 wire cpu_stb_o;
331 wire [31:0] cpu_dat_o;
332 wire cpu_ack_i;
333
334 assign xbar_cyc_o = cpu_cyc_o;
335 assign xbar_we_o = cpu_we_o;
336 assign xbar_sel_o = cpu_sel_o;
337 assign xbar_adr_o = cpu_adr_o;
338 assign xbar_dat_o = cpu_dat_o;
339
340 picorv32_wb #(
341 .STACKADDR(STACKADDR),
342 .PROGADDR_RESET(PROGADDR_RESET),
343 .PROGADDR_IRQ(PROGADDR_IRQ),
344 .BARREL_SHIFTER(1),
345 .COMPRESSED_ISA(1),
346 .ENABLE_MUL(1),
347 .ENABLE_DIV(1),
348 .ENABLE_IRQ(1),
349 .ENABLE_IRQ_QREGS(0)
350 ) cpu (
351 .wb_clk_i (wb_clk_i),
352 .wb_rst_i (wb_rst_i),
353 .trap (trap),
354 .irq (irq),
355 .mem_instr(mem_instr),
356 .wbm_adr_o(cpu_adr_o),
357 .wbm_dat_i(cpu_dat_i),
358 .wbm_stb_o(cpu_stb_o),
359 .wbm_ack_i(cpu_ack_i),
360 .wbm_cyc_o(cpu_cyc_o),
361 .wbm_dat_o(cpu_dat_o),
362 .wbm_we_o(cpu_we_o),
363 .wbm_sel_o(cpu_sel_o)
364 );
365
366 // Wishbone Slave SPIMEMIO
367 wire spimemio_flash_stb_i;
368 wire spimemio_flash_ack_o;
369 wire [31:0] spimemio_flash_dat_o;
370
371 wire spimemio_cfg_stb_i;
372 wire spimemio_cfg_ack_o;
373 wire [31:0] spimemio_cfg_dat_o;
374
375 spimemio_wb spimemio (
376 .wb_clk_i(wb_clk_i),
377 .wb_rst_i(wb_rst_i),
378
379 .wb_adr_i(cpu_adr_o),
380 .wb_dat_i(cpu_dat_o),
381 .wb_sel_i(cpu_sel_o),
382 .wb_we_i(cpu_we_o),
383 .wb_cyc_i(cpu_cyc_o),
384
385 // FLash Slave
386 .wb_flash_stb_i(spimemio_flash_stb_i),
387 .wb_flash_ack_o(spimemio_flash_ack_o),
388 .wb_flash_dat_o(spimemio_flash_dat_o),
389
390 // Config Register Slave
391 .wb_cfg_stb_i(spimemio_cfg_stb_i),
392 .wb_cfg_ack_o(spimemio_cfg_ack_o),
393 .wb_cfg_dat_o(spimemio_cfg_dat_o),
394
Tim Edwards04ba17f2020-10-02 22:27:50 -0400395 .pass_thru(pass_thru_mgmt),
396 .pass_thru_csb(pass_thru_mgmt_csb),
397 .pass_thru_sck(pass_thru_mgmt_sck),
398 .pass_thru_sdi(pass_thru_mgmt_sdi),
399 .pass_thru_sdo(pass_thru_mgmt_sdo),
400
shalanfd13eb52020-08-21 16:48:07 +0200401 .flash_csb (flash_csb),
402 .flash_clk (flash_clk),
403
404 .flash_csb_oeb (flash_csb_oeb),
405 .flash_clk_oeb (flash_clk_oeb),
406
407 .flash_io0_oeb (flash_io0_oeb),
408 .flash_io1_oeb (flash_io1_oeb),
409 .flash_io2_oeb (flash_io2_oeb),
410 .flash_io3_oeb (flash_io3_oeb),
411
412 .flash_csb_ieb (flash_csb_ieb),
413 .flash_clk_ieb (flash_clk_ieb),
414
415 .flash_io0_ieb (flash_io0_ieb),
416 .flash_io1_ieb (flash_io1_ieb),
417 .flash_io2_ieb (flash_io2_ieb),
418 .flash_io3_ieb (flash_io3_ieb),
419
420 .flash_io0_do (flash_io0_do),
421 .flash_io1_do (flash_io1_do),
422 .flash_io2_do (flash_io2_do),
423 .flash_io3_do (flash_io3_do),
424
425 .flash_io0_di (flash_io0_di),
426 .flash_io1_di (flash_io1_di),
427 .flash_io2_di (flash_io2_di),
428 .flash_io3_di (flash_io3_di)
429 );
430
431 // Wishbone Slave uart
432 wire uart_stb_i;
433 wire uart_ack_o;
434 wire [31:0] uart_dat_o;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400435 wire uart_enabled;
shalanfd13eb52020-08-21 16:48:07 +0200436
437 simpleuart_wb #(
438 .BASE_ADR(UART_BASE_ADR),
439 .CLK_DIV(UART_CLK_DIV),
440 .DATA(UART_DATA)
441 ) simpleuart (
442 // Wishbone Interface
443 .wb_clk_i(wb_clk_i),
444 .wb_rst_i(wb_rst_i),
445
446 .wb_adr_i(cpu_adr_o),
447 .wb_dat_i(cpu_dat_o),
448 .wb_sel_i(cpu_sel_o),
449 .wb_we_i(cpu_we_o),
450 .wb_cyc_i(cpu_cyc_o),
451
452 .wb_stb_i(uart_stb_i),
453 .wb_ack_o(uart_ack_o),
454 .wb_dat_o(uart_dat_o),
455
Tim Edwardsca2f3182020-10-06 10:05:11 -0400456 .uart_enabled(uart_enabled),
shalanfd13eb52020-08-21 16:48:07 +0200457 .ser_tx(ser_tx),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400458 .ser_rx(mgmt_in_data[5])
shalanfd13eb52020-08-21 16:48:07 +0200459 );
460
Tim Edwards04ba17f2020-10-02 22:27:50 -0400461 // Wishbone SPI master
462 wire spi_master_stb_i;
463 wire spi_master_ack_o;
464 wire [31:0] spi_master_dat_o;
465
466 simple_spi_master_wb #(
467 .BASE_ADR(SPI_MASTER_BASE_ADR),
468 .CONFIG(SPI_MASTER_CONFIG),
469 .DATA(SPI_MASTER_DATA)
470 ) simple_spi_master_inst (
471 // Wishbone Interface
472 .wb_clk_i(wb_clk_i),
473 .wb_rst_i(wb_rst_i),
474
475 .wb_adr_i(cpu_adr_o),
476 .wb_dat_i(cpu_dat_o),
477 .wb_sel_i(cpu_sel_o),
478 .wb_we_i(cpu_we_o),
479 .wb_cyc_i(cpu_cyc_o),
480
481 .wb_stb_i(spi_master_stb_i),
482 .wb_ack_o(spi_master_ack_o),
483 .wb_dat_o(spi_master_dat_o),
484
Tim Edwards81153202020-10-09 19:57:04 -0400485 .hk_connect(hk_connect),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400486 .csb(mgmt_out_pre[3]),
487 .sck(mgmt_out_pre[4]),
488 .sdi(mgmt_in_data[1]),
489 .sdo(mgmt_out_pre[2]),
490 .sdoenb(),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400491 .irq(irq_spi_master)
492 );
493
494 // Wishbone Counter-timer 0
495 wire counter_timer0_stb_i;
496 wire counter_timer0_ack_o;
497 wire [31:0] counter_timer0_dat_o;
498
499 counter_timer_wb #(
500 .BASE_ADR(COUNTER_TIMER0_BASE_ADR),
501 .CONFIG(COUNTER_TIMER0_CONFIG),
502 .VALUE(COUNTER_TIMER0_VALUE),
503 .DATA(COUNTER_TIMER0_DATA)
504 ) counter_timer_0 (
505 // Wishbone Interface
506 .wb_clk_i(wb_clk_i),
507 .wb_rst_i(wb_rst_i),
508
509 .wb_adr_i(cpu_adr_o),
510 .wb_dat_i(cpu_dat_o),
511 .wb_sel_i(cpu_sel_o),
512 .wb_we_i(cpu_we_o),
513 .wb_cyc_i(cpu_cyc_o),
514
515 .wb_stb_i(counter_timer0_stb_i),
516 .wb_ack_o(counter_timer0_ack_o),
517 .wb_dat_o(counter_timer0_dat_o),
518 .irq(irq_counter_timer0)
519 );
520
521 // Wishbone Counter-timer 1
522 wire counter_timer1_stb_i;
523 wire counter_timer1_ack_o;
524 wire [31:0] counter_timer1_dat_o;
525
526 counter_timer_wb #(
527 .BASE_ADR(COUNTER_TIMER1_BASE_ADR),
528 .CONFIG(COUNTER_TIMER1_CONFIG),
529 .VALUE(COUNTER_TIMER1_VALUE),
530 .DATA(COUNTER_TIMER1_DATA)
531 ) counter_timer_1 (
532 // Wishbone Interface
533 .wb_clk_i(wb_clk_i),
534 .wb_rst_i(wb_rst_i),
535
536 .wb_adr_i(cpu_adr_o),
537 .wb_dat_i(cpu_dat_o),
538 .wb_sel_i(cpu_sel_o),
539 .wb_we_i(cpu_we_o),
540 .wb_cyc_i(cpu_cyc_o),
541
542 .wb_stb_i(counter_timer1_stb_i),
543 .wb_ack_o(counter_timer1_ack_o),
544 .wb_dat_o(counter_timer1_dat_o),
545 .irq(irq_counter_timer1)
546 );
547
shalanfd13eb52020-08-21 16:48:07 +0200548 // Wishbone Slave GPIO Registers
549 wire gpio_stb_i;
550 wire gpio_ack_o;
551 wire [31:0] gpio_dat_o;
552
553 gpio_wb #(
554 .BASE_ADR(GPIO_BASE_ADR),
555 .GPIO_DATA(GPIO_DATA),
556 .GPIO_ENA(GPIO_ENA),
557 .GPIO_PD(GPIO_PD),
558 .GPIO_PU(GPIO_PU)
559 ) gpio_wb (
560 .wb_clk_i(wb_clk_i),
561 .wb_rst_i(wb_rst_i),
shalanfd13eb52020-08-21 16:48:07 +0200562 .wb_adr_i(cpu_adr_o),
563 .wb_dat_i(cpu_dat_o),
564 .wb_sel_i(cpu_sel_o),
565 .wb_we_i(cpu_we_o),
566 .wb_cyc_i(cpu_cyc_o),
shalanfd13eb52020-08-21 16:48:07 +0200567 .wb_stb_i(gpio_stb_i),
568 .wb_ack_o(gpio_ack_o),
569 .wb_dat_o(gpio_dat_o),
570 .gpio_in_pad(gpio_in_pad),
shalanfd13eb52020-08-21 16:48:07 +0200571 .gpio(gpio),
572 .gpio_oeb(gpio_oeb),
573 .gpio_pu(gpio_pu),
574 .gpio_pd(gpio_pd)
575 );
576
shalanfd13eb52020-08-21 16:48:07 +0200577 // Wishbone Slave System Control Register
578 wire sys_stb_i;
579 wire sys_ack_o;
580 wire [31:0] sys_dat_o;
581
582 sysctrl_wb #(
583 .BASE_ADR(SYS_BASE_ADR),
shalanfd13eb52020-08-21 16:48:07 +0200584 .PLL_OUT(PLL_OUT),
585 .TRAP_OUT(TRAP_OUT),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400586 .IRQ7_SRC(IRQ7_SRC)
shalanfd13eb52020-08-21 16:48:07 +0200587 ) sysctrl (
588 .wb_clk_i(wb_clk_i),
589 .wb_rst_i(wb_rst_i),
590
591 .wb_adr_i(cpu_adr_o),
592 .wb_dat_i(cpu_dat_o),
593 .wb_sel_i(cpu_sel_o),
594 .wb_we_i(cpu_we_o),
595 .wb_cyc_i(cpu_cyc_o),
596
597 .wb_stb_i(sys_stb_i),
598 .wb_ack_o(sys_ack_o),
599 .wb_dat_o(sys_dat_o),
600
shalanfd13eb52020-08-21 16:48:07 +0200601 .pll_output_dest(pll_output_dest),
602 .trap_output_dest(trap_output_dest),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400603 .irq_7_inputsrc(irq_7_inputsrc)
shalanfd13eb52020-08-21 16:48:07 +0200604 );
605
606 // Logic Analyzer
607 wire la_stb_i;
608 wire la_ack_o;
609 wire [31:0] la_dat_o;
610
611 la_wb #(
612 .BASE_ADR(LA_BASE_ADR),
613 .LA_DATA_0(LA_DATA_0),
614 .LA_DATA_1(LA_DATA_1),
615 .LA_DATA_3(LA_DATA_3),
616 .LA_ENA_0(LA_ENA_0),
617 .LA_ENA_1(LA_ENA_1),
618 .LA_ENA_2(LA_ENA_2),
619 .LA_ENA_3(LA_ENA_3)
620 ) la (
621 .wb_clk_i(wb_clk_i),
622 .wb_rst_i(wb_rst_i),
623
624 .wb_adr_i(cpu_adr_o),
625 .wb_dat_i(cpu_dat_o),
626 .wb_sel_i(cpu_sel_o),
627 .wb_we_i(cpu_we_o),
628 .wb_cyc_i(cpu_cyc_o),
629
630 .wb_stb_i(la_stb_i),
631 .wb_ack_o(la_ack_o),
632 .wb_dat_o(la_dat_o),
633
634 .la_data(la_output),
shalan0d14e6e2020-08-31 16:50:48 +0200635 .la_data_in(la_input),
636 .la_oen(la_oen)
shalanfd13eb52020-08-21 16:48:07 +0200637 );
638
Tim Edwards6d9739d2020-10-19 11:00:49 -0400639 // WB Slave User Project Control
shalan0d14e6e2020-08-31 16:50:48 +0200640 wire mprj_ctrl_stb_i;
641 wire mprj_ctrl_ack_o;
642 wire [31:0] mprj_ctrl_dat_o;
Tim Edwards9eda80d2020-10-08 21:36:44 -0400643 wire [MPRJ_IO_PADS-1:0] mgmt_out_pre;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400644
645 // Bits assigned to specific functions as outputs prevent the
646 // mprj GPIO-as-output from applying data when that function
647 // is active
648
649 assign mgmt_out_data[MPRJ_IO_PADS-1:7] = mgmt_out_pre[MPRJ_IO_PADS-1:7];
650 assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6];
651 assign mgmt_out_data[5:0] = mgmt_out_pre[5:0];
shalan0d14e6e2020-08-31 16:50:48 +0200652
653 mprj_ctrl_wb #(
654 .BASE_ADR(MPRJ_CTRL_ADR),
655 .IO_PADS(MPRJ_IO_PADS),
Tim Edwardsc18c4742020-10-03 11:26:39 -0400656 .PWR_PADS(MPRJ_PWR_PADS)
shalan0d14e6e2020-08-31 16:50:48 +0200657 ) mprj_ctrl (
658 .wb_clk_i(wb_clk_i),
659 .wb_rst_i(wb_rst_i),
660
661 .wb_adr_i(cpu_adr_o),
662 .wb_dat_i(cpu_dat_o),
663 .wb_sel_i(cpu_sel_o),
664 .wb_we_i(cpu_we_o),
665 .wb_cyc_i(cpu_cyc_o),
666 .wb_stb_i(mprj_ctrl_stb_i),
667 .wb_ack_o(mprj_ctrl_ack_o),
668 .wb_dat_o(mprj_ctrl_dat_o),
669
Tim Edwards04ba17f2020-10-02 22:27:50 -0400670 .serial_clock(mprj_io_loader_clock),
671 .serial_resetn(mprj_io_loader_resetn),
672 .serial_data_out(mprj_io_loader_data),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400673 .mgmt_gpio_out(mgmt_out_pre),
674 .mgmt_gpio_in(mgmt_in_data)
shalan0d14e6e2020-08-31 16:50:48 +0200675 );
676
shalanfd13eb52020-08-21 16:48:07 +0200677 // Wishbone Slave RAM
678 wire mem_stb_i;
679 wire mem_ack_o;
680 wire [31:0] mem_dat_o;
681
682 mem_wb #(
683 .MEM_WORDS(MEM_WORDS)
684 ) soc_mem (
685 .wb_clk_i(wb_clk_i),
686 .wb_rst_i(wb_rst_i),
687
688 .wb_adr_i(cpu_adr_o),
689 .wb_dat_i(cpu_dat_o),
690 .wb_sel_i(cpu_sel_o),
691 .wb_we_i(cpu_we_o),
692 .wb_cyc_i(cpu_cyc_o),
693
694 .wb_stb_i(mem_stb_i),
695 .wb_ack_o(mem_ack_o),
696 .wb_dat_o(mem_dat_o)
697 );
698
699 // Wishbone intercon logic
700 wb_intercon #(
701 .AW(ADR_WIDTH),
702 .DW(DAT_WIDTH),
703 .NS(NUM_SLAVES),
704 .ADR_MASK(ADR_MASK),
705 .SLAVE_ADR(SLAVE_ADR)
706 ) intercon (
707 // Master Interface
708 .wbm_adr_i(cpu_adr_o),
709 .wbm_stb_i(cpu_stb_o),
710 .wbm_dat_o(cpu_dat_i),
711 .wbm_ack_o(cpu_ack_i),
712
713 // Slaves Interface
Tim Edwards04ba17f2020-10-02 22:27:50 -0400714 .wbs_stb_o({ xbar_stb_o, sys_stb_i, spimemio_cfg_stb_i,
715 mprj_stb_o, mprj_ctrl_stb_i, la_stb_i,
716 spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i,
717 gpio_stb_i, uart_stb_i,
718 spimemio_flash_stb_i, mem_stb_i }),
719 .wbs_dat_i({ xbar_dat_i, sys_dat_o, spimemio_cfg_dat_o,
720 mprj_dat_i, mprj_ctrl_dat_o, la_dat_o,
721 spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o,
722 gpio_dat_o, uart_dat_o,
723 spimemio_flash_dat_o, mem_dat_o }),
724 .wbs_ack_i({ xbar_ack_i, sys_ack_o, spimemio_cfg_ack_o,
725 mprj_ack_i, mprj_ctrl_ack_o, la_ack_o,
726 spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o,
727 gpio_ack_o, uart_ack_o,
728 spimemio_flash_ack_o, mem_ack_o })
shalanfd13eb52020-08-21 16:48:07 +0200729 );
730
shalanfd13eb52020-08-21 16:48:07 +0200731endmodule
732
shalanfd13eb52020-08-21 16:48:07 +0200733// Implementation note:
734// Replace the following two modules with wrappers for your SRAM cells.
Tim Edwardsef8312e2020-09-22 17:20:06 -0400735
Tim Edwards04ba17f2020-10-02 22:27:50 -0400736module mgmt_soc_regs (
shalanfd13eb52020-08-21 16:48:07 +0200737 input clk, wen,
738 input [5:0] waddr,
739 input [5:0] raddr1,
740 input [5:0] raddr2,
741 input [31:0] wdata,
742 output [31:0] rdata1,
743 output [31:0] rdata2
744);
745 reg [31:0] regs [0:31];
746
747 always @(posedge clk)
748 if (wen) regs[waddr[4:0]] <= wdata;
749
750 assign rdata1 = regs[raddr1[4:0]];
751 assign rdata2 = regs[raddr2[4:0]];
752endmodule