blob: 82354361eb1d71b1413576302c6510c3d52643a1 [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
143 output [`MGMT_BLOCKS-1:0] mgmt_ena,
144 output [(`MGMT_BLOCKS*4)-1:0] mgmt_wen_mask,
145 output [`MGMT_BLOCKS-1:0] mgmt_wen,
146 output [7:0] mgmt_addr,
147 output [31:0] mgmt_wdata,
148 input [(`MGMT_BLOCKS*32)-1:0] mgmt_rdata,
149
150 // MGMT area RO interface for user RAM
151 output [`USER_BLOCKS-1:0] user_ena,
152 output [7:0] user_addr,
153 input [(`USER_BLOCKS*32)-1:0] user_rdata
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;
Manar55ec3692020-10-30 16:32:18 +0200162 parameter EXT_MRAM_BASE_ADR = 32'h 0100_0000;
163 parameter EXT_URAM_BASE_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
217 parameter [(`MGMT_BLOCKS*24)-1:0] MGMT_BLOCKS_ADR = {
218 {24'h 10_0000},
219 {24'h 00_0000}
220 };
221
222 parameter [(`USER_BLOCKS*24)-1:0] USER_BLOCKS_ADR = {
Manardb08adb2020-11-02 17:13:25 +0200223 {24'h 50_0000},
224 {24'h 40_0000},
Manar55ec3692020-10-30 16:32:18 +0200225 {24'h 30_0000},
226 {24'h 20_0000},
227 {24'h 10_0000},
228 {24'h 00_0000}
229 };
230
shalanfd13eb52020-08-21 16:48:07 +0200231 // Wishbone Interconnect
232 localparam ADR_WIDTH = 32;
233 localparam DAT_WIDTH = 32;
Manar55ec3692020-10-30 16:32:18 +0200234 localparam NUM_SLAVES = 14;
shalanfd13eb52020-08-21 16:48:07 +0200235
236 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = {
shalanfd13eb52020-08-21 16:48:07 +0200237 {8'hFF, {ADR_WIDTH-8{1'b0}}},
238 {8'hFF, {ADR_WIDTH-8{1'b0}}},
239 {8'hFF, {ADR_WIDTH-8{1'b0}}},
240 {8'hFF, {ADR_WIDTH-8{1'b0}}},
241 {8'hFF, {ADR_WIDTH-8{1'b0}}},
242 {8'hFF, {ADR_WIDTH-8{1'b0}}},
243 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalan0d14e6e2020-08-31 16:50:48 +0200244 {8'hFF, {ADR_WIDTH-8{1'b0}}},
245 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400246 {8'hFF, {ADR_WIDTH-8{1'b0}}},
247 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Manar55ec3692020-10-30 16:32:18 +0200248 {8'hFF, {ADR_WIDTH-8{1'b0}}},
249 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalanfd13eb52020-08-21 16:48:07 +0200250 {8'hFF, {ADR_WIDTH-8{1'b0}}}
251 };
shalan0d14e6e2020-08-31 16:50:48 +0200252
shalanfd13eb52020-08-21 16:48:07 +0200253 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = {
shalanfd13eb52020-08-21 16:48:07 +0200254 {SYS_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200255 {FLASH_CTRL_CFG},
shalan0d14e6e2020-08-31 16:50:48 +0200256 {MPRJ_BASE_ADR},
257 {MPRJ_CTRL_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200258 {LA_BASE_ADR},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400259 {SPI_MASTER_BASE_ADR},
260 {COUNTER_TIMER1_BASE_ADR},
261 {COUNTER_TIMER0_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200262 {GPIO_BASE_ADR},
263 {UART_BASE_ADR},
264 {FLASH_BASE_ADR},
Manar55ec3692020-10-30 16:32:18 +0200265 {EXT_URAM_BASE_ADR},
266 {EXT_MRAM_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200267 {RAM_BASE_ADR}
268 };
269
Tim Edwardsca2f3182020-10-06 10:05:11 -0400270 // The following functions are connected to specific user project
271 // area pins, when under control of the management area (during
272 // startup, and when not otherwise programmed for the user project).
273
274 // JTAG = jtag_out (inout)
275 // SDO = sdo_out (output) (shared with SPI master)
276 // SDI = mgmt_in_data[2] (input) (shared with SPI master)
277 // CSB = mgmt_in_data[3] (input) (shared with SPI master)
278 // SCK = mgmt_in_data[4] (input) (shared with SPI master)
279 // ser_rx = mgmt_in_data[5] (input)
280 // ser_tx = mgmt_out_data[6] (output)
281 // irq_pin = mgmt_in_data[7] (input)
282 // flash_csb = mgmt_out_data[8] (output) (user area flash)
283 // flash_sck = mgmt_out_data[9] (output) (user area flash)
284 // flash_io0 = mgmt_in/out_data[10] (input) (user area flash)
285 // flash_io1 = mgmt_in/out_data[11] (output) (user area flash)
Tim Edwards32d05422020-10-19 19:43:52 -0400286 // irq2_pin = mgmt_in_data[12] (input)
287 // trap_mon = mgmt_in_data[13] (output)
288 // clk1_mon = mgmt_in_data[14] (output)
289 // clk2_mon = mgmt_in_data[15] (output)
Tim Edwardsca2f3182020-10-06 10:05:11 -0400290
291 // OEB lines for [0] and [1] are the only ones connected directly to
292 // the pad. All others have OEB controlled by the configuration bit
293 // in the control block.
294
shalanfd13eb52020-08-21 16:48:07 +0200295 // memory-mapped I/O control registers
Tim Edwards04ba17f2020-10-02 22:27:50 -0400296 wire gpio_pullup; // Intermediate GPIO pullup
297 wire gpio_pulldown; // Intermediate GPIO pulldown
298 wire gpio_outenb; // Intermediate GPIO out enable (bar)
299 wire gpio_out; // Intermediate GPIO output
shalanfd13eb52020-08-21 16:48:07 +0200300
Tim Edwardsef8312e2020-09-22 17:20:06 -0400301 wire trap_output_dest; // Trap signal output destination
Tim Edwards32d05422020-10-19 19:43:52 -0400302 wire clk1_output_dest; // Core clock1 signal output destination
303 wire clk2_output_dest; // Core clock2 signal output destination
Tim Edwardsef8312e2020-09-22 17:20:06 -0400304 wire irq_7_inputsrc; // IRQ 7 source
Tim Edwards32d05422020-10-19 19:43:52 -0400305 wire irq_8_inputsrc; // IRQ 8 source
shalanfd13eb52020-08-21 16:48:07 +0200306
Tim Edwardsef8312e2020-09-22 17:20:06 -0400307 // Convert GPIO signals to sky130_fd_io pad signals
Tim Edwards04ba17f2020-10-02 22:27:50 -0400308 convert_gpio_sigs convert_gpio_bit (
shalanfd13eb52020-08-21 16:48:07 +0200309 .gpio_out(gpio_out),
310 .gpio_outenb(gpio_outenb),
311 .gpio_pu(gpio_pullup),
312 .gpio_pd(gpio_pulldown),
313 .gpio_out_pad(gpio_out_pad),
314 .gpio_outenb_pad(gpio_outenb_pad),
315 .gpio_inenb_pad(gpio_inenb_pad),
316 .gpio_mode1_pad(gpio_mode1_pad),
317 .gpio_mode0_pad(gpio_mode0_pad)
318 );
319
320 reg [31:0] irq;
321 wire irq_7;
Tim Edwards32d05422020-10-19 19:43:52 -0400322 wire irq_8;
shalanfd13eb52020-08-21 16:48:07 +0200323 wire irq_stall;
324 wire irq_uart;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400325 wire irq_spi_master;
326 wire irq_counter_timer0;
327 wire irq_counter_timer1;
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;
shalanfd13eb52020-08-21 16:48:07 +0200359
360 picorv32_wb #(
361 .STACKADDR(STACKADDR),
362 .PROGADDR_RESET(PROGADDR_RESET),
363 .PROGADDR_IRQ(PROGADDR_IRQ),
364 .BARREL_SHIFTER(1),
365 .COMPRESSED_ISA(1),
366 .ENABLE_MUL(1),
367 .ENABLE_DIV(1),
368 .ENABLE_IRQ(1),
369 .ENABLE_IRQ_QREGS(0)
370 ) cpu (
371 .wb_clk_i (wb_clk_i),
372 .wb_rst_i (wb_rst_i),
373 .trap (trap),
374 .irq (irq),
375 .mem_instr(mem_instr),
376 .wbm_adr_o(cpu_adr_o),
377 .wbm_dat_i(cpu_dat_i),
378 .wbm_stb_o(cpu_stb_o),
379 .wbm_ack_i(cpu_ack_i),
380 .wbm_cyc_o(cpu_cyc_o),
381 .wbm_dat_o(cpu_dat_o),
382 .wbm_we_o(cpu_we_o),
383 .wbm_sel_o(cpu_sel_o)
384 );
385
386 // Wishbone Slave SPIMEMIO
387 wire spimemio_flash_stb_i;
388 wire spimemio_flash_ack_o;
389 wire [31:0] spimemio_flash_dat_o;
390
391 wire spimemio_cfg_stb_i;
392 wire spimemio_cfg_ack_o;
393 wire [31:0] spimemio_cfg_dat_o;
394
395 spimemio_wb spimemio (
396 .wb_clk_i(wb_clk_i),
397 .wb_rst_i(wb_rst_i),
398
399 .wb_adr_i(cpu_adr_o),
400 .wb_dat_i(cpu_dat_o),
401 .wb_sel_i(cpu_sel_o),
402 .wb_we_i(cpu_we_o),
403 .wb_cyc_i(cpu_cyc_o),
404
405 // FLash Slave
406 .wb_flash_stb_i(spimemio_flash_stb_i),
407 .wb_flash_ack_o(spimemio_flash_ack_o),
408 .wb_flash_dat_o(spimemio_flash_dat_o),
409
410 // Config Register Slave
411 .wb_cfg_stb_i(spimemio_cfg_stb_i),
412 .wb_cfg_ack_o(spimemio_cfg_ack_o),
413 .wb_cfg_dat_o(spimemio_cfg_dat_o),
414
Tim Edwards04ba17f2020-10-02 22:27:50 -0400415 .pass_thru(pass_thru_mgmt),
416 .pass_thru_csb(pass_thru_mgmt_csb),
417 .pass_thru_sck(pass_thru_mgmt_sck),
418 .pass_thru_sdi(pass_thru_mgmt_sdi),
419 .pass_thru_sdo(pass_thru_mgmt_sdo),
420
shalanfd13eb52020-08-21 16:48:07 +0200421 .flash_csb (flash_csb),
422 .flash_clk (flash_clk),
423
424 .flash_csb_oeb (flash_csb_oeb),
425 .flash_clk_oeb (flash_clk_oeb),
426
427 .flash_io0_oeb (flash_io0_oeb),
428 .flash_io1_oeb (flash_io1_oeb),
429 .flash_io2_oeb (flash_io2_oeb),
430 .flash_io3_oeb (flash_io3_oeb),
431
432 .flash_csb_ieb (flash_csb_ieb),
433 .flash_clk_ieb (flash_clk_ieb),
434
435 .flash_io0_ieb (flash_io0_ieb),
436 .flash_io1_ieb (flash_io1_ieb),
437 .flash_io2_ieb (flash_io2_ieb),
438 .flash_io3_ieb (flash_io3_ieb),
439
440 .flash_io0_do (flash_io0_do),
441 .flash_io1_do (flash_io1_do),
442 .flash_io2_do (flash_io2_do),
443 .flash_io3_do (flash_io3_do),
444
445 .flash_io0_di (flash_io0_di),
446 .flash_io1_di (flash_io1_di),
447 .flash_io2_di (flash_io2_di),
448 .flash_io3_di (flash_io3_di)
449 );
450
451 // Wishbone Slave uart
452 wire uart_stb_i;
453 wire uart_ack_o;
454 wire [31:0] uart_dat_o;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400455 wire uart_enabled;
shalanfd13eb52020-08-21 16:48:07 +0200456
457 simpleuart_wb #(
458 .BASE_ADR(UART_BASE_ADR),
459 .CLK_DIV(UART_CLK_DIV),
460 .DATA(UART_DATA)
461 ) simpleuart (
462 // Wishbone Interface
463 .wb_clk_i(wb_clk_i),
464 .wb_rst_i(wb_rst_i),
465
466 .wb_adr_i(cpu_adr_o),
467 .wb_dat_i(cpu_dat_o),
468 .wb_sel_i(cpu_sel_o),
469 .wb_we_i(cpu_we_o),
470 .wb_cyc_i(cpu_cyc_o),
471
472 .wb_stb_i(uart_stb_i),
473 .wb_ack_o(uart_ack_o),
474 .wb_dat_o(uart_dat_o),
475
Tim Edwardsca2f3182020-10-06 10:05:11 -0400476 .uart_enabled(uart_enabled),
shalanfd13eb52020-08-21 16:48:07 +0200477 .ser_tx(ser_tx),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400478 .ser_rx(mgmt_in_data[5])
shalanfd13eb52020-08-21 16:48:07 +0200479 );
480
Tim Edwards04ba17f2020-10-02 22:27:50 -0400481 // Wishbone SPI master
482 wire spi_master_stb_i;
483 wire spi_master_ack_o;
484 wire [31:0] spi_master_dat_o;
485
486 simple_spi_master_wb #(
487 .BASE_ADR(SPI_MASTER_BASE_ADR),
488 .CONFIG(SPI_MASTER_CONFIG),
489 .DATA(SPI_MASTER_DATA)
490 ) simple_spi_master_inst (
491 // Wishbone Interface
492 .wb_clk_i(wb_clk_i),
493 .wb_rst_i(wb_rst_i),
494
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(spi_master_stb_i),
502 .wb_ack_o(spi_master_ack_o),
503 .wb_dat_o(spi_master_dat_o),
504
Tim Edwards81153202020-10-09 19:57:04 -0400505 .hk_connect(hk_connect),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400506 .csb(mgmt_out_pre[3]),
507 .sck(mgmt_out_pre[4]),
508 .sdi(mgmt_in_data[1]),
509 .sdo(mgmt_out_pre[2]),
510 .sdoenb(),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400511 .irq(irq_spi_master)
512 );
513
Tim Edwards7be29a22020-10-25 21:50:19 -0400514 wire counter_timer_strobe, counter_timer_offset;
515 wire counter_timer0_enable, counter_timer1_enable;
516 wire counter_timer0_stop, counter_timer1_stop;
Tim Edwards32d05422020-10-19 19:43:52 -0400517
Tim Edwards04ba17f2020-10-02 22:27:50 -0400518 // Wishbone Counter-timer 0
519 wire counter_timer0_stb_i;
520 wire counter_timer0_ack_o;
521 wire [31:0] counter_timer0_dat_o;
522
Tim Edwards7be29a22020-10-25 21:50:19 -0400523 counter_timer_low_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400524 .BASE_ADR(COUNTER_TIMER0_BASE_ADR),
525 .CONFIG(COUNTER_TIMER0_CONFIG),
526 .VALUE(COUNTER_TIMER0_VALUE),
527 .DATA(COUNTER_TIMER0_DATA)
528 ) counter_timer_0 (
529 // Wishbone Interface
530 .wb_clk_i(wb_clk_i),
531 .wb_rst_i(wb_rst_i),
532
533 .wb_adr_i(cpu_adr_o),
534 .wb_dat_i(cpu_dat_o),
535 .wb_sel_i(cpu_sel_o),
536 .wb_we_i(cpu_we_o),
537 .wb_cyc_i(cpu_cyc_o),
538
539 .wb_stb_i(counter_timer0_stb_i),
540 .wb_ack_o(counter_timer0_ack_o),
541 .wb_dat_o(counter_timer0_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400542
543 .enable_in(counter_timer1_enable),
544 .stop_in(counter_timer1_stop),
545 .strobe(counter_timer_strobe),
546 .is_offset(counter_timer_offset),
547 .enable_out(counter_timer0_enable),
548 .stop_out(counter_timer0_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400549 .irq(irq_counter_timer0)
550 );
551
552 // Wishbone Counter-timer 1
553 wire counter_timer1_stb_i;
554 wire counter_timer1_ack_o;
555 wire [31:0] counter_timer1_dat_o;
556
Tim Edwards7be29a22020-10-25 21:50:19 -0400557 counter_timer_high_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400558 .BASE_ADR(COUNTER_TIMER1_BASE_ADR),
559 .CONFIG(COUNTER_TIMER1_CONFIG),
560 .VALUE(COUNTER_TIMER1_VALUE),
561 .DATA(COUNTER_TIMER1_DATA)
562 ) counter_timer_1 (
563 // Wishbone Interface
564 .wb_clk_i(wb_clk_i),
565 .wb_rst_i(wb_rst_i),
566
567 .wb_adr_i(cpu_adr_o),
568 .wb_dat_i(cpu_dat_o),
569 .wb_sel_i(cpu_sel_o),
570 .wb_we_i(cpu_we_o),
571 .wb_cyc_i(cpu_cyc_o),
572
573 .wb_stb_i(counter_timer1_stb_i),
574 .wb_ack_o(counter_timer1_ack_o),
575 .wb_dat_o(counter_timer1_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400576
577 .enable_in(counter_timer0_enable),
578 .strobe(counter_timer_strobe),
579 .stop_in(counter_timer0_stop),
580 .is_offset(counter_timer_offset),
581 .enable_out(counter_timer1_enable),
582 .stop_out(counter_timer1_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400583 .irq(irq_counter_timer1)
584 );
585
shalanfd13eb52020-08-21 16:48:07 +0200586 // Wishbone Slave GPIO Registers
587 wire gpio_stb_i;
588 wire gpio_ack_o;
589 wire [31:0] gpio_dat_o;
590
591 gpio_wb #(
592 .BASE_ADR(GPIO_BASE_ADR),
593 .GPIO_DATA(GPIO_DATA),
594 .GPIO_ENA(GPIO_ENA),
595 .GPIO_PD(GPIO_PD),
596 .GPIO_PU(GPIO_PU)
597 ) gpio_wb (
598 .wb_clk_i(wb_clk_i),
599 .wb_rst_i(wb_rst_i),
shalanfd13eb52020-08-21 16:48:07 +0200600 .wb_adr_i(cpu_adr_o),
601 .wb_dat_i(cpu_dat_o),
602 .wb_sel_i(cpu_sel_o),
603 .wb_we_i(cpu_we_o),
604 .wb_cyc_i(cpu_cyc_o),
shalanfd13eb52020-08-21 16:48:07 +0200605 .wb_stb_i(gpio_stb_i),
606 .wb_ack_o(gpio_ack_o),
607 .wb_dat_o(gpio_dat_o),
608 .gpio_in_pad(gpio_in_pad),
Tim Edwards32d05422020-10-19 19:43:52 -0400609 .gpio(gpio_out),
610 .gpio_oeb(gpio_outenb),
611 .gpio_pu(gpio_pullup),
612 .gpio_pd(gpio_pulldown)
shalanfd13eb52020-08-21 16:48:07 +0200613 );
614
shalanfd13eb52020-08-21 16:48:07 +0200615 // Wishbone Slave System Control Register
616 wire sys_stb_i;
617 wire sys_ack_o;
618 wire [31:0] sys_dat_o;
619
620 sysctrl_wb #(
621 .BASE_ADR(SYS_BASE_ADR),
Tim Edwards32d05422020-10-19 19:43:52 -0400622 .PWRGOOD(PWRGOOD),
623 .CLK_OUT(CLK_OUT),
shalanfd13eb52020-08-21 16:48:07 +0200624 .TRAP_OUT(TRAP_OUT),
Tim Edwards32d05422020-10-19 19:43:52 -0400625 .IRQ_SRC(IRQ_SRC)
shalanfd13eb52020-08-21 16:48:07 +0200626 ) sysctrl (
627 .wb_clk_i(wb_clk_i),
628 .wb_rst_i(wb_rst_i),
629
630 .wb_adr_i(cpu_adr_o),
631 .wb_dat_i(cpu_dat_o),
632 .wb_sel_i(cpu_sel_o),
633 .wb_we_i(cpu_we_o),
634 .wb_cyc_i(cpu_cyc_o),
635
636 .wb_stb_i(sys_stb_i),
637 .wb_ack_o(sys_ack_o),
638 .wb_dat_o(sys_dat_o),
639
Tim Edwards05ad4fc2020-10-19 22:12:33 -0400640 .usr1_vcc_pwrgood(mprj_vcc_pwrgood),
641 .usr2_vcc_pwrgood(mprj2_vcc_pwrgood),
642 .usr1_vdd_pwrgood(mprj_vdd_pwrgood),
643 .usr2_vdd_pwrgood(mprj2_vdd_pwrgood),
shalanfd13eb52020-08-21 16:48:07 +0200644 .trap_output_dest(trap_output_dest),
Tim Edwards32d05422020-10-19 19:43:52 -0400645 .clk1_output_dest(clk1_output_dest),
646 .clk2_output_dest(clk2_output_dest),
647 .irq_7_inputsrc(irq_7_inputsrc),
648 .irq_8_inputsrc(irq_8_inputsrc)
shalanfd13eb52020-08-21 16:48:07 +0200649 );
650
651 // Logic Analyzer
652 wire la_stb_i;
653 wire la_ack_o;
654 wire [31:0] la_dat_o;
655
656 la_wb #(
657 .BASE_ADR(LA_BASE_ADR),
658 .LA_DATA_0(LA_DATA_0),
659 .LA_DATA_1(LA_DATA_1),
660 .LA_DATA_3(LA_DATA_3),
661 .LA_ENA_0(LA_ENA_0),
662 .LA_ENA_1(LA_ENA_1),
663 .LA_ENA_2(LA_ENA_2),
664 .LA_ENA_3(LA_ENA_3)
665 ) la (
666 .wb_clk_i(wb_clk_i),
667 .wb_rst_i(wb_rst_i),
668
669 .wb_adr_i(cpu_adr_o),
670 .wb_dat_i(cpu_dat_o),
671 .wb_sel_i(cpu_sel_o),
672 .wb_we_i(cpu_we_o),
673 .wb_cyc_i(cpu_cyc_o),
674
675 .wb_stb_i(la_stb_i),
676 .wb_ack_o(la_ack_o),
677 .wb_dat_o(la_dat_o),
678
679 .la_data(la_output),
shalan0d14e6e2020-08-31 16:50:48 +0200680 .la_data_in(la_input),
681 .la_oen(la_oen)
shalanfd13eb52020-08-21 16:48:07 +0200682 );
683
Tim Edwards6d9739d2020-10-19 11:00:49 -0400684 // WB Slave User Project Control
shalan0d14e6e2020-08-31 16:50:48 +0200685 wire mprj_ctrl_stb_i;
686 wire mprj_ctrl_ack_o;
687 wire [31:0] mprj_ctrl_dat_o;
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200688 wire [`MPRJ_IO_PADS-1:0] mgmt_out_pre;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400689
690 // Bits assigned to specific functions as outputs prevent the
691 // mprj GPIO-as-output from applying data when that function
692 // is active
693
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200694 assign mgmt_out_data[`MPRJ_IO_PADS-1:16] = mgmt_out_pre[`MPRJ_IO_PADS-1:16];
Tim Edwards32d05422020-10-19 19:43:52 -0400695
696 // Routing of output monitors (PLL, trap, clk1, clk2)
697 assign mgmt_out_data[15] = clk2_output_dest ? user_clk : mgmt_out_pre[15];
698 assign mgmt_out_data[14] = clk1_output_dest ? clk : mgmt_out_pre[14];
699 assign mgmt_out_data[13] = trap_output_dest ? trap : mgmt_out_pre[13];
700
701 assign mgmt_out_data[12:7] = mgmt_out_pre[12:7];
Tim Edwardsca2f3182020-10-06 10:05:11 -0400702 assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6];
703 assign mgmt_out_data[5:0] = mgmt_out_pre[5:0];
shalan0d14e6e2020-08-31 16:50:48 +0200704
705 mprj_ctrl_wb #(
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200706 .BASE_ADR(MPRJ_CTRL_ADR)
shalan0d14e6e2020-08-31 16:50:48 +0200707 ) mprj_ctrl (
708 .wb_clk_i(wb_clk_i),
709 .wb_rst_i(wb_rst_i),
710
711 .wb_adr_i(cpu_adr_o),
712 .wb_dat_i(cpu_dat_o),
713 .wb_sel_i(cpu_sel_o),
714 .wb_we_i(cpu_we_o),
715 .wb_cyc_i(cpu_cyc_o),
716 .wb_stb_i(mprj_ctrl_stb_i),
717 .wb_ack_o(mprj_ctrl_ack_o),
718 .wb_dat_o(mprj_ctrl_dat_o),
719
Tim Edwards04ba17f2020-10-02 22:27:50 -0400720 .serial_clock(mprj_io_loader_clock),
721 .serial_resetn(mprj_io_loader_resetn),
722 .serial_data_out(mprj_io_loader_data),
Tim Edwards496a08a2020-10-26 15:44:51 -0400723 .sdo_oenb_state(sdo_oenb_state),
724 .jtag_oenb_state(jtag_oenb_state),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400725 .mgmt_gpio_out(mgmt_out_pre),
Tim Edwardsba328902020-10-27 15:03:22 -0400726 .mgmt_gpio_in(mgmt_in_data),
727 .pwr_ctrl_out(pwr_ctrl_out)
shalan0d14e6e2020-08-31 16:50:48 +0200728 );
729
shalanfd13eb52020-08-21 16:48:07 +0200730 // Wishbone Slave RAM
731 wire mem_stb_i;
732 wire mem_ack_o;
733 wire [31:0] mem_dat_o;
734
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200735 mem_wb soc_mem (
shalanfd13eb52020-08-21 16:48:07 +0200736 .wb_clk_i(wb_clk_i),
737 .wb_rst_i(wb_rst_i),
738
739 .wb_adr_i(cpu_adr_o),
740 .wb_dat_i(cpu_dat_o),
741 .wb_sel_i(cpu_sel_o),
742 .wb_we_i(cpu_we_o),
743 .wb_cyc_i(cpu_cyc_o),
744
745 .wb_stb_i(mem_stb_i),
746 .wb_ack_o(mem_ack_o),
747 .wb_dat_o(mem_dat_o)
748 );
749
Manar55ec3692020-10-30 16:32:18 +0200750 wire uram_stb_i;
751 wire mram_stb_i;
752 wire uram_ack_o;
753 wire mram_ack_o;
754 wire [31:0] mram_dat_o;
755 wire [31:0] uram_dat_o;
756
757 // Storage area wishbone brige
758 storage_bridge_wb #(
759 .USER_BLOCKS(`USER_BLOCKS),
760 .MGMT_BLOCKS(`MGMT_BLOCKS),
761 .MGMT_BASE_ADR(EXT_MRAM_BASE_ADR),
762 .USER_BASE_ADR(EXT_URAM_BASE_ADR),
763 .MGMT_BLOCKS_ADR(MGMT_BLOCKS_ADR),
764 .USER_BLOCKS_ADR(USER_BLOCKS_ADR)
765 ) wb_bridge (
766 .wb_clk_i(wb_clk_i),
767 .wb_rst_i(wb_rst_i),
768
769 .wb_adr_i(cpu_adr_o),
770 .wb_dat_i(cpu_dat_o),
771 .wb_sel_i(cpu_sel_o),
772 .wb_we_i(cpu_we_o),
773 .wb_cyc_i(cpu_cyc_o),
774 .wb_stb_i({uram_stb_i, mram_stb_i}),
775 .wb_ack_o({uram_ack_o, mram_ack_o}),
776 .wb_mgmt_dat_o(mram_dat_o),
777
778 // MGMT_AREA RO WB Interface
779 .wb_user_dat_o(uram_dat_o),
780
781 // MGMT Area native memory interface
782 .mgmt_ena(mgmt_ena),
783 .mgmt_wen_mask(mgmt_wen_mask),
784 .mgmt_wen(mgmt_wen),
785 .mgmt_addr(mgmt_addr),
786 .mgmt_wdata(mgmt_wdata),
787 .mgmt_rdata(mgmt_rdata),
788
789 // MGMT_AREA RO interface
790 .mgmt_user_ena(user_ena),
791 .mgmt_user_addr(user_addr),
792 .mgmt_user_rdata(user_rdata)
793 );
794
shalanfd13eb52020-08-21 16:48:07 +0200795 // Wishbone intercon logic
796 wb_intercon #(
797 .AW(ADR_WIDTH),
798 .DW(DAT_WIDTH),
799 .NS(NUM_SLAVES),
800 .ADR_MASK(ADR_MASK),
801 .SLAVE_ADR(SLAVE_ADR)
802 ) intercon (
803 // Master Interface
804 .wbm_adr_i(cpu_adr_o),
805 .wbm_stb_i(cpu_stb_o),
806 .wbm_dat_o(cpu_dat_i),
807 .wbm_ack_o(cpu_ack_i),
808
809 // Slaves Interface
Manar98a7adc2020-10-19 23:21:36 +0200810 .wbs_stb_o({ sys_stb_i, spimemio_cfg_stb_i,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400811 mprj_stb_o, mprj_ctrl_stb_i, la_stb_i,
812 spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i,
813 gpio_stb_i, uart_stb_i,
Manar55ec3692020-10-30 16:32:18 +0200814 spimemio_flash_stb_i,uram_stb_i, mram_stb_i, mem_stb_i }),
Manar98a7adc2020-10-19 23:21:36 +0200815 .wbs_dat_i({ sys_dat_o, spimemio_cfg_dat_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400816 mprj_dat_i, mprj_ctrl_dat_o, la_dat_o,
817 spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o,
818 gpio_dat_o, uart_dat_o,
Manar55ec3692020-10-30 16:32:18 +0200819 spimemio_flash_dat_o, uram_dat_o, mram_dat_o, mem_dat_o }),
Manar98a7adc2020-10-19 23:21:36 +0200820 .wbs_ack_i({ sys_ack_o, spimemio_cfg_ack_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400821 mprj_ack_i, mprj_ctrl_ack_o, la_ack_o,
822 spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o,
823 gpio_ack_o, uart_ack_o,
Manar55ec3692020-10-30 16:32:18 +0200824 spimemio_flash_ack_o, uram_ack_o, mram_ack_o, mem_ack_o })
shalanfd13eb52020-08-21 16:48:07 +0200825 );
826
shalanfd13eb52020-08-21 16:48:07 +0200827endmodule
828
shalanfd13eb52020-08-21 16:48:07 +0200829// Implementation note:
830// Replace the following two modules with wrappers for your SRAM cells.
Tim Edwardsef8312e2020-09-22 17:20:06 -0400831
Tim Edwards04ba17f2020-10-02 22:27:50 -0400832module mgmt_soc_regs (
shalanfd13eb52020-08-21 16:48:07 +0200833 input clk, wen,
834 input [5:0] waddr,
835 input [5:0] raddr1,
836 input [5:0] raddr2,
837 input [31:0] wdata,
838 output [31:0] rdata1,
839 output [31:0] rdata2
840);
841 reg [31:0] regs [0:31];
842
843 always @(posedge clk)
844 if (wen) regs[waddr[4:0]] <= wdata;
845
846 assign rdata1 = regs[raddr1[4:0]];
847 assign rdata2 = regs[raddr2[4:0]];
848endmodule