From ab6650b2d02d0aa68ca2ce97ef47bb8a459a57ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Gr=C3=B8ndahl=20Olsen?= <22944947+RasmusGOlsen@users.noreply.github.com> Date: Mon, 8 Jan 2024 18:03:45 +0100 Subject: [PATCH] Add user defined properties cpuif and addrwidth --- hdl-src/regblock_udps.rdl | 10 ++++++++++ src/peakrdl_regblock/__peakrdl__.py | 18 +++++++++++++++--- src/peakrdl_regblock/udps/__init__.py | 3 +++ src/peakrdl_regblock/udps/cpuif.py | 24 ++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/peakrdl_regblock/udps/cpuif.py diff --git a/hdl-src/regblock_udps.rdl b/hdl-src/regblock_udps.rdl index d9e36ba..593b15c 100644 --- a/hdl-src/regblock_udps.rdl +++ b/hdl-src/regblock_udps.rdl @@ -36,3 +36,13 @@ property wr_swacc { component = field; type = boolean; }; + +property cpuif { + component = addrmap; + type = string; +}; + +property addrwidth { + component = addrmap; + type = longint unsigned; +}; diff --git a/src/peakrdl_regblock/__peakrdl__.py b/src/peakrdl_regblock/__peakrdl__.py index c7de7a5..a0bf2d5 100644 --- a/src/peakrdl_regblock/__peakrdl__.py +++ b/src/peakrdl_regblock/__peakrdl__.py @@ -86,7 +86,6 @@ def add_exporter_arguments(self, arg_group: 'argparse.ArgumentParser') -> None: arg_group.add_argument( "--cpuif", choices=cpuifs.keys(), - default="apb3", help="Select the CPU interface protocol to use [apb3]" ) @@ -202,12 +201,25 @@ def do_export(self, top_node: 'AddrmapNode', options: 'argparse.Namespace') -> N else: raise RuntimeError + # Get cpuif. Favor command-line over SystemRDL, defaults to apb3. + if options.cpuif is not None: + cpuif = cpuifs[options.cpuif] + elif top_node.get_property('cpuif') is not None: + cpuif_name = top_node.get_property('cpuif') + if cpuif_name not in cpuifs: + raise RuntimeError(f"error: unknown cpuif: {cpuif_name} (choose from: {' '.join(cpuifs.keys())})") + cpuif = cpuifs[cpuif_name] + else: + cpuif = cpuifs['apb3'] + + # Get cpuif addr_width. Favor command-line over SystemRDL. + addr_width = options.addr_width or top_node.get_property('addrwidth') x = RegblockExporter() x.export( top_node, options.output, - cpuif_cls=cpuifs[options.cpuif], + cpuif_cls=cpuif, module_name=options.module_name, package_name=options.package_name, reuse_hwif_typedefs=(options.type_style == "lexical"), @@ -218,7 +230,7 @@ def do_export(self, top_node: 'AddrmapNode', options: 'argparse.Namespace') -> N retime_external_mem=retime_external_mem, retime_external_addrmap=retime_external_addrmap, generate_hwif_report=options.hwif_report, - address_width=options.addr_width, + address_width=addr_width, default_reset_activelow=default_reset_activelow, default_reset_async=default_reset_async, ) diff --git a/src/peakrdl_regblock/udps/__init__.py b/src/peakrdl_regblock/udps/__init__.py index 5c40f24..7dcc9d6 100644 --- a/src/peakrdl_regblock/udps/__init__.py +++ b/src/peakrdl_regblock/udps/__init__.py @@ -1,6 +1,7 @@ from .rw_buffering import BufferWrites, WBufferTrigger from .rw_buffering import BufferReads, RBufferTrigger from .extended_swacc import ReadSwacc, WriteSwacc +from .cpuif import CpuIf, AddrWidth ALL_UDPS = [ BufferWrites, @@ -9,4 +10,6 @@ RBufferTrigger, ReadSwacc, WriteSwacc, + CpuIf, + AddrWidth, ] diff --git a/src/peakrdl_regblock/udps/cpuif.py b/src/peakrdl_regblock/udps/cpuif.py new file mode 100644 index 0000000..f679289 --- /dev/null +++ b/src/peakrdl_regblock/udps/cpuif.py @@ -0,0 +1,24 @@ +from typing import TYPE_CHECKING, Any + +from systemrdl.udp import UDPDefinition +from systemrdl.component import Addrmap + +if TYPE_CHECKING: + from systemrdl.node import Node + +class CpuIf(UDPDefinition): + name = "cpuif" + valid_components = {Addrmap} + valid_type = str + + def get_unassigned_default(self, node: 'Node') -> Any: + return None + + +class AddrWidth(UDPDefinition): + name = "addrwidth" + valid_components = {Addrmap} + valid_type = int + + def get_unassigned_default(self, node: 'Node') -> Any: + return None