PeakRDL C-Header is a Python package used to generate a C Header file, typically representing a register abstraction layer, from a SystemRDL register model. It enables direct C-language access to hardware registers by generating C struct definitions that mirror the hardware address space. The library is currently active, with its latest version being 1.1.0, and maintains a regular release cadence, with updates addressing features and fixes.
pip install peakrdl-cheaderVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `peakrdl-cheader` via its Python API. It involves compiling a SystemRDL file using `systemrdl.RDLCompiler` to obtain an elaborated register model, then passing this model to `CHeaderExporter.export()` with desired configuration options to generate a C header file. This approach is useful for integrating the generator into custom build pipelines. Alternatively, for command-line usage, the `peakrdl` CLI tool provides a `c-header` subcommand.
Review the LGPLv3 license terms to ensure compatibility with your project's licensing and compliance requirements.
When enabling bitfield generation, set `bitfield_order_ltoh=True` or `bitfield_order_ltoh=False` (for HTOL) in the `CHeaderExporter` constructor, or use the `--bitfields ltoh` or `--bitfields htol` CLI options. Run generated test cases on your target to verify correctness.
Utilize the `type_style` parameter (e.g., 'lexical' or 'hierarchical') to control how C `typedef` names are generated. 'hierarchical' style uses the component's full hierarchy to ensure unique names.
For designs with registers > 64 bits, explicitly set `wide_reg_subword_size` (e.g., 8, 16, 32, or 64) in the `CHeaderExporter` to define the desired sub-word array size.
When using `generate_bitfields=True`, ensure `bitfield_order_ltoh` is set correctly to `True` or `False` based on your C compiler's behavior. Example: `exporter = CHeaderExporter(generate_bitfields=True, bitfield_order_ltoh=True)`.
Adjust the `type_style` parameter in `CHeaderExporter`. Use `type_style="hierarchical"` to derive names from the full SystemRDL component hierarchy for uniqueness, or `type_style="lexical"` to use RDL lexical scope names.
Set the `wide_reg_subword_size` parameter in `CHeaderExporter` to specify how larger registers should be broken down (e.g., `wide_reg_subword_size=32` for an array of 32-bit words).