blob: 55d0d2db3bc02f83963840a83442375fa960d3e4 [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"
Manar14d35ac2020-10-21 22:47:15 +020045`include "mem_synth_wb.v"
shalanfd13eb52020-08-21 16:48:07 +020046
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020047module mgmt_soc (
shalanfd13eb52020-08-21 16:48:07 +020048`ifdef LVS
49 inout vdd1v8, /* 1.8V domain */
50 inout vss,
51`endif
shalanfd13eb52020-08-21 16:48:07 +020052 input clk,
53 input resetn,
54
Tim Edwards04ba17f2020-10-02 22:27:50 -040055 // Trap state from CPU
56 output trap,
57
58 // GPIO (one pin)
59 output gpio_out_pad, // Connect to out on gpio pad
60 input gpio_in_pad, // Connect to in on gpio pad
61 output gpio_mode0_pad, // Connect to dm[0] on gpio pad
62 output gpio_mode1_pad, // Connect to dm[2] on gpio pad
63 output gpio_outenb_pad, // Connect to oe_n on gpio pad
64 output gpio_inenb_pad, // Connect to inp_dis on gpio pad
shalanfd13eb52020-08-21 16:48:07 +020065
66 // LA signals
Tim Edwards6d9739d2020-10-19 11:00:49 -040067 input [127:0] la_input, // From User Project to cpu
68 output [127:0] la_output, // From CPU to User Project
shalan0d14e6e2020-08-31 16:50:48 +020069 output [127:0] la_oen, // LA output enable (active low)
70
Tim Edwards6d9739d2020-10-19 11:00:49 -040071 // User Project I/O Configuration (serial load)
Tim Edwards05ad4fc2020-10-19 22:12:33 -040072 input mprj_vcc_pwrgood,
73 input mprj2_vcc_pwrgood,
74 input mprj_vdd_pwrgood,
75 input mprj2_vdd_pwrgood,
Tim Edwards04ba17f2020-10-02 22:27:50 -040076 output mprj_io_loader_resetn,
77 output mprj_io_loader_clock,
78 output mprj_io_loader_data,
shalanfd13eb52020-08-21 16:48:07 +020079
Tim Edwards6d9739d2020-10-19 11:00:49 -040080 // User Project pad data (when management SoC controls the pad)
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020081 input [`MPRJ_IO_PADS-1:0] mgmt_in_data,
82 output [`MPRJ_IO_PADS-1:0] mgmt_out_data,
83 output [`MPRJ_PWR_PADS-1:0] pwr_ctrl_out,
shalanfd13eb52020-08-21 16:48:07 +020084
85 // IRQ
shalanfd13eb52020-08-21 16:48:07 +020086 input irq_spi, // IRQ from standalone SPI
87
shalanfd13eb52020-08-21 16:48:07 +020088 // Flash memory control (SPI master)
89 output flash_csb,
90 output flash_clk,
91
92 output flash_csb_oeb,
93 output flash_clk_oeb,
94
95 output flash_io0_oeb,
96 output flash_io1_oeb,
97 output flash_io2_oeb,
98 output flash_io3_oeb,
99
100 output flash_csb_ieb,
101 output flash_clk_ieb,
102
103 output flash_io0_ieb,
104 output flash_io1_ieb,
105 output flash_io2_ieb,
106 output flash_io3_ieb,
107
108 output flash_io0_do,
109 output flash_io1_do,
110 output flash_io2_do,
111 output flash_io3_do,
112
113 input flash_io0_di,
114 input flash_io1_di,
115 input flash_io2_di,
116 input flash_io3_di,
117
Tim Edwards04ba17f2020-10-02 22:27:50 -0400118 // SPI pass-thru mode
119 input pass_thru_mgmt,
120 input pass_thru_mgmt_csb,
121 input pass_thru_mgmt_sck,
122 input pass_thru_mgmt_sdi,
123 output pass_thru_mgmt_sdo,
124
Tim Edwards496a08a2020-10-26 15:44:51 -0400125 // State of JTAG and SDO pins (override for management output use)
126 output sdo_oenb_state,
127 output jtag_oenb_state,
Tim Edwards81153202020-10-09 19:57:04 -0400128 // SPI master->slave direct link
129 output hk_connect,
Tim Edwards32d05422020-10-19 19:43:52 -0400130 // User clock monitoring
131 input user_clk,
Tim Edwards81153202020-10-09 19:57:04 -0400132
Tim Edwards6d9739d2020-10-19 11:00:49 -0400133 // WB MI A (User project)
shalan0d14e6e2020-08-31 16:50:48 +0200134 input mprj_ack_i,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400135 input [31:0] mprj_dat_i,
shalan0d14e6e2020-08-31 16:50:48 +0200136 output mprj_cyc_o,
Tim Edwardsef8312e2020-09-22 17:20:06 -0400137 output mprj_stb_o,
138 output mprj_we_o,
139 output [3:0] mprj_sel_o,
140 output [31:0] mprj_adr_o,
Manar98a7adc2020-10-19 23:21:36 +0200141 output [31:0] mprj_dat_o
shalanfd13eb52020-08-21 16:48:07 +0200142);
143 /* Memory reverted back to 256 words while memory has to be synthesized */
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200144 parameter [31:0] STACKADDR = (4*(`MEM_WORDS + `MEM_SYNTH_WORDS)); // end of memory
shalanfd13eb52020-08-21 16:48:07 +0200145 parameter [31:0] PROGADDR_RESET = 32'h 1000_0000;
146 parameter [31:0] PROGADDR_IRQ = 32'h 0000_0000;
147
148 // Slaves Base Addresses
Tim Edwards04ba17f2020-10-02 22:27:50 -0400149 parameter RAM_BASE_ADR = 32'h 0000_0000;
Manar14d35ac2020-10-21 22:47:15 +0200150 parameter RAM_SYNTH_BASE_ADR = 32'h 0100_0000;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400151 parameter FLASH_BASE_ADR = 32'h 1000_0000;
152 parameter UART_BASE_ADR = 32'h 2000_0000;
153 parameter GPIO_BASE_ADR = 32'h 2100_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400154 parameter COUNTER_TIMER0_BASE_ADR = 32'h 2200_0000;
155 parameter COUNTER_TIMER1_BASE_ADR = 32'h 2300_0000;
156 parameter SPI_MASTER_BASE_ADR = 32'h 2400_0000;
157 parameter LA_BASE_ADR = 32'h 2500_0000;
158 parameter MPRJ_CTRL_ADR = 32'h 2600_0000;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400159 parameter FLASH_CTRL_CFG = 32'h 2D00_0000;
Tim Edwards856b0922020-10-09 16:30:22 -0400160 parameter SYS_BASE_ADR = 32'h 2F00_0000;
161 parameter MPRJ_BASE_ADR = 32'h 3000_0000; // WB MI A
shalanfd13eb52020-08-21 16:48:07 +0200162
163 // UART
164 parameter UART_CLK_DIV = 8'h00;
165 parameter UART_DATA = 8'h04;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400166
167 // SPI Master
168 parameter SPI_MASTER_CONFIG = 8'h00;
169 parameter SPI_MASTER_DATA = 8'h04;
170
171 // Counter-timer 0
172 parameter COUNTER_TIMER0_CONFIG = 8'h00;
173 parameter COUNTER_TIMER0_VALUE = 8'h04;
174 parameter COUNTER_TIMER0_DATA = 8'h08;
175
176 // Counter-timer 1
177 parameter COUNTER_TIMER1_CONFIG = 8'h00;
178 parameter COUNTER_TIMER1_VALUE = 8'h04;
179 parameter COUNTER_TIMER1_DATA = 8'h08;
shalanfd13eb52020-08-21 16:48:07 +0200180
181 // SOC GPIO
182 parameter GPIO_DATA = 8'h00;
183 parameter GPIO_ENA = 8'h04;
184 parameter GPIO_PU = 8'h08;
185 parameter GPIO_PD = 8'h0c;
186
shalan0d14e6e2020-08-31 16:50:48 +0200187 // LA
shalanfd13eb52020-08-21 16:48:07 +0200188 parameter LA_DATA_0 = 8'h00;
189 parameter LA_DATA_1 = 8'h04;
190 parameter LA_DATA_2 = 8'h08;
191 parameter LA_DATA_3 = 8'h0c;
192 parameter LA_ENA_0 = 8'h10;
193 parameter LA_ENA_1 = 8'h14;
194 parameter LA_ENA_2 = 8'h18;
195 parameter LA_ENA_3 = 8'h1c;
196
shalanfd13eb52020-08-21 16:48:07 +0200197 // System Control Registers
Tim Edwards32d05422020-10-19 19:43:52 -0400198 parameter PWRGOOD = 8'h00;
199 parameter CLK_OUT = 8'h04;
200 parameter TRAP_OUT = 8'h08;
201 parameter IRQ_SRC = 8'h0c;
shalanfd13eb52020-08-21 16:48:07 +0200202
203 // Wishbone Interconnect
204 localparam ADR_WIDTH = 32;
205 localparam DAT_WIDTH = 32;
Manar14d35ac2020-10-21 22:47:15 +0200206 localparam NUM_SLAVES = 13;
shalanfd13eb52020-08-21 16:48:07 +0200207
208 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] ADR_MASK = {
shalanfd13eb52020-08-21 16:48:07 +0200209 {8'hFF, {ADR_WIDTH-8{1'b0}}},
210 {8'hFF, {ADR_WIDTH-8{1'b0}}},
211 {8'hFF, {ADR_WIDTH-8{1'b0}}},
212 {8'hFF, {ADR_WIDTH-8{1'b0}}},
213 {8'hFF, {ADR_WIDTH-8{1'b0}}},
214 {8'hFF, {ADR_WIDTH-8{1'b0}}},
215 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalan0d14e6e2020-08-31 16:50:48 +0200216 {8'hFF, {ADR_WIDTH-8{1'b0}}},
217 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400218 {8'hFF, {ADR_WIDTH-8{1'b0}}},
219 {8'hFF, {ADR_WIDTH-8{1'b0}}},
Manar14d35ac2020-10-21 22:47:15 +0200220 {8'hFF, {ADR_WIDTH-8{1'b0}}},
shalanfd13eb52020-08-21 16:48:07 +0200221 {8'hFF, {ADR_WIDTH-8{1'b0}}}
222 };
shalan0d14e6e2020-08-31 16:50:48 +0200223
shalanfd13eb52020-08-21 16:48:07 +0200224 parameter [NUM_SLAVES*ADR_WIDTH-1: 0] SLAVE_ADR = {
shalanfd13eb52020-08-21 16:48:07 +0200225 {SYS_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200226 {FLASH_CTRL_CFG},
shalan0d14e6e2020-08-31 16:50:48 +0200227 {MPRJ_BASE_ADR},
228 {MPRJ_CTRL_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200229 {LA_BASE_ADR},
Tim Edwards04ba17f2020-10-02 22:27:50 -0400230 {SPI_MASTER_BASE_ADR},
231 {COUNTER_TIMER1_BASE_ADR},
232 {COUNTER_TIMER0_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200233 {GPIO_BASE_ADR},
234 {UART_BASE_ADR},
235 {FLASH_BASE_ADR},
Manar14d35ac2020-10-21 22:47:15 +0200236 {RAM_SYNTH_BASE_ADR},
shalanfd13eb52020-08-21 16:48:07 +0200237 {RAM_BASE_ADR}
238 };
239
Tim Edwardsca2f3182020-10-06 10:05:11 -0400240 // The following functions are connected to specific user project
241 // area pins, when under control of the management area (during
242 // startup, and when not otherwise programmed for the user project).
243
244 // JTAG = jtag_out (inout)
245 // SDO = sdo_out (output) (shared with SPI master)
246 // SDI = mgmt_in_data[2] (input) (shared with SPI master)
247 // CSB = mgmt_in_data[3] (input) (shared with SPI master)
248 // SCK = mgmt_in_data[4] (input) (shared with SPI master)
249 // ser_rx = mgmt_in_data[5] (input)
250 // ser_tx = mgmt_out_data[6] (output)
251 // irq_pin = mgmt_in_data[7] (input)
252 // flash_csb = mgmt_out_data[8] (output) (user area flash)
253 // flash_sck = mgmt_out_data[9] (output) (user area flash)
254 // flash_io0 = mgmt_in/out_data[10] (input) (user area flash)
255 // flash_io1 = mgmt_in/out_data[11] (output) (user area flash)
Tim Edwards32d05422020-10-19 19:43:52 -0400256 // irq2_pin = mgmt_in_data[12] (input)
257 // trap_mon = mgmt_in_data[13] (output)
258 // clk1_mon = mgmt_in_data[14] (output)
259 // clk2_mon = mgmt_in_data[15] (output)
Tim Edwardsca2f3182020-10-06 10:05:11 -0400260
261 // OEB lines for [0] and [1] are the only ones connected directly to
262 // the pad. All others have OEB controlled by the configuration bit
263 // in the control block.
264
shalanfd13eb52020-08-21 16:48:07 +0200265 // memory-mapped I/O control registers
Tim Edwards04ba17f2020-10-02 22:27:50 -0400266 wire gpio_pullup; // Intermediate GPIO pullup
267 wire gpio_pulldown; // Intermediate GPIO pulldown
268 wire gpio_outenb; // Intermediate GPIO out enable (bar)
269 wire gpio_out; // Intermediate GPIO output
shalanfd13eb52020-08-21 16:48:07 +0200270
Tim Edwardsef8312e2020-09-22 17:20:06 -0400271 wire trap_output_dest; // Trap signal output destination
Tim Edwards32d05422020-10-19 19:43:52 -0400272 wire clk1_output_dest; // Core clock1 signal output destination
273 wire clk2_output_dest; // Core clock2 signal output destination
Tim Edwardsef8312e2020-09-22 17:20:06 -0400274 wire irq_7_inputsrc; // IRQ 7 source
Tim Edwards32d05422020-10-19 19:43:52 -0400275 wire irq_8_inputsrc; // IRQ 8 source
shalanfd13eb52020-08-21 16:48:07 +0200276
Tim Edwardsef8312e2020-09-22 17:20:06 -0400277 // Convert GPIO signals to sky130_fd_io pad signals
Tim Edwards04ba17f2020-10-02 22:27:50 -0400278 convert_gpio_sigs convert_gpio_bit (
shalanfd13eb52020-08-21 16:48:07 +0200279 .gpio_out(gpio_out),
280 .gpio_outenb(gpio_outenb),
281 .gpio_pu(gpio_pullup),
282 .gpio_pd(gpio_pulldown),
283 .gpio_out_pad(gpio_out_pad),
284 .gpio_outenb_pad(gpio_outenb_pad),
285 .gpio_inenb_pad(gpio_inenb_pad),
286 .gpio_mode1_pad(gpio_mode1_pad),
287 .gpio_mode0_pad(gpio_mode0_pad)
288 );
289
290 reg [31:0] irq;
291 wire irq_7;
Tim Edwards32d05422020-10-19 19:43:52 -0400292 wire irq_8;
shalanfd13eb52020-08-21 16:48:07 +0200293 wire irq_stall;
294 wire irq_uart;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400295 wire irq_spi_master;
296 wire irq_counter_timer0;
297 wire irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200298
shalanfd13eb52020-08-21 16:48:07 +0200299 assign irq_stall = 0;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400300 assign irq_7 = (irq_7_inputsrc == 1'b1) ? mgmt_in_data[7] : 1'b0;
Tim Edwards32d05422020-10-19 19:43:52 -0400301 assign irq_8 = (irq_8_inputsrc == 1'b1) ? mgmt_in_data[12] : 1'b0;
shalanfd13eb52020-08-21 16:48:07 +0200302
303 always @* begin
304 irq = 0;
305 irq[3] = irq_stall;
306 irq[4] = irq_uart;
shalanfd13eb52020-08-21 16:48:07 +0200307 irq[6] = irq_spi;
308 irq[7] = irq_7;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400309 irq[9] = irq_spi_master;
310 irq[10] = irq_counter_timer0;
311 irq[11] = irq_counter_timer1;
shalanfd13eb52020-08-21 16:48:07 +0200312 end
313
Tim Edwards3245e2f2020-10-10 14:02:11 -0400314 // Assumption : no syscon module and wb_clk is the clock coming from the
315 // caravel_clocking module
316
shalanfd13eb52020-08-21 16:48:07 +0200317 assign wb_clk_i = clk;
318 assign wb_rst_i = ~resetn; // Redundant
319
320 // Wishbone Master
321 wire [31:0] cpu_adr_o;
322 wire [31:0] cpu_dat_i;
323 wire [3:0] cpu_sel_o;
324 wire cpu_we_o;
325 wire cpu_cyc_o;
326 wire cpu_stb_o;
327 wire [31:0] cpu_dat_o;
328 wire cpu_ack_i;
shalanfd13eb52020-08-21 16:48:07 +0200329
330 picorv32_wb #(
331 .STACKADDR(STACKADDR),
332 .PROGADDR_RESET(PROGADDR_RESET),
333 .PROGADDR_IRQ(PROGADDR_IRQ),
334 .BARREL_SHIFTER(1),
335 .COMPRESSED_ISA(1),
336 .ENABLE_MUL(1),
337 .ENABLE_DIV(1),
338 .ENABLE_IRQ(1),
339 .ENABLE_IRQ_QREGS(0)
340 ) cpu (
341 .wb_clk_i (wb_clk_i),
342 .wb_rst_i (wb_rst_i),
343 .trap (trap),
344 .irq (irq),
345 .mem_instr(mem_instr),
346 .wbm_adr_o(cpu_adr_o),
347 .wbm_dat_i(cpu_dat_i),
348 .wbm_stb_o(cpu_stb_o),
349 .wbm_ack_i(cpu_ack_i),
350 .wbm_cyc_o(cpu_cyc_o),
351 .wbm_dat_o(cpu_dat_o),
352 .wbm_we_o(cpu_we_o),
353 .wbm_sel_o(cpu_sel_o)
354 );
355
356 // Wishbone Slave SPIMEMIO
357 wire spimemio_flash_stb_i;
358 wire spimemio_flash_ack_o;
359 wire [31:0] spimemio_flash_dat_o;
360
361 wire spimemio_cfg_stb_i;
362 wire spimemio_cfg_ack_o;
363 wire [31:0] spimemio_cfg_dat_o;
364
365 spimemio_wb spimemio (
366 .wb_clk_i(wb_clk_i),
367 .wb_rst_i(wb_rst_i),
368
369 .wb_adr_i(cpu_adr_o),
370 .wb_dat_i(cpu_dat_o),
371 .wb_sel_i(cpu_sel_o),
372 .wb_we_i(cpu_we_o),
373 .wb_cyc_i(cpu_cyc_o),
374
375 // FLash Slave
376 .wb_flash_stb_i(spimemio_flash_stb_i),
377 .wb_flash_ack_o(spimemio_flash_ack_o),
378 .wb_flash_dat_o(spimemio_flash_dat_o),
379
380 // Config Register Slave
381 .wb_cfg_stb_i(spimemio_cfg_stb_i),
382 .wb_cfg_ack_o(spimemio_cfg_ack_o),
383 .wb_cfg_dat_o(spimemio_cfg_dat_o),
384
Tim Edwards04ba17f2020-10-02 22:27:50 -0400385 .pass_thru(pass_thru_mgmt),
386 .pass_thru_csb(pass_thru_mgmt_csb),
387 .pass_thru_sck(pass_thru_mgmt_sck),
388 .pass_thru_sdi(pass_thru_mgmt_sdi),
389 .pass_thru_sdo(pass_thru_mgmt_sdo),
390
shalanfd13eb52020-08-21 16:48:07 +0200391 .flash_csb (flash_csb),
392 .flash_clk (flash_clk),
393
394 .flash_csb_oeb (flash_csb_oeb),
395 .flash_clk_oeb (flash_clk_oeb),
396
397 .flash_io0_oeb (flash_io0_oeb),
398 .flash_io1_oeb (flash_io1_oeb),
399 .flash_io2_oeb (flash_io2_oeb),
400 .flash_io3_oeb (flash_io3_oeb),
401
402 .flash_csb_ieb (flash_csb_ieb),
403 .flash_clk_ieb (flash_clk_ieb),
404
405 .flash_io0_ieb (flash_io0_ieb),
406 .flash_io1_ieb (flash_io1_ieb),
407 .flash_io2_ieb (flash_io2_ieb),
408 .flash_io3_ieb (flash_io3_ieb),
409
410 .flash_io0_do (flash_io0_do),
411 .flash_io1_do (flash_io1_do),
412 .flash_io2_do (flash_io2_do),
413 .flash_io3_do (flash_io3_do),
414
415 .flash_io0_di (flash_io0_di),
416 .flash_io1_di (flash_io1_di),
417 .flash_io2_di (flash_io2_di),
418 .flash_io3_di (flash_io3_di)
419 );
420
421 // Wishbone Slave uart
422 wire uart_stb_i;
423 wire uart_ack_o;
424 wire [31:0] uart_dat_o;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400425 wire uart_enabled;
shalanfd13eb52020-08-21 16:48:07 +0200426
427 simpleuart_wb #(
428 .BASE_ADR(UART_BASE_ADR),
429 .CLK_DIV(UART_CLK_DIV),
430 .DATA(UART_DATA)
431 ) simpleuart (
432 // Wishbone Interface
433 .wb_clk_i(wb_clk_i),
434 .wb_rst_i(wb_rst_i),
435
436 .wb_adr_i(cpu_adr_o),
437 .wb_dat_i(cpu_dat_o),
438 .wb_sel_i(cpu_sel_o),
439 .wb_we_i(cpu_we_o),
440 .wb_cyc_i(cpu_cyc_o),
441
442 .wb_stb_i(uart_stb_i),
443 .wb_ack_o(uart_ack_o),
444 .wb_dat_o(uart_dat_o),
445
Tim Edwardsca2f3182020-10-06 10:05:11 -0400446 .uart_enabled(uart_enabled),
shalanfd13eb52020-08-21 16:48:07 +0200447 .ser_tx(ser_tx),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400448 .ser_rx(mgmt_in_data[5])
shalanfd13eb52020-08-21 16:48:07 +0200449 );
450
Tim Edwards04ba17f2020-10-02 22:27:50 -0400451 // Wishbone SPI master
452 wire spi_master_stb_i;
453 wire spi_master_ack_o;
454 wire [31:0] spi_master_dat_o;
455
456 simple_spi_master_wb #(
457 .BASE_ADR(SPI_MASTER_BASE_ADR),
458 .CONFIG(SPI_MASTER_CONFIG),
459 .DATA(SPI_MASTER_DATA)
460 ) simple_spi_master_inst (
461 // Wishbone Interface
462 .wb_clk_i(wb_clk_i),
463 .wb_rst_i(wb_rst_i),
464
465 .wb_adr_i(cpu_adr_o),
466 .wb_dat_i(cpu_dat_o),
467 .wb_sel_i(cpu_sel_o),
468 .wb_we_i(cpu_we_o),
469 .wb_cyc_i(cpu_cyc_o),
470
471 .wb_stb_i(spi_master_stb_i),
472 .wb_ack_o(spi_master_ack_o),
473 .wb_dat_o(spi_master_dat_o),
474
Tim Edwards81153202020-10-09 19:57:04 -0400475 .hk_connect(hk_connect),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400476 .csb(mgmt_out_pre[3]),
477 .sck(mgmt_out_pre[4]),
478 .sdi(mgmt_in_data[1]),
479 .sdo(mgmt_out_pre[2]),
480 .sdoenb(),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400481 .irq(irq_spi_master)
482 );
483
Tim Edwards7be29a22020-10-25 21:50:19 -0400484 wire counter_timer_strobe, counter_timer_offset;
485 wire counter_timer0_enable, counter_timer1_enable;
486 wire counter_timer0_stop, counter_timer1_stop;
Tim Edwards32d05422020-10-19 19:43:52 -0400487
Tim Edwards04ba17f2020-10-02 22:27:50 -0400488 // Wishbone Counter-timer 0
489 wire counter_timer0_stb_i;
490 wire counter_timer0_ack_o;
491 wire [31:0] counter_timer0_dat_o;
492
Tim Edwards7be29a22020-10-25 21:50:19 -0400493 counter_timer_low_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400494 .BASE_ADR(COUNTER_TIMER0_BASE_ADR),
495 .CONFIG(COUNTER_TIMER0_CONFIG),
496 .VALUE(COUNTER_TIMER0_VALUE),
497 .DATA(COUNTER_TIMER0_DATA)
498 ) counter_timer_0 (
499 // Wishbone Interface
500 .wb_clk_i(wb_clk_i),
501 .wb_rst_i(wb_rst_i),
502
503 .wb_adr_i(cpu_adr_o),
504 .wb_dat_i(cpu_dat_o),
505 .wb_sel_i(cpu_sel_o),
506 .wb_we_i(cpu_we_o),
507 .wb_cyc_i(cpu_cyc_o),
508
509 .wb_stb_i(counter_timer0_stb_i),
510 .wb_ack_o(counter_timer0_ack_o),
511 .wb_dat_o(counter_timer0_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400512
513 .enable_in(counter_timer1_enable),
514 .stop_in(counter_timer1_stop),
515 .strobe(counter_timer_strobe),
516 .is_offset(counter_timer_offset),
517 .enable_out(counter_timer0_enable),
518 .stop_out(counter_timer0_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400519 .irq(irq_counter_timer0)
520 );
521
522 // Wishbone Counter-timer 1
523 wire counter_timer1_stb_i;
524 wire counter_timer1_ack_o;
525 wire [31:0] counter_timer1_dat_o;
526
Tim Edwards7be29a22020-10-25 21:50:19 -0400527 counter_timer_high_wb #(
Tim Edwards04ba17f2020-10-02 22:27:50 -0400528 .BASE_ADR(COUNTER_TIMER1_BASE_ADR),
529 .CONFIG(COUNTER_TIMER1_CONFIG),
530 .VALUE(COUNTER_TIMER1_VALUE),
531 .DATA(COUNTER_TIMER1_DATA)
532 ) counter_timer_1 (
533 // Wishbone Interface
534 .wb_clk_i(wb_clk_i),
535 .wb_rst_i(wb_rst_i),
536
537 .wb_adr_i(cpu_adr_o),
538 .wb_dat_i(cpu_dat_o),
539 .wb_sel_i(cpu_sel_o),
540 .wb_we_i(cpu_we_o),
541 .wb_cyc_i(cpu_cyc_o),
542
543 .wb_stb_i(counter_timer1_stb_i),
544 .wb_ack_o(counter_timer1_ack_o),
545 .wb_dat_o(counter_timer1_dat_o),
Tim Edwards7be29a22020-10-25 21:50:19 -0400546
547 .enable_in(counter_timer0_enable),
548 .strobe(counter_timer_strobe),
549 .stop_in(counter_timer0_stop),
550 .is_offset(counter_timer_offset),
551 .enable_out(counter_timer1_enable),
552 .stop_out(counter_timer1_stop),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400553 .irq(irq_counter_timer1)
554 );
555
shalanfd13eb52020-08-21 16:48:07 +0200556 // Wishbone Slave GPIO Registers
557 wire gpio_stb_i;
558 wire gpio_ack_o;
559 wire [31:0] gpio_dat_o;
560
561 gpio_wb #(
562 .BASE_ADR(GPIO_BASE_ADR),
563 .GPIO_DATA(GPIO_DATA),
564 .GPIO_ENA(GPIO_ENA),
565 .GPIO_PD(GPIO_PD),
566 .GPIO_PU(GPIO_PU)
567 ) gpio_wb (
568 .wb_clk_i(wb_clk_i),
569 .wb_rst_i(wb_rst_i),
shalanfd13eb52020-08-21 16:48:07 +0200570 .wb_adr_i(cpu_adr_o),
571 .wb_dat_i(cpu_dat_o),
572 .wb_sel_i(cpu_sel_o),
573 .wb_we_i(cpu_we_o),
574 .wb_cyc_i(cpu_cyc_o),
shalanfd13eb52020-08-21 16:48:07 +0200575 .wb_stb_i(gpio_stb_i),
576 .wb_ack_o(gpio_ack_o),
577 .wb_dat_o(gpio_dat_o),
578 .gpio_in_pad(gpio_in_pad),
Tim Edwards32d05422020-10-19 19:43:52 -0400579 .gpio(gpio_out),
580 .gpio_oeb(gpio_outenb),
581 .gpio_pu(gpio_pullup),
582 .gpio_pd(gpio_pulldown)
shalanfd13eb52020-08-21 16:48:07 +0200583 );
584
shalanfd13eb52020-08-21 16:48:07 +0200585 // Wishbone Slave System Control Register
586 wire sys_stb_i;
587 wire sys_ack_o;
588 wire [31:0] sys_dat_o;
589
590 sysctrl_wb #(
591 .BASE_ADR(SYS_BASE_ADR),
Tim Edwards32d05422020-10-19 19:43:52 -0400592 .PWRGOOD(PWRGOOD),
593 .CLK_OUT(CLK_OUT),
shalanfd13eb52020-08-21 16:48:07 +0200594 .TRAP_OUT(TRAP_OUT),
Tim Edwards32d05422020-10-19 19:43:52 -0400595 .IRQ_SRC(IRQ_SRC)
shalanfd13eb52020-08-21 16:48:07 +0200596 ) sysctrl (
597 .wb_clk_i(wb_clk_i),
598 .wb_rst_i(wb_rst_i),
599
600 .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),
605
606 .wb_stb_i(sys_stb_i),
607 .wb_ack_o(sys_ack_o),
608 .wb_dat_o(sys_dat_o),
609
Tim Edwards05ad4fc2020-10-19 22:12:33 -0400610 .usr1_vcc_pwrgood(mprj_vcc_pwrgood),
611 .usr2_vcc_pwrgood(mprj2_vcc_pwrgood),
612 .usr1_vdd_pwrgood(mprj_vdd_pwrgood),
613 .usr2_vdd_pwrgood(mprj2_vdd_pwrgood),
shalanfd13eb52020-08-21 16:48:07 +0200614 .trap_output_dest(trap_output_dest),
Tim Edwards32d05422020-10-19 19:43:52 -0400615 .clk1_output_dest(clk1_output_dest),
616 .clk2_output_dest(clk2_output_dest),
617 .irq_7_inputsrc(irq_7_inputsrc),
618 .irq_8_inputsrc(irq_8_inputsrc)
shalanfd13eb52020-08-21 16:48:07 +0200619 );
620
621 // Logic Analyzer
622 wire la_stb_i;
623 wire la_ack_o;
624 wire [31:0] la_dat_o;
625
626 la_wb #(
627 .BASE_ADR(LA_BASE_ADR),
628 .LA_DATA_0(LA_DATA_0),
629 .LA_DATA_1(LA_DATA_1),
630 .LA_DATA_3(LA_DATA_3),
631 .LA_ENA_0(LA_ENA_0),
632 .LA_ENA_1(LA_ENA_1),
633 .LA_ENA_2(LA_ENA_2),
634 .LA_ENA_3(LA_ENA_3)
635 ) la (
636 .wb_clk_i(wb_clk_i),
637 .wb_rst_i(wb_rst_i),
638
639 .wb_adr_i(cpu_adr_o),
640 .wb_dat_i(cpu_dat_o),
641 .wb_sel_i(cpu_sel_o),
642 .wb_we_i(cpu_we_o),
643 .wb_cyc_i(cpu_cyc_o),
644
645 .wb_stb_i(la_stb_i),
646 .wb_ack_o(la_ack_o),
647 .wb_dat_o(la_dat_o),
648
649 .la_data(la_output),
shalan0d14e6e2020-08-31 16:50:48 +0200650 .la_data_in(la_input),
651 .la_oen(la_oen)
shalanfd13eb52020-08-21 16:48:07 +0200652 );
653
Tim Edwards6d9739d2020-10-19 11:00:49 -0400654 // WB Slave User Project Control
shalan0d14e6e2020-08-31 16:50:48 +0200655 wire mprj_ctrl_stb_i;
656 wire mprj_ctrl_ack_o;
657 wire [31:0] mprj_ctrl_dat_o;
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200658 wire [`MPRJ_IO_PADS-1:0] mgmt_out_pre;
Tim Edwardsca2f3182020-10-06 10:05:11 -0400659
660 // Bits assigned to specific functions as outputs prevent the
661 // mprj GPIO-as-output from applying data when that function
662 // is active
663
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200664 assign mgmt_out_data[`MPRJ_IO_PADS-1:16] = mgmt_out_pre[`MPRJ_IO_PADS-1:16];
Tim Edwards32d05422020-10-19 19:43:52 -0400665
666 // Routing of output monitors (PLL, trap, clk1, clk2)
667 assign mgmt_out_data[15] = clk2_output_dest ? user_clk : mgmt_out_pre[15];
668 assign mgmt_out_data[14] = clk1_output_dest ? clk : mgmt_out_pre[14];
669 assign mgmt_out_data[13] = trap_output_dest ? trap : mgmt_out_pre[13];
670
671 assign mgmt_out_data[12:7] = mgmt_out_pre[12:7];
Tim Edwardsca2f3182020-10-06 10:05:11 -0400672 assign mgmt_out_data[6] = uart_enabled ? ser_tx : mgmt_out_pre[6];
673 assign mgmt_out_data[5:0] = mgmt_out_pre[5:0];
shalan0d14e6e2020-08-31 16:50:48 +0200674
675 mprj_ctrl_wb #(
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200676 .BASE_ADR(MPRJ_CTRL_ADR)
shalan0d14e6e2020-08-31 16:50:48 +0200677 ) mprj_ctrl (
678 .wb_clk_i(wb_clk_i),
679 .wb_rst_i(wb_rst_i),
680
681 .wb_adr_i(cpu_adr_o),
682 .wb_dat_i(cpu_dat_o),
683 .wb_sel_i(cpu_sel_o),
684 .wb_we_i(cpu_we_o),
685 .wb_cyc_i(cpu_cyc_o),
686 .wb_stb_i(mprj_ctrl_stb_i),
687 .wb_ack_o(mprj_ctrl_ack_o),
688 .wb_dat_o(mprj_ctrl_dat_o),
689
Tim Edwards04ba17f2020-10-02 22:27:50 -0400690 .serial_clock(mprj_io_loader_clock),
691 .serial_resetn(mprj_io_loader_resetn),
692 .serial_data_out(mprj_io_loader_data),
Tim Edwards496a08a2020-10-26 15:44:51 -0400693 .sdo_oenb_state(sdo_oenb_state),
694 .jtag_oenb_state(jtag_oenb_state),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400695 .mgmt_gpio_out(mgmt_out_pre),
Tim Edwardsba328902020-10-27 15:03:22 -0400696 .mgmt_gpio_in(mgmt_in_data),
697 .pwr_ctrl_out(pwr_ctrl_out)
shalan0d14e6e2020-08-31 16:50:48 +0200698 );
699
shalanfd13eb52020-08-21 16:48:07 +0200700 // Wishbone Slave RAM
701 wire mem_stb_i;
702 wire mem_ack_o;
703 wire [31:0] mem_dat_o;
704
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200705 mem_wb soc_mem (
shalanfd13eb52020-08-21 16:48:07 +0200706 .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
715 .wb_stb_i(mem_stb_i),
716 .wb_ack_o(mem_ack_o),
717 .wb_dat_o(mem_dat_o)
718 );
719
Manar14d35ac2020-10-21 22:47:15 +0200720 // Wishbone Slave Synthesized RAM
721 wire mem_synth_stb_i;
722 wire mem_synth_ack_o;
723 wire [31:0] mem_synth_dat_o;
724
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200725 mem_synth_wb soc_mem_synth (
Manar14d35ac2020-10-21 22:47:15 +0200726 .wb_clk_i(wb_clk_i),
727 .wb_rst_i(wb_rst_i),
728 .wb_adr_i(cpu_adr_o),
729 .wb_dat_i(cpu_dat_o),
730 .wb_sel_i(cpu_sel_o),
731 .wb_we_i(cpu_we_o),
732 .wb_cyc_i(cpu_cyc_o),
733 .wb_stb_i(mem_synth_stb_i),
734 .wb_ack_o(mem_synth_ack_o),
735 .wb_dat_o(mem_synth_dat_o)
736 );
737
shalanfd13eb52020-08-21 16:48:07 +0200738 // Wishbone intercon logic
739 wb_intercon #(
740 .AW(ADR_WIDTH),
741 .DW(DAT_WIDTH),
742 .NS(NUM_SLAVES),
743 .ADR_MASK(ADR_MASK),
744 .SLAVE_ADR(SLAVE_ADR)
745 ) intercon (
746 // Master Interface
747 .wbm_adr_i(cpu_adr_o),
748 .wbm_stb_i(cpu_stb_o),
749 .wbm_dat_o(cpu_dat_i),
750 .wbm_ack_o(cpu_ack_i),
751
752 // Slaves Interface
Manar98a7adc2020-10-19 23:21:36 +0200753 .wbs_stb_o({ sys_stb_i, spimemio_cfg_stb_i,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400754 mprj_stb_o, mprj_ctrl_stb_i, la_stb_i,
755 spi_master_stb_i, counter_timer1_stb_i, counter_timer0_stb_i,
756 gpio_stb_i, uart_stb_i,
Manar14d35ac2020-10-21 22:47:15 +0200757 spimemio_flash_stb_i, mem_synth_stb_i, mem_stb_i }),
Manar98a7adc2020-10-19 23:21:36 +0200758 .wbs_dat_i({ sys_dat_o, spimemio_cfg_dat_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400759 mprj_dat_i, mprj_ctrl_dat_o, la_dat_o,
760 spi_master_dat_o, counter_timer1_dat_o, counter_timer0_dat_o,
761 gpio_dat_o, uart_dat_o,
Manar14d35ac2020-10-21 22:47:15 +0200762 spimemio_flash_dat_o,mem_synth_dat_o, mem_dat_o }),
Manar98a7adc2020-10-19 23:21:36 +0200763 .wbs_ack_i({ sys_ack_o, spimemio_cfg_ack_o,
Tim Edwards04ba17f2020-10-02 22:27:50 -0400764 mprj_ack_i, mprj_ctrl_ack_o, la_ack_o,
765 spi_master_ack_o, counter_timer1_ack_o, counter_timer0_ack_o,
766 gpio_ack_o, uart_ack_o,
Manar14d35ac2020-10-21 22:47:15 +0200767 spimemio_flash_ack_o, mem_synth_ack_o, mem_ack_o })
shalanfd13eb52020-08-21 16:48:07 +0200768 );
769
shalanfd13eb52020-08-21 16:48:07 +0200770endmodule
771
shalanfd13eb52020-08-21 16:48:07 +0200772// Implementation note:
773// Replace the following two modules with wrappers for your SRAM cells.
Tim Edwardsef8312e2020-09-22 17:20:06 -0400774
Tim Edwards04ba17f2020-10-02 22:27:50 -0400775module mgmt_soc_regs (
shalanfd13eb52020-08-21 16:48:07 +0200776 input clk, wen,
777 input [5:0] waddr,
778 input [5:0] raddr1,
779 input [5:0] raddr2,
780 input [31:0] wdata,
781 output [31:0] rdata1,
782 output [31:0] rdata2
783);
784 reg [31:0] regs [0:31];
785
786 always @(posedge clk)
787 if (wen) regs[waddr[4:0]] <= wdata;
788
789 assign rdata1 = regs[raddr1[4:0]];
790 assign rdata2 = regs[raddr2[4:0]];
791endmodule