Exporter API#

If you are not using the PeakRDL command-line tool, you can still generate busdecoders programmatically using the exporter API:

class peakrdl_busdecoder.BusDecoderExporter(**kwargs: Unpack[ExporterKwargs])#
export(node: RootNode | AddrmapNode, output_dir: str, **kwargs: Unpack[ExporterKwargs]) → None#
Parameters:
  • node (AddrmapNode) – Top-level SystemRDL node to export.

  • output_dir (str) – Path to the output directory where generated SystemVerilog will be written. Output includes two files: a module definition and package definition.

  • cpuif_cls (peakrdl_busdecoder.cpuif.CpuifBase) – Specify the class type that implements the CPU interface of your choice. Defaults to AMBA APB4.

  • module_name (str) – Override the SystemVerilog module name. By default, the module name is the top-level node’s name.

  • package_name (str) – Override the SystemVerilog package name. By default, the package name is the top-level node’s name with a “_pkg” suffix.

  • address_width (int) – Override the CPU interface’s address width. By default, address width is sized to the contents of the busdecoder.

  • data_width (int) – Override the CPU interface’s data width with a power of two of at least 8 bits, no smaller than the widest internal register accesswidth. By default, the width is inferred from internal register accesswidths, or falls back to 32 bits with a warning when none are available.

  • cpuif_unroll (bool) – Unroll arrayed addressable nodes into separate instances in the CPU interface. By default, arrayed nodes are kept as arrays.

  • max_decode_depth (int) – Maximum depth for address decoder to descend into nested addressable components. A value of 0 decodes all levels (infinite depth). A value of 1 decodes only top-level children. A value of 2 decodes top-level and one level deeper, etc. By default, the decoder descends 1 level deep.

  • clk_src (str | None) –

    Selects where the bus decoder gets its clock and reset. None (default) resolves to “off” for unbuffered APB and “design” for buffered APB and AXI4-Lite.

    • ”off”: no clock/reset ports or logic. Only unbuffered APB supports this mode, preserving the 0.7.x APB port shape.

    • ”cpuif”: clk/reset are bundled with the CPU interface. The slave bus carries the protocol-defined clock/reset (PCLK/PRESETn for APB, ACLK/ARESETn for AXI4-Lite). Flat master ports forward clock/reset; SystemVerilog interface endpoints must be wired externally because their modports treat these as inputs.

    • ”design”: the CPU interface carries no clk/reset. The module exposes top-level clk and rst ports; the design is responsible for distributing clock/reset to downstream slaves.

    AHB-Lite always uses ingress HCLK/HRESETn, ignores “design” and “cpuif”, and rejects “off”.

  • gate_signals (bool) – Gate downstream broadcast payload signals with the per-slave select. For APB this drives PADDR/PWDATA/PSTRB/PPROT to ‘0 on unselected masters. By default, payload signals fan out unmodified. PENABLE is always gated with the per-slave select.

  • apb_buffer (str) – Select transaction-aware APB request/response buffering. “none” (default) leaves the combinational path unchanged. “in” captures request payload at the upstream SETUP edge and holds it through one downstream SETUP/ACCESS transfer; the response remains combinational and child/upstream completion share an edge. “out” forwards live upstream payload, captures the child response at completion, removes the child request, and retains the registered response until upstream acceptance. “both” combines these stages. Only one transfer may be outstanding. With no child waits, upstream ACCESS takes 1/2/2/3 cycles for none/in/out/both; minimum completion spacing including SETUP is 2/3/3/4 cycles. Each child wait adds one. Non-“none” modes require APB and clk_src='design' (selected automatically when clk_src is None) and use design clk and active-high asynchronous rst. Reset clears retained state, suppresses child requests/upstream ready, and aborts pending work without undoing completed child side effects. A fresh upstream SETUP is required after reset; held stale ACCESS is not replayed.

  • axi4lite_max_outstanding (int) – Maximum accepted AXI4-Lite read transactions and paired write transactions retained by their respective order queues. Defaults to 4. AW and W each also have one independent holding register.

Clock/reset selection#

Omitting clk_src or passing clk_src=None selects "off" for unbuffered APB and "design" for buffered APB and AXI4-Lite. The explicit values are "off", "cpuif", and "design". Unbuffered APB’s default preserves its clockless 0.7.x decoder port shape. Non-"none" apb_buffer requires "design"; explicit "off" or "cpuif" with buffering is rejected. Omit clk_src, select "design", or disable buffering.

AXI4-Lite rejects "off"; use the default "design" or select "cpuif" and connect the corresponding clock/reset. AHB-Lite always requires ingress HCLK/HRESETn: it ignores "design" and "cpuif" and rejects "off". See Introduction for port and wiring details and Migrating from 0.7.x for updated APB imports.

Example#

Below is a simple example that demonstrates how to generate a SystemVerilog implementation from SystemRDL source.

import sys

from systemrdl import RDLCompiler, RDLCompileError
from peakrdl_busdecoder import BusDecoderExporter
from peakrdl_busdecoder.cpuif.axi4lite import AXI4LiteCpuif

input_files = [
    "PATH/TO/my_register_block.rdl"
]

# Create an instance of the compiler
rdlc = RDLCompiler()

try:
    # Compile your RDL files
    for input_file in input_files:
        rdlc.compile_file(input_file)

    # Elaborate the design
    root = rdlc.elaborate()
except RDLCompileError:
    # A compilation error occurred. Exit with error code
    sys.exit(1)

# Export a SystemVerilog implementation
exporter = BusDecoderExporter()
exporter.export(
    root, "path/to/output_dir",
    cpuif_cls=AXI4LiteCpuif,
    clk_src="design",  # Wire the generated clk/rst inputs in the RTL design.
)