blob: 31530a603a498474e5c86c0eefb8cadff633a41a [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001// Copyright lowRISC contributors.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
Michael Schaffner7b0807d2020-10-27 19:54:52 -07004${gencmd}
Eunchan Kim436d2242019-10-29 17:25:51 -07005<%
6import re
7import topgen.lib as lib
8
Michael Schaffner57c490d2020-04-29 15:08:55 -07009num_mio_inputs = sum([x["width"] for x in top["pinmux"]["inputs"]])
10num_mio_outputs = sum([x["width"] for x in top["pinmux"]["outputs"]])
Michael Schaffner57c490d2020-04-29 15:08:55 -070011num_mio = top["pinmux"]["num_mio"]
Eunchan Kim436d2242019-10-29 17:25:51 -070012
Michael Schaffner57c490d2020-04-29 15:08:55 -070013num_dio_inputs = sum([x["width"] if x["type"] == "input" else 0 for x in top["pinmux"]["dio"]])
14num_dio_outputs = sum([x["width"] if x["type"] == "output" else 0 for x in top["pinmux"]["dio"]])
15num_dio_inouts = sum([x["width"] if x["type"] == "inout" else 0 for x in top["pinmux"]["dio"]])
Eunchan Kim436d2242019-10-29 17:25:51 -070016num_dio = sum([x["width"] if "width" in x else 1 for x in top["pinmux"]["dio"]])
17
Eunchan Kim1d5bbcc2020-04-27 20:51:38 -070018num_im = sum([x["width"] if "width" in x else 1 for x in top["inter_signal"]["external"]])
19
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -080020max_miolength = max([len(x["name"]) for x in top["pinmux"]["inputs"] + top["pinmux"]["outputs"]])
Eunchan Kim436d2242019-10-29 17:25:51 -070021max_diolength = max([len(x["name"]) for x in top["pinmux"]["dio"]])
22
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -080023max_sigwidth = max([x["width"] if "width" in x else 1 for x in top["pinmux"]["inputs"] + top["pinmux"]["outputs"]])
Eunchan Kim436d2242019-10-29 17:25:51 -070024max_sigwidth = len("{}".format(max_sigwidth))
25
Timothy Chen0550d692020-04-20 17:19:35 -070026clks_attr = top['clocks']
Timothy Chenf56c1b52020-04-28 17:00:43 -070027cpu_clk = top['clocks']['hier_paths']['top'] + "clk_proc_main"
28cpu_rst = top["reset_paths"]["sys"]
29dm_rst = top["reset_paths"]["lc"]
Michael Schaffnerbe5cb9c2020-11-19 19:53:47 -080030esc_clk = top['clocks']['hier_paths']['top'] + "clk_io_div4_timers"
31esc_rst = top["reset_paths"]["sys_io_div4"]
Timothy Chen7f8cc8e2020-11-11 13:15:57 -080032
33unused_resets = lib.get_unused_resets(top)
Timothy Chen90b82422021-02-03 23:45:21 -080034unused_im_defs, undriven_im_defs = lib.get_dangling_im_def(top["inter_signal"]["definitions"])
35
lowRISC Contributors802543a2019-08-31 12:12:56 +010036%>\
Eunchan Kim632c6f72019-09-30 11:11:51 -070037module top_${top["name"]} #(
Pirmin Vogel15e1b912020-09-16 14:43:22 +020038 // Auto-inferred parameters
39% for m in top["module"]:
Timothy Chen94432212021-03-01 22:29:18 -080040 % if not lib.is_inst(m):
41<% continue %>
42 % endif
Rupert Swarbrick611a6422021-02-12 11:56:48 +000043 % for p_exp in filter(lambda p: p.get("expose") == "true", m["param_list"]):
Pirmin Vogelc32adb32020-09-21 14:13:27 +020044 parameter ${p_exp["type"]} ${p_exp["name_top"]} = ${p_exp["default"]},
Pirmin Vogel15e1b912020-09-16 14:43:22 +020045 % endfor
46% endfor
47
48 // Manually defined parameters
Pirmin Vogel4eb25022020-08-27 15:27:33 +020049 parameter ibex_pkg::regfile_e IbexRegFile = ibex_pkg::RegFileFF,
Tom Roberts7824ccc2020-11-05 11:34:03 +000050 parameter bit IbexICache = 1,
Philipp Wagnera37bcfa2020-05-19 22:46:41 +010051 parameter bit IbexPipeLine = 0,
52 parameter BootRomInitFile = ""
Timothy Chen7ff53122019-09-19 15:20:43 -070053) (
Timothy Chen79972ad2020-06-30 17:13:49 -070054 // Reset, clocks defined as part of intermodule
lowRISC Contributors802543a2019-08-31 12:12:56 +010055 input rst_ni,
56
57 // JTAG interface
58 input jtag_tck_i,
59 input jtag_tms_i,
60 input jtag_trst_ni,
Michael Schaffner60157962020-05-01 19:11:28 -070061 input jtag_tdi_i,
62 output jtag_tdo_o,
lowRISC Contributors802543a2019-08-31 12:12:56 +010063
Michael Schaffner57c490d2020-04-29 15:08:55 -070064% if num_mio != 0:
Eunchan Kim436d2242019-10-29 17:25:51 -070065 // Multiplexed I/O
Michael Schaffner57c490d2020-04-29 15:08:55 -070066 input ${lib.bitarray(num_mio, max_sigwidth)} mio_in_i,
67 output logic ${lib.bitarray(num_mio, max_sigwidth)} mio_out_o,
68 output logic ${lib.bitarray(num_mio, max_sigwidth)} mio_oe_o,
Eunchan Kim436d2242019-10-29 17:25:51 -070069% endif
70% if num_dio != 0:
Eunchan Kim436d2242019-10-29 17:25:51 -070071 // Dedicated I/O
Michael Schaffner57c490d2020-04-29 15:08:55 -070072 input ${lib.bitarray(num_dio, max_sigwidth)} dio_in_i,
73 output logic ${lib.bitarray(num_dio, max_sigwidth)} dio_out_o,
74 output logic ${lib.bitarray(num_dio, max_sigwidth)} dio_oe_o,
Eunchan Kim436d2242019-10-29 17:25:51 -070075% endif
Michael Schaffner60157962020-05-01 19:11:28 -070076
Michael Schaffner43ce8d52021-02-10 17:04:57 -080077% if "pinmux" in top:
Michael Schaffner60157962020-05-01 19:11:28 -070078 // pad attributes to padring
Michael Schaffner43ce8d52021-02-10 17:04:57 -080079 output logic[pinmux_reg_pkg::NMioPads-1:0]
80 [pinmux_reg_pkg::AttrDw-1:0] mio_attr_o,
81 output logic[pinmux_reg_pkg::NDioPads-1:0]
82 [pinmux_reg_pkg::AttrDw-1:0] dio_attr_o,
Michael Schaffner60157962020-05-01 19:11:28 -070083% endif
84
Eunchan Kim1d5bbcc2020-04-27 20:51:38 -070085% if num_im != 0:
86
87 // Inter-module Signal External type
88 % for sig in top["inter_signal"]["external"]:
89 ${"input " if sig["direction"] == "in" else "output"} ${lib.im_defname(sig)} ${lib.bitarray(sig["width"],1)} ${sig["signame"]},
90 % endfor
91% endif
Timothy Chen5649c2a2021-02-08 18:32:22 -080092 input scan_rst_ni, // reset used for test mode
93 input scan_en_i,
Michael Schaffner8bf4fe62021-02-18 12:56:08 -080094 input lc_ctrl_pkg::lc_tx_t scanmode_i // lc_ctrl_pkg::On for Scan
lowRISC Contributors802543a2019-08-31 12:12:56 +010095);
96
Philipp Wagner086b7032019-10-25 17:06:15 +010097 // JTAG IDCODE for development versions of this code.
98 // Manufacturers of OpenTitan chips must replace this code with one of their
99 // own IDs.
100 // Field structure as defined in the IEEE 1149.1 (JTAG) specification,
101 // section 12.1.1.
Michael Schaffnerd4d5d2f2020-04-17 15:45:55 -0700102 localparam logic [31:0] JTAG_IDCODE = {
Philipp Wagner086b7032019-10-25 17:06:15 +0100103 4'h0, // Version
104 16'h4F54, // Part Number: "OT"
Philipp Wagnerf57964e2019-11-04 17:57:06 +0000105 11'h426, // Manufacturer Identity: Google
Philipp Wagner086b7032019-10-25 17:06:15 +0100106 1'b1 // (fixed)
107 };
108
lowRISC Contributors802543a2019-08-31 12:12:56 +0100109 import tlul_pkg::*;
110 import top_pkg::*;
111 import tl_main_pkg::*;
Michael Schaffner7b0807d2020-10-27 19:54:52 -0700112 // Compile-time random constants
Pirmin Vogel9e508bd2020-12-10 13:59:48 +0100113 import top_${top["name"]}_rnd_cnst_pkg::*;
lowRISC Contributors802543a2019-08-31 12:12:56 +0100114
Eunchan Kim436d2242019-10-29 17:25:51 -0700115 // Signals
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -0800116 logic [${num_mio_inputs - 1}:0] mio_p2d;
117 logic [${num_mio_outputs - 1}:0] mio_d2p;
118 logic [${num_mio_outputs - 1}:0] mio_d2p_en;
Michael Schaffner60157962020-05-01 19:11:28 -0700119 logic [${num_dio - 1}:0] dio_p2d;
120 logic [${num_dio - 1}:0] dio_d2p;
121 logic [${num_dio - 1}:0] dio_d2p_en;
Eunchan Kim436d2242019-10-29 17:25:51 -0700122% for m in top["module"]:
Timothy Chen94432212021-03-01 22:29:18 -0800123 % if not lib.is_inst(m):
124<% continue %>
125 % endif
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000126<%
127 block = name_to_block[m['type']]
128 inouts, inputs, outputs = block.xputs
129%>\
Eunchan Kim436d2242019-10-29 17:25:51 -0700130 // ${m["name"]}
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000131 % for p_in in inputs + inouts:
132 logic ${lib.bitarray(p_in.bits.width(), max_sigwidth)} cio_${m["name"]}_${p_in.name}_p2d;
Eunchan Kim436d2242019-10-29 17:25:51 -0700133 % endfor
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000134 % for p_out in outputs + inouts:
135 logic ${lib.bitarray(p_out.bits.width(), max_sigwidth)} cio_${m["name"]}_${p_out.name}_d2p;
136 logic ${lib.bitarray(p_out.bits.width(), max_sigwidth)} cio_${m["name"]}_${p_out.name}_en_d2p;
Eunchan Kim436d2242019-10-29 17:25:51 -0700137 % endfor
138% endfor
139
140
lowRISC Contributors802543a2019-08-31 12:12:56 +0100141<%
Eunchan Kim88a86152020-04-13 16:12:08 -0700142 # Interrupt source 0 is tied to 0 to conform RISC-V PLIC spec.
143 # So, total number of interrupts are the number of entries in the list + 1
144 interrupt_num = sum([x["width"] if "width" in x else 1 for x in top["interrupt"]]) + 1
lowRISC Contributors802543a2019-08-31 12:12:56 +0100145%>\
146 logic [${interrupt_num-1}:0] intr_vector;
147 // Interrupt source list
148% for m in top["module"]:
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000149<%
150 block = name_to_block[m['type']]
151%>\
Timothy Chen94432212021-03-01 22:29:18 -0800152 % if not lib.is_inst(m):
153<% continue %>
154 % endif
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000155 % for intr in block.interrupts:
156 % if intr.bits.width() != 1:
157 logic [${intr.bits.width()-1}:0] intr_${m["name"]}_${intr.name};
lowRISC Contributors802543a2019-08-31 12:12:56 +0100158 % else:
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000159 logic intr_${m["name"]}_${intr.name};
lowRISC Contributors802543a2019-08-31 12:12:56 +0100160 % endif
161 % endfor
162% endfor
163
Michael Schaffner666dde12019-10-25 11:57:54 -0700164
Michael Schaffnerd4d5d2f2020-04-17 15:45:55 -0700165<% add_spaces = " " * len(str((interrupt_num-1).bit_length()-1)) %>
Michael Schaffner1ba89b82019-11-03 14:25:54 -0800166 logic [0:0]${add_spaces}irq_plic;
167 logic [0:0]${add_spaces}msip;
Eunchan Kim88a86152020-04-13 16:12:08 -0700168 logic [${(interrupt_num-1).bit_length()-1}:0] irq_id[1];
169 logic [${(interrupt_num-1).bit_length()-1}:0] unused_irq_id[1];
lowRISC Contributors802543a2019-08-31 12:12:56 +0100170
Michael Schaffner1ba89b82019-11-03 14:25:54 -0800171 // this avoids lint errors
172 assign unused_irq_id = irq_id;
lowRISC Contributors802543a2019-08-31 12:12:56 +0100173
Michael Schaffner666dde12019-10-25 11:57:54 -0700174 // Alert list
Philipp Wagner79725e12020-03-03 23:34:38 +0000175 prim_alert_pkg::alert_tx_t [alert_pkg::NAlerts-1:0] alert_tx;
176 prim_alert_pkg::alert_rx_t [alert_pkg::NAlerts-1:0] alert_rx;
Michael Schaffner666dde12019-10-25 11:57:54 -0700177
178% if not top["alert"]:
179 for (genvar k = 0; k < alert_pkg::NAlerts; k++) begin : gen_alert_tie_off
180 // tie off if no alerts present in the system
181 assign alert_tx[k].alert_p = 1'b0;
182 assign alert_tx[k].alert_n = 1'b1;
183 end
184% endif
185
Eunchan Kim40098a92020-04-17 12:22:36 -0700186## Inter-module Definitions
187% if len(top["inter_signal"]["definitions"]) >= 1:
188 // define inter-module signals
189% endif
190% for sig in top["inter_signal"]["definitions"]:
191 ${lib.im_defname(sig)} ${lib.bitarray(sig["width"],1)} ${sig["signame"]};
192% endfor
193
Timothy Chen075ed372021-02-04 14:42:29 -0800194## Mixed connection to port
195## Index greater than 0 means a port is assigned to an inter-module array
196## whereas an index of 0 means a port is directly driven by a module
197 // define mixed connection to port
198% for port in top['inter_signal']['external']:
199 % if port['index'] > 0:
200 % if port['direction'] == 'in':
201 assign ${port['netname']}[${port['index']}] = ${port['signame']};
202 % else:
203 assign ${port['signame']} = ${port['netname']}[${port['index']}];
204 % endif
205 % endif
206% endfor
207
Timothy Chen90b82422021-02-03 23:45:21 -0800208## Partial inter-module definition tie-off
209 // define partial inter-module tie-off
210% for sig in unused_im_defs:
211 % for idx in range(sig['end_idx'], sig['width']):
212 ${lib.im_defname(sig)} unused_${sig["signame"]}${idx};
213 % endfor
214% endfor
215
216 // assign partial inter-module tie-off
217% for sig in unused_im_defs:
218 % for idx in range(sig['end_idx'], sig['width']):
219 assign unused_${sig["signame"]}${idx} = ${sig["signame"]}[${idx}];
220 % endfor
221% endfor
222% for sig in undriven_im_defs:
223 % for idx in range(sig['end_idx'], sig['width']):
224 assign ${sig["signame"]}[${idx}] = ${lib.im_netname(sig, sig['suffix'], True)};
225 % endfor
226% endfor
227
Pirmin Vogela2d411d2020-07-13 17:33:42 +0200228## Inter-module signal collection
Pirmin Vogela2d411d2020-07-13 17:33:42 +0200229
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800230 // Unused reset signals
231% for k, v in unused_resets.items():
232 logic unused_d${v.lower()}_rst_${k};
233% endfor
234% for k, v in unused_resets.items():
235 assign unused_d${v.lower()}_rst_${k} = ${lib.get_reset_path(k, v, top['resets'])};
236% endfor
237
Timothy Chen3193b002019-10-04 16:56:05 -0700238 // Non-debug module reset == reset for everything except for the debug module
239 logic ndmreset_req;
240
Timothy Chen3193b002019-10-04 16:56:05 -0700241 // debug request from rv_dm to core
lowRISC Contributors802543a2019-08-31 12:12:56 +0100242 logic debug_req;
243
244 // processor core
245 rv_core_ibex #(
Philipp Wagner25d889222020-04-03 11:52:41 +0100246 .PMPEnable (1),
247 .PMPGranularity (0), // 2^(PMPGranularity+2) == 4 byte granularity
248 .PMPNumRegions (16),
Pirmin Vogel185d1bf2020-08-27 13:30:10 +0200249 .MHPMCounterNum (10),
250 .MHPMCounterWidth (32),
Greg Chadwickdadb1af2020-04-16 17:10:23 +0100251 .RV32E (0),
Pirmin Vogele3814642020-08-27 12:44:23 +0200252 .RV32M (ibex_pkg::RV32MSingleCycle),
253 .RV32B (ibex_pkg::RV32BNone),
Pirmin Vogel4eb25022020-08-27 15:27:33 +0200254 .RegFile (IbexRegFile),
Greg Chadwickdadb1af2020-04-16 17:10:23 +0100255 .BranchTargetALU (1),
256 .WritebackStage (1),
Tom Roberts7824ccc2020-11-05 11:34:03 +0000257 .ICache (IbexICache),
258 .ICacheECC (1),
Pirmin Vogele3814642020-08-27 12:44:23 +0200259 .BranchPredictor (0),
Greg Chadwickdadb1af2020-04-16 17:10:23 +0100260 .DbgTriggerEn (1),
Tom Roberts78bb2ae2020-06-03 15:24:22 +0100261 .SecureIbex (0),
Rupert Swarbrickda341bf2021-03-10 15:45:25 +0000262 .DmHaltAddr (ADDR_SPACE_DEBUG_MEM + dm::HaltAddress[31:0]),
263 .DmExceptionAddr (ADDR_SPACE_DEBUG_MEM + dm::ExceptionAddress[31:0]),
Greg Chadwickdadb1af2020-04-16 17:10:23 +0100264 .PipeLine (IbexPipeLine)
Michael Schaffnera39557e2020-03-17 18:30:21 -0700265 ) u_rv_core_ibex (
lowRISC Contributors802543a2019-08-31 12:12:56 +0100266 // clock and reset
Timothy Chenf56c1b52020-04-28 17:00:43 -0700267 .clk_i (${cpu_clk}),
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800268 .rst_ni (${cpu_rst}[rstmgr_pkg::Domain0Sel]),
Michael Schaffnerbe5cb9c2020-11-19 19:53:47 -0800269 .clk_esc_i (${esc_clk}),
270 .rst_esc_ni (${esc_rst}[rstmgr_pkg::Domain0Sel]),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100271 .test_en_i (1'b0),
272 // static pinning
Greg Chadwick53ef2ec2019-09-03 14:53:54 +0100273 .hart_id_i (32'b0),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100274 .boot_addr_i (ADDR_SPACE_ROM),
275 // TL-UL buses
Eunchan Kime0d37fe2020-08-03 12:05:21 -0700276 .tl_i_o (main_tl_corei_req),
277 .tl_i_i (main_tl_corei_rsp),
278 .tl_d_o (main_tl_cored_req),
279 .tl_d_i (main_tl_cored_rsp),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100280 // interrupts
281 .irq_software_i (msip),
282 .irq_timer_i (intr_rv_timer_timer_expired_0_0),
283 .irq_external_i (irq_plic),
Michael Schaffnerbdcbd202020-07-27 12:18:21 -0700284 // escalation input from alert handler (NMI)
Timothy Chene4e857d2020-12-16 18:00:01 -0800285 .esc_tx_i (alert_handler_esc_tx[0]),
286 .esc_rx_o (alert_handler_esc_rx[0]),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100287 // debug interface
288 .debug_req_i (debug_req),
Timothy Chenf524c212020-12-17 14:08:45 -0800289 // crash dump interface
Tom Robertsc88e97f2021-03-04 13:38:20 +0000290 .crash_dump_o (rv_core_ibex_crash_dump),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100291 // CPU control signals
Michael Schaffnerdc0c1e92021-03-02 14:41:31 -0800292 .lc_cpu_en_i (lc_ctrl_lc_cpu_en),
Timothy Chen92b526e2021-02-01 21:23:42 -0800293 .core_sleep_o (pwrmgr_aon_pwr_cpu.core_sleeping)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100294 );
295
296 // Debug Module (RISC-V Debug Spec 0.13)
297 //
298
Michael Schaffnera03f1582020-11-19 22:16:27 -0800299 // TODO: this will be routed to the pinmux for TAP selection
300 // based on straps and LC control signals.
Michael Schaffner382210d2020-12-07 12:18:42 -0800301 jtag_pkg::jtag_req_t jtag_req;
302 jtag_pkg::jtag_rsp_t jtag_rsp;
Michael Schaffnera03f1582020-11-19 22:16:27 -0800303 logic unused_jtag_tdo_oe_o;
304
305 assign jtag_req.tck = jtag_tck_i;
306 assign jtag_req.tms = jtag_tms_i;
307 assign jtag_req.trst_n = jtag_trst_ni;
308 assign jtag_req.tdi = jtag_tdi_i;
309 assign jtag_tdo_o = jtag_rsp.tdo;
310 assign unused_jtag_tdo_oe_o = jtag_rsp.tdo_oe;
311
lowRISC Contributors802543a2019-08-31 12:12:56 +0100312 rv_dm #(
Philipp Wagner086b7032019-10-25 17:06:15 +0100313 .NrHarts (1),
314 .IdcodeValue (JTAG_IDCODE)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100315 ) u_dm_top (
Timothy Chenf56c1b52020-04-28 17:00:43 -0700316 .clk_i (${cpu_clk}),
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800317 .rst_ni (${dm_rst}[rstmgr_pkg::Domain0Sel]),
Michael Schaffner7ce0e522021-02-25 16:39:42 -0800318 .hw_debug_en_i (lc_ctrl_lc_hw_debug_en),
Michael Schaffner8bf4fe62021-02-18 12:56:08 -0800319 .scanmode_i,
Timothy Chen3193b002019-10-04 16:56:05 -0700320 .ndmreset_o (ndmreset_req),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100321 .dmactive_o (),
322 .debug_req_o (debug_req),
323 .unavailable_i (1'b0),
324
325 // bus device with debug memory (for execution-based debug)
Eunchan Kime0d37fe2020-08-03 12:05:21 -0700326 .tl_d_i (main_tl_debug_mem_req),
327 .tl_d_o (main_tl_debug_mem_rsp),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100328
329 // bus host (for system bus accesses, SBA)
Eunchan Kime0d37fe2020-08-03 12:05:21 -0700330 .tl_h_o (main_tl_dm_sba_req),
331 .tl_h_i (main_tl_dm_sba_rsp),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100332
333 //JTAG
Michael Schaffnera03f1582020-11-19 22:16:27 -0800334 .jtag_req_i (jtag_req),
335 .jtag_rsp_o (jtag_rsp)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100336 );
337
Timothy Chen92b526e2021-02-01 21:23:42 -0800338 assign rstmgr_aon_cpu.ndmreset_req = ndmreset_req;
339 assign rstmgr_aon_cpu.rst_cpu_n = ${top["reset_paths"]["sys"]}[rstmgr_pkg::Domain0Sel];
Timothy Chenc59f7012020-04-16 19:11:42 -0700340
lowRISC Contributors802543a2019-08-31 12:12:56 +0100341## Memory Instantiation
342% for m in top["memory"]:
Timothy Chen3193b002019-10-04 16:56:05 -0700343<%
344 resets = m['reset_connections']
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700345 clocks = m['clock_connections']
Timothy Chen3193b002019-10-04 16:56:05 -0700346%>\
Michael Schaffnerbd9a3542020-12-21 13:08:32 -0800347 % if m["type"] == "ram_1p_scr":
lowRISC Contributors802543a2019-08-31 12:12:56 +0100348<%
349 data_width = int(top["datawidth"])
Timothy Chen466585e2021-03-01 15:06:01 -0800350 full_data_width = data_width + int(m["integ_width"])
lowRISC Contributors802543a2019-08-31 12:12:56 +0100351 dw_byte = data_width // 8
352 addr_width = ((int(m["size"], 0) // dw_byte) -1).bit_length()
353 sram_depth = (int(m["size"], 0) // dw_byte)
Eunchan Kim436d2242019-10-29 17:25:51 -0700354 max_char = len(str(max(data_width, addr_width)))
lowRISC Contributors802543a2019-08-31 12:12:56 +0100355%>\
356 // sram device
Eunchan Kim436d2242019-10-29 17:25:51 -0700357 logic ${lib.bitarray(1, max_char)} ${m["name"]}_req;
Michael Schaffnerbd9a3542020-12-21 13:08:32 -0800358 logic ${lib.bitarray(1, max_char)} ${m["name"]}_gnt;
Eunchan Kim436d2242019-10-29 17:25:51 -0700359 logic ${lib.bitarray(1, max_char)} ${m["name"]}_we;
Timothy Chen12cce142021-03-02 18:11:01 -0800360 logic ${lib.bitarray(1, max_char)} ${m["name"]}_intg_err;
Eunchan Kim436d2242019-10-29 17:25:51 -0700361 logic ${lib.bitarray(addr_width, max_char)} ${m["name"]}_addr;
Timothy Chena6833b12021-03-03 14:58:38 -0800362 logic ${lib.bitarray(data_width, max_char)} ${m["name"]}_wdata;
363 logic ${lib.bitarray(data_width, max_char)} ${m["name"]}_wmask;
Timothy Chen466585e2021-03-01 15:06:01 -0800364 logic ${lib.bitarray(full_data_width, max_char)} ${m["name"]}_rdata;
Eunchan Kim436d2242019-10-29 17:25:51 -0700365 logic ${lib.bitarray(1, max_char)} ${m["name"]}_rvalid;
Philipp Wagnere1efc182020-05-21 18:26:17 +0100366 logic ${lib.bitarray(2, max_char)} ${m["name"]}_rerror;
lowRISC Contributors802543a2019-08-31 12:12:56 +0100367
368 tlul_adapter_sram #(
369 .SramAw(${addr_width}),
370 .SramDw(${data_width}),
Timothy Chen12cce142021-03-02 18:11:01 -0800371 .Outstanding(2),
372 .CmdIntgCheck(1),
373 .EnableRspIntgGen(1),
374 .EnableDataIntgGen(1) // TODO: Needs to be updated for integrity passthrough
Michael Schaffnera39557e2020-03-17 18:30:21 -0700375 ) u_tl_adapter_${m["name"]} (
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700376 % for key in clocks:
Timothy Chen0550d692020-04-20 17:19:35 -0700377 .${key} (${clocks[key]}),
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700378 % endfor
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800379 % for key, value in resets.items():
380 .${key} (${value}),
Timothy Chen3193b002019-10-04 16:56:05 -0700381 % endfor
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800382 .tl_i (${m["name"]}_tl_req),
383 .tl_o (${m["name"]}_tl_rsp),
Timothy Chen15d98b72021-02-10 20:58:34 -0800384 .en_ifetch_i (${m["inter_signal_list"][2]["top_signame"]}),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800385 .req_o (${m["name"]}_req),
386 .gnt_i (${m["name"]}_gnt),
387 .we_o (${m["name"]}_we),
388 .addr_o (${m["name"]}_addr),
389 .wdata_o (${m["name"]}_wdata),
390 .wmask_o (${m["name"]}_wmask),
Timothy Chen12cce142021-03-02 18:11:01 -0800391 .intg_error_o(${m["name"]}_intg_err),
Timothy Chen466585e2021-03-01 15:06:01 -0800392 .rdata_i (${m["name"]}_rdata[${data_width-1}:0]),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800393 .rvalid_i (${m["name"]}_rvalid),
394 .rerror_i (${m["name"]}_rerror)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100395 );
396
Michael Schaffnerbec47c72020-11-06 14:03:54 -0800397 prim_ram_1p_scr #(
Timothy Chen466585e2021-03-01 15:06:01 -0800398 .Width(${full_data_width}),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100399 .Depth(${sram_depth}),
Timothy Chen466585e2021-03-01 15:06:01 -0800400 .EnableParity(0),
Michael Schaffnerbec47c72020-11-06 14:03:54 -0800401 .CfgWidth(8)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100402 ) u_ram1p_${m["name"]} (
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700403 % for key in clocks:
Timothy Chen0550d692020-04-20 17:19:35 -0700404 .${key} (${clocks[key]}),
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700405 % endfor
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800406 % for key, value in resets.items():
407 .${key} (${value}),
Timothy Chen3193b002019-10-04 16:56:05 -0700408 % endfor
lowRISC Contributors802543a2019-08-31 12:12:56 +0100409
Timothy Chen12cce142021-03-02 18:11:01 -0800410 .key_valid_i (${m["inter_signal_list"][1]["top_signame"]}_req.valid),
411 .key_i (${m["inter_signal_list"][1]["top_signame"]}_req.key),
412 .nonce_i (${m["inter_signal_list"][1]["top_signame"]}_req.nonce),
Michael Schaffnerbec47c72020-11-06 14:03:54 -0800413
Timothy Chen12cce142021-03-02 18:11:01 -0800414 .req_i (${m["name"]}_req),
415 .intg_error_i(${m["name"]}_intg_err),
416 .gnt_o (${m["name"]}_gnt),
417 .write_i (${m["name"]}_we),
418 .addr_i (${m["name"]}_addr),
419 .wdata_i (${full_data_width}'(${m["name"]}_wdata)),
420 .wmask_i (${full_data_width}'(${m["name"]}_wmask)),
421 .rdata_o (${m["name"]}_rdata),
422 .rvalid_o (${m["name"]}_rvalid),
423 .rerror_o (${m["name"]}_rerror),
424 .raddr_o (${m["inter_signal_list"][1]["top_signame"]}_rsp.raddr),
425 .intg_error_o(${m["inter_signal_list"][3]["top_signame"]}),
426 .cfg_i ( '0 )
lowRISC Contributors802543a2019-08-31 12:12:56 +0100427 );
Michael Schaffnerbec47c72020-11-06 14:03:54 -0800428
Michael Schaffnerbd9a3542020-12-21 13:08:32 -0800429 assign ${m["inter_signal_list"][1]["top_signame"]}_rsp.rerror = ${m["name"]}_rerror;
430
lowRISC Contributors802543a2019-08-31 12:12:56 +0100431 % elif m["type"] == "rom":
432<%
433 data_width = int(top["datawidth"])
Timothy Chen466585e2021-03-01 15:06:01 -0800434 full_data_width = data_width + int(m['integ_width'])
lowRISC Contributors802543a2019-08-31 12:12:56 +0100435 dw_byte = data_width // 8
436 addr_width = ((int(m["size"], 0) // dw_byte) -1).bit_length()
437 rom_depth = (int(m["size"], 0) // dw_byte)
Eunchan Kim436d2242019-10-29 17:25:51 -0700438 max_char = len(str(max(data_width, addr_width)))
lowRISC Contributors802543a2019-08-31 12:12:56 +0100439%>\
440 // ROM device
Eunchan Kim436d2242019-10-29 17:25:51 -0700441 logic ${lib.bitarray(1, max_char)} ${m["name"]}_req;
442 logic ${lib.bitarray(addr_width, max_char)} ${m["name"]}_addr;
Timothy Chen466585e2021-03-01 15:06:01 -0800443 logic ${lib.bitarray(full_data_width, max_char)} ${m["name"]}_rdata;
Eunchan Kim436d2242019-10-29 17:25:51 -0700444 logic ${lib.bitarray(1, max_char)} ${m["name"]}_rvalid;
lowRISC Contributors802543a2019-08-31 12:12:56 +0100445
446 tlul_adapter_sram #(
447 .SramAw(${addr_width}),
448 .SramDw(${data_width}),
Eunchan Kim6c731a82020-03-04 14:48:52 -0800449 .Outstanding(2),
Timothy Chen12cce142021-03-02 18:11:01 -0800450 .ErrOnWrite(1),
451 .CmdIntgCheck(1),
452 .EnableRspIntgGen(1),
453 .EnableDataIntgGen(1) // TODO: Needs to be updated for intgerity passthrough
Michael Schaffnera39557e2020-03-17 18:30:21 -0700454 ) u_tl_adapter_${m["name"]} (
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700455 % for key in clocks:
Timothy Chen0550d692020-04-20 17:19:35 -0700456 .${key} (${clocks[key]}),
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700457 % endfor
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800458 % for key, value in resets.items():
459 .${key} (${value}),
Timothy Chen3193b002019-10-04 16:56:05 -0700460 % endfor
lowRISC Contributors802543a2019-08-31 12:12:56 +0100461
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800462 .tl_i (${m["name"]}_tl_req),
463 .tl_o (${m["name"]}_tl_rsp),
Timothy Chen15d98b72021-02-10 20:58:34 -0800464 .en_ifetch_i (tlul_pkg::InstrEn),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800465 .req_o (${m["name"]}_req),
466 .gnt_i (1'b1), // Always grant as only one requester exists
467 .we_o (),
468 .addr_o (${m["name"]}_addr),
469 .wdata_o (),
470 .wmask_o (),
Timothy Chen12cce142021-03-02 18:11:01 -0800471 .intg_error_o(), // Connect to ROM checker and ROM scramble later
Timothy Chen466585e2021-03-01 15:06:01 -0800472 .rdata_i (${m["name"]}_rdata[${data_width-1}:0]),
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800473 .rvalid_i (${m["name"]}_rvalid),
474 .rerror_i (2'b00)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100475 );
476
Michael Schaffner0beb8a42020-06-05 23:17:40 -0700477 prim_rom_adv #(
Timothy Chen466585e2021-03-01 15:06:01 -0800478 .Width(${full_data_width}),
Philipp Wagnera37bcfa2020-05-19 22:46:41 +0100479 .Depth(${rom_depth}),
480 .MemInitFile(BootRomInitFile)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100481 ) u_rom_${m["name"]} (
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700482 % for key in clocks:
Timothy Chen0550d692020-04-20 17:19:35 -0700483 .${key} (${clocks[key]}),
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700484 % endfor
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800485 % for key, value in resets.items():
486 .${key} (${value}),
Timothy Chen3193b002019-10-04 16:56:05 -0700487 % endfor
Michael Schaffner0beb8a42020-06-05 23:17:40 -0700488 .req_i (${m["name"]}_req),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100489 .addr_i (${m["name"]}_addr),
Michael Schaffner0beb8a42020-06-05 23:17:40 -0700490 .rdata_o (${m["name"]}_rdata),
491 .rvalid_o (${m["name"]}_rvalid),
492 .cfg_i ('0) // tied off for now
lowRISC Contributors802543a2019-08-31 12:12:56 +0100493 );
494
lowRISC Contributors802543a2019-08-31 12:12:56 +0100495 % elif m["type"] == "eflash":
496
lowRISC Contributors802543a2019-08-31 12:12:56 +0100497 // host to flash communication
498 logic flash_host_req;
499 logic flash_host_req_rdy;
500 logic flash_host_req_done;
Timothy Chene96730f2020-09-14 23:10:42 -0700501 logic flash_host_rderr;
Timothy Chen14518402020-04-13 15:25:22 -0700502 logic [flash_ctrl_pkg::BusWidth-1:0] flash_host_rdata;
Timothy Chenb35a3402020-06-23 00:14:11 -0700503 logic [flash_ctrl_pkg::BusAddrW-1:0] flash_host_addr;
lowRISC Contributors802543a2019-08-31 12:12:56 +0100504
Timothy Chen5aec5282019-09-10 21:10:56 -0700505 tlul_adapter_sram #(
Timothy Chenb35a3402020-06-23 00:14:11 -0700506 .SramAw(flash_ctrl_pkg::BusAddrW),
Timothy Chen14518402020-04-13 15:25:22 -0700507 .SramDw(flash_ctrl_pkg::BusWidth),
Eunchan Kim6c731a82020-03-04 14:48:52 -0800508 .Outstanding(2),
Timothy Chen5aec5282019-09-10 21:10:56 -0700509 .ByteAccess(0),
Timothy Chen12cce142021-03-02 18:11:01 -0800510 .ErrOnWrite(1),
511 .CmdIntgCheck(1),
512 .EnableRspIntgGen(1),
513 .EnableDataIntgGen(1)
Michael Schaffnera39557e2020-03-17 18:30:21 -0700514 ) u_tl_adapter_${m["name"]} (
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700515 % for key in clocks:
Timothy Chen0550d692020-04-20 17:19:35 -0700516 .${key} (${clocks[key]}),
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700517 % endfor
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800518 % for key, value in resets.items():
519 .${key} (${value}),
Timothy Chen3193b002019-10-04 16:56:05 -0700520 % endfor
lowRISC Contributors802543a2019-08-31 12:12:56 +0100521
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800522 .tl_i (${m["name"]}_tl_req),
523 .tl_o (${m["name"]}_tl_rsp),
Timothy Chen15d98b72021-02-10 20:58:34 -0800524 .en_ifetch_i (tlul_pkg::InstrEn), // tie this to secure boot somehow
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800525 .req_o (flash_host_req),
526 .gnt_i (flash_host_req_rdy),
527 .we_o (),
528 .addr_o (flash_host_addr),
529 .wdata_o (),
530 .wmask_o (),
Timothy Chen12cce142021-03-02 18:11:01 -0800531 .intg_error_o(), // TODO: connect to flash controller and flash scramble later
Timothy Chen1a9a60f2021-02-10 18:04:39 -0800532 .rdata_i (flash_host_rdata),
533 .rvalid_i (flash_host_req_done),
534 .rerror_i ({flash_host_rderr,1'b0})
lowRISC Contributors802543a2019-08-31 12:12:56 +0100535 );
536
Timothy Chen14518402020-04-13 15:25:22 -0700537 flash_phy u_flash_${m["name"]} (
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700538 % for key in clocks:
Timothy Chen0550d692020-04-20 17:19:35 -0700539 .${key} (${clocks[key]}),
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700540 % endfor
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800541 % for key, value in resets.items():
542 .${key} (${value}),
Timothy Chen3193b002019-10-04 16:56:05 -0700543 % endfor
Timothy Chenb1ba59b2021-01-07 12:18:11 -0800544 .host_req_i (flash_host_req),
545 .host_addr_i (flash_host_addr),
546 .host_req_rdy_o (flash_host_req_rdy),
547 .host_req_done_o (flash_host_req_done),
548 .host_rderr_o (flash_host_rderr),
549 .host_rdata_o (flash_host_rdata),
550 .flash_ctrl_i (${m["inter_signal_list"][0]["top_signame"]}_req),
551 .flash_ctrl_o (${m["inter_signal_list"][0]["top_signame"]}_rsp),
552 .lc_nvm_debug_en_i (${m["inter_signal_list"][2]["top_signame"]}),
Timothy Chenb1ba59b2021-01-07 12:18:11 -0800553 .flash_bist_enable_i,
Timothy Chend2c9ff42020-11-19 16:03:54 -0800554 .flash_power_down_h_i,
555 .flash_power_ready_h_i,
556 .flash_test_mode_a_i,
557 .flash_test_voltage_h_i,
558 .scanmode_i,
Timothy Chen010e3cc2021-02-02 14:55:09 -0800559 .scan_en_i,
Timothy Chend2c9ff42020-11-19 16:03:54 -0800560 .scan_rst_ni
lowRISC Contributors802543a2019-08-31 12:12:56 +0100561 );
562
563 % else:
564 // flash memory is embedded within controller
565 % endif
566% endfor
lowRISC Contributors802543a2019-08-31 12:12:56 +0100567## Peripheral Instantiation
Timothy Chen3193b002019-10-04 16:56:05 -0700568
Michael Schaffner666dde12019-10-25 11:57:54 -0700569<% alert_idx = 0 %>
lowRISC Contributors802543a2019-08-31 12:12:56 +0100570% for m in top["module"]:
Timothy Chen3193b002019-10-04 16:56:05 -0700571<%
Timothy Chen94432212021-03-01 22:29:18 -0800572if not lib.is_inst(m):
573 continue
574
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000575block = name_to_block[m['type']]
576inouts, inputs, outputs = block.xputs
Timothy Chen3193b002019-10-04 16:56:05 -0700577
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000578port_list = inputs + outputs + inouts
579max_sigwidth = max(len(x.name) for x in port_list) if port_list else 0
580max_intrwidth = (max(len(x.name) for x in block.interrupts)
581 if block.interrupts else 0)
Timothy Chen3193b002019-10-04 16:56:05 -0700582%>\
Pirmin Vogel15e1b912020-09-16 14:43:22 +0200583 % if m["param_list"]:
lowRISC Contributors802543a2019-08-31 12:12:56 +0100584 ${m["type"]} #(
Pirmin Vogel15e1b912020-09-16 14:43:22 +0200585 % for i in m["param_list"]:
Rupert Swarbrick611a6422021-02-12 11:56:48 +0000586 .${i["name"]}(${i["name_top" if i.get("expose") == "true" or i.get("randtype", "none") != "none" else "default"]})${"," if not loop.last else ""}
lowRISC Contributors802543a2019-08-31 12:12:56 +0100587 % endfor
Michael Schaffnera39557e2020-03-17 18:30:21 -0700588 ) u_${m["name"]} (
lowRISC Contributors802543a2019-08-31 12:12:56 +0100589 % else:
Michael Schaffnera39557e2020-03-17 18:30:21 -0700590 ${m["type"]} u_${m["name"]} (
lowRISC Contributors802543a2019-08-31 12:12:56 +0100591 % endif
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000592 % for p_in in inputs + inouts:
Pirmin Vogelb054fc02020-03-11 11:23:03 +0100593 % if loop.first:
Eunchan Kim436d2242019-10-29 17:25:51 -0700594
595 // Input
Pirmin Vogelb054fc02020-03-11 11:23:03 +0100596 % endif
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000597 .${lib.ljust("cio_"+p_in.name+"_i",max_sigwidth+9)} (cio_${m["name"]}_${p_in.name}_p2d),
Pirmin Vogelb054fc02020-03-11 11:23:03 +0100598 % endfor
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000599 % for p_out in outputs + inouts:
Pirmin Vogelb054fc02020-03-11 11:23:03 +0100600 % if loop.first:
Eunchan Kim436d2242019-10-29 17:25:51 -0700601
602 // Output
Pirmin Vogelb054fc02020-03-11 11:23:03 +0100603 % endif
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000604 .${lib.ljust("cio_"+p_out.name+"_o", max_sigwidth+9)} (cio_${m["name"]}_${p_out.name}_d2p),
605 .${lib.ljust("cio_"+p_out.name+"_en_o",max_sigwidth+9)} (cio_${m["name"]}_${p_out.name}_en_d2p),
Pirmin Vogelb054fc02020-03-11 11:23:03 +0100606 % endfor
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000607 % for intr in block.interrupts:
Eunchan Kim436d2242019-10-29 17:25:51 -0700608 % if loop.first:
609
610 // Interrupt
611 % endif
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000612 .${lib.ljust("intr_"+intr.name+"_o",max_intrwidth+7)} (intr_${m["name"]}_${intr.name}),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100613 % endfor
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000614 % if block.alerts:
Michael Schaffnerd4d5d2f2020-04-17 15:45:55 -0700615<%
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000616w = len(block.alerts)
Michael Schaffnerd4d5d2f2020-04-17 15:45:55 -0700617slice = str(alert_idx+w-1) + ":" + str(alert_idx)
618%>
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000619 % for alert in block.alerts:
620 // [${alert_idx}]: ${alert.name}<% alert_idx += 1 %>
Michael Schaffner666dde12019-10-25 11:57:54 -0700621 % endfor
622 .alert_tx_o ( alert_tx[${slice}] ),
623 .alert_rx_i ( alert_rx[${slice}] ),
624 % endif
Eunchan Kim436d2242019-10-29 17:25:51 -0700625 ## TODO: Inter-module Connection
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000626 % if m.get('inter_signal_list'):
Eunchan Kim436d2242019-10-29 17:25:51 -0700627
Eunchan Kime4a85072020-02-05 16:00:00 -0800628 // Inter-module signals
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000629 % for sig in m['inter_signal_list']:
Eunchan Kimb7d72312020-03-30 10:51:55 -0700630 ## TODO: handle below condition in lib.py
Rupert Swarbrickb6500262021-02-23 15:16:16 +0000631 % if sig['type'] == "req_rsp":
Eunchan Kim40098a92020-04-17 12:22:36 -0700632 .${lib.im_portname(sig,"req")}(${lib.im_netname(sig, "req")}),
633 .${lib.im_portname(sig,"rsp")}(${lib.im_netname(sig, "rsp")}),
Rupert Swarbrickb6500262021-02-23 15:16:16 +0000634 % elif sig['type'] == "uni":
Eunchan Kim40098a92020-04-17 12:22:36 -0700635 ## TODO: Broadcast type
636 ## TODO: default for logic type
637 .${lib.im_portname(sig)}(${lib.im_netname(sig)}),
Eunchan Kime4a85072020-02-05 16:00:00 -0800638 % endif
639 % endfor
lowRISC Contributors802543a2019-08-31 12:12:56 +0100640 % endif
641 % if m["type"] == "rv_plic":
Eunchan Kim436d2242019-10-29 17:25:51 -0700642
lowRISC Contributors802543a2019-08-31 12:12:56 +0100643 .intr_src_i (intr_vector),
644 .irq_o (irq_plic),
645 .irq_id_o (irq_id),
646 .msip_o (msip),
647 % endif
Eunchan Kim436d2242019-10-29 17:25:51 -0700648 % if m["type"] == "pinmux":
649
Michael Schaffner60157962020-05-01 19:11:28 -0700650 .periph_to_mio_i (mio_d2p ),
651 .periph_to_mio_oe_i (mio_d2p_en ),
652 .mio_to_periph_o (mio_p2d ),
Eunchan Kim436d2242019-10-29 17:25:51 -0700653
Michael Schaffner43ce8d52021-02-10 17:04:57 -0800654 .mio_attr_o,
Michael Schaffner57c490d2020-04-29 15:08:55 -0700655 .mio_out_o,
656 .mio_oe_o,
657 .mio_in_i,
658
Michael Schaffner60157962020-05-01 19:11:28 -0700659 .periph_to_dio_i (dio_d2p ),
660 .periph_to_dio_oe_i (dio_d2p_en ),
661 .dio_to_periph_o (dio_p2d ),
Michael Schaffner57c490d2020-04-29 15:08:55 -0700662
Michael Schaffner43ce8d52021-02-10 17:04:57 -0800663 .dio_attr_o,
Michael Schaffner57c490d2020-04-29 15:08:55 -0700664 .dio_out_o,
665 .dio_oe_o,
666 .dio_in_i,
Michael Schaffner60157962020-05-01 19:11:28 -0700667
Michael Schaffner60157962020-05-01 19:11:28 -0700668 % endif
Michael Schaffner666dde12019-10-25 11:57:54 -0700669 % if m["type"] == "alert_handler":
Michael Schaffner666dde12019-10-25 11:57:54 -0700670 // alert signals
671 .alert_rx_o ( alert_rx ),
672 .alert_tx_i ( alert_tx ),
Michael Schaffner666dde12019-10-25 11:57:54 -0700673 % endif
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000674 % if block.scan:
Michael Schaffner8bf4fe62021-02-18 12:56:08 -0800675 .scanmode_i,
Eunchan Kim2cfadab2019-10-02 12:41:11 -0700676 % endif
Rupert Swarbrickeb619e62021-03-05 15:01:54 +0000677 % if block.scan_reset:
Timothy Chen9d5b5b62020-06-29 17:55:48 -0700678 .scan_rst_ni (scan_rst_ni),
679 % endif
Timothy Chenb0f55772021-02-01 15:43:47 -0800680
681 // Clock and reset connections
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700682 % for k, v in m["clock_connections"].items():
Timothy Chen0550d692020-04-20 17:19:35 -0700683 .${k} (${v}),
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700684 % endfor
Timothy Chen3193b002019-10-04 16:56:05 -0700685 % for k, v in m["reset_connections"].items():
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800686 .${k} (${v})${"," if not loop.last else ""}
Timothy Chen3193b002019-10-04 16:56:05 -0700687 % endfor
lowRISC Contributors802543a2019-08-31 12:12:56 +0100688 );
689
690% endfor
691 // interrupt assignments
692 assign intr_vector = {
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -0800693 % for k, intr in enumerate(top["interrupt"][::-1]):
694 intr_${intr["name"]}, // ID ${len(top["interrupt"])-k}
lowRISC Contributors802543a2019-08-31 12:12:56 +0100695 % endfor
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -0800696 1'b 0 // ID 0 is a special case and tied to zero.
lowRISC Contributors802543a2019-08-31 12:12:56 +0100697 };
698
699 // TL-UL Crossbar
lowRISC Contributors802543a2019-08-31 12:12:56 +0100700% for xbar in top["xbar"]:
701<%
702 name_len = max([len(x["name"]) for x in xbar["nodes"]]);
703%>\
704 xbar_${xbar["name"]} u_xbar_${xbar["name"]} (
Timothy Chen80bd8aa2019-10-04 15:57:11 -0700705 % for k, v in xbar["clock_connections"].items():
Timothy Chen0550d692020-04-20 17:19:35 -0700706 .${k} (${v}),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100707 % endfor
Timothy Chen3193b002019-10-04 16:56:05 -0700708 % for k, v in xbar["reset_connections"].items():
Timothy Chen7f8cc8e2020-11-11 13:15:57 -0800709 .${k} (${v}),
Timothy Chen3193b002019-10-04 16:56:05 -0700710 % endfor
Eunchan Kime0d37fe2020-08-03 12:05:21 -0700711
712 ## Inter-module signal
713 % for sig in xbar["inter_signal_list"]:
Rupert Swarbrickb6500262021-02-23 15:16:16 +0000714<% assert sig['type'] == "req_rsp" %>\
Eunchan Kime0d37fe2020-08-03 12:05:21 -0700715 // port: ${sig['name']}
716 .${lib.im_portname(sig,"req")}(${lib.im_netname(sig, "req")}),
717 .${lib.im_portname(sig,"rsp")}(${lib.im_netname(sig, "rsp")}),
718
lowRISC Contributors802543a2019-08-31 12:12:56 +0100719 % endfor
720
721 .scanmode_i
lowRISC Contributors802543a2019-08-31 12:12:56 +0100722 );
Eunchan Kimc7452942019-12-19 17:04:37 -0800723% endfor
lowRISC Contributors802543a2019-08-31 12:12:56 +0100724
Eunchan Kim436d2242019-10-29 17:25:51 -0700725% if "pinmux" in top:
726 // Pinmux connections
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -0800727 % if num_mio_outputs != 0:
Michael Schaffner60157962020-05-01 19:11:28 -0700728 assign mio_d2p = {
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -0800729 % for sig in list(reversed(top["pinmux"]["outputs"])):
Eunchan Kim436d2242019-10-29 17:25:51 -0700730 cio_${sig["name"]}_d2p${"" if loop.last else ","}
731 % endfor
732 };
Michael Schaffner60157962020-05-01 19:11:28 -0700733 assign mio_d2p_en = {
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -0800734 % for sig in list(reversed(top["pinmux"]["outputs"])):
Eunchan Kim436d2242019-10-29 17:25:51 -0700735 cio_${sig["name"]}_en_d2p${"" if loop.last else ","}
736 % endfor
737 };
738 % endif
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -0800739 % if num_mio_inputs != 0:
Eunchan Kim436d2242019-10-29 17:25:51 -0700740 assign {
Michael Schaffnerb5b8eba2021-02-09 20:07:04 -0800741 % for sig in list(reversed(top["pinmux"]["inputs"])):
Eunchan Kim436d2242019-10-29 17:25:51 -0700742 cio_${sig["name"]}_p2d${"" if loop.last else ","}
743 % endfor
Michael Schaffner60157962020-05-01 19:11:28 -0700744 } = mio_p2d;
Eunchan Kim436d2242019-10-29 17:25:51 -0700745 % endif
746% endif
747
748% if num_dio != 0:
Michael Schaffner57c490d2020-04-29 15:08:55 -0700749 // Dedicated IO connections
Michael Schaffner60157962020-05-01 19:11:28 -0700750 // Input-only DIOs have no d2p signals
Michael Schaffnerdbd087e2021-02-12 17:58:30 -0800751 assign dio_d2p = {<% vector_idx = num_dio - 1 %>
Eunchan Kim436d2242019-10-29 17:25:51 -0700752 % for sig in top["pinmux"]["dio"]:
Michael Schaffner57c490d2020-04-29 15:08:55 -0700753 % if sig["type"] in ["output", "inout"]:
Michael Schaffnerdbd087e2021-02-12 17:58:30 -0800754 % if sig["width"] > 1:
755 % for i in range(sig["width"]-1,-1,-1):
756 cio_${sig["name"]}_d2p[${i}]${"" if vector_idx - sig["width"] + 1 == 0 else ","} // DIO${vector_idx}<% vector_idx -= 1 %>
757 % endfor
758 % else:
759 cio_${sig["name"]}_d2p${"" if vector_idx == 0 else ","} // DIO${vector_idx}<% vector_idx -= 1 %>
760 % endif
Michael Schaffner57c490d2020-04-29 15:08:55 -0700761 % else:
Michael Schaffnerdbd087e2021-02-12 17:58:30 -0800762 % if sig["width"] > 1:
763 ${sig["width"]}'b0${"" if vector_idx - sig["width"] + 1 == 0 else ","} // DIO${vector_idx} - DIO${vector_idx-sig["width"] + 1}: cio_${sig["name"]}<% vector_idx -= sig["width"] %>
764 % else:
765 ${sig["width"]}'b0${"" if vector_idx == 0 else ","} // DIO${vector_idx}: cio_${sig["name"]}<% vector_idx -= 1 %>
766 % endif
Michael Schaffner57c490d2020-04-29 15:08:55 -0700767 % endif
768 % endfor
769 };
770
Michael Schaffnerdbd087e2021-02-12 17:58:30 -0800771 assign dio_d2p_en = {<% vector_idx = num_dio - 1 %>
Michael Schaffner57c490d2020-04-29 15:08:55 -0700772 % for sig in top["pinmux"]["dio"]:
773 % if sig["type"] in ["output", "inout"]:
Michael Schaffnerdbd087e2021-02-12 17:58:30 -0800774 % if sig["width"] > 1:
775 % for i in range(sig["width"]-1,-1,-1):
776 cio_${sig["name"]}_en_d2p[${i}]${"" if vector_idx - sig["width"] + 1 == 0 else ","} // DIO${vector_idx}<% vector_idx -= 1 %>
777 % endfor
778 % else:
779 cio_${sig["name"]}_en_d2p${"" if vector_idx == 0 else ","} // DIO${vector_idx}<% vector_idx -= 1 %>
780 % endif
Michael Schaffner57c490d2020-04-29 15:08:55 -0700781 % else:
Michael Schaffnerdbd087e2021-02-12 17:58:30 -0800782 % if sig["width"] > 1:
783 ${sig["width"]}'b0${"" if vector_idx - sig["width"] + 1 == 0 else ","} // DIO${vector_idx} - DIO${vector_idx-sig["width"] + 1}: cio_${sig["name"]}<% vector_idx -= sig["width"] %>
784 % else:
785 ${sig["width"]}'b0${"" if vector_idx == 0 else ","} // DIO${vector_idx}: cio_${sig["name"]}<% vector_idx -= 1 %>
786 % endif
Michael Schaffner57c490d2020-04-29 15:08:55 -0700787 % endif
788 % endfor
789 };
790
Michael Schaffnerdbd087e2021-02-12 17:58:30 -0800791 // Output-only DIOs have no p2d signal<% vector_idx = num_dio - 1 %>
Michael Schaffner60157962020-05-01 19:11:28 -0700792 % for sig in top["pinmux"]["dio"]:
Michael Schaffner57c490d2020-04-29 15:08:55 -0700793 % if sig["type"] in ["input", "inout"]:
Michael Schaffnerdbd087e2021-02-12 17:58:30 -0800794 % if sig["width"] > 1:
795 % for i in range(sig["width"]-1,-1,-1):
796 assign cio_${sig["name"]}_p2d[${i}]${" " * (max_diolength - len(str(i)) - 2 - len(sig["name"]))} = dio_p2d[${vector_idx}]; // DIO${vector_idx}<% vector_idx -= 1 %>
797 % endfor
798 % else:
799 assign cio_${sig["name"]}_p2d${" " * (max_diolength - len(sig["name"]))} = dio_p2d[${vector_idx}]; // DIO${vector_idx}<% vector_idx -= 1 %>
800 % endif
Michael Schaffner60157962020-05-01 19:11:28 -0700801 % else:
Michael Schaffnerdbd087e2021-02-12 17:58:30 -0800802 % if sig["width"] > 1:
803 % for i in range(sig["width"]-1,-1,-1):
804 // DIO${vector_idx}: cio_${sig["name"]}[${i}] // DIO${vector_idx}<% vector_idx -= 1 %>
805 % endfor
806 % else:
807 // DIO${vector_idx}: cio_${sig["name"]} // DIO${vector_idx}<% vector_idx -= 1 %>
808 % endif
Michael Schaffner57c490d2020-04-29 15:08:55 -0700809 % endif
Eunchan Kim436d2242019-10-29 17:25:51 -0700810 % endfor
811% endif
812
Nils Graf78607aa2019-09-16 15:47:23 -0700813 // make sure scanmode_i is never X (including during reset)
Eunchan Kim57071c02020-08-07 13:59:05 -0700814 `ASSERT_KNOWN(scanmodeKnown, scanmode_i, clk_main_i, 0)
Nils Graf78607aa2019-09-16 15:47:23 -0700815
lowRISC Contributors802543a2019-08-31 12:12:56 +0100816endmodule