blob: 0183909b813ca6f051b62093e596fa29720dd28d [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 = {
223 {24'h 30_0000},
224 {24'h 20_0000},
225 {24'h 10_0000},
226 {24'h 00_0000}
227 };
228
shalanfd13eb52020-08-21 16:48:07 +0200229 // Wishbone Interconnect
230 localparam ADR_WIDTH = 32;
231 localparam DAT_WIDTH = 32;
Manar55ec3692020-10-30 16:32:18 +0200232 localparam NUM_SLAVES = 14;
shalanfd13eb52020-08-21 16:48:07 +0200233
234 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = {
shalanfd13eb52020-08-21 16:48:07 +0200235 {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}}},
240 {8'hFF, {ADR_WIDTH-8{1'b0}}},
241 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalan0d14e6e2020-08-31 16:50:48 +0200242 {8'hFF, {ADR_WIDTH-8{1'b0}}},
243 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400244 {8'hFF, {ADR_WIDTH-8{1'b0}}},
245 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Manar55ec3692020-10-30 16:32:18 +0200246 {8'hFF, {ADR_WIDTH-8{1'b0}}},
247 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalanfd13eb52020-08-21 16:48:07 +0200248 {8'hFF, {ADR_WIDTH-8{1'b0}}}
249 };
shalan0d14e6e2020-08-31 16:50:48 +0200250
shalanfd13eb52020-08-21 16:48:07 +0200251 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = {
shalanfd13eb52020-08-21 16:48:07 +0200252 {SYS_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200253 {FLASH_CTRL_CFG},
shalan0d14e6e2020-08-31 16:50:48 +0200254 {MPRJ_BASE_ADR},
255 {MPRJ_CTRL_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200256 {LA_BASE_ADR},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400257 {SPI_MASTER_BASE_ADR},
258 {COUNTER_TIMER1_BASE_ADR},
259 {COUNTER_TIMER0_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200260 {GPIO_BASE_ADR},
261 {UART_BASE_ADR},
262 {FLASH_BASE_ADR},
Manar55ec3692020-10-30 16:32:18 +0200263 {EXT_URAM_BASE_ADR},
264 {EXT_MRAM_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200265 {RAM_BASE_ADR}
266 };
267
Tim Edwardsca2f3182020-10-06 10:05:11 -0400268 // The following functions are connected to specific user project
269 // area pins, when under control of the management area (during
270 // startup, and when not otherwise programmed for the user project).
271
272 // JTAG = jtag_out (inout)
273 // SDO = sdo_out (output) (shared with SPI master)
274 // SDI = mgmt_in_data[2] (input) (shared with SPI master)
275 // CSB = mgmt_in_data[3] (input) (shared with SPI master)
276 // SCK = mgmt_in_data[4] (input) (shared with SPI master)
277 // ser_rx = mgmt_in_data[5] (input)
278 // ser_tx = mgmt_out_data[6] (output)
279 // irq_pin = mgmt_in_data[7] (input)
280 // flash_csb = mgmt_out_data[8] (output) (user area flash)
281 // flash_sck = mgmt_out_data[9] (output) (user area flash)
282 // flash_io0 = mgmt_in/out_data[10] (input) (user area flash)
283 // flash_io1 = mgmt_in/out_data[11] (output) (user area flash)
Tim Edwards32d05422020-10-19 19:43:52 -0400284 // irq2_pin = mgmt_in_data[12] (input)
285 // trap_mon = mgmt_in_data[13] (output)
286 // clk1_mon = mgmt_in_data[14] (output)
287 // clk2_mon = mgmt_in_data[15] (output)
Tim Edwardsca2f3182020-10-06 10:05:11 -0400288
289 // OEB lines for [0] and [1] are the only ones connected directly to
290 // the pad. All others have OEB controlled by the configuration bit
291 // in the control block.
292
shalanfd13eb52020-08-21 16:48:07 +0200293 // memory-mapped I/O control registers
Tim Edwards04ba17f2020-10-02 22:27:50 -0400294 wire gpio_pullup; // Intermediate GPIO pullup
295 wire gpio_pulldown; // Intermediate GPIO pulldown
296 wire gpio_outenb; // Intermediate GPIO out enable (bar)
297 wire gpio_out; // Intermediate GPIO output
shalanfd13eb52020-08-21 16:48:07 +0200298
Tim Edwardsef8312e2020-09-22 17:20:06 -0400299 wire trap_output_dest; // Trap signal output destination
Tim Edwards32d05422020-10-19 19:43:52 -0400300 wire clk1_output_dest; // Core clock1 signal output destination
301 wire clk2_output_dest; // Core clock2 signal output destination
Tim Edwardsef8312e2020-09-22 17:20:06 -0400302 wire irq_7_inputsrc; // IRQ 7 source
Tim Edwards32d05422020-10-19 19:43:52 -0400303 wire irq_8_inputsrc; // IRQ 8 source
shalanfd13eb52020-08-21 16:48:07 +0200304
Tim Edwardsef8312e2020-09-22 17:20:06 -0400305 // Convert GPIO signals to sky130_fd_io pad signals
Tim Edwards04ba17f2020-10-02 22:27:50 -0400306 convert_gpio_sigs convert_gpio_bit (
shalanfd13eb52020-08-21 16:48:07 +0200307 .gpio_out(gpio_out),
308 .gpio_outenb(gpio_outenb),
309 .gpio_pu(gpio_pullup),
310 .gpio_pd(gpio_pulldown),
311 .gpio_out_pad(gpio_out_pad),
312 .gpio_outenb_pad(gpio_outenb_pad),
313 .gpio_inenb_pad(gpio_inenb_pad),
314 .gpio_mode1_pad(gpio_mode1_pad),
315 .gpio_mode0_pad(gpio_mode0_pad)
316 );
317
318 reg [31:0] irq;
319 wire irq_7;
Tim Edwards32d05422020-10-19 19:43:52 -0400320 wire irq_8;
shalanfd13eb52020-08-21 16:48:07 +0200321 wire irq_stall;
322 wire irq_uart;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400323 wire irq_spi_master;
324 wire irq_counter_timer0;
325 wire irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200326
shalanfd13eb52020-08-21 16:48:07 +0200327 assign irq_stall = 0;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400328 assign irq_7 = (irq_7_inputsrc == 1'b1) ? mgmt_in_data[7] : 1'b0;
Tim Edwards32d05422020-10-19 19:43:52 -0400329 assign irq_8 = (irq_8_inputsrc == 1'b1) ? mgmt_in_data[12] : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200330
331 always @* begin
332 irq = 0;
333 irq[3] = irq_stall;
334 irq[4] = irq_uart;
shalanfd13eb52020-08-21 16:48:07 +0200335 irq[6] = irq_spi;
336 irq[7] = irq_7;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400337 irq[9] = irq_spi_master;
338 irq[10] = irq_counter_timer0;
339 irq[11] = irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200340 end
341
Tim Edwards3245e2f2020-10-10 14:02:11 -0400342 // Assumption : no syscon module and wb_clk is the clock coming from the
343 // caravel_clocking module
344
shalanfd13eb52020-08-21 16:48:07 +0200345 assign wb_clk_i = clk;
346 assign wb_rst_i = ~resetn; // Redundant
347
348 // Wishbone Master
349 wire [31:0] cpu_adr_o;
350 wire [31:0] cpu_dat_i;
351 wire [3:0] cpu_sel_o;
352 wire cpu_we_o;
353 wire cpu_cyc_o;
354 wire cpu_stb_o;
355 wire [31:0] cpu_dat_o;
356 wire cpu_ack_i;
shalanfd13eb52020-08-21 16:48:07 +0200357
358 picorv32_wb #(
359 .STACKADDR(STACKADDR),
360 .PROGADDR_RESET(PROGADDR_RESET),
361 .PROGADDR_IRQ(PROGADDR_IRQ),
362 .BARREL_SHIFTER(1),
363 .COMPRESSED_ISA(1),
364 .ENABLE_MUL(1),
365 .ENABLE_DIV(1),
366 .ENABLE_IRQ(1),
367 .ENABLE_IRQ_QREGS(0)
368 ) cpu (
369 .wb_clk_i (wb_clk_i),
370 .wb_rst_i (wb_rst_i),
371 .trap (trap),
372 .irq (irq),
373 .mem_instr(mem_instr),
374 .wbm_adr_o(cpu_adr_o),
375 .wbm_dat_i(cpu_dat_i),
376 .wbm_stb_o(cpu_stb_o),
377 .wbm_ack_i(cpu_ack_i),
378 .wbm_cyc_o(cpu_cyc_o),
379 .wbm_dat_o(cpu_dat_o),
380 .wbm_we_o(cpu_we_o),
381 .wbm_sel_o(cpu_sel_o)
382 );
383
384 // Wishbone Slave SPIMEMIO
385 wire spimemio_flash_stb_i;
386 wire spimemio_flash_ack_o;
387 wire [31:0] spimemio_flash_dat_o;
388
389 wire spimemio_cfg_stb_i;
390 wire spimemio_cfg_ack_o;
391 wire [31:0] spimemio_cfg_dat_o;
392
393 spimemio_wb spimemio (
394 .wb_clk_i(wb_clk_i),
395 .wb_rst_i(wb_rst_i),
396
397 .wb_adr_i(cpu_adr_o),
398 .wb_dat_i(cpu_dat_o),
399 .wb_sel_i(cpu_sel_o),
400 .wb_we_i(cpu_we_o),
401 .wb_cyc_i(cpu_cyc_o),
402
403 // FLash Slave
404 .wb_flash_stb_i(spimemio_flash_stb_i),
405 .wb_flash_ack_o(spimemio_flash_ack_o),
406 .wb_flash_dat_o(spimemio_flash_dat_o),
407
408 // Config Register Slave
409 .wb_cfg_stb_i(spimemio_cfg_stb_i),
410 .wb_cfg_ack_o(spimemio_cfg_ack_o),
411 .wb_cfg_dat_o(spimemio_cfg_dat_o),
412
Tim Edwards04ba17f2020-10-02 22:27:50 -0400413 .pass_thru(pass_thru_mgmt),
414 .pass_thru_csb(pass_thru_mgmt_csb),
415 .pass_thru_sck(pass_thru_mgmt_sck),
416 .pass_thru_sdi(pass_thru_mgmt_sdi),
417 .pass_thru_sdo(pass_thru_mgmt_sdo),
418
shalanfd13eb52020-08-21 16:48:07 +0200419 .flash_csb (flash_csb),
420 .flash_clk (flash_clk),
421
422 .flash_csb_oeb (flash_csb_oeb),
423 .flash_clk_oeb (flash_clk_oeb),
424
425 .flash_io0_oeb (flash_io0_oeb),
426 .flash_io1_oeb (flash_io1_oeb),
427 .flash_io2_oeb (flash_io2_oeb),
428 .flash_io3_oeb (flash_io3_oeb),
429
430 .flash_csb_ieb (flash_csb_ieb),
431 .flash_clk_ieb (flash_clk_ieb),
432
433 .flash_io0_ieb (flash_io0_ieb),
434 .flash_io1_ieb (flash_io1_ieb),
435 .flash_io2_ieb (flash_io2_ieb),
436 .flash_io3_ieb (flash_io3_ieb),
437
438 .flash_io0_do (flash_io0_do),
439 .flash_io1_do (flash_io1_do),
440 .flash_io2_do (flash_io2_do),
441 .flash_io3_do (flash_io3_do),
442
443 .flash_io0_di (flash_io0_di),
444 .flash_io1_di (flash_io1_di),
445 .flash_io2_di (flash_io2_di),
446 .flash_io3_di (flash_io3_di)
447 );
448
449 // Wishbone Slave uart
450 wire uart_stb_i;
451 wire uart_ack_o;
452 wire [31:0] uart_dat_o;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400453 wire uart_enabled;
shalanfd13eb52020-08-21 16:48:07 +0200454
455 simpleuart_wb #(
456 .BASE_ADR(UART_BASE_ADR),
457 .CLK_DIV(UART_CLK_DIV),
458 .DATA(UART_DATA)
459 ) simpleuart (
460 // Wishbone Interface
461 .wb_clk_i(wb_clk_i),
462 .wb_rst_i(wb_rst_i),
463
464 .wb_adr_i(cpu_adr_o),
465 .wb_dat_i(cpu_dat_o),
466 .wb_sel_i(cpu_sel_o),
467 .wb_we_i(cpu_we_o),
468 .wb_cyc_i(cpu_cyc_o),
469
470 .wb_stb_i(uart_stb_i),
471 .wb_ack_o(uart_ack_o),
472 .wb_dat_o(uart_dat_o),
473
Tim Edwardsca2f3182020-10-06 10:05:11 -0400474 .uart_enabled(uart_enabled),
shalanfd13eb52020-08-21 16:48:07 +0200475 .ser_tx(ser_tx),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400476 .ser_rx(mgmt_in_data[5])
shalanfd13eb52020-08-21 16:48:07 +0200477 );
478
Tim Edwards04ba17f2020-10-02 22:27:50 -0400479 // Wishbone SPI master
480 wire spi_master_stb_i;
481 wire spi_master_ack_o;
482 wire [31:0] spi_master_dat_o;
483
484 simple_spi_master_wb #(
485 .BASE_ADR(SPI_MASTER_BASE_ADR),
486 .CONFIG(SPI_MASTER_CONFIG),
487 .DATA(SPI_MASTER_DATA)
488 ) simple_spi_master_inst (
489 // Wishbone Interface
490 .wb_clk_i(wb_clk_i),
491 .wb_rst_i(wb_rst_i),
492
493 .wb_adr_i(cpu_adr_o),
494 .wb_dat_i(cpu_dat_o),
495 .wb_sel_i(cpu_sel_o),
496 .wb_we_i(cpu_we_o),
497 .wb_cyc_i(cpu_cyc_o),
498
499 .wb_stb_i(spi_master_stb_i),
500 .wb_ack_o(spi_master_ack_o),
501 .wb_dat_o(spi_master_dat_o),
502
Tim Edwards81153202020-10-09 19:57:04 -0400503 .hk_connect(hk_connect),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400504 .csb(mgmt_out_pre[3]),
505 .sck(mgmt_out_pre[4]),
506 .sdi(mgmt_in_data[1]),
507 .sdo(mgmt_out_pre[2]),
508 .sdoenb(),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400509 .irq(irq_spi_master)
510 );
511
Tim Edwards7be29a22020-10-25 21:50:19 -0400512 wire counter_timer_strobe, counter_timer_offset;
513 wire counter_timer0_enable, counter_timer1_enable;
514 wire counter_timer0_stop, counter_timer1_stop;
Tim Edwards32d05422020-10-19 19:43:52 -0400515
Tim Edwards04ba17f2020-10-02 22:27:50 -0400516 // Wishbone Counter-timer 0
517 wire counter_timer0_stb_i;
518 wire counter_timer0_ack_o;
519 wire [31:0] counter_timer0_dat_o;
520
Tim Edwards7be29a22020-10-25 21:50:19 -0400521 counter_timer_low_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400522 .BASE_ADR(COUNTER_TIMER0_BASE_ADR),
523 .CONFIG(COUNTER_TIMER0_CONFIG),
524 .VALUE(COUNTER_TIMER0_VALUE),
525 .DATA(COUNTER_TIMER0_DATA)
526 ) counter_timer_0 (
527 // Wishbone Interface
528 .wb_clk_i(wb_clk_i),
529 .wb_rst_i(wb_rst_i),
530
531 .wb_adr_i(cpu_adr_o),
532 .wb_dat_i(cpu_dat_o),
533 .wb_sel_i(cpu_sel_o),
534 .wb_we_i(cpu_we_o),
535 .wb_cyc_i(cpu_cyc_o),
536
537 .wb_stb_i(counter_timer0_stb_i),
538 .wb_ack_o(counter_timer0_ack_o),
539 .wb_dat_o(counter_timer0_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400540
541 .enable_in(counter_timer1_enable),
542 .stop_in(counter_timer1_stop),
543 .strobe(counter_timer_strobe),
544 .is_offset(counter_timer_offset),
545 .enable_out(counter_timer0_enable),
546 .stop_out(counter_timer0_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400547 .irq(irq_counter_timer0)
548 );
549
550 // Wishbone Counter-timer 1
551 wire counter_timer1_stb_i;
552 wire counter_timer1_ack_o;
553 wire [31:0] counter_timer1_dat_o;
554
Tim Edwards7be29a22020-10-25 21:50:19 -0400555 counter_timer_high_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400556 .BASE_ADR(COUNTER_TIMER1_BASE_ADR),
557 .CONFIG(COUNTER_TIMER1_CONFIG),
558 .VALUE(COUNTER_TIMER1_VALUE),
559 .DATA(COUNTER_TIMER1_DATA)
560 ) counter_timer_1 (
561 // Wishbone Interface
562 .wb_clk_i(wb_clk_i),
563 .wb_rst_i(wb_rst_i),
564
565 .wb_adr_i(cpu_adr_o),
566 .wb_dat_i(cpu_dat_o),
567 .wb_sel_i(cpu_sel_o),
568 .wb_we_i(cpu_we_o),
569 .wb_cyc_i(cpu_cyc_o),
570
571 .wb_stb_i(counter_timer1_stb_i),
572 .wb_ack_o(counter_timer1_ack_o),
573 .wb_dat_o(counter_timer1_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400574
575 .enable_in(counter_timer0_enable),
576 .strobe(counter_timer_strobe),
577 .stop_in(counter_timer0_stop),
578 .is_offset(counter_timer_offset),
579 .enable_out(counter_timer1_enable),
580 .stop_out(counter_timer1_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400581 .irq(irq_counter_timer1)
582 );
583
shalanfd13eb52020-08-21 16:48:07 +0200584 // Wishbone Slave GPIO Registers
585 wire gpio_stb_i;
586 wire gpio_ack_o;
587 wire [31:0] gpio_dat_o;
588
589 gpio_wb #(
590 .BASE_ADR(GPIO_BASE_ADR),
591 .GPIO_DATA(GPIO_DATA),
592 .GPIO_ENA(GPIO_ENA),
593 .GPIO_PD(GPIO_PD),
594 .GPIO_PU(GPIO_PU)
595 ) gpio_wb (
596 .wb_clk_i(wb_clk_i),
597 .wb_rst_i(wb_rst_i),
shalanfd13eb52020-08-21 16:48:07 +0200598 .wb_adr_i(cpu_adr_o),
599 .wb_dat_i(cpu_dat_o),
600 .wb_sel_i(cpu_sel_o),
601 .wb_we_i(cpu_we_o),
602 .wb_cyc_i(cpu_cyc_o),
shalanfd13eb52020-08-21 16:48:07 +0200603 .wb_stb_i(gpio_stb_i),
604 .wb_ack_o(gpio_ack_o),
605 .wb_dat_o(gpio_dat_o),
606 .gpio_in_pad(gpio_in_pad),
Tim Edwards32d05422020-10-19 19:43:52 -0400607 .gpio(gpio_out),
608 .gpio_oeb(gpio_outenb),
609 .gpio_pu(gpio_pullup),
610 .gpio_pd(gpio_pulldown)
shalanfd13eb52020-08-21 16:48:07 +0200611 );
612
shalanfd13eb52020-08-21 16:48:07 +0200613 // Wishbone Slave System Control Register
614 wire sys_stb_i;
615 wire sys_ack_o;
616 wire [31:0] sys_dat_o;
617
618 sysctrl_wb #(
619 .BASE_ADR(SYS_BASE_ADR),
Tim Edwards32d05422020-10-19 19:43:52 -0400620 .PWRGOOD(PWRGOOD),
621 .CLK_OUT(CLK_OUT),
shalanfd13eb52020-08-21 16:48:07 +0200622 .TRAP_OUT(TRAP_OUT),
Tim Edwards32d05422020-10-19 19:43:52 -0400623 .IRQ_SRC(IRQ_SRC)
shalanfd13eb52020-08-21 16:48:07 +0200624 ) sysctrl (
625 .wb_clk_i(wb_clk_i),
626 .wb_rst_i(wb_rst_i),
627
628 .wb_adr_i(cpu_adr_o),
629 .wb_dat_i(cpu_dat_o),
630 .wb_sel_i(cpu_sel_o),
631 .wb_we_i(cpu_we_o),
632 .wb_cyc_i(cpu_cyc_o),
633
634 .wb_stb_i(sys_stb_i),
635 .wb_ack_o(sys_ack_o),
636 .wb_dat_o(sys_dat_o),
637
Tim Edwards05ad4fc2020-10-19 22:12:33 -0400638 .usr1_vcc_pwrgood(mprj_vcc_pwrgood),
639 .usr2_vcc_pwrgood(mprj2_vcc_pwrgood),
640 .usr1_vdd_pwrgood(mprj_vdd_pwrgood),
641 .usr2_vdd_pwrgood(mprj2_vdd_pwrgood),
shalanfd13eb52020-08-21 16:48:07 +0200642 .trap_output_dest(trap_output_dest),
Tim Edwards32d05422020-10-19 19:43:52 -0400643 .clk1_output_dest(clk1_output_dest),
644 .clk2_output_dest(clk2_output_dest),
645 .irq_7_inputsrc(irq_7_inputsrc),
646 .irq_8_inputsrc(irq_8_inputsrc)
shalanfd13eb52020-08-21 16:48:07 +0200647 );
648
649 // Logic Analyzer
650 wire la_stb_i;
651 wire la_ack_o;
652 wire [31:0] la_dat_o;
653
654 la_wb #(
655 .BASE_ADR(LA_BASE_ADR),
656 .LA_DATA_0(LA_DATA_0),
657 .LA_DATA_1(LA_DATA_1),
658 .LA_DATA_3(LA_DATA_3),
659 .LA_ENA_0(LA_ENA_0),
660 .LA_ENA_1(LA_ENA_1),
661 .LA_ENA_2(LA_ENA_2),
662 .LA_ENA_3(LA_ENA_3)
663 ) la (
664 .wb_clk_i(wb_clk_i),
665 .wb_rst_i(wb_rst_i),
666
667 .wb_adr_i(cpu_adr_o),
668 .wb_dat_i(cpu_dat_o),
669 .wb_sel_i(cpu_sel_o),
670 .wb_we_i(cpu_we_o),
671 .wb_cyc_i(cpu_cyc_o),
672
673 .wb_stb_i(la_stb_i),
674 .wb_ack_o(la_ack_o),
675 .wb_dat_o(la_dat_o),
676
677 .la_data(la_output),
shalan0d14e6e2020-08-31 16:50:48 +0200678 .la_data_in(la_input),
679 .la_oen(la_oen)
shalanfd13eb52020-08-21 16:48:07 +0200680 );
681
Tim Edwards6d9739d2020-10-19 11:00:49 -0400682 // WB Slave User Project Control
shalan0d14e6e2020-08-31 16:50:48 +0200683 wire mprj_ctrl_stb_i;
684 wire mprj_ctrl_ack_o;
685 wire [31:0] mprj_ctrl_dat_o;
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200686 wire [`MPRJ_IO_PADS-1:0] mgmt_out_pre;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400687
688 // Bits assigned to specific functions as outputs prevent the
689 // mprj GPIO-as-output from applying data when that function
690 // is active
691
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200692 assign mgmt_out_data[`MPRJ_IO_PADS-1:16] = mgmt_out_pre[`MPRJ_IO_PADS-1:16];
Tim Edwards32d05422020-10-19 19:43:52 -0400693
694 // Routing of output monitors (PLL, trap, clk1, clk2)
695 assign mgmt_out_data[15] = clk2_output_dest ? user_clk : mgmt_out_pre[15];
696 assign mgmt_out_data[14] = clk1_output_dest ? clk : mgmt_out_pre[14];
697 assign mgmt_out_data[13] = trap_output_dest ? trap : mgmt_out_pre[13];
698
699 assign mgmt_out_data[12:7] = mgmt_out_pre[12:7];
Tim Edwardsca2f3182020-10-06 10:05:11 -0400700 assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6];
701 assign mgmt_out_data[5:0] = mgmt_out_pre[5:0];
shalan0d14e6e2020-08-31 16:50:48 +0200702
703 mprj_ctrl_wb #(
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200704 .BASE_ADR(MPRJ_CTRL_ADR)
shalan0d14e6e2020-08-31 16:50:48 +0200705 ) mprj_ctrl (
706 .wb_clk_i(wb_clk_i),
707 .wb_rst_i(wb_rst_i),
708
709 .wb_adr_i(cpu_adr_o),
710 .wb_dat_i(cpu_dat_o),
711 .wb_sel_i(cpu_sel_o),
712 .wb_we_i(cpu_we_o),
713 .wb_cyc_i(cpu_cyc_o),
714 .wb_stb_i(mprj_ctrl_stb_i),
715 .wb_ack_o(mprj_ctrl_ack_o),
716 .wb_dat_o(mprj_ctrl_dat_o),
717
Tim Edwards04ba17f2020-10-02 22:27:50 -0400718 .serial_clock(mprj_io_loader_clock),
719 .serial_resetn(mprj_io_loader_resetn),
720 .serial_data_out(mprj_io_loader_data),
Tim Edwards496a08a2020-10-26 15:44:51 -0400721 .sdo_oenb_state(sdo_oenb_state),
722 .jtag_oenb_state(jtag_oenb_state),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400723 .mgmt_gpio_out(mgmt_out_pre),
Tim Edwardsba328902020-10-27 15:03:22 -0400724 .mgmt_gpio_in(mgmt_in_data),
725 .pwr_ctrl_out(pwr_ctrl_out)
shalan0d14e6e2020-08-31 16:50:48 +0200726 );
727
shalanfd13eb52020-08-21 16:48:07 +0200728 // Wishbone Slave RAM
729 wire mem_stb_i;
730 wire mem_ack_o;
731 wire [31:0] mem_dat_o;
732
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200733 mem_wb soc_mem (
shalanfd13eb52020-08-21 16:48:07 +0200734 .wb_clk_i(wb_clk_i),
735 .wb_rst_i(wb_rst_i),
736
737 .wb_adr_i(cpu_adr_o),
738 .wb_dat_i(cpu_dat_o),
739 .wb_sel_i(cpu_sel_o),
740 .wb_we_i(cpu_we_o),
741 .wb_cyc_i(cpu_cyc_o),
742
743 .wb_stb_i(mem_stb_i),
744 .wb_ack_o(mem_ack_o),
745 .wb_dat_o(mem_dat_o)
746 );
747
Manar55ec3692020-10-30 16:32:18 +0200748 wire uram_stb_i;
749 wire mram_stb_i;
750 wire uram_ack_o;
751 wire mram_ack_o;
752 wire [31:0] mram_dat_o;
753 wire [31:0] uram_dat_o;
754
755 // Storage area wishbone brige
756 storage_bridge_wb #(
757 .USER_BLOCKS(`USER_BLOCKS),
758 .MGMT_BLOCKS(`MGMT_BLOCKS),
759 .MGMT_BASE_ADR(EXT_MRAM_BASE_ADR),
760 .USER_BASE_ADR(EXT_URAM_BASE_ADR),
761 .MGMT_BLOCKS_ADR(MGMT_BLOCKS_ADR),
762 .USER_BLOCKS_ADR(USER_BLOCKS_ADR)
763 ) wb_bridge (
764 .wb_clk_i(wb_clk_i),
765 .wb_rst_i(wb_rst_i),
766
767 .wb_adr_i(cpu_adr_o),
768 .wb_dat_i(cpu_dat_o),
769 .wb_sel_i(cpu_sel_o),
770 .wb_we_i(cpu_we_o),
771 .wb_cyc_i(cpu_cyc_o),
772 .wb_stb_i({uram_stb_i, mram_stb_i}),
773 .wb_ack_o({uram_ack_o, mram_ack_o}),
774 .wb_mgmt_dat_o(mram_dat_o),
775
776 // MGMT_AREA RO WB Interface
777 .wb_user_dat_o(uram_dat_o),
778
779 // MGMT Area native memory interface
780 .mgmt_ena(mgmt_ena),
781 .mgmt_wen_mask(mgmt_wen_mask),
782 .mgmt_wen(mgmt_wen),
783 .mgmt_addr(mgmt_addr),
784 .mgmt_wdata(mgmt_wdata),
785 .mgmt_rdata(mgmt_rdata),
786
787 // MGMT_AREA RO interface
788 .mgmt_user_ena(user_ena),
789 .mgmt_user_addr(user_addr),
790 .mgmt_user_rdata(user_rdata)
791 );
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,
Manar55ec3692020-10-30 16:32:18 +0200812 spimemio_flash_stb_i,uram_stb_i, mram_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,
Manar55ec3692020-10-30 16:32:18 +0200817 spimemio_flash_dat_o, uram_dat_o, mram_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,
Manar55ec3692020-10-30 16:32:18 +0200822 spimemio_flash_ack_o, uram_ack_o, mram_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