blob: 4aba1fe77355c9edd9ba617532554c723aa4388f [file] [log] [blame]
Tim Edwardsef8312e2020-09-22 17:20:06 -04001/*--------------------------------------------------------------*/
2/* caravel, a project harness for the Google/SkyWater sky130 */
3/* fabrication process and open source PDK */
4/* */
5/* Copyright 2020 efabless, Inc. */
6/* Written by Tim Edwards, December 2019 */
7/* and Mohamed Shalan, August 2020 */
8/* This file is open source hardware released under the */
9/* Apache 2.0 license. See file LICENSE. */
10/* */
11/*--------------------------------------------------------------*/
12
13`timescale 1 ns / 1 ps
14
Tim Edwardse2ef6732020-10-12 17:25:12 -040015`define USE_POWER_PINS
Tim Edwardsc5265b82020-09-25 17:08:59 -040016`define UNIT_DELAY #1
Tim Edwardsef8312e2020-09-22 17:20:06 -040017
Ahmed Ghazy22d29d62020-10-28 03:42:02 +020018`include "defines.v"
Tim Edwardsef8312e2020-09-22 17:20:06 -040019`include "pads.v"
20
Tim Edwards4286ae12020-10-11 14:52:01 -040021/* NOTE: Need to pass the PDK root directory to iverilog with option -I */
Tim Edwardsef8312e2020-09-22 17:20:06 -040022
Tim Edwards4286ae12020-10-11 14:52:01 -040023`include "libs.ref/sky130_fd_io/verilog/sky130_fd_io.v"
Tim Edwards4c733352020-10-12 16:32:36 -040024`include "libs.ref/sky130_fd_io/verilog/sky130_ef_io.v"
Tim Edwards4286ae12020-10-11 14:52:01 -040025
26`include "libs.ref/sky130_fd_sc_hd/verilog/primitives.v"
27`include "libs.ref/sky130_fd_sc_hd/verilog/sky130_fd_sc_hd.v"
28`include "libs.ref/sky130_fd_sc_hvl/verilog/primitives.v"
29`include "libs.ref/sky130_fd_sc_hvl/verilog/sky130_fd_sc_hvl.v"
Tim Edwardsef8312e2020-09-22 17:20:06 -040030
31`include "mgmt_soc.v"
Tim Edwards44bab472020-10-04 22:09:54 -040032`include "housekeeping_spi.v"
Tim Edwardsef8312e2020-09-22 17:20:06 -040033`include "digital_pll.v"
Tim Edwards3245e2f2020-10-10 14:02:11 -040034`include "caravel_clocking.v"
Tim Edwardsef8312e2020-09-22 17:20:06 -040035`include "mgmt_core.v"
Tim Edwards53d92182020-10-11 21:47:40 -040036`include "mgmt_protect.v"
Tim Edwardsef8312e2020-09-22 17:20:06 -040037`include "mprj_io.v"
38`include "chip_io.v"
Tim Edwards04ba17f2020-10-02 22:27:50 -040039`include "user_id_programming.v"
Tim Edwardsb86fc842020-10-13 17:11:54 -040040`include "user_project_wrapper.v"
Tim Edwards04ba17f2020-10-02 22:27:50 -040041`include "gpio_control_block.v"
Tim Edwards3245e2f2020-10-10 14:02:11 -040042`include "clock_div.v"
Tim Edwardsf51dd082020-10-05 16:30:24 -040043`include "simple_por.v"
Tim Edwardsef8312e2020-09-22 17:20:06 -040044
Tim Edwards05537512020-10-06 14:59:26 -040045/*------------------------------*/
46/* Include user project here */
47/*------------------------------*/
48`include "user_proj_example.v"
49
Tim Edwardsef8312e2020-09-22 17:20:06 -040050`ifdef USE_OPENRAM
Manar14d35ac2020-10-21 22:47:15 +020051 `include "sram_1rw1r_32_256_8_sky130.v"
Tim Edwardsef8312e2020-09-22 17:20:06 -040052`endif
53
54module caravel (
Tim Edwards9eda80d2020-10-08 21:36:44 -040055 inout vddio, // Common 3.3V padframe/ESD power
56 inout vssio, // Common padframe/ESD ground
57 inout vdda, // Management 3.3V power
58 inout vssa, // Common analog ground
59 inout vccd, // Management/Common 1.8V power
60 inout vssd, // Common digital ground
61 inout vdda1, // User area 1 3.3V power
62 inout vdda2, // User area 2 3.3V power
63 inout vssa1, // User area 1 analog ground
64 inout vssa2, // User area 2 analog ground
65 inout vccd1, // User area 1 1.8V power
66 inout vccd2, // User area 2 1.8V power
67 inout vssd1, // User area 1 digital ground
68 inout vssd2, // User area 2 digital ground
69
Tim Edwards04ba17f2020-10-02 22:27:50 -040070 inout gpio, // Used for external LDO control
Tim Edwardsef8312e2020-09-22 17:20:06 -040071 inout [`MPRJ_IO_PADS-1:0] mprj_io,
Tim Edwardsba328902020-10-27 15:03:22 -040072 output [`MPRJ_PWR_PADS-1:0] pwr_ctrl_out,
Tim Edwardsef8312e2020-09-22 17:20:06 -040073 input clock, // CMOS core clock input, not a crystal
Tim Edwards04ba17f2020-10-02 22:27:50 -040074 input resetb,
75
76 // Note that only two pins are available on the flash so dual and
77 // quad flash modes are not available.
78
Tim Edwardsef8312e2020-09-22 17:20:06 -040079 output flash_csb,
80 output flash_clk,
81 output flash_io0,
Tim Edwards04ba17f2020-10-02 22:27:50 -040082 output flash_io1
Tim Edwardsef8312e2020-09-22 17:20:06 -040083);
84
Tim Edwards04ba17f2020-10-02 22:27:50 -040085 //------------------------------------------------------------
86 // This value is uniquely defined for each user project.
87 //------------------------------------------------------------
88 parameter USER_PROJECT_ID = 32'h0;
Tim Edwardsef8312e2020-09-22 17:20:06 -040089
Tim Edwards04ba17f2020-10-02 22:27:50 -040090 // These pins are overlaid on mprj_io space. They have the function
91 // below when the management processor is in reset, or in the default
92 // configuration. They are assigned to uses in the user space by the
93 // configuration program running off of the SPI flash. Note that even
94 // when the user has taken control of these pins, they can be restored
95 // to the original use by setting the resetb pin low. The SPI pins and
96 // UART pins can be connected directly to an FTDI chip as long as the
97 // FTDI chip sets these lines to high impedence (input function) at
98 // all times except when holding the chip in reset.
99
100 // JTAG = mprj_io[0] (inout)
101 // SDO = mprj_io[1] (output)
102 // SDI = mprj_io[2] (input)
103 // CSB = mprj_io[3] (input)
104 // SCK = mprj_io[4] (input)
105 // ser_rx = mprj_io[5] (input)
106 // ser_tx = mprj_io[6] (output)
107 // irq = mprj_io[7] (input)
108
109 // These pins are reserved for any project that wants to incorporate
110 // its own processor and flash controller. While a user project can
111 // technically use any available I/O pins for the purpose, these
112 // four pins connect to a pass-through mode from the SPI slave (pins
113 // 1-4 above) so that any SPI flash connected to these specific pins
114 // can be accessed through the SPI slave even when the processor is in
115 // reset.
116
Tim Edwards44bab472020-10-04 22:09:54 -0400117 // user_flash_csb = mprj_io[8]
118 // user_flash_sck = mprj_io[9]
119 // user_flash_io0 = mprj_io[10]
120 // user_flash_io1 = mprj_io[11]
Tim Edwards04ba17f2020-10-02 22:27:50 -0400121
122 // One-bit GPIO dedicated to management SoC (outside of user control)
123 wire gpio_out_core;
124 wire gpio_in_core;
125 wire gpio_mode0_core;
126 wire gpio_mode1_core;
127 wire gpio_outenb_core;
128 wire gpio_inenb_core;
129
Tim Edwards6d9739d2020-10-19 11:00:49 -0400130 // User Project Control (pad-facing)
Tim Edwards04ba17f2020-10-02 22:27:50 -0400131 wire mprj_io_loader_resetn;
132 wire mprj_io_loader_clock;
133 wire mprj_io_loader_data;
134
Tim Edwardsef8312e2020-09-22 17:20:06 -0400135 wire [`MPRJ_IO_PADS-1:0] mprj_io_hldh_n;
136 wire [`MPRJ_IO_PADS-1:0] mprj_io_enh;
137 wire [`MPRJ_IO_PADS-1:0] mprj_io_inp_dis;
Tim Edwards44bab472020-10-04 22:09:54 -0400138 wire [`MPRJ_IO_PADS-1:0] mprj_io_oeb;
Tim Edwardsef8312e2020-09-22 17:20:06 -0400139 wire [`MPRJ_IO_PADS-1:0] mprj_io_ib_mode_sel;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400140 wire [`MPRJ_IO_PADS-1:0] mprj_io_vtrip_sel;
141 wire [`MPRJ_IO_PADS-1:0] mprj_io_slow_sel;
142 wire [`MPRJ_IO_PADS-1:0] mprj_io_holdover;
Tim Edwardsef8312e2020-09-22 17:20:06 -0400143 wire [`MPRJ_IO_PADS-1:0] mprj_io_analog_en;
144 wire [`MPRJ_IO_PADS-1:0] mprj_io_analog_sel;
145 wire [`MPRJ_IO_PADS-1:0] mprj_io_analog_pol;
146 wire [`MPRJ_IO_PADS*3-1:0] mprj_io_dm;
147 wire [`MPRJ_IO_PADS-1:0] mprj_io_in;
148 wire [`MPRJ_IO_PADS-1:0] mprj_io_out;
149
Tim Edwards6d9739d2020-10-19 11:00:49 -0400150 // User Project Control (user-facing)
Tim Edwards44bab472020-10-04 22:09:54 -0400151 wire [`MPRJ_IO_PADS-1:0] user_io_oeb;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400152 wire [`MPRJ_IO_PADS-1:0] user_io_in;
153 wire [`MPRJ_IO_PADS-1:0] user_io_out;
154
155 /* Padframe control signals */
156 wire [`MPRJ_IO_PADS-1:0] gpio_serial_link;
157 wire mgmt_serial_clock;
158 wire mgmt_serial_resetn;
159
Tim Edwards6d9739d2020-10-19 11:00:49 -0400160 // User Project Control management I/O
Tim Edwards44bab472020-10-04 22:09:54 -0400161 // There are two types of GPIO connections:
162 // (1) Full Bidirectional: Management connects to in, out, and oeb
163 // Uses: JTAG and SDO
164 // (2) Selectable bidirectional: Management connects to in and out,
165 // which are tied together. oeb is grounded (oeb from the
166 // configuration is used)
167
168 // SDI = mprj_io[2] (input)
169 // CSB = mprj_io[3] (input)
170 // SCK = mprj_io[4] (input)
171 // ser_rx = mprj_io[5] (input)
172 // ser_tx = mprj_io[6] (output)
173 // irq = mprj_io[7] (input)
174
175 wire [`MPRJ_IO_PADS-1:0] mgmt_io_in;
176 wire jtag_out, sdo_out;
177 wire jtag_outenb, sdo_outenb;
178
179 wire [`MPRJ_IO_PADS-3:0] mgmt_io_nc1; /* no-connects */
180 wire [`MPRJ_IO_PADS-3:0] mgmt_io_nc3; /* no-connects */
181 wire [1:0] mgmt_io_nc2; /* no-connects */
182
Tim Edwards04ba17f2020-10-02 22:27:50 -0400183 // Power-on-reset signal. The reset pad generates the sense-inverted
184 // reset at 3.3V. The 1.8V signal and the inverted 1.8V signal are
185 // derived.
186
Tim Edwardsef8312e2020-09-22 17:20:06 -0400187 wire porb_h;
188 wire porb_l;
Tim Edwardsef8312e2020-09-22 17:20:06 -0400189
Tim Edwardsf51dd082020-10-05 16:30:24 -0400190 wire rstb_h;
191 wire rstb_l;
192
Tim Edwards44bab472020-10-04 22:09:54 -0400193 // To be considered: Master hold signal on all user pads (?)
194 // For now, set holdh_n to 1 (NOTE: This is in the 3.3V domain)
195 // and setting enh to porb_h.
Tim Edwards9eda80d2020-10-08 21:36:44 -0400196 assign mprj_io_hldh_n = {`MPRJ_IO_PADS{vddio}};
Tim Edwards44bab472020-10-04 22:09:54 -0400197 assign mprj_io_enh = {`MPRJ_IO_PADS{porb_h}};
198
Tim Edwardsef8312e2020-09-22 17:20:06 -0400199 chip_io padframe(
200 // Package Pins
Tim Edwards9eda80d2020-10-08 21:36:44 -0400201 .vddio(vddio),
202 .vssio(vssio),
203 .vdda(vdda),
204 .vssa(vssa),
205 .vccd(vccd),
206 .vssd(vssd),
207 .vdda1(vdda1),
208 .vdda2(vdda2),
209 .vssa1(vssa1),
210 .vssa2(vssa2),
211 .vccd1(vccd1),
212 .vccd2(vccd2),
213 .vssd1(vssd1),
214 .vssd2(vssd2),
215
Tim Edwardsef8312e2020-09-22 17:20:06 -0400216 .gpio(gpio),
217 .mprj_io(mprj_io),
218 .clock(clock),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400219 .resetb(resetb),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400220 .flash_csb(flash_csb),
221 .flash_clk(flash_clk),
222 .flash_io0(flash_io0),
223 .flash_io1(flash_io1),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400224 // SoC Core Interface
Tim Edwardsef8312e2020-09-22 17:20:06 -0400225 .porb_h(porb_h),
Tim Edwardsf51dd082020-10-05 16:30:24 -0400226 .resetb_core_h(rstb_h),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400227 .clock_core(clock_core),
228 .gpio_out_core(gpio_out_core),
229 .gpio_in_core(gpio_in_core),
230 .gpio_mode0_core(gpio_mode0_core),
231 .gpio_mode1_core(gpio_mode1_core),
232 .gpio_outenb_core(gpio_outenb_core),
233 .gpio_inenb_core(gpio_inenb_core),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400234 .flash_csb_core(flash_csb_core),
235 .flash_clk_core(flash_clk_core),
236 .flash_csb_oeb_core(flash_csb_oeb_core),
237 .flash_clk_oeb_core(flash_clk_oeb_core),
238 .flash_io0_oeb_core(flash_io0_oeb_core),
239 .flash_io1_oeb_core(flash_io1_oeb_core),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400240 .flash_csb_ieb_core(flash_csb_ieb_core),
241 .flash_clk_ieb_core(flash_clk_ieb_core),
242 .flash_io0_ieb_core(flash_io0_ieb_core),
243 .flash_io1_ieb_core(flash_io1_ieb_core),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400244 .flash_io0_do_core(flash_io0_do_core),
245 .flash_io1_do_core(flash_io1_do_core),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400246 .flash_io0_di_core(flash_io0_di_core),
247 .flash_io1_di_core(flash_io1_di_core),
Tim Edwards44bab472020-10-04 22:09:54 -0400248 .por(~porb_l),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400249 .mprj_io_in(mprj_io_in),
250 .mprj_io_out(mprj_io_out),
Tim Edwards44bab472020-10-04 22:09:54 -0400251 .mprj_io_oeb(mprj_io_oeb),
Manar14d35ac2020-10-21 22:47:15 +0200252 .mprj_io_hldh_n(mprj_io_hldh_n),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400253 .mprj_io_enh(mprj_io_enh),
Manar14d35ac2020-10-21 22:47:15 +0200254 .mprj_io_inp_dis(mprj_io_inp_dis),
255 .mprj_io_ib_mode_sel(mprj_io_ib_mode_sel),
256 .mprj_io_vtrip_sel(mprj_io_vtrip_sel),
257 .mprj_io_slow_sel(mprj_io_slow_sel),
258 .mprj_io_holdover(mprj_io_holdover),
259 .mprj_io_analog_en(mprj_io_analog_en),
260 .mprj_io_analog_sel(mprj_io_analog_sel),
261 .mprj_io_analog_pol(mprj_io_analog_pol),
262 .mprj_io_dm(mprj_io_dm)
Tim Edwardsef8312e2020-09-22 17:20:06 -0400263 );
264
265 // SoC core
Tim Edwards04ba17f2020-10-02 22:27:50 -0400266 wire caravel_clk;
Tim Edwards7a8cbb12020-10-12 11:32:11 -0400267 wire caravel_clk2;
Tim Edwards04ba17f2020-10-02 22:27:50 -0400268 wire caravel_rstn;
Tim Edwardsef8312e2020-09-22 17:20:06 -0400269
270 wire [7:0] spi_ro_config_core;
271
272 // LA signals
273 wire [127:0] la_output_core; // From CPU to MPRJ
274 wire [127:0] la_data_in_mprj; // From CPU to MPRJ
275 wire [127:0] la_data_out_mprj; // From CPU to MPRJ
276 wire [127:0] la_output_mprj; // From MPRJ to CPU
277 wire [127:0] la_oen; // LA output enable from CPU perspective (active-low)
278
Tim Edwards6d9739d2020-10-19 11:00:49 -0400279 // WB MI A (User Project)
Tim Edwardsef8312e2020-09-22 17:20:06 -0400280 wire mprj_cyc_o_core;
281 wire mprj_stb_o_core;
282 wire mprj_we_o_core;
283 wire [3:0] mprj_sel_o_core;
284 wire [31:0] mprj_adr_o_core;
285 wire [31:0] mprj_dat_o_core;
286 wire mprj_ack_i_core;
287 wire [31:0] mprj_dat_i_core;
288
289 // WB MI B (xbar)
290 wire xbar_cyc_o_core;
291 wire xbar_stb_o_core;
292 wire xbar_we_o_core;
293 wire [3:0] xbar_sel_o_core;
294 wire [31:0] xbar_adr_o_core;
295 wire [31:0] xbar_dat_o_core;
296 wire xbar_ack_i_core;
297 wire [31:0] xbar_dat_i_core;
298
Tim Edwards04ba17f2020-10-02 22:27:50 -0400299 // Mask revision
300 wire [31:0] mask_rev;
301
Manar14d35ac2020-10-21 22:47:15 +0200302 wire mprj_clock;
303 wire mprj_clock2;
304 wire mprj_resetn;
305 wire mprj_cyc_o_user;
306 wire mprj_stb_o_user;
307 wire mprj_we_o_user;
308 wire [3:0] mprj_sel_o_user;
309 wire [31:0] mprj_adr_o_user;
310 wire [31:0] mprj_dat_o_user;
311 wire mprj_vcc_pwrgood;
312 wire mprj2_vcc_pwrgood;
313 wire mprj_vdd_pwrgood;
314 wire mprj2_vdd_pwrgood;
315
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200316 mgmt_core soc (
Tim Edwardsef8312e2020-09-22 17:20:06 -0400317 `ifdef LVS
Tim Edwards9eda80d2020-10-08 21:36:44 -0400318 .vdd(vccd),
319 .vss(vssa),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400320 `endif
Tim Edwards04ba17f2020-10-02 22:27:50 -0400321 // GPIO (1 pin)
Tim Edwardsef8312e2020-09-22 17:20:06 -0400322 .gpio_out_pad(gpio_out_core),
323 .gpio_in_pad(gpio_in_core),
324 .gpio_mode0_pad(gpio_mode0_core),
325 .gpio_mode1_pad(gpio_mode1_core),
326 .gpio_outenb_pad(gpio_outenb_core),
327 .gpio_inenb_pad(gpio_inenb_core),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400328 // Primary SPI flash controller
Tim Edwardsef8312e2020-09-22 17:20:06 -0400329 .flash_csb(flash_csb_core),
330 .flash_clk(flash_clk_core),
331 .flash_csb_oeb(flash_csb_oeb_core),
332 .flash_clk_oeb(flash_clk_oeb_core),
333 .flash_io0_oeb(flash_io0_oeb_core),
334 .flash_io1_oeb(flash_io1_oeb_core),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400335 .flash_csb_ieb(flash_csb_ieb_core),
336 .flash_clk_ieb(flash_clk_ieb_core),
337 .flash_io0_ieb(flash_io0_ieb_core),
338 .flash_io1_ieb(flash_io1_ieb_core),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400339 .flash_io0_do(flash_io0_do_core),
340 .flash_io1_do(flash_io1_do_core),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400341 .flash_io0_di(flash_io0_di_core),
342 .flash_io1_di(flash_io1_di_core),
Tim Edwardsf51dd082020-10-05 16:30:24 -0400343 // Master Reset
344 .resetb(rstb_l),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400345 .porb(porb_l),
346 // Clocks and reset
Tim Edwardsef8312e2020-09-22 17:20:06 -0400347 .clock(clock_core),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400348 .core_clk(caravel_clk),
Tim Edwards7a8cbb12020-10-12 11:32:11 -0400349 .user_clk(caravel_clk2),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400350 .core_rstn(caravel_rstn),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400351 // Logic Analyzer
352 .la_input(la_data_out_mprj),
353 .la_output(la_output_core),
354 .la_oen(la_oen),
Tim Edwards6d9739d2020-10-19 11:00:49 -0400355 // User Project IO Control
Tim Edwards05ad4fc2020-10-19 22:12:33 -0400356 .mprj_vcc_pwrgood(mprj_vcc_pwrgood),
357 .mprj2_vcc_pwrgood(mprj2_vcc_pwrgood),
358 .mprj_vdd_pwrgood(mprj_vdd_pwrgood),
359 .mprj2_vdd_pwrgood(mprj2_vdd_pwrgood),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400360 .mprj_io_loader_resetn(mprj_io_loader_resetn),
361 .mprj_io_loader_clock(mprj_io_loader_clock),
362 .mprj_io_loader_data(mprj_io_loader_data),
Tim Edwards44bab472020-10-04 22:09:54 -0400363 .mgmt_in_data(mgmt_io_in),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400364 .mgmt_out_data({mgmt_io_in[(`MPRJ_IO_PADS-1):2], mgmt_io_nc2}),
Tim Edwardsba328902020-10-27 15:03:22 -0400365 .pwr_ctrl_out(pwr_ctrl_out),
Tim Edwardsca2f3182020-10-06 10:05:11 -0400366 .sdo_out(sdo_out),
367 .sdo_outenb(sdo_outenb),
368 .jtag_out(jtag_out),
369 .jtag_outenb(jtag_outenb),
Tim Edwards6d9739d2020-10-19 11:00:49 -0400370 // User Project Slave ports (WB MI A)
Tim Edwardsef8312e2020-09-22 17:20:06 -0400371 .mprj_cyc_o(mprj_cyc_o_core),
372 .mprj_stb_o(mprj_stb_o_core),
373 .mprj_we_o(mprj_we_o_core),
374 .mprj_sel_o(mprj_sel_o_core),
375 .mprj_adr_o(mprj_adr_o_core),
376 .mprj_dat_o(mprj_dat_o_core),
377 .mprj_ack_i(mprj_ack_i_core),
378 .mprj_dat_i(mprj_dat_i_core),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400379 // mask data
380 .mask_rev(mask_rev)
Tim Edwardsef8312e2020-09-22 17:20:06 -0400381 );
382
Tim Edwards53d92182020-10-11 21:47:40 -0400383 /* Clock and reset to user space are passed through a tristate */
384 /* buffer like the above, but since they are intended to be */
385 /* always active, connect the enable to the logic-1 output from */
386 /* the vccd1 domain. */
387
Tim Edwards53d92182020-10-11 21:47:40 -0400388 mgmt_protect mgmt_buffers (
Tim Edwards53d92182020-10-11 21:47:40 -0400389 .vccd(vccd),
390 .vssd(vssd),
391 .vccd1(vccd1),
392 .vssd1(vssd1),
Tim Edwards05ad4fc2020-10-19 22:12:33 -0400393 .vdda1(vdda1),
394 .vssa1(vssa1),
395 .vdda2(vdda2),
396 .vssa2(vssa2),
Tim Edwards21a9aac2020-10-12 22:05:18 -0400397
Tim Edwards53d92182020-10-11 21:47:40 -0400398 .caravel_clk(caravel_clk),
Tim Edwards7a8cbb12020-10-12 11:32:11 -0400399 .caravel_clk2(caravel_clk2),
Tim Edwards53d92182020-10-11 21:47:40 -0400400 .caravel_rstn(caravel_rstn),
401 .mprj_cyc_o_core(mprj_cyc_o_core),
402 .mprj_stb_o_core(mprj_stb_o_core),
403 .mprj_we_o_core(mprj_we_o_core),
404 .mprj_sel_o_core(mprj_sel_o_core),
405 .mprj_adr_o_core(mprj_adr_o_core),
406 .mprj_dat_o_core(mprj_dat_o_core),
407 .la_output_core(la_output_core),
408 .la_oen(la_oen),
409
410 .user_clock(mprj_clock),
Tim Edwards7a8cbb12020-10-12 11:32:11 -0400411 .user_clock2(mprj_clock2),
Tim Edwards53d92182020-10-11 21:47:40 -0400412 .user_resetn(mprj_resetn),
413 .mprj_cyc_o_user(mprj_cyc_o_user),
414 .mprj_stb_o_user(mprj_stb_o_user),
415 .mprj_we_o_user(mprj_we_o_user),
416 .mprj_sel_o_user(mprj_sel_o_user),
417 .mprj_adr_o_user(mprj_adr_o_user),
418 .mprj_dat_o_user(mprj_dat_o_user),
Tim Edwards32d05422020-10-19 19:43:52 -0400419 .la_data_in_mprj(la_data_in_mprj),
Tim Edwards05ad4fc2020-10-19 22:12:33 -0400420 .user1_vcc_powergood(mprj_vcc_pwrgood),
421 .user2_vcc_powergood(mprj2_vcc_pwrgood),
422 .user1_vdd_powergood(mprj_vdd_pwrgood),
423 .user2_vdd_powergood(mprj2_vdd_pwrgood)
Tim Edwardsef8312e2020-09-22 17:20:06 -0400424 );
Tim Edwards53d92182020-10-11 21:47:40 -0400425
Tim Edwardsef8312e2020-09-22 17:20:06 -0400426
Tim Edwardsb86fc842020-10-13 17:11:54 -0400427 /*----------------------------------------------*/
428 /* Wrapper module around the user project */
429 /*----------------------------------------------*/
Tim Edwards05537512020-10-06 14:59:26 -0400430
Ahmed Ghazy22d29d62020-10-28 03:42:02 +0200431 user_project_wrapper mprj (
Tim Edwards21a9aac2020-10-12 22:05:18 -0400432 .vdda1(vdda1), // User area 1 3.3V power
433 .vdda2(vdda2), // User area 2 3.3V power
434 .vssa1(vssa1), // User area 1 analog ground
435 .vssa2(vssa2), // User area 2 analog ground
436 .vccd1(vccd1), // User area 1 1.8V power
437 .vccd2(vccd2), // User area 2 1.8V power
438 .vssd1(vssd1), // User area 1 digital ground
439 .vssd2(vssd2), // User area 2 digital ground
440
Tim Edwards53d92182020-10-11 21:47:40 -0400441 .wb_clk_i(mprj_clock),
442 .wb_rst_i(!mprj_resetn),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400443 // MGMT SoC Wishbone Slave
Tim Edwards53d92182020-10-11 21:47:40 -0400444 .wbs_cyc_i(mprj_cyc_o_user),
445 .wbs_stb_i(mprj_stb_o_user),
446 .wbs_we_i(mprj_we_o_user),
447 .wbs_sel_i(mprj_sel_o_user),
448 .wbs_adr_i(mprj_adr_o_user),
449 .wbs_dat_i(mprj_dat_o_user),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400450 .wbs_ack_o(mprj_ack_i_core),
451 .wbs_dat_o(mprj_dat_i_core),
452 // Logic Analyzer
453 .la_data_in(la_data_in_mprj),
454 .la_data_out(la_data_out_mprj),
455 .la_oen (la_oen),
456 // IO Pads
Tim Edwards05537512020-10-06 14:59:26 -0400457 .io_in (user_io_in),
Tim Edwardsef2b68d2020-10-11 17:00:44 -0400458 .io_out(user_io_out),
Tim Edwardsb86fc842020-10-13 17:11:54 -0400459 .io_oeb(user_io_oeb),
460 // Independent clock
461 .user_clock2(mprj_clock2)
Tim Edwardsef8312e2020-09-22 17:20:06 -0400462 );
463
Tim Edwards05537512020-10-06 14:59:26 -0400464 /*--------------------------------------*/
465 /* End user project instantiation */
466 /*--------------------------------------*/
467
Tim Edwards04ba17f2020-10-02 22:27:50 -0400468 wire [`MPRJ_IO_PADS-1:0] gpio_serial_link_shifted;
469
Tim Edwards251e0df2020-10-05 11:02:12 -0400470 assign gpio_serial_link_shifted = {gpio_serial_link[`MPRJ_IO_PADS-2:0], mprj_io_loader_data};
Tim Edwards04ba17f2020-10-02 22:27:50 -0400471
Tim Edwards251e0df2020-10-05 11:02:12 -0400472 // Each control block sits next to an I/O pad in the user area.
473 // It gets input through a serial chain from the previous control
474 // block and passes it to the next control block. Due to the nature
475 // of the shift register, bits are presented in reverse, as the first
476 // bit in ends up as the last bit of the last I/O pad control block.
Tim Edwards44bab472020-10-04 22:09:54 -0400477
Tim Edwards89f09242020-10-05 15:17:34 -0400478 // There are two types of block; the first two are configured to be
479 // full bidirectional under control of the management Soc (JTAG and
480 // SDO). The rest are configured to be default (input).
481
Tim Edwards251e0df2020-10-05 11:02:12 -0400482 gpio_control_block #(
Tim Edwards89f09242020-10-05 15:17:34 -0400483 .DM_INIT(3'b110), // Mode = output, strong up/down
Tim Edwards496a08a2020-10-26 15:44:51 -0400484 .OENB_INIT(1'b1) // Enable output signaling from wire
Tim Edwards89f09242020-10-05 15:17:34 -0400485 ) gpio_control_bidir [1:0] (
Tim Edwards53d92182020-10-11 21:47:40 -0400486 `ifdef LVS
487 inout vccd,
488 inout vssd,
489 inout vccd1,
490 inout vssd1,
491 `endif
Tim Edwards44bab472020-10-04 22:09:54 -0400492
Tim Edwards04ba17f2020-10-02 22:27:50 -0400493 // Management Soc-facing signals
494
Tim Edwardsc18c4742020-10-03 11:26:39 -0400495 .resetn(mprj_io_loader_resetn),
496 .serial_clock(mprj_io_loader_clock),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400497
Tim Edwards89f09242020-10-05 15:17:34 -0400498 .mgmt_gpio_in(mgmt_io_in[1:0]),
499 .mgmt_gpio_out({sdo_out, jtag_out}),
500 .mgmt_gpio_oeb({sdo_outenb, jtag_outenb}),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400501
502 // Serial data chain for pad configuration
Tim Edwards89f09242020-10-05 15:17:34 -0400503 .serial_data_in(gpio_serial_link_shifted[1:0]),
504 .serial_data_out(gpio_serial_link[1:0]),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400505
506 // User-facing signals
Tim Edwards89f09242020-10-05 15:17:34 -0400507 .user_gpio_out(user_io_out[1:0]),
508 .user_gpio_oeb(user_io_oeb[1:0]),
509 .user_gpio_in(user_io_in[1:0]),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400510
511 // Pad-facing signals (Pad GPIOv2)
Tim Edwards89f09242020-10-05 15:17:34 -0400512 .pad_gpio_inenb(mprj_io_inp_dis[1:0]),
513 .pad_gpio_ib_mode_sel(mprj_io_ib_mode_sel[1:0]),
514 .pad_gpio_vtrip_sel(mprj_io_vtrip_sel[1:0]),
515 .pad_gpio_slow_sel(mprj_io_slow_sel[1:0]),
516 .pad_gpio_holdover(mprj_io_holdover[1:0]),
517 .pad_gpio_ana_en(mprj_io_analog_en[1:0]),
518 .pad_gpio_ana_sel(mprj_io_analog_sel[1:0]),
519 .pad_gpio_ana_pol(mprj_io_analog_pol[1:0]),
520 .pad_gpio_dm(mprj_io_dm[5:0]),
521 .pad_gpio_outenb(mprj_io_oeb[1:0]),
522 .pad_gpio_out(mprj_io_out[1:0]),
523 .pad_gpio_in(mprj_io_in[1:0])
524 );
525
526 gpio_control_block gpio_control_in [`MPRJ_IO_PADS-1:2] (
Tim Edwards53d92182020-10-11 21:47:40 -0400527 `ifdef LVS
528 inout vccd,
529 inout vssd,
530 inout vccd1,
531 inout vssd1,
532 `endif
Tim Edwards89f09242020-10-05 15:17:34 -0400533
534 // Management Soc-facing signals
535
536 .resetn(mprj_io_loader_resetn),
537 .serial_clock(mprj_io_loader_clock),
538
539 .mgmt_gpio_in(mgmt_io_in[(`MPRJ_IO_PADS-1):2]),
540 .mgmt_gpio_out(mgmt_io_in[(`MPRJ_IO_PADS-1):2]),
541 .mgmt_gpio_oeb(1'b1),
542
543 // Serial data chain for pad configuration
544 .serial_data_in(gpio_serial_link_shifted[(`MPRJ_IO_PADS-1):2]),
545 .serial_data_out(gpio_serial_link[(`MPRJ_IO_PADS-1):2]),
546
547 // User-facing signals
548 .user_gpio_out(user_io_out[(`MPRJ_IO_PADS-1):2]),
549 .user_gpio_oeb(user_io_oeb[(`MPRJ_IO_PADS-1):2]),
550 .user_gpio_in(user_io_in[(`MPRJ_IO_PADS-1):2]),
551
552 // Pad-facing signals (Pad GPIOv2)
553 .pad_gpio_inenb(mprj_io_inp_dis[(`MPRJ_IO_PADS-1):2]),
554 .pad_gpio_ib_mode_sel(mprj_io_ib_mode_sel[(`MPRJ_IO_PADS-1):2]),
555 .pad_gpio_vtrip_sel(mprj_io_vtrip_sel[(`MPRJ_IO_PADS-1):2]),
556 .pad_gpio_slow_sel(mprj_io_slow_sel[(`MPRJ_IO_PADS-1):2]),
557 .pad_gpio_holdover(mprj_io_holdover[(`MPRJ_IO_PADS-1):2]),
558 .pad_gpio_ana_en(mprj_io_analog_en[(`MPRJ_IO_PADS-1):2]),
559 .pad_gpio_ana_sel(mprj_io_analog_sel[(`MPRJ_IO_PADS-1):2]),
560 .pad_gpio_ana_pol(mprj_io_analog_pol[(`MPRJ_IO_PADS-1):2]),
561 .pad_gpio_dm(mprj_io_dm[(`MPRJ_IO_PADS*3-1):6]),
562 .pad_gpio_outenb(mprj_io_oeb[(`MPRJ_IO_PADS-1):2]),
563 .pad_gpio_out(mprj_io_out[(`MPRJ_IO_PADS-1):2]),
564 .pad_gpio_in(mprj_io_in[(`MPRJ_IO_PADS-1):2])
Tim Edwards04ba17f2020-10-02 22:27:50 -0400565 );
566
Tim Edwardsf51dd082020-10-05 16:30:24 -0400567 sky130_fd_sc_hvl__lsbufhv2lv porb_level (
Tim Edwards21a9aac2020-10-12 22:05:18 -0400568 .VPWR(vddio),
569 .VPB(vddio),
570 .LVPWR(vccd),
571 .VNB(vssio),
572 .VGND(vssio),
Tim Edwardsef8312e2020-09-22 17:20:06 -0400573 .A(porb_h),
574 .X(porb_l)
575 );
576
Tim Edwards04ba17f2020-10-02 22:27:50 -0400577 user_id_programming #(
578 .USER_PROJECT_ID(USER_PROJECT_ID)
579 ) user_id_value (
Tim Edwards21a9aac2020-10-12 22:05:18 -0400580 .vdd1v8(vccd),
581 .vss(vssd),
Tim Edwards04ba17f2020-10-02 22:27:50 -0400582 .mask_rev(mask_rev)
583 );
584
Tim Edwardsf51dd082020-10-05 16:30:24 -0400585 // Power-on-reset circuit
586 simple_por por (
Tim Edwards9eda80d2020-10-08 21:36:44 -0400587 .vdd3v3(vddio),
588 .vss(vssio),
Tim Edwardsf51dd082020-10-05 16:30:24 -0400589 .porb_h(porb_h)
590 );
591
592 // XRES (chip input pin reset) reset level converter
593 sky130_fd_sc_hvl__lsbufhv2lv rstb_level (
Tim Edwards21a9aac2020-10-12 22:05:18 -0400594 .VPWR(vddio),
595 .VPB(vddio),
596 .LVPWR(vccd),
597 .VNB(vssio),
598 .VGND(vssio),
Tim Edwardsf51dd082020-10-05 16:30:24 -0400599 .A(rstb_h),
600 .X(rstb_l)
601 );
602
Tim Edwardsef8312e2020-09-22 17:20:06 -0400603endmodule