blob: 17a73f4dce1c4fbd6656b198d764eb8b30d38550 [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;
Tim Edwards581068f2020-11-19 12:45:25 -0500324 wire ser_tx;
325
326 wire wb_clk_i;
327 wire wb_rst_i;
shalanfd13eb52020-08-21 16:48:07 +0200328
shalanfd13eb52020-08-21 16:48:07 +0200329 assign irq_stall = 0;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400330 assign irq_7 = (irq_7_inputsrc == 1'b1) ? mgmt_in_data[7] : 1'b0;
Tim Edwards32d05422020-10-19 19:43:52 -0400331 assign irq_8 = (irq_8_inputsrc == 1'b1) ? mgmt_in_data[12] : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200332
333 always @* begin
334 irq = 0;
335 irq[3] = irq_stall;
336 irq[4] = irq_uart;
shalanfd13eb52020-08-21 16:48:07 +0200337 irq[6] = irq_spi;
338 irq[7] = irq_7;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400339 irq[9] = irq_spi_master;
340 irq[10] = irq_counter_timer0;
341 irq[11] = irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200342 end
343
Tim Edwards3245e2f2020-10-10 14:02:11 -0400344 // Assumption : no syscon module and wb_clk is the clock coming from the
345 // caravel_clocking module
346
shalanfd13eb52020-08-21 16:48:07 +0200347 assign wb_clk_i = clk;
348 assign wb_rst_i = ~resetn; // Redundant
349
350 // Wishbone Master
351 wire [31:0] cpu_adr_o;
352 wire [31:0] cpu_dat_i;
353 wire [3:0] cpu_sel_o;
354 wire cpu_we_o;
355 wire cpu_cyc_o;
356 wire cpu_stb_o;
357 wire [31:0] cpu_dat_o;
358 wire cpu_ack_i;
Tim Edwards581068f2020-11-19 12:45:25 -0500359 wire mem_instr;
shalanfd13eb52020-08-21 16:48:07 +0200360
361 picorv32_wb #(
362 .STACKADDR(STACKADDR),
363 .PROGADDR_RESET(PROGADDR_RESET),
364 .PROGADDR_IRQ(PROGADDR_IRQ),
365 .BARREL_SHIFTER(1),
366 .COMPRESSED_ISA(1),
367 .ENABLE_MUL(1),
368 .ENABLE_DIV(1),
369 .ENABLE_IRQ(1),
370 .ENABLE_IRQ_QREGS(0)
371 ) cpu (
372 .wb_clk_i (wb_clk_i),
373 .wb_rst_i (wb_rst_i),
374 .trap (trap),
375 .irq (irq),
376 .mem_instr(mem_instr),
377 .wbm_adr_o(cpu_adr_o),
378 .wbm_dat_i(cpu_dat_i),
379 .wbm_stb_o(cpu_stb_o),
380 .wbm_ack_i(cpu_ack_i),
381 .wbm_cyc_o(cpu_cyc_o),
382 .wbm_dat_o(cpu_dat_o),
383 .wbm_we_o(cpu_we_o),
384 .wbm_sel_o(cpu_sel_o)
385 );
386
387 // Wishbone Slave SPIMEMIO
388 wire spimemio_flash_stb_i;
389 wire spimemio_flash_ack_o;
390 wire [31:0] spimemio_flash_dat_o;
391
392 wire spimemio_cfg_stb_i;
393 wire spimemio_cfg_ack_o;
394 wire [31:0] spimemio_cfg_dat_o;
395
396 spimemio_wb spimemio (
397 .wb_clk_i(wb_clk_i),
398 .wb_rst_i(wb_rst_i),
399
400 .wb_adr_i(cpu_adr_o),
401 .wb_dat_i(cpu_dat_o),
402 .wb_sel_i(cpu_sel_o),
403 .wb_we_i(cpu_we_o),
404 .wb_cyc_i(cpu_cyc_o),
405
406 // FLash Slave
407 .wb_flash_stb_i(spimemio_flash_stb_i),
408 .wb_flash_ack_o(spimemio_flash_ack_o),
409 .wb_flash_dat_o(spimemio_flash_dat_o),
410
411 // Config Register Slave
412 .wb_cfg_stb_i(spimemio_cfg_stb_i),
413 .wb_cfg_ack_o(spimemio_cfg_ack_o),
414 .wb_cfg_dat_o(spimemio_cfg_dat_o),
415
Tim Edwards04ba17f2020-10-02 22:27:50 -0400416 .pass_thru(pass_thru_mgmt),
417 .pass_thru_csb(pass_thru_mgmt_csb),
418 .pass_thru_sck(pass_thru_mgmt_sck),
419 .pass_thru_sdi(pass_thru_mgmt_sdi),
420 .pass_thru_sdo(pass_thru_mgmt_sdo),
421
shalanfd13eb52020-08-21 16:48:07 +0200422 .flash_csb (flash_csb),
423 .flash_clk (flash_clk),
424
425 .flash_csb_oeb (flash_csb_oeb),
426 .flash_clk_oeb (flash_clk_oeb),
427
428 .flash_io0_oeb (flash_io0_oeb),
429 .flash_io1_oeb (flash_io1_oeb),
430 .flash_io2_oeb (flash_io2_oeb),
431 .flash_io3_oeb (flash_io3_oeb),
432
433 .flash_csb_ieb (flash_csb_ieb),
434 .flash_clk_ieb (flash_clk_ieb),
435
436 .flash_io0_ieb (flash_io0_ieb),
437 .flash_io1_ieb (flash_io1_ieb),
438 .flash_io2_ieb (flash_io2_ieb),
439 .flash_io3_ieb (flash_io3_ieb),
440
441 .flash_io0_do (flash_io0_do),
442 .flash_io1_do (flash_io1_do),
443 .flash_io2_do (flash_io2_do),
444 .flash_io3_do (flash_io3_do),
445
446 .flash_io0_di (flash_io0_di),
447 .flash_io1_di (flash_io1_di),
448 .flash_io2_di (flash_io2_di),
449 .flash_io3_di (flash_io3_di)
450 );
451
452 // Wishbone Slave uart
453 wire uart_stb_i;
454 wire uart_ack_o;
455 wire [31:0] uart_dat_o;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400456 wire uart_enabled;
shalanfd13eb52020-08-21 16:48:07 +0200457
458 simpleuart_wb #(
459 .BASE_ADR(UART_BASE_ADR),
460 .CLK_DIV(UART_CLK_DIV),
461 .DATA(UART_DATA)
462 ) simpleuart (
463 // Wishbone Interface
464 .wb_clk_i(wb_clk_i),
465 .wb_rst_i(wb_rst_i),
466
467 .wb_adr_i(cpu_adr_o),
468 .wb_dat_i(cpu_dat_o),
469 .wb_sel_i(cpu_sel_o),
470 .wb_we_i(cpu_we_o),
471 .wb_cyc_i(cpu_cyc_o),
472
473 .wb_stb_i(uart_stb_i),
474 .wb_ack_o(uart_ack_o),
475 .wb_dat_o(uart_dat_o),
476
Tim Edwardsca2f3182020-10-06 10:05:11 -0400477 .uart_enabled(uart_enabled),
shalanfd13eb52020-08-21 16:48:07 +0200478 .ser_tx(ser_tx),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400479 .ser_rx(mgmt_in_data[5])
shalanfd13eb52020-08-21 16:48:07 +0200480 );
481
Tim Edwards04ba17f2020-10-02 22:27:50 -0400482 // Wishbone SPI master
483 wire spi_master_stb_i;
484 wire spi_master_ack_o;
485 wire [31:0] spi_master_dat_o;
486
487 simple_spi_master_wb #(
488 .BASE_ADR(SPI_MASTER_BASE_ADR),
489 .CONFIG(SPI_MASTER_CONFIG),
490 .DATA(SPI_MASTER_DATA)
491 ) simple_spi_master_inst (
492 // Wishbone Interface
493 .wb_clk_i(wb_clk_i),
494 .wb_rst_i(wb_rst_i),
495
496 .wb_adr_i(cpu_adr_o),
497 .wb_dat_i(cpu_dat_o),
498 .wb_sel_i(cpu_sel_o),
499 .wb_we_i(cpu_we_o),
500 .wb_cyc_i(cpu_cyc_o),
501
502 .wb_stb_i(spi_master_stb_i),
503 .wb_ack_o(spi_master_ack_o),
504 .wb_dat_o(spi_master_dat_o),
505
Tim Edwards81153202020-10-09 19:57:04 -0400506 .hk_connect(hk_connect),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400507 .csb(mgmt_out_pre[3]),
508 .sck(mgmt_out_pre[4]),
509 .sdi(mgmt_in_data[1]),
510 .sdo(mgmt_out_pre[2]),
511 .sdoenb(),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400512 .irq(irq_spi_master)
513 );
514
Tim Edwards7be29a22020-10-25 21:50:19 -0400515 wire counter_timer_strobe, counter_timer_offset;
516 wire counter_timer0_enable, counter_timer1_enable;
517 wire counter_timer0_stop, counter_timer1_stop;
Tim Edwards32d05422020-10-19 19:43:52 -0400518
Tim Edwards04ba17f2020-10-02 22:27:50 -0400519 // Wishbone Counter-timer 0
520 wire counter_timer0_stb_i;
521 wire counter_timer0_ack_o;
522 wire [31:0] counter_timer0_dat_o;
523
Tim Edwards7be29a22020-10-25 21:50:19 -0400524 counter_timer_low_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400525 .BASE_ADR(COUNTER_TIMER0_BASE_ADR),
526 .CONFIG(COUNTER_TIMER0_CONFIG),
527 .VALUE(COUNTER_TIMER0_VALUE),
528 .DATA(COUNTER_TIMER0_DATA)
529 ) counter_timer_0 (
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_timer0_stb_i),
541 .wb_ack_o(counter_timer0_ack_o),
542 .wb_dat_o(counter_timer0_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400543
544 .enable_in(counter_timer1_enable),
545 .stop_in(counter_timer1_stop),
546 .strobe(counter_timer_strobe),
547 .is_offset(counter_timer_offset),
548 .enable_out(counter_timer0_enable),
549 .stop_out(counter_timer0_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400550 .irq(irq_counter_timer0)
551 );
552
553 // Wishbone Counter-timer 1
554 wire counter_timer1_stb_i;
555 wire counter_timer1_ack_o;
556 wire [31:0] counter_timer1_dat_o;
557
Tim Edwards7be29a22020-10-25 21:50:19 -0400558 counter_timer_high_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400559 .BASE_ADR(COUNTER_TIMER1_BASE_ADR),
560 .CONFIG(COUNTER_TIMER1_CONFIG),
561 .VALUE(COUNTER_TIMER1_VALUE),
562 .DATA(COUNTER_TIMER1_DATA)
563 ) counter_timer_1 (
564 // Wishbone Interface
565 .wb_clk_i(wb_clk_i),
566 .wb_rst_i(wb_rst_i),
567
568 .wb_adr_i(cpu_adr_o),
569 .wb_dat_i(cpu_dat_o),
570 .wb_sel_i(cpu_sel_o),
571 .wb_we_i(cpu_we_o),
572 .wb_cyc_i(cpu_cyc_o),
573
574 .wb_stb_i(counter_timer1_stb_i),
575 .wb_ack_o(counter_timer1_ack_o),
576 .wb_dat_o(counter_timer1_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400577
578 .enable_in(counter_timer0_enable),
579 .strobe(counter_timer_strobe),
580 .stop_in(counter_timer0_stop),
581 .is_offset(counter_timer_offset),
582 .enable_out(counter_timer1_enable),
583 .stop_out(counter_timer1_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400584 .irq(irq_counter_timer1)
585 );
586
shalanfd13eb52020-08-21 16:48:07 +0200587 // Wishbone Slave GPIO Registers
588 wire gpio_stb_i;
589 wire gpio_ack_o;
590 wire [31:0] gpio_dat_o;
591
592 gpio_wb #(
593 .BASE_ADR(GPIO_BASE_ADR),
594 .GPIO_DATA(GPIO_DATA),
595 .GPIO_ENA(GPIO_ENA),
596 .GPIO_PD(GPIO_PD),
597 .GPIO_PU(GPIO_PU)
598 ) gpio_wb (
599 .wb_clk_i(wb_clk_i),
600 .wb_rst_i(wb_rst_i),
shalanfd13eb52020-08-21 16:48:07 +0200601 .wb_adr_i(cpu_adr_o),
602 .wb_dat_i(cpu_dat_o),
603 .wb_sel_i(cpu_sel_o),
604 .wb_we_i(cpu_we_o),
605 .wb_cyc_i(cpu_cyc_o),
shalanfd13eb52020-08-21 16:48:07 +0200606 .wb_stb_i(gpio_stb_i),
607 .wb_ack_o(gpio_ack_o),
608 .wb_dat_o(gpio_dat_o),
609 .gpio_in_pad(gpio_in_pad),
Tim Edwards32d05422020-10-19 19:43:52 -0400610 .gpio(gpio_out),
611 .gpio_oeb(gpio_outenb),
612 .gpio_pu(gpio_pullup),
613 .gpio_pd(gpio_pulldown)
shalanfd13eb52020-08-21 16:48:07 +0200614 );
615
shalanfd13eb52020-08-21 16:48:07 +0200616 // Wishbone Slave System Control Register
617 wire sys_stb_i;
618 wire sys_ack_o;
619 wire [31:0] sys_dat_o;
620
621 sysctrl_wb #(
622 .BASE_ADR(SYS_BASE_ADR),
Tim Edwards32d05422020-10-19 19:43:52 -0400623 .PWRGOOD(PWRGOOD),
624 .CLK_OUT(CLK_OUT),
shalanfd13eb52020-08-21 16:48:07 +0200625 .TRAP_OUT(TRAP_OUT),
Tim Edwards32d05422020-10-19 19:43:52 -0400626 .IRQ_SRC(IRQ_SRC)
shalanfd13eb52020-08-21 16:48:07 +0200627 ) sysctrl (
628 .wb_clk_i(wb_clk_i),
629 .wb_rst_i(wb_rst_i),
630
631 .wb_adr_i(cpu_adr_o),
632 .wb_dat_i(cpu_dat_o),
633 .wb_sel_i(cpu_sel_o),
634 .wb_we_i(cpu_we_o),
635 .wb_cyc_i(cpu_cyc_o),
636
637 .wb_stb_i(sys_stb_i),
638 .wb_ack_o(sys_ack_o),
639 .wb_dat_o(sys_dat_o),
640
Tim Edwards05ad4fc2020-10-19 22:12:33 -0400641 .usr1_vcc_pwrgood(mprj_vcc_pwrgood),
642 .usr2_vcc_pwrgood(mprj2_vcc_pwrgood),
643 .usr1_vdd_pwrgood(mprj_vdd_pwrgood),
644 .usr2_vdd_pwrgood(mprj2_vdd_pwrgood),
shalanfd13eb52020-08-21 16:48:07 +0200645 .trap_output_dest(trap_output_dest),
Tim Edwards32d05422020-10-19 19:43:52 -0400646 .clk1_output_dest(clk1_output_dest),
647 .clk2_output_dest(clk2_output_dest),
648 .irq_7_inputsrc(irq_7_inputsrc),
649 .irq_8_inputsrc(irq_8_inputsrc)
shalanfd13eb52020-08-21 16:48:07 +0200650 );
651
652 // Logic Analyzer
653 wire la_stb_i;
654 wire la_ack_o;
655 wire [31:0] la_dat_o;
656
657 la_wb #(
658 .BASE_ADR(LA_BASE_ADR),
659 .LA_DATA_0(LA_DATA_0),
660 .LA_DATA_1(LA_DATA_1),
661 .LA_DATA_3(LA_DATA_3),
662 .LA_ENA_0(LA_ENA_0),
663 .LA_ENA_1(LA_ENA_1),
664 .LA_ENA_2(LA_ENA_2),
665 .LA_ENA_3(LA_ENA_3)
666 ) la (
667 .wb_clk_i(wb_clk_i),
668 .wb_rst_i(wb_rst_i),
669
670 .wb_adr_i(cpu_adr_o),
671 .wb_dat_i(cpu_dat_o),
672 .wb_sel_i(cpu_sel_o),
673 .wb_we_i(cpu_we_o),
674 .wb_cyc_i(cpu_cyc_o),
675
676 .wb_stb_i(la_stb_i),
677 .wb_ack_o(la_ack_o),
678 .wb_dat_o(la_dat_o),
679
680 .la_data(la_output),
shalan0d14e6e2020-08-31 16:50:48 +0200681 .la_data_in(la_input),
682 .la_oen(la_oen)
shalanfd13eb52020-08-21 16:48:07 +0200683 );
684
Manarcd4cff72020-11-04 16:22:59 +0200685 // User project WB MI A port
686 assign mprj_cyc_o = cpu_cyc_o;
687 assign mprj_we_o = cpu_we_o;
688 assign mprj_sel_o = cpu_sel_o;
689 assign mprj_adr_o = cpu_adr_o;
690 assign mprj_dat_o = cpu_dat_o;
691
Tim Edwards6d9739d2020-10-19 11:00:49 -0400692 // WB Slave User Project Control
shalan0d14e6e2020-08-31 16:50:48 +0200693 wire mprj_ctrl_stb_i;
694 wire mprj_ctrl_ack_o;
695 wire [31:0] mprj_ctrl_dat_o;
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200696 wire [`MPRJ_IO_PADS-1:0] mgmt_out_pre;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400697
698 // Bits assigned to specific functions as outputs prevent the
699 // mprj GPIO-as-output from applying data when that function
700 // is active
701
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200702 assign mgmt_out_data[`MPRJ_IO_PADS-1:16] = mgmt_out_pre[`MPRJ_IO_PADS-1:16];
Tim Edwards32d05422020-10-19 19:43:52 -0400703
704 // Routing of output monitors (PLL, trap, clk1, clk2)
705 assign mgmt_out_data[15] = clk2_output_dest ? user_clk : mgmt_out_pre[15];
706 assign mgmt_out_data[14] = clk1_output_dest ? clk : mgmt_out_pre[14];
707 assign mgmt_out_data[13] = trap_output_dest ? trap : mgmt_out_pre[13];
708
709 assign mgmt_out_data[12:7] = mgmt_out_pre[12:7];
Tim Edwardsca2f3182020-10-06 10:05:11 -0400710 assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6];
711 assign mgmt_out_data[5:0] = mgmt_out_pre[5:0];
shalan0d14e6e2020-08-31 16:50:48 +0200712
713 mprj_ctrl_wb #(
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200714 .BASE_ADR(MPRJ_CTRL_ADR)
shalan0d14e6e2020-08-31 16:50:48 +0200715 ) mprj_ctrl (
716 .wb_clk_i(wb_clk_i),
717 .wb_rst_i(wb_rst_i),
718
719 .wb_adr_i(cpu_adr_o),
720 .wb_dat_i(cpu_dat_o),
721 .wb_sel_i(cpu_sel_o),
722 .wb_we_i(cpu_we_o),
723 .wb_cyc_i(cpu_cyc_o),
724 .wb_stb_i(mprj_ctrl_stb_i),
725 .wb_ack_o(mprj_ctrl_ack_o),
726 .wb_dat_o(mprj_ctrl_dat_o),
727
Tim Edwards04ba17f2020-10-02 22:27:50 -0400728 .serial_clock(mprj_io_loader_clock),
729 .serial_resetn(mprj_io_loader_resetn),
730 .serial_data_out(mprj_io_loader_data),
Tim Edwards496a08a2020-10-26 15:44:51 -0400731 .sdo_oenb_state(sdo_oenb_state),
732 .jtag_oenb_state(jtag_oenb_state),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400733 .mgmt_gpio_out(mgmt_out_pre),
Tim Edwardsba328902020-10-27 15:03:22 -0400734 .mgmt_gpio_in(mgmt_in_data),
735 .pwr_ctrl_out(pwr_ctrl_out)
shalan0d14e6e2020-08-31 16:50:48 +0200736 );
737
shalanfd13eb52020-08-21 16:48:07 +0200738 // Wishbone Slave RAM
739 wire mem_stb_i;
740 wire mem_ack_o;
741 wire [31:0] mem_dat_o;
742
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200743 mem_wb soc_mem (
Manar61dce922020-11-10 19:26:28 +0200744 `ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +0200745 .VPWR(vdd1v8),
746 .VGND(vss),
747 `endif
shalanfd13eb52020-08-21 16:48:07 +0200748 .wb_clk_i(wb_clk_i),
749 .wb_rst_i(wb_rst_i),
750
751 .wb_adr_i(cpu_adr_o),
752 .wb_dat_i(cpu_dat_o),
753 .wb_sel_i(cpu_sel_o),
754 .wb_we_i(cpu_we_o),
755 .wb_cyc_i(cpu_cyc_o),
756
757 .wb_stb_i(mem_stb_i),
758 .wb_ack_o(mem_ack_o),
759 .wb_dat_o(mem_dat_o)
760 );
761
Manarffe6cad2020-11-09 19:09:04 +0200762 wire stg_rw_stb_i;
763 wire stg_ro_stb_i;
764 wire stg_rw_ack_o;
765 wire stg_ro_ack_o;
766 wire [31:0] stg_rw_dat_o;
767 wire [31:0] stg_ro_dat_o;
Manar55ec3692020-10-30 16:32:18 +0200768
769 // Storage area wishbone brige
770 storage_bridge_wb #(
Manarffe6cad2020-11-09 19:09:04 +0200771 .RW_BLOCKS_ADR(RW_BLOCKS_ADR),
772 .RO_BLOCKS_ADR(RO_BLOCKS_ADR)
Manar55ec3692020-10-30 16:32:18 +0200773 ) wb_bridge (
774 .wb_clk_i(wb_clk_i),
775 .wb_rst_i(wb_rst_i),
Manar55ec3692020-10-30 16:32:18 +0200776 .wb_adr_i(cpu_adr_o),
777 .wb_dat_i(cpu_dat_o),
778 .wb_sel_i(cpu_sel_o),
779 .wb_we_i(cpu_we_o),
780 .wb_cyc_i(cpu_cyc_o),
Manarffe6cad2020-11-09 19:09:04 +0200781 .wb_stb_i({stg_ro_stb_i, stg_rw_stb_i}),
782 .wb_ack_o({stg_ro_ack_o, stg_rw_ack_o}),
783 .wb_rw_dat_o(stg_rw_dat_o),
Manar55ec3692020-10-30 16:32:18 +0200784 // MGMT_AREA RO WB Interface
Manarffe6cad2020-11-09 19:09:04 +0200785 .wb_ro_dat_o(stg_ro_dat_o),
Manar55ec3692020-10-30 16:32:18 +0200786 // MGMT Area native memory interface
787 .mgmt_ena(mgmt_ena),
788 .mgmt_wen_mask(mgmt_wen_mask),
789 .mgmt_wen(mgmt_wen),
790 .mgmt_addr(mgmt_addr),
791 .mgmt_wdata(mgmt_wdata),
792 .mgmt_rdata(mgmt_rdata),
Manar55ec3692020-10-30 16:32:18 +0200793 // MGMT_AREA RO interface
Manarffe6cad2020-11-09 19:09:04 +0200794 .mgmt_ena_ro(mgmt_ena_ro),
795 .mgmt_addr_ro(mgmt_addr_ro),
796 .mgmt_rdata_ro(mgmt_rdata_ro)
Manar55ec3692020-10-30 16:32:18 +0200797 );
798
shalanfd13eb52020-08-21 16:48:07 +0200799 // Wishbone intercon logic
800 wb_intercon #(
801 .AW(ADR_WIDTH),
802 .DW(DAT_WIDTH),
803 .NS(NUM_SLAVES),
804 .ADR_MASK(ADR_MASK),
805 .SLAVE_ADR(SLAVE_ADR)
806 ) intercon (
807 // Master Interface
808 .wbm_adr_i(cpu_adr_o),
809 .wbm_stb_i(cpu_stb_o),
810 .wbm_dat_o(cpu_dat_i),
811 .wbm_ack_o(cpu_ack_i),
812
813 // Slaves Interface
Manar98a7adc2020-10-19 23:21:36 +0200814 .wbs_stb_o({ sys_stb_i, spimemio_cfg_stb_i,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400815 mprj_stb_o, mprj_ctrl_stb_i, la_stb_i,
816 spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i,
817 gpio_stb_i, uart_stb_i,
Manarffe6cad2020-11-09 19:09:04 +0200818 spimemio_flash_stb_i, stg_ro_stb_i, stg_rw_stb_i, mem_stb_i }),
Manar98a7adc2020-10-19 23:21:36 +0200819 .wbs_dat_i({ sys_dat_o, spimemio_cfg_dat_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400820 mprj_dat_i, mprj_ctrl_dat_o, la_dat_o,
821 spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o,
822 gpio_dat_o, uart_dat_o,
Manarffe6cad2020-11-09 19:09:04 +0200823 spimemio_flash_dat_o, stg_ro_dat_o ,stg_rw_dat_o, mem_dat_o }),
Manar98a7adc2020-10-19 23:21:36 +0200824 .wbs_ack_i({ sys_ack_o, spimemio_cfg_ack_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400825 mprj_ack_i, mprj_ctrl_ack_o, la_ack_o,
826 spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o,
827 gpio_ack_o, uart_ack_o,
Manarffe6cad2020-11-09 19:09:04 +0200828 spimemio_flash_ack_o, stg_ro_ack_o, stg_rw_ack_o, mem_ack_o })
shalanfd13eb52020-08-21 16:48:07 +0200829 );
830
shalanfd13eb52020-08-21 16:48:07 +0200831endmodule
832
shalanfd13eb52020-08-21 16:48:07 +0200833// Implementation note:
834// Replace the following two modules with wrappers for your SRAM cells.
Tim Edwardsef8312e2020-09-22 17:20:06 -0400835
Tim Edwards04ba17f2020-10-02 22:27:50 -0400836module mgmt_soc_regs (
shalanfd13eb52020-08-21 16:48:07 +0200837 input clk, wen,
838 input [5:0] waddr,
839 input [5:0] raddr1,
840 input [5:0] raddr2,
841 input [31:0] wdata,
842 output [31:0] rdata1,
843 output [31:0] rdata2
844);
845 reg [31:0] regs [0:31];
846
847 always @(posedge clk)
848 if (wen) regs[waddr[4:0]] <= wdata;
849
850 assign rdata1 = regs[raddr1[4:0]];
851 assign rdata2 = regs[raddr2[4:0]];
852endmodule
Tim Edwards581068f2020-11-19 12:45:25 -0500853`default_nettype wire