blob: 234c618330716aabd1eca5837ce32cdb6781db60 [file] [log] [blame]
Srikrishna Iyer5b4dde92020-05-14 00:02:15 -07001// 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}
Srikrishna Iyer5b4dde92020-05-14 00:02:15 -07005<%
6import topgen.lib as lib
Srikrishna Iyer5b4dde92020-05-14 00:02:15 -07007%>\
Michael Schaffner74c4ff22021-03-30 15:43:46 -07008package top_${top["name"]}_pkg;
Rupert Swarbrick200d8b42021-03-08 12:32:11 +00009% for (inst_name, if_name), region in helper.devices():
10<%
11 if_desc = inst_name if if_name is None else '{} device on {}'.format(if_name, inst_name)
12 hex_base_addr = "32'h{:X}".format(region.base_addr)
13 hex_size_bytes = "32'h{:X}".format(region.size_bytes)
14%>\
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070015 /**
Michael Schaffner74c4ff22021-03-30 15:43:46 -070016 * Peripheral base address for ${if_desc} in top ${top["name"]}.
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070017 */
Rupert Swarbrick200d8b42021-03-08 12:32:11 +000018 parameter int unsigned ${region.base_addr_name().as_c_define()} = ${hex_base_addr};
Srikrishna Iyer5b4dde92020-05-14 00:02:15 -070019
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070020 /**
Michael Schaffner74c4ff22021-03-30 15:43:46 -070021 * Peripheral size in bytes for ${if_desc} in top ${top["name"]}.
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070022 */
Rupert Swarbrick200d8b42021-03-08 12:32:11 +000023 parameter int unsigned ${region.size_bytes_name().as_c_define()} = ${hex_size_bytes};
Srikrishna Iyer5b4dde92020-05-14 00:02:15 -070024
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070025% endfor
26% for name, region in helper.memories():
Rupert Swarbrick200d8b42021-03-08 12:32:11 +000027<%
28 hex_base_addr = "32'h{:x}".format(region.base_addr)
29 hex_size_bytes = "32'h{:x}".format(region.size_bytes)
30%>\
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070031 /**
Michael Schaffner74c4ff22021-03-30 15:43:46 -070032 * Memory base address for ${name} in top ${top["name"]}.
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070033 */
Rupert Swarbrick200d8b42021-03-08 12:32:11 +000034 parameter int unsigned ${region.base_addr_name().as_c_define()} = ${hex_base_addr};
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070035
36 /**
Michael Schaffner74c4ff22021-03-30 15:43:46 -070037 * Memory size for ${name} in top ${top["name"]}.
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070038 */
Rupert Swarbrick200d8b42021-03-08 12:32:11 +000039 parameter int unsigned ${region.size_bytes_name().as_c_define()} = ${hex_size_bytes};
Srikrishna Iyerd7bed872020-10-14 11:51:10 -070040
41% endfor
Michael Schaffner74c4ff22021-03-30 15:43:46 -070042
43 // Enumeration of IO power domains.
44 // Only used in ASIC target.
Timothy Chenb3d45f62021-04-10 00:29:49 -070045 typedef enum logic [${len(top["pinout"]["banks"]).bit_length()-1}:0] {
Michael Schaffner74c4ff22021-03-30 15:43:46 -070046% for bank in top["pinout"]["banks"]:
47 ${lib.Name(['io', 'bank', bank]).as_camel_case()} = ${loop.index},
48% endfor
49 IoBankCount = ${len(top["pinout"]["banks"])}
50 } pwr_dom_e;
51
52 // Enumeration for MIO signals on the top-level.
53 typedef enum {
54% for sig in top["pinmux"]["ios"]:
55 % if sig['type'] in ['inout', 'input'] and sig['connection'] == 'muxed':
56 ${lib.get_io_enum_literal(sig, 'mio_in')} = ${sig['glob_idx']},
57 % endif
58% endfor
59<% total = top["pinmux"]['io_counts']['muxed']['inouts'] + \
60 top["pinmux"]['io_counts']['muxed']['inputs'] %>\
61 ${lib.Name.from_snake_case("mio_in_count").as_camel_case()} = ${total}
62 } mio_in_e;
63
64 typedef enum {
65% for sig in top["pinmux"]["ios"]:
66 % if sig['type'] in ['inout', 'output'] and sig['connection'] == 'muxed':
67 ${lib.get_io_enum_literal(sig, 'mio_out')} = ${sig['glob_idx']},
68 % endif
69% endfor
70<% total = top["pinmux"]['io_counts']['muxed']['inouts'] + \
71 top["pinmux"]['io_counts']['muxed']['outputs'] %>\
72 ${lib.Name.from_snake_case("mio_out_count").as_camel_case()} = ${total}
73 } mio_out_e;
74
75 // Enumeration for DIO signals, used on both the top and chip-levels.
76 typedef enum {
77% for sig in top["pinmux"]["ios"]:
78 % if sig['connection'] != 'muxed':
79 ${lib.get_io_enum_literal(sig, 'dio')} = ${sig['glob_idx']},
80 % endif
81% endfor
82<% total = top["pinmux"]['io_counts']['dedicated']['inouts'] + \
83 top["pinmux"]['io_counts']['dedicated']['inputs'] + \
84 top["pinmux"]['io_counts']['dedicated']['outputs'] %>\
85 ${lib.Name.from_snake_case("dio_count").as_camel_case()} = ${total}
86 } dio_e;
87
88 // Raw MIO/DIO input array indices on chip-level.
89 // TODO: Does not account for target specific stubbed/added pads.
90 // Need to make a target-specific package for those.
91 typedef enum {
92% for pad in top["pinout"]["pads"]:
93 % if pad["connection"] == "muxed":
94 ${lib.Name.from_snake_case("mio_pad_" + pad["name"]).as_camel_case()} = ${pad["idx"]},
95 % endif
96% endfor
97 ${lib.Name.from_snake_case("mio_pad_count").as_camel_case()}
98 } mio_pad_e;
99
100 typedef enum {
101% for pad in top["pinout"]["pads"]:
102 % if pad["connection"] != "muxed":
103 ${lib.Name.from_snake_case("dio_pad_" + pad["name"]).as_camel_case()} = ${pad["idx"]},
104 % endif
105% endfor
106 ${lib.Name.from_snake_case("dio_pad_count").as_camel_case()}
107 } dio_pad_e;
Srikrishna Iyer5b4dde92020-05-14 00:02:15 -0700108
109 // TODO: Enumeration for PLIC Interrupt source peripheral.
110 // TODO: Enumeration for PLIC Interrupt Ids.
111
112endpackage