blob: 4f26b40d66eb346d40d3a0e3bb7cd90b7001c270 [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"
Tim Edwards7be29a22020-10-25 21:50:19 -040036`include "counter_timer_high.v"
37`include "counter_timer_low.v"
shalanfd13eb52020-08-21 16:48:07 +020038`include "wb_intercon.v"
39`include "mem_wb.v"
40`include "gpio_wb.v"
shalanfd13eb52020-08-21 16:48:07 +020041`include "sysctrl.v"
42`include "la_wb.v"
shalan0d14e6e2020-08-31 16:50:48 +020043`include "mprj_ctrl.v"
Tim Edwards04ba17f2020-10-02 22:27:50 -040044`include "convert_gpio_sigs.v"
shalanfd13eb52020-08-21 16:48:07 +020045
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020046module mgmt_soc (
shalanfd13eb52020-08-21 16:48:07 +020047`ifdef LVS
48 inout vdd1v8, /* 1.8V domain */
49 inout vss,
50`endif
shalanfd13eb52020-08-21 16:48:07 +020051 input clk,
52 input resetn,
53
Tim Edwards04ba17f2020-10-02 22:27:50 -040054 // Trap state from CPU
55 output trap,
56
57 // GPIO (one pin)
58 output gpio_out_pad, // Connect to out on gpio pad
59 input gpio_in_pad, // Connect to in on gpio pad
60 output gpio_mode0_pad, // Connect to dm[0] on gpio pad
61 output gpio_mode1_pad, // Connect to dm[2] on gpio pad
62 output gpio_outenb_pad, // Connect to oe_n on gpio pad
63 output gpio_inenb_pad, // Connect to inp_dis on gpio pad
shalanfd13eb52020-08-21 16:48:07 +020064
65 // LA signals
Tim Edwards6d9739d2020-10-19 11:00:49 -040066 input [127:0] la_input, // From User Project to cpu
67 output [127:0] la_output, // From CPU to User Project
shalan0d14e6e2020-08-31 16:50:48 +020068 output [127:0] la_oen, // LA output enable (active low)
69
Tim Edwards6d9739d2020-10-19 11:00:49 -040070 // User Project I/O Configuration (serial load)
Tim Edwards05ad4fc2020-10-19 22:12:33 -040071 input mprj_vcc_pwrgood,
72 input mprj2_vcc_pwrgood,
73 input mprj_vdd_pwrgood,
74 input mprj2_vdd_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)
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020080 input [`MPRJ_IO_PADS-1:0] mgmt_in_data,
81 output [`MPRJ_IO_PADS-1:0] mgmt_out_data,
82 output [`MPRJ_PWR_PADS-1:0] pwr_ctrl_out,
shalanfd13eb52020-08-21 16:48:07 +020083
84 // IRQ
shalanfd13eb52020-08-21 16:48:07 +020085 input irq_spi, // IRQ from standalone SPI
86
shalanfd13eb52020-08-21 16:48:07 +020087 // Flash memory control (SPI master)
88 output flash_csb,
89 output flash_clk,
90
91 output flash_csb_oeb,
92 output flash_clk_oeb,
93
94 output flash_io0_oeb,
95 output flash_io1_oeb,
96 output flash_io2_oeb,
97 output flash_io3_oeb,
98
99 output flash_csb_ieb,
100 output flash_clk_ieb,
101
102 output flash_io0_ieb,
103 output flash_io1_ieb,
104 output flash_io2_ieb,
105 output flash_io3_ieb,
106
107 output flash_io0_do,
108 output flash_io1_do,
109 output flash_io2_do,
110 output flash_io3_do,
111
112 input flash_io0_di,
113 input flash_io1_di,
114 input flash_io2_di,
115 input flash_io3_di,
116
Tim Edwards04ba17f2020-10-02 22:27:50 -0400117 // SPI pass-thru mode
118 input pass_thru_mgmt,
119 input pass_thru_mgmt_csb,
120 input pass_thru_mgmt_sck,
121 input pass_thru_mgmt_sdi,
122 output pass_thru_mgmt_sdo,
123
Tim Edwards496a08a2020-10-26 15:44:51 -0400124 // State of JTAG and SDO pins (override for management output use)
125 output sdo_oenb_state,
126 output jtag_oenb_state,
Tim Edwards81153202020-10-09 19:57:04 -0400127 // SPI master->slave direct link
128 output hk_connect,
Tim Edwards32d05422020-10-19 19:43:52 -0400129 // User clock monitoring
130 input user_clk,
Tim Edwards81153202020-10-09 19:57:04 -0400131
Tim Edwards6d9739d2020-10-19 11:00:49 -0400132 // WB MI A (User project)
shalan0d14e6e2020-08-31 16:50:48 +0200133 input mprj_ack_i,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400134 input [31:0] mprj_dat_i,
shalan0d14e6e2020-08-31 16:50:48 +0200135 output mprj_cyc_o,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400136 output mprj_stb_o,
137 output mprj_we_o,
138 output [3:0] mprj_sel_o,
139 output [31:0] mprj_adr_o,
Manar55ec3692020-10-30 16:32:18 +0200140 output [31:0] mprj_dat_o,
141
142 // MGMT area R/W interface for mgmt RAM
Manarffe6cad2020-11-09 19:09:04 +0200143 output [`RAM_BLOCKS-1:0] mgmt_ena,
144 output [(`RAM_BLOCKS*4)-1:0] mgmt_wen_mask,
145 output [`RAM_BLOCKS-1:0] mgmt_wen,
Manar55ec3692020-10-30 16:32:18 +0200146 output [7:0] mgmt_addr,
147 output [31:0] mgmt_wdata,
Manarffe6cad2020-11-09 19:09:04 +0200148 input [(`RAM_BLOCKS*32)-1:0] mgmt_rdata,
Manar55ec3692020-10-30 16:32:18 +0200149
150 // MGMT area RO interface for user RAM
Manarffe6cad2020-11-09 19:09:04 +0200151 output mgmt_ena_ro,
152 output [7:0] mgmt_addr_ro,
153 input [31:0] mgmt_rdata_ro
shalanfd13eb52020-08-21 16:48:07 +0200154);
155 /* Memory reverted back to 256 words while memory has to be synthesized */
Manarec9b5362020-10-28 22:24:06 +0200156 parameter [31:0] STACKADDR = (4*(`MEM_WORDS)); // end of memory
shalanfd13eb52020-08-21 16:48:07 +0200157 parameter [31:0] PROGADDR_RESET = 32'h 1000_0000;
158 parameter [31:0] PROGADDR_IRQ = 32'h 0000_0000;
159
160 // Slaves Base Addresses
Tim Edwards04ba17f2020-10-02 22:27:50 -0400161 parameter RAM_BASE_ADR = 32'h 0000_0000;
Manarffe6cad2020-11-09 19:09:04 +0200162 parameter STORAGE_RW_ADR = 32'h 0100_0000;
163 parameter STORAGE_RO_ADR = 32'h 0200_0000;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400164 parameter FLASH_BASE_ADR = 32'h 1000_0000;
165 parameter UART_BASE_ADR = 32'h 2000_0000;
166 parameter GPIO_BASE_ADR = 32'h 2100_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400167 parameter COUNTER_TIMER0_BASE_ADR = 32'h 2200_0000;
168 parameter COUNTER_TIMER1_BASE_ADR = 32'h 2300_0000;
169 parameter SPI_MASTER_BASE_ADR = 32'h 2400_0000;
170 parameter LA_BASE_ADR = 32'h 2500_0000;
171 parameter MPRJ_CTRL_ADR = 32'h 2600_0000;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400172 parameter FLASH_CTRL_CFG = 32'h 2D00_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400173 parameter SYS_BASE_ADR = 32'h 2F00_0000;
174 parameter MPRJ_BASE_ADR = 32'h 3000_0000; // WB MI A
Manar55ec3692020-10-30 16:32:18 +0200175
shalanfd13eb52020-08-21 16:48:07 +0200176 // UART
177 parameter UART_CLK_DIV = 8'h00;
178 parameter UART_DATA = 8'h04;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400179
180 // SPI Master
181 parameter SPI_MASTER_CONFIG = 8'h00;
182 parameter SPI_MASTER_DATA = 8'h04;
183
184 // Counter-timer 0
185 parameter COUNTER_TIMER0_CONFIG = 8'h00;
186 parameter COUNTER_TIMER0_VALUE = 8'h04;
187 parameter COUNTER_TIMER0_DATA = 8'h08;
188
189 // Counter-timer 1
190 parameter COUNTER_TIMER1_CONFIG = 8'h00;
191 parameter COUNTER_TIMER1_VALUE = 8'h04;
192 parameter COUNTER_TIMER1_DATA = 8'h08;
shalanfd13eb52020-08-21 16:48:07 +0200193
194 // SOC GPIO
195 parameter GPIO_DATA = 8'h00;
196 parameter GPIO_ENA = 8'h04;
197 parameter GPIO_PU = 8'h08;
198 parameter GPIO_PD = 8'h0c;
199
shalan0d14e6e2020-08-31 16:50:48 +0200200 // LA
shalanfd13eb52020-08-21 16:48:07 +0200201 parameter LA_DATA_0 = 8'h00;
202 parameter LA_DATA_1 = 8'h04;
203 parameter LA_DATA_2 = 8'h08;
204 parameter LA_DATA_3 = 8'h0c;
205 parameter LA_ENA_0 = 8'h10;
206 parameter LA_ENA_1 = 8'h14;
207 parameter LA_ENA_2 = 8'h18;
208 parameter LA_ENA_3 = 8'h1c;
209
shalanfd13eb52020-08-21 16:48:07 +0200210 // System Control Registers
Tim Edwards32d05422020-10-19 19:43:52 -0400211 parameter PWRGOOD = 8'h00;
212 parameter CLK_OUT = 8'h04;
213 parameter TRAP_OUT = 8'h08;
214 parameter IRQ_SRC = 8'h0c;
shalanfd13eb52020-08-21 16:48:07 +0200215
Manar55ec3692020-10-30 16:32:18 +0200216 // Storage area RAM blocks
Manarffe6cad2020-11-09 19:09:04 +0200217 parameter [(`RAM_BLOCKS*24)-1:0] RW_BLOCKS_ADR = {
Manar55ec3692020-10-30 16:32:18 +0200218 {24'h 10_0000},
219 {24'h 00_0000}
220 };
221
Manarffe6cad2020-11-09 19:09:04 +0200222 parameter [23:0] RO_BLOCKS_ADR = {
Manar55ec3692020-10-30 16:32:18 +0200223 {24'h 00_0000}
224 };
225
shalanfd13eb52020-08-21 16:48:07 +0200226 // Wishbone Interconnect
227 localparam ADR_WIDTH = 32;
228 localparam DAT_WIDTH = 32;
Manar55ec3692020-10-30 16:32:18 +0200229 localparam NUM_SLAVES = 14;
shalanfd13eb52020-08-21 16:48:07 +0200230
231 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = {
shalanfd13eb52020-08-21 16:48:07 +0200232 {8'hFF, {ADR_WIDTH-8{1'b0}}},
233 {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}}},
shalan0d14e6e2020-08-31 16:50:48 +0200239 {8'hFF, {ADR_WIDTH-8{1'b0}}},
240 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400241 {8'hFF, {ADR_WIDTH-8{1'b0}}},
242 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Manar55ec3692020-10-30 16:32:18 +0200243 {8'hFF, {ADR_WIDTH-8{1'b0}}},
244 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalanfd13eb52020-08-21 16:48:07 +0200245 {8'hFF, {ADR_WIDTH-8{1'b0}}}
246 };
shalan0d14e6e2020-08-31 16:50:48 +0200247
shalanfd13eb52020-08-21 16:48:07 +0200248 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = {
shalanfd13eb52020-08-21 16:48:07 +0200249 {SYS_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200250 {FLASH_CTRL_CFG},
shalan0d14e6e2020-08-31 16:50:48 +0200251 {MPRJ_BASE_ADR},
252 {MPRJ_CTRL_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200253 {LA_BASE_ADR},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400254 {SPI_MASTER_BASE_ADR},
255 {COUNTER_TIMER1_BASE_ADR},
256 {COUNTER_TIMER0_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200257 {GPIO_BASE_ADR},
258 {UART_BASE_ADR},
259 {FLASH_BASE_ADR},
Manarffe6cad2020-11-09 19:09:04 +0200260 {STORAGE_RO_ADR},
261 {STORAGE_RW_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200262 {RAM_BASE_ADR}
263 };
264
Tim Edwardsca2f3182020-10-06 10:05:11 -0400265 // The following functions are connected to specific user project
266 // area pins, when under control of the management area (during
267 // startup, and when not otherwise programmed for the user project).
268
269 // JTAG = jtag_out (inout)
270 // SDO = sdo_out (output) (shared with SPI master)
271 // SDI = mgmt_in_data[2] (input) (shared with SPI master)
272 // CSB = mgmt_in_data[3] (input) (shared with SPI master)
273 // SCK = mgmt_in_data[4] (input) (shared with SPI master)
274 // ser_rx = mgmt_in_data[5] (input)
275 // ser_tx = mgmt_out_data[6] (output)
276 // irq_pin = mgmt_in_data[7] (input)
277 // flash_csb = mgmt_out_data[8] (output) (user area flash)
278 // flash_sck = mgmt_out_data[9] (output) (user area flash)
279 // flash_io0 = mgmt_in/out_data[10] (input) (user area flash)
280 // flash_io1 = mgmt_in/out_data[11] (output) (user area flash)
Tim Edwards32d05422020-10-19 19:43:52 -0400281 // irq2_pin = mgmt_in_data[12] (input)
282 // trap_mon = mgmt_in_data[13] (output)
283 // clk1_mon = mgmt_in_data[14] (output)
284 // clk2_mon = mgmt_in_data[15] (output)
Tim Edwardsca2f3182020-10-06 10:05:11 -0400285
286 // OEB lines for [0] and [1] are the only ones connected directly to
287 // the pad. All others have OEB controlled by the configuration bit
288 // in the control block.
289
shalanfd13eb52020-08-21 16:48:07 +0200290 // memory-mapped I/O control registers
Tim Edwards04ba17f2020-10-02 22:27:50 -0400291 wire gpio_pullup; // Intermediate GPIO pullup
292 wire gpio_pulldown; // Intermediate GPIO pulldown
293 wire gpio_outenb; // Intermediate GPIO out enable (bar)
294 wire gpio_out; // Intermediate GPIO output
shalanfd13eb52020-08-21 16:48:07 +0200295
Tim Edwardsef8312e2020-09-22 17:20:06 -0400296 wire trap_output_dest; // Trap signal output destination
Tim Edwards32d05422020-10-19 19:43:52 -0400297 wire clk1_output_dest; // Core clock1 signal output destination
298 wire clk2_output_dest; // Core clock2 signal output destination
Tim Edwardsef8312e2020-09-22 17:20:06 -0400299 wire irq_7_inputsrc; // IRQ 7 source
Tim Edwards32d05422020-10-19 19:43:52 -0400300 wire irq_8_inputsrc; // IRQ 8 source
shalanfd13eb52020-08-21 16:48:07 +0200301
Tim Edwardsef8312e2020-09-22 17:20:06 -0400302 // Convert GPIO signals to sky130_fd_io pad signals
Tim Edwards04ba17f2020-10-02 22:27:50 -0400303 convert_gpio_sigs convert_gpio_bit (
shalanfd13eb52020-08-21 16:48:07 +0200304 .gpio_out(gpio_out),
305 .gpio_outenb(gpio_outenb),
306 .gpio_pu(gpio_pullup),
307 .gpio_pd(gpio_pulldown),
308 .gpio_out_pad(gpio_out_pad),
309 .gpio_outenb_pad(gpio_outenb_pad),
310 .gpio_inenb_pad(gpio_inenb_pad),
311 .gpio_mode1_pad(gpio_mode1_pad),
312 .gpio_mode0_pad(gpio_mode0_pad)
313 );
314
315 reg [31:0] irq;
316 wire irq_7;
Tim Edwards32d05422020-10-19 19:43:52 -0400317 wire irq_8;
shalanfd13eb52020-08-21 16:48:07 +0200318 wire irq_stall;
319 wire irq_uart;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400320 wire irq_spi_master;
321 wire irq_counter_timer0;
322 wire irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200323
shalanfd13eb52020-08-21 16:48:07 +0200324 assign irq_stall = 0;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400325 assign irq_7 = (irq_7_inputsrc == 1'b1) ? mgmt_in_data[7] : 1'b0;
Tim Edwards32d05422020-10-19 19:43:52 -0400326 assign irq_8 = (irq_8_inputsrc == 1'b1) ? mgmt_in_data[12] : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200327
328 always @* begin
329 irq = 0;
330 irq[3] = irq_stall;
331 irq[4] = irq_uart;
shalanfd13eb52020-08-21 16:48:07 +0200332 irq[6] = irq_spi;
333 irq[7] = irq_7;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400334 irq[9] = irq_spi_master;
335 irq[10] = irq_counter_timer0;
336 irq[11] = irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200337 end
338
Tim Edwards3245e2f2020-10-10 14:02:11 -0400339 // Assumption : no syscon module and wb_clk is the clock coming from the
340 // caravel_clocking module
341
shalanfd13eb52020-08-21 16:48:07 +0200342 assign wb_clk_i = clk;
343 assign wb_rst_i = ~resetn; // Redundant
344
345 // Wishbone Master
346 wire [31:0] cpu_adr_o;
347 wire [31:0] cpu_dat_i;
348 wire [3:0] cpu_sel_o;
349 wire cpu_we_o;
350 wire cpu_cyc_o;
351 wire cpu_stb_o;
352 wire [31:0] cpu_dat_o;
353 wire cpu_ack_i;
shalanfd13eb52020-08-21 16:48:07 +0200354
355 picorv32_wb #(
356 .STACKADDR(STACKADDR),
357 .PROGADDR_RESET(PROGADDR_RESET),
358 .PROGADDR_IRQ(PROGADDR_IRQ),
359 .BARREL_SHIFTER(1),
360 .COMPRESSED_ISA(1),
361 .ENABLE_MUL(1),
362 .ENABLE_DIV(1),
363 .ENABLE_IRQ(1),
364 .ENABLE_IRQ_QREGS(0)
365 ) cpu (
366 .wb_clk_i (wb_clk_i),
367 .wb_rst_i (wb_rst_i),
368 .trap (trap),
369 .irq (irq),
370 .mem_instr(mem_instr),
371 .wbm_adr_o(cpu_adr_o),
372 .wbm_dat_i(cpu_dat_i),
373 .wbm_stb_o(cpu_stb_o),
374 .wbm_ack_i(cpu_ack_i),
375 .wbm_cyc_o(cpu_cyc_o),
376 .wbm_dat_o(cpu_dat_o),
377 .wbm_we_o(cpu_we_o),
378 .wbm_sel_o(cpu_sel_o)
379 );
380
381 // Wishbone Slave SPIMEMIO
382 wire spimemio_flash_stb_i;
383 wire spimemio_flash_ack_o;
384 wire [31:0] spimemio_flash_dat_o;
385
386 wire spimemio_cfg_stb_i;
387 wire spimemio_cfg_ack_o;
388 wire [31:0] spimemio_cfg_dat_o;
389
390 spimemio_wb spimemio (
391 .wb_clk_i(wb_clk_i),
392 .wb_rst_i(wb_rst_i),
393
394 .wb_adr_i(cpu_adr_o),
395 .wb_dat_i(cpu_dat_o),
396 .wb_sel_i(cpu_sel_o),
397 .wb_we_i(cpu_we_o),
398 .wb_cyc_i(cpu_cyc_o),
399
400 // FLash Slave
401 .wb_flash_stb_i(spimemio_flash_stb_i),
402 .wb_flash_ack_o(spimemio_flash_ack_o),
403 .wb_flash_dat_o(spimemio_flash_dat_o),
404
405 // Config Register Slave
406 .wb_cfg_stb_i(spimemio_cfg_stb_i),
407 .wb_cfg_ack_o(spimemio_cfg_ack_o),
408 .wb_cfg_dat_o(spimemio_cfg_dat_o),
409
Tim Edwards04ba17f2020-10-02 22:27:50 -0400410 .pass_thru(pass_thru_mgmt),
411 .pass_thru_csb(pass_thru_mgmt_csb),
412 .pass_thru_sck(pass_thru_mgmt_sck),
413 .pass_thru_sdi(pass_thru_mgmt_sdi),
414 .pass_thru_sdo(pass_thru_mgmt_sdo),
415
shalanfd13eb52020-08-21 16:48:07 +0200416 .flash_csb (flash_csb),
417 .flash_clk (flash_clk),
418
419 .flash_csb_oeb (flash_csb_oeb),
420 .flash_clk_oeb (flash_clk_oeb),
421
422 .flash_io0_oeb (flash_io0_oeb),
423 .flash_io1_oeb (flash_io1_oeb),
424 .flash_io2_oeb (flash_io2_oeb),
425 .flash_io3_oeb (flash_io3_oeb),
426
427 .flash_csb_ieb (flash_csb_ieb),
428 .flash_clk_ieb (flash_clk_ieb),
429
430 .flash_io0_ieb (flash_io0_ieb),
431 .flash_io1_ieb (flash_io1_ieb),
432 .flash_io2_ieb (flash_io2_ieb),
433 .flash_io3_ieb (flash_io3_ieb),
434
435 .flash_io0_do (flash_io0_do),
436 .flash_io1_do (flash_io1_do),
437 .flash_io2_do (flash_io2_do),
438 .flash_io3_do (flash_io3_do),
439
440 .flash_io0_di (flash_io0_di),
441 .flash_io1_di (flash_io1_di),
442 .flash_io2_di (flash_io2_di),
443 .flash_io3_di (flash_io3_di)
444 );
445
446 // Wishbone Slave uart
447 wire uart_stb_i;
448 wire uart_ack_o;
449 wire [31:0] uart_dat_o;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400450 wire uart_enabled;
shalanfd13eb52020-08-21 16:48:07 +0200451
452 simpleuart_wb #(
453 .BASE_ADR(UART_BASE_ADR),
454 .CLK_DIV(UART_CLK_DIV),
455 .DATA(UART_DATA)
456 ) simpleuart (
457 // Wishbone Interface
458 .wb_clk_i(wb_clk_i),
459 .wb_rst_i(wb_rst_i),
460
461 .wb_adr_i(cpu_adr_o),
462 .wb_dat_i(cpu_dat_o),
463 .wb_sel_i(cpu_sel_o),
464 .wb_we_i(cpu_we_o),
465 .wb_cyc_i(cpu_cyc_o),
466
467 .wb_stb_i(uart_stb_i),
468 .wb_ack_o(uart_ack_o),
469 .wb_dat_o(uart_dat_o),
470
Tim Edwardsca2f3182020-10-06 10:05:11 -0400471 .uart_enabled(uart_enabled),
shalanfd13eb52020-08-21 16:48:07 +0200472 .ser_tx(ser_tx),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400473 .ser_rx(mgmt_in_data[5])
shalanfd13eb52020-08-21 16:48:07 +0200474 );
475
Tim Edwards04ba17f2020-10-02 22:27:50 -0400476 // Wishbone SPI master
477 wire spi_master_stb_i;
478 wire spi_master_ack_o;
479 wire [31:0] spi_master_dat_o;
480
481 simple_spi_master_wb #(
482 .BASE_ADR(SPI_MASTER_BASE_ADR),
483 .CONFIG(SPI_MASTER_CONFIG),
484 .DATA(SPI_MASTER_DATA)
485 ) simple_spi_master_inst (
486 // Wishbone Interface
487 .wb_clk_i(wb_clk_i),
488 .wb_rst_i(wb_rst_i),
489
490 .wb_adr_i(cpu_adr_o),
491 .wb_dat_i(cpu_dat_o),
492 .wb_sel_i(cpu_sel_o),
493 .wb_we_i(cpu_we_o),
494 .wb_cyc_i(cpu_cyc_o),
495
496 .wb_stb_i(spi_master_stb_i),
497 .wb_ack_o(spi_master_ack_o),
498 .wb_dat_o(spi_master_dat_o),
499
Tim Edwards81153202020-10-09 19:57:04 -0400500 .hk_connect(hk_connect),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400501 .csb(mgmt_out_pre[3]),
502 .sck(mgmt_out_pre[4]),
503 .sdi(mgmt_in_data[1]),
504 .sdo(mgmt_out_pre[2]),
505 .sdoenb(),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400506 .irq(irq_spi_master)
507 );
508
Tim Edwards7be29a22020-10-25 21:50:19 -0400509 wire counter_timer_strobe, counter_timer_offset;
510 wire counter_timer0_enable, counter_timer1_enable;
511 wire counter_timer0_stop, counter_timer1_stop;
Tim Edwards32d05422020-10-19 19:43:52 -0400512
Tim Edwards04ba17f2020-10-02 22:27:50 -0400513 // Wishbone Counter-timer 0
514 wire counter_timer0_stb_i;
515 wire counter_timer0_ack_o;
516 wire [31:0] counter_timer0_dat_o;
517
Tim Edwards7be29a22020-10-25 21:50:19 -0400518 counter_timer_low_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400519 .BASE_ADR(COUNTER_TIMER0_BASE_ADR),
520 .CONFIG(COUNTER_TIMER0_CONFIG),
521 .VALUE(COUNTER_TIMER0_VALUE),
522 .DATA(COUNTER_TIMER0_DATA)
523 ) counter_timer_0 (
524 // Wishbone Interface
525 .wb_clk_i(wb_clk_i),
526 .wb_rst_i(wb_rst_i),
527
528 .wb_adr_i(cpu_adr_o),
529 .wb_dat_i(cpu_dat_o),
530 .wb_sel_i(cpu_sel_o),
531 .wb_we_i(cpu_we_o),
532 .wb_cyc_i(cpu_cyc_o),
533
534 .wb_stb_i(counter_timer0_stb_i),
535 .wb_ack_o(counter_timer0_ack_o),
536 .wb_dat_o(counter_timer0_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400537
538 .enable_in(counter_timer1_enable),
539 .stop_in(counter_timer1_stop),
540 .strobe(counter_timer_strobe),
541 .is_offset(counter_timer_offset),
542 .enable_out(counter_timer0_enable),
543 .stop_out(counter_timer0_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400544 .irq(irq_counter_timer0)
545 );
546
547 // Wishbone Counter-timer 1
548 wire counter_timer1_stb_i;
549 wire counter_timer1_ack_o;
550 wire [31:0] counter_timer1_dat_o;
551
Tim Edwards7be29a22020-10-25 21:50:19 -0400552 counter_timer_high_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400553 .BASE_ADR(COUNTER_TIMER1_BASE_ADR),
554 .CONFIG(COUNTER_TIMER1_CONFIG),
555 .VALUE(COUNTER_TIMER1_VALUE),
556 .DATA(COUNTER_TIMER1_DATA)
557 ) counter_timer_1 (
558 // Wishbone Interface
559 .wb_clk_i(wb_clk_i),
560 .wb_rst_i(wb_rst_i),
561
562 .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),
567
568 .wb_stb_i(counter_timer1_stb_i),
569 .wb_ack_o(counter_timer1_ack_o),
570 .wb_dat_o(counter_timer1_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400571
572 .enable_in(counter_timer0_enable),
573 .strobe(counter_timer_strobe),
574 .stop_in(counter_timer0_stop),
575 .is_offset(counter_timer_offset),
576 .enable_out(counter_timer1_enable),
577 .stop_out(counter_timer1_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400578 .irq(irq_counter_timer1)
579 );
580
shalanfd13eb52020-08-21 16:48:07 +0200581 // Wishbone Slave GPIO Registers
582 wire gpio_stb_i;
583 wire gpio_ack_o;
584 wire [31:0] gpio_dat_o;
585
586 gpio_wb #(
587 .BASE_ADR(GPIO_BASE_ADR),
588 .GPIO_DATA(GPIO_DATA),
589 .GPIO_ENA(GPIO_ENA),
590 .GPIO_PD(GPIO_PD),
591 .GPIO_PU(GPIO_PU)
592 ) gpio_wb (
593 .wb_clk_i(wb_clk_i),
594 .wb_rst_i(wb_rst_i),
shalanfd13eb52020-08-21 16:48:07 +0200595 .wb_adr_i(cpu_adr_o),
596 .wb_dat_i(cpu_dat_o),
597 .wb_sel_i(cpu_sel_o),
598 .wb_we_i(cpu_we_o),
599 .wb_cyc_i(cpu_cyc_o),
shalanfd13eb52020-08-21 16:48:07 +0200600 .wb_stb_i(gpio_stb_i),
601 .wb_ack_o(gpio_ack_o),
602 .wb_dat_o(gpio_dat_o),
603 .gpio_in_pad(gpio_in_pad),
Tim Edwards32d05422020-10-19 19:43:52 -0400604 .gpio(gpio_out),
605 .gpio_oeb(gpio_outenb),
606 .gpio_pu(gpio_pullup),
607 .gpio_pd(gpio_pulldown)
shalanfd13eb52020-08-21 16:48:07 +0200608 );
609
shalanfd13eb52020-08-21 16:48:07 +0200610 // Wishbone Slave System Control Register
611 wire sys_stb_i;
612 wire sys_ack_o;
613 wire [31:0] sys_dat_o;
614
615 sysctrl_wb #(
616 .BASE_ADR(SYS_BASE_ADR),
Tim Edwards32d05422020-10-19 19:43:52 -0400617 .PWRGOOD(PWRGOOD),
618 .CLK_OUT(CLK_OUT),
shalanfd13eb52020-08-21 16:48:07 +0200619 .TRAP_OUT(TRAP_OUT),
Tim Edwards32d05422020-10-19 19:43:52 -0400620 .IRQ_SRC(IRQ_SRC)
shalanfd13eb52020-08-21 16:48:07 +0200621 ) sysctrl (
622 .wb_clk_i(wb_clk_i),
623 .wb_rst_i(wb_rst_i),
624
625 .wb_adr_i(cpu_adr_o),
626 .wb_dat_i(cpu_dat_o),
627 .wb_sel_i(cpu_sel_o),
628 .wb_we_i(cpu_we_o),
629 .wb_cyc_i(cpu_cyc_o),
630
631 .wb_stb_i(sys_stb_i),
632 .wb_ack_o(sys_ack_o),
633 .wb_dat_o(sys_dat_o),
634
Tim Edwards05ad4fc2020-10-19 22:12:33 -0400635 .usr1_vcc_pwrgood(mprj_vcc_pwrgood),
636 .usr2_vcc_pwrgood(mprj2_vcc_pwrgood),
637 .usr1_vdd_pwrgood(mprj_vdd_pwrgood),
638 .usr2_vdd_pwrgood(mprj2_vdd_pwrgood),
shalanfd13eb52020-08-21 16:48:07 +0200639 .trap_output_dest(trap_output_dest),
Tim Edwards32d05422020-10-19 19:43:52 -0400640 .clk1_output_dest(clk1_output_dest),
641 .clk2_output_dest(clk2_output_dest),
642 .irq_7_inputsrc(irq_7_inputsrc),
643 .irq_8_inputsrc(irq_8_inputsrc)
shalanfd13eb52020-08-21 16:48:07 +0200644 );
645
646 // Logic Analyzer
647 wire la_stb_i;
648 wire la_ack_o;
649 wire [31:0] la_dat_o;
650
651 la_wb #(
652 .BASE_ADR(LA_BASE_ADR),
653 .LA_DATA_0(LA_DATA_0),
654 .LA_DATA_1(LA_DATA_1),
655 .LA_DATA_3(LA_DATA_3),
656 .LA_ENA_0(LA_ENA_0),
657 .LA_ENA_1(LA_ENA_1),
658 .LA_ENA_2(LA_ENA_2),
659 .LA_ENA_3(LA_ENA_3)
660 ) la (
661 .wb_clk_i(wb_clk_i),
662 .wb_rst_i(wb_rst_i),
663
664 .wb_adr_i(cpu_adr_o),
665 .wb_dat_i(cpu_dat_o),
666 .wb_sel_i(cpu_sel_o),
667 .wb_we_i(cpu_we_o),
668 .wb_cyc_i(cpu_cyc_o),
669
670 .wb_stb_i(la_stb_i),
671 .wb_ack_o(la_ack_o),
672 .wb_dat_o(la_dat_o),
673
674 .la_data(la_output),
shalan0d14e6e2020-08-31 16:50:48 +0200675 .la_data_in(la_input),
676 .la_oen(la_oen)
shalanfd13eb52020-08-21 16:48:07 +0200677 );
678
Manarcd4cff72020-11-04 16:22:59 +0200679 // User project WB MI A port
680 assign mprj_cyc_o = cpu_cyc_o;
681 assign mprj_we_o = cpu_we_o;
682 assign mprj_sel_o = cpu_sel_o;
683 assign mprj_adr_o = cpu_adr_o;
684 assign mprj_dat_o = cpu_dat_o;
685
Tim Edwards6d9739d2020-10-19 11:00:49 -0400686 // WB Slave User Project Control
shalan0d14e6e2020-08-31 16:50:48 +0200687 wire mprj_ctrl_stb_i;
688 wire mprj_ctrl_ack_o;
689 wire [31:0] mprj_ctrl_dat_o;
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200690 wire [`MPRJ_IO_PADS-1:0] mgmt_out_pre;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400691
692 // Bits assigned to specific functions as outputs prevent the
693 // mprj GPIO-as-output from applying data when that function
694 // is active
695
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200696 assign mgmt_out_data[`MPRJ_IO_PADS-1:16] = mgmt_out_pre[`MPRJ_IO_PADS-1:16];
Tim Edwards32d05422020-10-19 19:43:52 -0400697
698 // Routing of output monitors (PLL, trap, clk1, clk2)
699 assign mgmt_out_data[15] = clk2_output_dest ? user_clk : mgmt_out_pre[15];
700 assign mgmt_out_data[14] = clk1_output_dest ? clk : mgmt_out_pre[14];
701 assign mgmt_out_data[13] = trap_output_dest ? trap : mgmt_out_pre[13];
702
703 assign mgmt_out_data[12:7] = mgmt_out_pre[12:7];
Tim Edwardsca2f3182020-10-06 10:05:11 -0400704 assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6];
705 assign mgmt_out_data[5:0] = mgmt_out_pre[5:0];
shalan0d14e6e2020-08-31 16:50:48 +0200706
707 mprj_ctrl_wb #(
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200708 .BASE_ADR(MPRJ_CTRL_ADR)
shalan0d14e6e2020-08-31 16:50:48 +0200709 ) mprj_ctrl (
710 .wb_clk_i(wb_clk_i),
711 .wb_rst_i(wb_rst_i),
712
713 .wb_adr_i(cpu_adr_o),
714 .wb_dat_i(cpu_dat_o),
715 .wb_sel_i(cpu_sel_o),
716 .wb_we_i(cpu_we_o),
717 .wb_cyc_i(cpu_cyc_o),
718 .wb_stb_i(mprj_ctrl_stb_i),
719 .wb_ack_o(mprj_ctrl_ack_o),
720 .wb_dat_o(mprj_ctrl_dat_o),
721
Tim Edwards04ba17f2020-10-02 22:27:50 -0400722 .serial_clock(mprj_io_loader_clock),
723 .serial_resetn(mprj_io_loader_resetn),
724 .serial_data_out(mprj_io_loader_data),
Tim Edwards496a08a2020-10-26 15:44:51 -0400725 .sdo_oenb_state(sdo_oenb_state),
726 .jtag_oenb_state(jtag_oenb_state),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400727 .mgmt_gpio_out(mgmt_out_pre),
Tim Edwardsba328902020-10-27 15:03:22 -0400728 .mgmt_gpio_in(mgmt_in_data),
729 .pwr_ctrl_out(pwr_ctrl_out)
shalan0d14e6e2020-08-31 16:50:48 +0200730 );
731
shalanfd13eb52020-08-21 16:48:07 +0200732 // Wishbone Slave RAM
733 wire mem_stb_i;
734 wire mem_ack_o;
735 wire [31:0] mem_dat_o;
736
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200737 mem_wb soc_mem (
Manar68e03632020-11-09 13:25:13 +0200738 `ifdef LVS
739 .VPWR(vdd1v8),
740 .VGND(vss),
741 `endif
shalanfd13eb52020-08-21 16:48:07 +0200742 .wb_clk_i(wb_clk_i),
743 .wb_rst_i(wb_rst_i),
744
745 .wb_adr_i(cpu_adr_o),
746 .wb_dat_i(cpu_dat_o),
747 .wb_sel_i(cpu_sel_o),
748 .wb_we_i(cpu_we_o),
749 .wb_cyc_i(cpu_cyc_o),
750
751 .wb_stb_i(mem_stb_i),
752 .wb_ack_o(mem_ack_o),
753 .wb_dat_o(mem_dat_o)
754 );
755
Manarffe6cad2020-11-09 19:09:04 +0200756 wire stg_rw_stb_i;
757 wire stg_ro_stb_i;
758 wire stg_rw_ack_o;
759 wire stg_ro_ack_o;
760 wire [31:0] stg_rw_dat_o;
761 wire [31:0] stg_ro_dat_o;
Manar55ec3692020-10-30 16:32:18 +0200762
763 // Storage area wishbone brige
764 storage_bridge_wb #(
Manarffe6cad2020-11-09 19:09:04 +0200765 .RW_BLOCKS_ADR(RW_BLOCKS_ADR),
766 .RO_BLOCKS_ADR(RO_BLOCKS_ADR)
Manar55ec3692020-10-30 16:32:18 +0200767 ) wb_bridge (
768 .wb_clk_i(wb_clk_i),
769 .wb_rst_i(wb_rst_i),
Manar55ec3692020-10-30 16:32:18 +0200770 .wb_adr_i(cpu_adr_o),
771 .wb_dat_i(cpu_dat_o),
772 .wb_sel_i(cpu_sel_o),
773 .wb_we_i(cpu_we_o),
774 .wb_cyc_i(cpu_cyc_o),
Manarffe6cad2020-11-09 19:09:04 +0200775 .wb_stb_i({stg_ro_stb_i, stg_rw_stb_i}),
776 .wb_ack_o({stg_ro_ack_o, stg_rw_ack_o}),
777 .wb_rw_dat_o(stg_rw_dat_o),
Manar55ec3692020-10-30 16:32:18 +0200778 // MGMT_AREA RO WB Interface
Manarffe6cad2020-11-09 19:09:04 +0200779 .wb_ro_dat_o(stg_ro_dat_o),
Manar55ec3692020-10-30 16:32:18 +0200780 // MGMT Area native memory interface
781 .mgmt_ena(mgmt_ena),
782 .mgmt_wen_mask(mgmt_wen_mask),
783 .mgmt_wen(mgmt_wen),
784 .mgmt_addr(mgmt_addr),
785 .mgmt_wdata(mgmt_wdata),
786 .mgmt_rdata(mgmt_rdata),
Manar55ec3692020-10-30 16:32:18 +0200787 // MGMT_AREA RO interface
Manarffe6cad2020-11-09 19:09:04 +0200788 .mgmt_ena_ro(mgmt_ena_ro),
789 .mgmt_addr_ro(mgmt_addr_ro),
790 .mgmt_rdata_ro(mgmt_rdata_ro)
Manar55ec3692020-10-30 16:32:18 +0200791 );
792
shalanfd13eb52020-08-21 16:48:07 +0200793 // Wishbone intercon logic
794 wb_intercon #(
795 .AW(ADR_WIDTH),
796 .DW(DAT_WIDTH),
797 .NS(NUM_SLAVES),
798 .ADR_MASK(ADR_MASK),
799 .SLAVE_ADR(SLAVE_ADR)
800 ) intercon (
801 // Master Interface
802 .wbm_adr_i(cpu_adr_o),
803 .wbm_stb_i(cpu_stb_o),
804 .wbm_dat_o(cpu_dat_i),
805 .wbm_ack_o(cpu_ack_i),
806
807 // Slaves Interface
Manar98a7adc2020-10-19 23:21:36 +0200808 .wbs_stb_o({ sys_stb_i, spimemio_cfg_stb_i,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400809 mprj_stb_o, mprj_ctrl_stb_i, la_stb_i,
810 spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i,
811 gpio_stb_i, uart_stb_i,
Manarffe6cad2020-11-09 19:09:04 +0200812 spimemio_flash_stb_i, stg_ro_stb_i, stg_rw_stb_i, mem_stb_i }),
Manar98a7adc2020-10-19 23:21:36 +0200813 .wbs_dat_i({ sys_dat_o, spimemio_cfg_dat_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400814 mprj_dat_i, mprj_ctrl_dat_o, la_dat_o,
815 spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o,
816 gpio_dat_o, uart_dat_o,
Manarffe6cad2020-11-09 19:09:04 +0200817 spimemio_flash_dat_o, stg_ro_dat_o ,stg_rw_dat_o, mem_dat_o }),
Manar98a7adc2020-10-19 23:21:36 +0200818 .wbs_ack_i({ sys_ack_o, spimemio_cfg_ack_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400819 mprj_ack_i, mprj_ctrl_ack_o, la_ack_o,
820 spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o,
821 gpio_ack_o, uart_ack_o,
Manarffe6cad2020-11-09 19:09:04 +0200822 spimemio_flash_ack_o, stg_ro_ack_o, stg_rw_ack_o, mem_ack_o })
shalanfd13eb52020-08-21 16:48:07 +0200823 );
824
shalanfd13eb52020-08-21 16:48:07 +0200825endmodule
826
shalanfd13eb52020-08-21 16:48:07 +0200827// Implementation note:
828// Replace the following two modules with wrappers for your SRAM cells.
Tim Edwardsef8312e2020-09-22 17:20:06 -0400829
Tim Edwards04ba17f2020-10-02 22:27:50 -0400830module mgmt_soc_regs (
shalanfd13eb52020-08-21 16:48:07 +0200831 input clk, wen,
832 input [5:0] waddr,
833 input [5:0] raddr1,
834 input [5:0] raddr2,
835 input [31:0] wdata,
836 output [31:0] rdata1,
837 output [31:0] rdata2
838);
839 reg [31:0] regs [0:31];
840
841 always @(posedge clk)
842 if (wen) regs[waddr[4:0]] <= wdata;
843
844 assign rdata1 = regs[raddr1[4:0]];
845 assign rdata2 = regs[raddr2[4:0]];
846endmodule