Working with Python API

The recommended way of defining your registers and fields is to use a .toml data file. However depending on your needs it might make sense to define them directly in Python instead. This page will showcase a simple example of how to get started with this.

The Python code below sets up a RegisterList with two Registers and some fields. After this it performs a VHDL code generation.

Register TOML format example.
 1# Standard libraries
 2import sys
 3from pathlib import Path
 5# First party libraries
 6from hdl_registers.generator.vhdl.register_package import VhdlRegisterPackageGenerator
 7from hdl_registers.register_list import RegisterList
10def main(output_folder: Path):
11    """
12    Set up some dummy registers and fields using the Python API.
13    """
14    register_list = RegisterList(name="caesar")
16    register = register_list.append_register(
17        name="config", mode="r_w", description="Configuration register."
18    )
20    register.append_bit_vector(
21        name="tuser",
22        description="Value to set for **TUSER** in the data stream.",
23        width=4,
24        default_value="0101",
25    )
27    register.append_integer(
28        name="increment",
29        description="Offset that will be added to data.",
30        min_value=-4,
31        max_value=3,
32        default_value=0,
33    )
35    register = register_list.append_register(
36        name="status", mode="r", description="General status register."
37    )
39    VhdlRegisterPackageGenerator(register_list=register_list, output_folder=output_folder).create()
42if __name__ == "__main__":
43    main(output_folder=Path(sys.argv[1]))

The articles in the the menubar on the left all showcase how to utilize the different features using the Python API as well as a TOML file. Please read these articles for further information.