blob: 8d7dc716734bb82157718f6c5c5f6a933ae710e1 [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 Edwards32d05422020-10-19 19:43:52 -040073 input mprj_pwrgood,
74 input mprj2_pwrgood,
Tim Edwards04ba17f2020-10-02 22:27:50 -040075 output mprj_io_loader_resetn,
76 output mprj_io_loader_clock,
77 output mprj_io_loader_data,
shalanfd13eb52020-08-21 16:48:07 +020078
Tim Edwards6d9739d2020-10-19 11:00:49 -040079 // User Project pad data (when management SoC controls the pad)
Tim Edwards44bab472020-10-04 22:09:54 -040080 input [MPRJ_IO_PADS-1:0] mgmt_in_data,
81 output [MPRJ_IO_PADS-1:0] mgmt_out_data,
shalanfd13eb52020-08-21 16:48:07 +020082
83 // IRQ
shalanfd13eb52020-08-21 16:48:07 +020084 input irq_spi, // IRQ from standalone SPI
85
shalanfd13eb52020-08-21 16:48:07 +020086 // Flash memory control (SPI master)
87 output flash_csb,
88 output flash_clk,
89
90 output flash_csb_oeb,
91 output flash_clk_oeb,
92
93 output flash_io0_oeb,
94 output flash_io1_oeb,
95 output flash_io2_oeb,
96 output flash_io3_oeb,
97
98 output flash_csb_ieb,
99 output flash_clk_ieb,
100
101 output flash_io0_ieb,
102 output flash_io1_ieb,
103 output flash_io2_ieb,
104 output flash_io3_ieb,
105
106 output flash_io0_do,
107 output flash_io1_do,
108 output flash_io2_do,
109 output flash_io3_do,
110
111 input flash_io0_di,
112 input flash_io1_di,
113 input flash_io2_di,
114 input flash_io3_di,
115
Tim Edwards04ba17f2020-10-02 22:27:50 -0400116 // SPI pass-thru mode
117 input pass_thru_mgmt,
118 input pass_thru_mgmt_csb,
119 input pass_thru_mgmt_sck,
120 input pass_thru_mgmt_sdi,
121 output pass_thru_mgmt_sdo,
122
Tim Edwards81153202020-10-09 19:57:04 -0400123 // SPI master->slave direct link
124 output hk_connect,
Tim Edwards32d05422020-10-19 19:43:52 -0400125 // User clock monitoring
126 input user_clk,
Tim Edwards81153202020-10-09 19:57:04 -0400127
Tim Edwards6d9739d2020-10-19 11:00:49 -0400128 // WB MI A (User project)
shalan0d14e6e2020-08-31 16:50:48 +0200129 input mprj_ack_i,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400130 input [31:0] mprj_dat_i,
shalan0d14e6e2020-08-31 16:50:48 +0200131 output mprj_cyc_o,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400132 output mprj_stb_o,
133 output mprj_we_o,
134 output [3:0] mprj_sel_o,
135 output [31:0] mprj_adr_o,
Manar98a7adc2020-10-19 23:21:36 +0200136 output [31:0] mprj_dat_o
shalanfd13eb52020-08-21 16:48:07 +0200137);
138 /* Memory reverted back to 256 words while memory has to be synthesized */
shalan0d14e6e2020-08-31 16:50:48 +0200139 parameter integer MEM_WORDS = 8192;
shalanfd13eb52020-08-21 16:48:07 +0200140 parameter [31:0] STACKADDR = (4*MEM_WORDS); // end of memory
141 parameter [31:0] PROGADDR_RESET = 32'h 1000_0000;
142 parameter [31:0] PROGADDR_IRQ = 32'h 0000_0000;
143
144 // Slaves Base Addresses
Tim Edwards04ba17f2020-10-02 22:27:50 -0400145 parameter RAM_BASE_ADR = 32'h 0000_0000;
146 parameter FLASH_BASE_ADR = 32'h 1000_0000;
147 parameter UART_BASE_ADR = 32'h 2000_0000;
148 parameter GPIO_BASE_ADR = 32'h 2100_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400149 parameter COUNTER_TIMER0_BASE_ADR = 32'h 2200_0000;
150 parameter COUNTER_TIMER1_BASE_ADR = 32'h 2300_0000;
151 parameter SPI_MASTER_BASE_ADR = 32'h 2400_0000;
152 parameter LA_BASE_ADR = 32'h 2500_0000;
153 parameter MPRJ_CTRL_ADR = 32'h 2600_0000;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400154 parameter FLASH_CTRL_CFG = 32'h 2D00_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400155 parameter SYS_BASE_ADR = 32'h 2F00_0000;
156 parameter MPRJ_BASE_ADR = 32'h 3000_0000; // WB MI A
shalanfd13eb52020-08-21 16:48:07 +0200157
158 // UART
159 parameter UART_CLK_DIV = 8'h00;
160 parameter UART_DATA = 8'h04;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400161
162 // SPI Master
163 parameter SPI_MASTER_CONFIG = 8'h00;
164 parameter SPI_MASTER_DATA = 8'h04;
165
166 // Counter-timer 0
167 parameter COUNTER_TIMER0_CONFIG = 8'h00;
168 parameter COUNTER_TIMER0_VALUE = 8'h04;
169 parameter COUNTER_TIMER0_DATA = 8'h08;
170
171 // Counter-timer 1
172 parameter COUNTER_TIMER1_CONFIG = 8'h00;
173 parameter COUNTER_TIMER1_VALUE = 8'h04;
174 parameter COUNTER_TIMER1_DATA = 8'h08;
shalanfd13eb52020-08-21 16:48:07 +0200175
176 // SOC GPIO
177 parameter GPIO_DATA = 8'h00;
178 parameter GPIO_ENA = 8'h04;
179 parameter GPIO_PU = 8'h08;
180 parameter GPIO_PD = 8'h0c;
181
shalan0d14e6e2020-08-31 16:50:48 +0200182 // LA
shalanfd13eb52020-08-21 16:48:07 +0200183 parameter LA_DATA_0 = 8'h00;
184 parameter LA_DATA_1 = 8'h04;
185 parameter LA_DATA_2 = 8'h08;
186 parameter LA_DATA_3 = 8'h0c;
187 parameter LA_ENA_0 = 8'h10;
188 parameter LA_ENA_1 = 8'h14;
189 parameter LA_ENA_2 = 8'h18;
190 parameter LA_ENA_3 = 8'h1c;
191
shalanfd13eb52020-08-21 16:48:07 +0200192 // System Control Registers
Tim Edwards32d05422020-10-19 19:43:52 -0400193 parameter PWRGOOD = 8'h00;
194 parameter CLK_OUT = 8'h04;
195 parameter TRAP_OUT = 8'h08;
196 parameter IRQ_SRC = 8'h0c;
shalanfd13eb52020-08-21 16:48:07 +0200197
198 // Wishbone Interconnect
199 localparam ADR_WIDTH = 32;
200 localparam DAT_WIDTH = 32;
Manar98a7adc2020-10-19 23:21:36 +0200201 localparam NUM_SLAVES = 12;
shalanfd13eb52020-08-21 16:48:07 +0200202
203 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = {
shalanfd13eb52020-08-21 16:48:07 +0200204 {8'hFF, {ADR_WIDTH-8{1'b0}}},
205 {8'hFF, {ADR_WIDTH-8{1'b0}}},
206 {8'hFF, {ADR_WIDTH-8{1'b0}}},
207 {8'hFF, {ADR_WIDTH-8{1'b0}}},
208 {8'hFF, {ADR_WIDTH-8{1'b0}}},
209 {8'hFF, {ADR_WIDTH-8{1'b0}}},
210 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalan0d14e6e2020-08-31 16:50:48 +0200211 {8'hFF, {ADR_WIDTH-8{1'b0}}},
212 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400213 {8'hFF, {ADR_WIDTH-8{1'b0}}},
214 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalanfd13eb52020-08-21 16:48:07 +0200215 {8'hFF, {ADR_WIDTH-8{1'b0}}}
216 };
shalan0d14e6e2020-08-31 16:50:48 +0200217
shalanfd13eb52020-08-21 16:48:07 +0200218 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = {
shalanfd13eb52020-08-21 16:48:07 +0200219 {SYS_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200220 {FLASH_CTRL_CFG},
shalan0d14e6e2020-08-31 16:50:48 +0200221 {MPRJ_BASE_ADR},
222 {MPRJ_CTRL_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200223 {LA_BASE_ADR},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400224 {SPI_MASTER_BASE_ADR},
225 {COUNTER_TIMER1_BASE_ADR},
226 {COUNTER_TIMER0_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200227 {GPIO_BASE_ADR},
228 {UART_BASE_ADR},
229 {FLASH_BASE_ADR},
230 {RAM_BASE_ADR}
231 };
232
Tim Edwardsca2f3182020-10-06 10:05:11 -0400233 // The following functions are connected to specific user project
234 // area pins, when under control of the management area (during
235 // startup, and when not otherwise programmed for the user project).
236
237 // JTAG = jtag_out (inout)
238 // SDO = sdo_out (output) (shared with SPI master)
239 // SDI = mgmt_in_data[2] (input) (shared with SPI master)
240 // CSB = mgmt_in_data[3] (input) (shared with SPI master)
241 // SCK = mgmt_in_data[4] (input) (shared with SPI master)
242 // ser_rx = mgmt_in_data[5] (input)
243 // ser_tx = mgmt_out_data[6] (output)
244 // irq_pin = mgmt_in_data[7] (input)
245 // flash_csb = mgmt_out_data[8] (output) (user area flash)
246 // flash_sck = mgmt_out_data[9] (output) (user area flash)
247 // flash_io0 = mgmt_in/out_data[10] (input) (user area flash)
248 // flash_io1 = mgmt_in/out_data[11] (output) (user area flash)
Tim Edwards32d05422020-10-19 19:43:52 -0400249 // irq2_pin = mgmt_in_data[12] (input)
250 // trap_mon = mgmt_in_data[13] (output)
251 // clk1_mon = mgmt_in_data[14] (output)
252 // clk2_mon = mgmt_in_data[15] (output)
Tim Edwardsca2f3182020-10-06 10:05:11 -0400253
254 // OEB lines for [0] and [1] are the only ones connected directly to
255 // the pad. All others have OEB controlled by the configuration bit
256 // in the control block.
257
shalanfd13eb52020-08-21 16:48:07 +0200258 // memory-mapped I/O control registers
Tim Edwards04ba17f2020-10-02 22:27:50 -0400259 wire gpio_pullup; // Intermediate GPIO pullup
260 wire gpio_pulldown; // Intermediate GPIO pulldown
261 wire gpio_outenb; // Intermediate GPIO out enable (bar)
262 wire gpio_out; // Intermediate GPIO output
shalanfd13eb52020-08-21 16:48:07 +0200263
Tim Edwardsef8312e2020-09-22 17:20:06 -0400264 wire trap_output_dest; // Trap signal output destination
Tim Edwards32d05422020-10-19 19:43:52 -0400265 wire clk1_output_dest; // Core clock1 signal output destination
266 wire clk2_output_dest; // Core clock2 signal output destination
Tim Edwardsef8312e2020-09-22 17:20:06 -0400267 wire irq_7_inputsrc; // IRQ 7 source
Tim Edwards32d05422020-10-19 19:43:52 -0400268 wire irq_8_inputsrc; // IRQ 8 source
shalanfd13eb52020-08-21 16:48:07 +0200269
Tim Edwardsef8312e2020-09-22 17:20:06 -0400270 // Convert GPIO signals to sky130_fd_io pad signals
Tim Edwards04ba17f2020-10-02 22:27:50 -0400271 convert_gpio_sigs convert_gpio_bit (
shalanfd13eb52020-08-21 16:48:07 +0200272 .gpio_out(gpio_out),
273 .gpio_outenb(gpio_outenb),
274 .gpio_pu(gpio_pullup),
275 .gpio_pd(gpio_pulldown),
276 .gpio_out_pad(gpio_out_pad),
277 .gpio_outenb_pad(gpio_outenb_pad),
278 .gpio_inenb_pad(gpio_inenb_pad),
279 .gpio_mode1_pad(gpio_mode1_pad),
280 .gpio_mode0_pad(gpio_mode0_pad)
281 );
282
283 reg [31:0] irq;
284 wire irq_7;
Tim Edwards32d05422020-10-19 19:43:52 -0400285 wire irq_8;
shalanfd13eb52020-08-21 16:48:07 +0200286 wire irq_stall;
287 wire irq_uart;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400288 wire irq_spi_master;
289 wire irq_counter_timer0;
290 wire irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200291
shalanfd13eb52020-08-21 16:48:07 +0200292 assign irq_stall = 0;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400293 assign irq_7 = (irq_7_inputsrc == 1'b1) ? mgmt_in_data[7] : 1'b0;
Tim Edwards32d05422020-10-19 19:43:52 -0400294 assign irq_8 = (irq_8_inputsrc == 1'b1) ? mgmt_in_data[12] : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200295
296 always @* begin
297 irq = 0;
298 irq[3] = irq_stall;
299 irq[4] = irq_uart;
shalanfd13eb52020-08-21 16:48:07 +0200300 irq[6] = irq_spi;
301 irq[7] = irq_7;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400302 irq[9] = irq_spi_master;
303 irq[10] = irq_counter_timer0;
304 irq[11] = irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200305 end
306
Tim Edwards3245e2f2020-10-10 14:02:11 -0400307 // Assumption : no syscon module and wb_clk is the clock coming from the
308 // caravel_clocking module
309
shalanfd13eb52020-08-21 16:48:07 +0200310 assign wb_clk_i = clk;
311 assign wb_rst_i = ~resetn; // Redundant
312
313 // Wishbone Master
314 wire [31:0] cpu_adr_o;
315 wire [31:0] cpu_dat_i;
316 wire [3:0] cpu_sel_o;
317 wire cpu_we_o;
318 wire cpu_cyc_o;
319 wire cpu_stb_o;
320 wire [31:0] cpu_dat_o;
321 wire cpu_ack_i;
shalanfd13eb52020-08-21 16:48:07 +0200322
323 picorv32_wb #(
324 .STACKADDR(STACKADDR),
325 .PROGADDR_RESET(PROGADDR_RESET),
326 .PROGADDR_IRQ(PROGADDR_IRQ),
327 .BARREL_SHIFTER(1),
328 .COMPRESSED_ISA(1),
329 .ENABLE_MUL(1),
330 .ENABLE_DIV(1),
331 .ENABLE_IRQ(1),
332 .ENABLE_IRQ_QREGS(0)
333 ) cpu (
334 .wb_clk_i (wb_clk_i),
335 .wb_rst_i (wb_rst_i),
336 .trap (trap),
337 .irq (irq),
338 .mem_instr(mem_instr),
339 .wbm_adr_o(cpu_adr_o),
340 .wbm_dat_i(cpu_dat_i),
341 .wbm_stb_o(cpu_stb_o),
342 .wbm_ack_i(cpu_ack_i),
343 .wbm_cyc_o(cpu_cyc_o),
344 .wbm_dat_o(cpu_dat_o),
345 .wbm_we_o(cpu_we_o),
346 .wbm_sel_o(cpu_sel_o)
347 );
348
349 // Wishbone Slave SPIMEMIO
350 wire spimemio_flash_stb_i;
351 wire spimemio_flash_ack_o;
352 wire [31:0] spimemio_flash_dat_o;
353
354 wire spimemio_cfg_stb_i;
355 wire spimemio_cfg_ack_o;
356 wire [31:0] spimemio_cfg_dat_o;
357
358 spimemio_wb spimemio (
359 .wb_clk_i(wb_clk_i),
360 .wb_rst_i(wb_rst_i),
361
362 .wb_adr_i(cpu_adr_o),
363 .wb_dat_i(cpu_dat_o),
364 .wb_sel_i(cpu_sel_o),
365 .wb_we_i(cpu_we_o),
366 .wb_cyc_i(cpu_cyc_o),
367
368 // FLash Slave
369 .wb_flash_stb_i(spimemio_flash_stb_i),
370 .wb_flash_ack_o(spimemio_flash_ack_o),
371 .wb_flash_dat_o(spimemio_flash_dat_o),
372
373 // Config Register Slave
374 .wb_cfg_stb_i(spimemio_cfg_stb_i),
375 .wb_cfg_ack_o(spimemio_cfg_ack_o),
376 .wb_cfg_dat_o(spimemio_cfg_dat_o),
377
Tim Edwards04ba17f2020-10-02 22:27:50 -0400378 .pass_thru(pass_thru_mgmt),
379 .pass_thru_csb(pass_thru_mgmt_csb),
380 .pass_thru_sck(pass_thru_mgmt_sck),
381 .pass_thru_sdi(pass_thru_mgmt_sdi),
382 .pass_thru_sdo(pass_thru_mgmt_sdo),
383
shalanfd13eb52020-08-21 16:48:07 +0200384 .flash_csb (flash_csb),
385 .flash_clk (flash_clk),
386
387 .flash_csb_oeb (flash_csb_oeb),
388 .flash_clk_oeb (flash_clk_oeb),
389
390 .flash_io0_oeb (flash_io0_oeb),
391 .flash_io1_oeb (flash_io1_oeb),
392 .flash_io2_oeb (flash_io2_oeb),
393 .flash_io3_oeb (flash_io3_oeb),
394
395 .flash_csb_ieb (flash_csb_ieb),
396 .flash_clk_ieb (flash_clk_ieb),
397
398 .flash_io0_ieb (flash_io0_ieb),
399 .flash_io1_ieb (flash_io1_ieb),
400 .flash_io2_ieb (flash_io2_ieb),
401 .flash_io3_ieb (flash_io3_ieb),
402
403 .flash_io0_do (flash_io0_do),
404 .flash_io1_do (flash_io1_do),
405 .flash_io2_do (flash_io2_do),
406 .flash_io3_do (flash_io3_do),
407
408 .flash_io0_di (flash_io0_di),
409 .flash_io1_di (flash_io1_di),
410 .flash_io2_di (flash_io2_di),
411 .flash_io3_di (flash_io3_di)
412 );
413
414 // Wishbone Slave uart
415 wire uart_stb_i;
416 wire uart_ack_o;
417 wire [31:0] uart_dat_o;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400418 wire uart_enabled;
shalanfd13eb52020-08-21 16:48:07 +0200419
420 simpleuart_wb #(
421 .BASE_ADR(UART_BASE_ADR),
422 .CLK_DIV(UART_CLK_DIV),
423 .DATA(UART_DATA)
424 ) simpleuart (
425 // Wishbone Interface
426 .wb_clk_i(wb_clk_i),
427 .wb_rst_i(wb_rst_i),
428
429 .wb_adr_i(cpu_adr_o),
430 .wb_dat_i(cpu_dat_o),
431 .wb_sel_i(cpu_sel_o),
432 .wb_we_i(cpu_we_o),
433 .wb_cyc_i(cpu_cyc_o),
434
435 .wb_stb_i(uart_stb_i),
436 .wb_ack_o(uart_ack_o),
437 .wb_dat_o(uart_dat_o),
438
Tim Edwardsca2f3182020-10-06 10:05:11 -0400439 .uart_enabled(uart_enabled),
shalanfd13eb52020-08-21 16:48:07 +0200440 .ser_tx(ser_tx),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400441 .ser_rx(mgmt_in_data[5])
shalanfd13eb52020-08-21 16:48:07 +0200442 );
443
Tim Edwards04ba17f2020-10-02 22:27:50 -0400444 // Wishbone SPI master
445 wire spi_master_stb_i;
446 wire spi_master_ack_o;
447 wire [31:0] spi_master_dat_o;
448
449 simple_spi_master_wb #(
450 .BASE_ADR(SPI_MASTER_BASE_ADR),
451 .CONFIG(SPI_MASTER_CONFIG),
452 .DATA(SPI_MASTER_DATA)
453 ) simple_spi_master_inst (
454 // Wishbone Interface
455 .wb_clk_i(wb_clk_i),
456 .wb_rst_i(wb_rst_i),
457
458 .wb_adr_i(cpu_adr_o),
459 .wb_dat_i(cpu_dat_o),
460 .wb_sel_i(cpu_sel_o),
461 .wb_we_i(cpu_we_o),
462 .wb_cyc_i(cpu_cyc_o),
463
464 .wb_stb_i(spi_master_stb_i),
465 .wb_ack_o(spi_master_ack_o),
466 .wb_dat_o(spi_master_dat_o),
467
Tim Edwards81153202020-10-09 19:57:04 -0400468 .hk_connect(hk_connect),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400469 .csb(mgmt_out_pre[3]),
470 .sck(mgmt_out_pre[4]),
471 .sdi(mgmt_in_data[1]),
472 .sdo(mgmt_out_pre[2]),
473 .sdoenb(),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400474 .irq(irq_spi_master)
475 );
476
Tim Edwards32d05422020-10-19 19:43:52 -0400477 wire strobe_counter_timer0, strobe_counter_timer1;
478
Tim Edwards04ba17f2020-10-02 22:27:50 -0400479 // Wishbone Counter-timer 0
480 wire counter_timer0_stb_i;
481 wire counter_timer0_ack_o;
482 wire [31:0] counter_timer0_dat_o;
483
484 counter_timer_wb #(
485 .BASE_ADR(COUNTER_TIMER0_BASE_ADR),
486 .CONFIG(COUNTER_TIMER0_CONFIG),
487 .VALUE(COUNTER_TIMER0_VALUE),
488 .DATA(COUNTER_TIMER0_DATA)
489 ) counter_timer_0 (
490 // Wishbone Interface
491 .wb_clk_i(wb_clk_i),
492 .wb_rst_i(wb_rst_i),
Tim Edwards32d05422020-10-19 19:43:52 -0400493 .strobe_in(strobe_counter_timer1),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400494
495 .wb_adr_i(cpu_adr_o),
496 .wb_dat_i(cpu_dat_o),
497 .wb_sel_i(cpu_sel_o),
498 .wb_we_i(cpu_we_o),
499 .wb_cyc_i(cpu_cyc_o),
500
501 .wb_stb_i(counter_timer0_stb_i),
502 .wb_ack_o(counter_timer0_ack_o),
503 .wb_dat_o(counter_timer0_dat_o),
Tim Edwards32d05422020-10-19 19:43:52 -0400504 .strobe_out(strobe_counter_timer0),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400505 .irq(irq_counter_timer0)
506 );
507
508 // Wishbone Counter-timer 1
509 wire counter_timer1_stb_i;
510 wire counter_timer1_ack_o;
511 wire [31:0] counter_timer1_dat_o;
512
513 counter_timer_wb #(
514 .BASE_ADR(COUNTER_TIMER1_BASE_ADR),
515 .CONFIG(COUNTER_TIMER1_CONFIG),
516 .VALUE(COUNTER_TIMER1_VALUE),
517 .DATA(COUNTER_TIMER1_DATA)
518 ) counter_timer_1 (
519 // Wishbone Interface
520 .wb_clk_i(wb_clk_i),
521 .wb_rst_i(wb_rst_i),
Tim Edwards32d05422020-10-19 19:43:52 -0400522 .strobe_in(strobe_counter_timer0),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400523
524 .wb_adr_i(cpu_adr_o),
525 .wb_dat_i(cpu_dat_o),
526 .wb_sel_i(cpu_sel_o),
527 .wb_we_i(cpu_we_o),
528 .wb_cyc_i(cpu_cyc_o),
529
530 .wb_stb_i(counter_timer1_stb_i),
531 .wb_ack_o(counter_timer1_ack_o),
532 .wb_dat_o(counter_timer1_dat_o),
Tim Edwards32d05422020-10-19 19:43:52 -0400533 .strobe_out(strobe_counter_timer1),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400534 .irq(irq_counter_timer1)
535 );
536
shalanfd13eb52020-08-21 16:48:07 +0200537 // 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),
shalanfd13eb52020-08-21 16:48:07 +0200551 .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),
shalanfd13eb52020-08-21 16:48:07 +0200556 .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),
Tim Edwards32d05422020-10-19 19:43:52 -0400560 .gpio(gpio_out),
561 .gpio_oeb(gpio_outenb),
562 .gpio_pu(gpio_pullup),
563 .gpio_pd(gpio_pulldown)
shalanfd13eb52020-08-21 16:48:07 +0200564 );
565
shalanfd13eb52020-08-21 16:48:07 +0200566 // 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),
Tim Edwards32d05422020-10-19 19:43:52 -0400573 .PWRGOOD(PWRGOOD),
574 .CLK_OUT(CLK_OUT),
shalanfd13eb52020-08-21 16:48:07 +0200575 .TRAP_OUT(TRAP_OUT),
Tim Edwards32d05422020-10-19 19:43:52 -0400576 .IRQ_SRC(IRQ_SRC)
shalanfd13eb52020-08-21 16:48:07 +0200577 ) sysctrl (
578 .wb_clk_i(wb_clk_i),
579 .wb_rst_i(wb_rst_i),
580
581 .wb_adr_i(cpu_adr_o),
582 .wb_dat_i(cpu_dat_o),
583 .wb_sel_i(cpu_sel_o),
584 .wb_we_i(cpu_we_o),
585 .wb_cyc_i(cpu_cyc_o),
586
587 .wb_stb_i(sys_stb_i),
588 .wb_ack_o(sys_ack_o),
589 .wb_dat_o(sys_dat_o),
590
Tim Edwards32d05422020-10-19 19:43:52 -0400591 .usr1_pwrgood(mprj_pwrgood),
592 .usr2_pwrgood(mprj2_pwrgood),
shalanfd13eb52020-08-21 16:48:07 +0200593 .trap_output_dest(trap_output_dest),
Tim Edwards32d05422020-10-19 19:43:52 -0400594 .clk1_output_dest(clk1_output_dest),
595 .clk2_output_dest(clk2_output_dest),
596 .irq_7_inputsrc(irq_7_inputsrc),
597 .irq_8_inputsrc(irq_8_inputsrc)
shalanfd13eb52020-08-21 16:48:07 +0200598 );
599
600 // Logic Analyzer
601 wire la_stb_i;
602 wire la_ack_o;
603 wire [31:0] la_dat_o;
604
605 la_wb #(
606 .BASE_ADR(LA_BASE_ADR),
607 .LA_DATA_0(LA_DATA_0),
608 .LA_DATA_1(LA_DATA_1),
609 .LA_DATA_3(LA_DATA_3),
610 .LA_ENA_0(LA_ENA_0),
611 .LA_ENA_1(LA_ENA_1),
612 .LA_ENA_2(LA_ENA_2),
613 .LA_ENA_3(LA_ENA_3)
614 ) la (
615 .wb_clk_i(wb_clk_i),
616 .wb_rst_i(wb_rst_i),
617
618 .wb_adr_i(cpu_adr_o),
619 .wb_dat_i(cpu_dat_o),
620 .wb_sel_i(cpu_sel_o),
621 .wb_we_i(cpu_we_o),
622 .wb_cyc_i(cpu_cyc_o),
623
624 .wb_stb_i(la_stb_i),
625 .wb_ack_o(la_ack_o),
626 .wb_dat_o(la_dat_o),
627
628 .la_data(la_output),
shalan0d14e6e2020-08-31 16:50:48 +0200629 .la_data_in(la_input),
630 .la_oen(la_oen)
shalanfd13eb52020-08-21 16:48:07 +0200631 );
632
Tim Edwards6d9739d2020-10-19 11:00:49 -0400633 // WB Slave User Project Control
shalan0d14e6e2020-08-31 16:50:48 +0200634 wire mprj_ctrl_stb_i;
635 wire mprj_ctrl_ack_o;
636 wire [31:0] mprj_ctrl_dat_o;
Tim Edwards9eda80d2020-10-08 21:36:44 -0400637 wire [MPRJ_IO_PADS-1:0] mgmt_out_pre;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400638
639 // Bits assigned to specific functions as outputs prevent the
640 // mprj GPIO-as-output from applying data when that function
641 // is active
642
Tim Edwards32d05422020-10-19 19:43:52 -0400643 assign mgmt_out_data[MPRJ_IO_PADS-1:16] = mgmt_out_pre[MPRJ_IO_PADS-1:16];
644
645 // Routing of output monitors (PLL, trap, clk1, clk2)
646 assign mgmt_out_data[15] = clk2_output_dest ? user_clk : mgmt_out_pre[15];
647 assign mgmt_out_data[14] = clk1_output_dest ? clk : mgmt_out_pre[14];
648 assign mgmt_out_data[13] = trap_output_dest ? trap : mgmt_out_pre[13];
649
650 assign mgmt_out_data[12:7] = mgmt_out_pre[12:7];
Tim Edwardsca2f3182020-10-06 10:05:11 -0400651 assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6];
652 assign mgmt_out_data[5:0] = mgmt_out_pre[5:0];
shalan0d14e6e2020-08-31 16:50:48 +0200653
654 mprj_ctrl_wb #(
655 .BASE_ADR(MPRJ_CTRL_ADR),
656 .IO_PADS(MPRJ_IO_PADS),
Tim Edwardsc18c4742020-10-03 11:26:39 -0400657 .PWR_PADS(MPRJ_PWR_PADS)
shalan0d14e6e2020-08-31 16:50:48 +0200658 ) mprj_ctrl (
659 .wb_clk_i(wb_clk_i),
660 .wb_rst_i(wb_rst_i),
661
662 .wb_adr_i(cpu_adr_o),
663 .wb_dat_i(cpu_dat_o),
664 .wb_sel_i(cpu_sel_o),
665 .wb_we_i(cpu_we_o),
666 .wb_cyc_i(cpu_cyc_o),
667 .wb_stb_i(mprj_ctrl_stb_i),
668 .wb_ack_o(mprj_ctrl_ack_o),
669 .wb_dat_o(mprj_ctrl_dat_o),
670
Tim Edwards04ba17f2020-10-02 22:27:50 -0400671 .serial_clock(mprj_io_loader_clock),
672 .serial_resetn(mprj_io_loader_resetn),
673 .serial_data_out(mprj_io_loader_data),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400674 .mgmt_gpio_out(mgmt_out_pre),
675 .mgmt_gpio_in(mgmt_in_data)
shalan0d14e6e2020-08-31 16:50:48 +0200676 );
677
shalanfd13eb52020-08-21 16:48:07 +0200678 // Wishbone Slave RAM
679 wire mem_stb_i;
680 wire mem_ack_o;
681 wire [31:0] mem_dat_o;
682
683 mem_wb #(
684 .MEM_WORDS(MEM_WORDS)
685 ) soc_mem (
686 .wb_clk_i(wb_clk_i),
687 .wb_rst_i(wb_rst_i),
688
689 .wb_adr_i(cpu_adr_o),
690 .wb_dat_i(cpu_dat_o),
691 .wb_sel_i(cpu_sel_o),
692 .wb_we_i(cpu_we_o),
693 .wb_cyc_i(cpu_cyc_o),
694
695 .wb_stb_i(mem_stb_i),
696 .wb_ack_o(mem_ack_o),
697 .wb_dat_o(mem_dat_o)
698 );
699
700 // Wishbone intercon logic
701 wb_intercon #(
702 .AW(ADR_WIDTH),
703 .DW(DAT_WIDTH),
704 .NS(NUM_SLAVES),
705 .ADR_MASK(ADR_MASK),
706 .SLAVE_ADR(SLAVE_ADR)
707 ) intercon (
708 // Master Interface
709 .wbm_adr_i(cpu_adr_o),
710 .wbm_stb_i(cpu_stb_o),
711 .wbm_dat_o(cpu_dat_i),
712 .wbm_ack_o(cpu_ack_i),
713
714 // Slaves Interface
Manar98a7adc2020-10-19 23:21:36 +0200715 .wbs_stb_o({ sys_stb_i, spimemio_cfg_stb_i,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400716 mprj_stb_o, mprj_ctrl_stb_i, la_stb_i,
717 spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i,
718 gpio_stb_i, uart_stb_i,
719 spimemio_flash_stb_i, mem_stb_i }),
Manar98a7adc2020-10-19 23:21:36 +0200720 .wbs_dat_i({ sys_dat_o, spimemio_cfg_dat_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400721 mprj_dat_i, mprj_ctrl_dat_o, la_dat_o,
722 spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o,
723 gpio_dat_o, uart_dat_o,
724 spimemio_flash_dat_o, mem_dat_o }),
Manar98a7adc2020-10-19 23:21:36 +0200725 .wbs_ack_i({ sys_ack_o, spimemio_cfg_ack_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400726 mprj_ack_i, mprj_ctrl_ack_o, la_ack_o,
727 spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o,
728 gpio_ack_o, uart_ack_o,
729 spimemio_flash_ack_o, mem_ack_o })
shalanfd13eb52020-08-21 16:48:07 +0200730 );
731
shalanfd13eb52020-08-21 16:48:07 +0200732endmodule
733
shalanfd13eb52020-08-21 16:48:07 +0200734// Implementation note:
735// Replace the following two modules with wrappers for your SRAM cells.
Tim Edwardsef8312e2020-09-22 17:20:06 -0400736
Tim Edwards04ba17f2020-10-02 22:27:50 -0400737module mgmt_soc_regs (
shalanfd13eb52020-08-21 16:48:07 +0200738 input clk, wen,
739 input [5:0] waddr,
740 input [5:0] raddr1,
741 input [5:0] raddr2,
742 input [31:0] wdata,
743 output [31:0] rdata1,
744 output [31:0] rdata2
745);
746 reg [31:0] regs [0:31];
747
748 always @(posedge clk)
749 if (wen) regs[waddr[4:0]] <= wdata;
750
751 assign rdata1 = regs[raddr1[4:0]];
752 assign rdata2 = regs[raddr2[4:0]];
753endmodule