Python API

If you want to embed this tool into your own script, you can do so with the following API.

Example

The following example shows how to compile a SystemRDL file and then generate the C header using the Python API.

from systemrdl import RDLCompiler
from peakrdl_cheader.exporter import CHeaderExporter

# compile the SystemRDL
rdlc = RDLCompiler()
rdlc.compile_file('example.rdl')
top = rdlc.elaborate()

# generate the C header
exporter = CHeaderExporter()
exporter.export(node=top, path='out.h')

Exporter Class

class peakrdl_cheader.exporter.CHeaderExporter
export(node: RootNode | AddrmapNode, path: str, **kwargs: Any) None
Parameters:
  • node (AddrmapNode) – Top-level SystemRDL node to export.

  • path (str) – Output header file path

  • std (CStandard) – Select which GNU C standard to conform to

  • reuse_typedefs (bool) –

    By default, the exporter will attempt to re-use typedefs for nodes that are equivalent. This allows for better modularity and type reuse. Struct type names are derived using the SystemRDL component’s type name and declared lexical scope path.

    If this is not desireable, override this parameter to False and structs will be generated more naively using their hierarchical paths.

  • generate_bitfields (bool) – If set, registers are exported as nested union/structs to provide structured access to individual bitfields.

  • bitfield_order_ltoh (bool) – The packing order of C struct bitfields is implementation defined. If True, packing will assume low-to-high bit-packing order.

  • wide_reg_subword_size (int) – C’s <stdint.h> types only extend up to 64-bit types. If a register is encountered that is larger than this, the generated header will represent it using an array of smaller sub-words. Set the desired sub-word size. Shall be 8, 16, 32 or 64.

  • explode_top (bool) –

    If set, the top-level hiearchy is skipped. Instead, definitions for all the direct children are generated.

    Note that only block-like definitons are generated. i.e: children that are registers are skipped.

  • instantiate (bool) – If set, header will also include a macro that instantiates each top-level block at a defined hardware address, allowing for direct access.

  • inst_offset (int) – Apply an additional address offset to instance definitions.

  • testcase (bool) – Generate a testcase C file