Skip to content

Commit

Permalink
[topgen] Only create pinmux if there is an instance
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Schilling <[email protected]>
  • Loading branch information
Razer6 committed Nov 27, 2024
1 parent c69a568 commit e7b74af
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion util/topgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,8 @@ def _process_top(
sys.exit()

# Generate Pinmux
generate_pinmux(completecfg, out_path)
if lib.find_module(completecfg['module'], 'pinmux'):
generate_pinmux(completecfg, out_path)

# Generate Pwrmgr if there is an instance
if lib.find_module(completecfg['module'], 'pwrmgr'):
Expand Down
6 changes: 4 additions & 2 deletions util/topgen/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,10 @@ def __init__(self, top_info, name_to_block: Dict[str, IpBlock], enum_type, array
self._init_plic_targets()
self._init_plic_mapping()
self._init_alert_mapping()
self._init_pinmux_mapping()
self._init_pad_mapping()
# Only generate pinmux and pad mappings if there is a pinmux
if find_module(self.top['module'], 'pinmux'):
self._init_pinmux_mapping()
self._init_pad_mapping()
# Only generate pwrmgr mappings if there is a pwrmgr
if find_module(self.top['module'], 'pwrmgr'):
self._init_pwrmgr_wakeups()
Expand Down
7 changes: 4 additions & 3 deletions util/topgen/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,9 +1308,10 @@ def merge_top(topcfg: OrderedDict,
# Combine the alert (should be processed prior to xbar)
amend_alert(topcfg, name_to_block)

# Creates input/output list in the pinmux
log.info("Processing PINMUX")
amend_pinmux_io(topcfg, name_to_block)
if lib.find_module(topcfg['module'], 'pinmux'):
# Creates input/output list in the pinmux
log.info("Processing PINMUX")
amend_pinmux_io(topcfg, name_to_block)

# Combine xbar into topcfg
for xbar in xbarobjs:
Expand Down
5 changes: 5 additions & 0 deletions util/topgen/templates/toplevel.h.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import textwrap
import topgen.lib as lib

has_pwrmgr = lib.find_module(top['module'], 'pwrmgr')
has_pinmux = lib.find_module(top['module'], 'pinmux')
%>\

#ifndef ${helper.header_macro_prefix}_TOP_${top["name"].upper()}_H_
Expand All @@ -23,7 +24,9 @@ has_pwrmgr = lib.find_module(top['module'], 'pwrmgr')
* - Device Memory Information (for Peripherals and Memory)
* - PLIC Interrupt ID Names and Source Mappings
* - Alert ID Names and Source Mappings
% if has_pinmux:
* - Pinmux Pin/Select Names
% endif
% if has_pwrmgr:
* - Power Manager Wakeups
% endif
Expand Down Expand Up @@ -139,6 +142,7 @@ ${helper.alert_alerts.render()}
* `${helper.alert_sources.name.as_c_type()}`.
*/
${helper.alert_mapping.render_declaration()}
% if has_pinmux:

#define PINMUX_MIO_PERIPH_INSEL_IDX_OFFSET 2

Expand Down Expand Up @@ -175,6 +179,7 @@ ${helper.pinmux_outsel.render()}
* Dedicated Pad Selects
*/
${helper.direct_pads.render()}
% endif

/**
* Muxed Pad Selects
Expand Down
5 changes: 5 additions & 0 deletions util/topgen/templates/toplevel.rs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import textwrap
import topgen.lib as lib

has_pwrmgr = lib.find_module(top['module'], 'pwrmgr')
has_pinmux = lib.find_module(top['module'], 'pinmux')
%>\
${helper.file_header.render()}
// This file was generated automatically.
Expand All @@ -22,7 +23,9 @@ ${helper.file_header.render()}
//! - Device Memory Information (for Peripherals and Memory)
//! - PLIC Interrupt ID Names and Source Mappings
//! - Alert ID Names and Source Mappings
% if has_pinmux:
//! - Pinmux Pin/Select Names
% endif
% if has_pwrmgr:
//! - Power Manager Wakeups
% endif
Expand Down Expand Up @@ -111,6 +114,7 @@ ${helper.plic_mapping.render_definition()}
/// This array is a mapping from `${helper.alert_alerts.short_name.as_rust_type()}` to
/// `${helper.alert_sources.short_name.as_rust_type()}`.
${helper.alert_mapping.render_definition()}
% if has_pinmux:

// PERIPH_INSEL ranges from 0 to NUM_MIO_PADS + 2 -1}
// 0 and 1 are tied to value 0 and 1
Expand Down Expand Up @@ -139,6 +143,7 @@ ${helper.direct_pads.render(gen_cast=True)}

/// Muxed Pad Selects
${helper.muxed_pads.render(gen_cast=True)}
% endif
% if has_pwrmgr:

/// Power Manager Wakeup Signals
Expand Down

0 comments on commit e7b74af

Please sign in to comment.