hdl_registers.generator.python package
Submodules
hdl_registers.generator.python.accessor module
- class hdl_registers.generator.python.accessor.PythonAccessorGenerator(register_list: RegisterList, output_folder: Path)
Bases:
RegisterCodeGenerator
Generate a Python class to read/write/print register and field values on a target device. Field and register values are represented using their native Python types, for easy handling. Meaning, no manual type casting back and forth for the user.
See the Python code generator article for usage details. See also
PythonRegisterAccessorInterface
.Needs to have the result from the
PythonPickleGenerator
generator in the same output folder.- SHORT_DESCRIPTION = 'Python accessor'
hdl_registers.generator.python.pickle module
- class hdl_registers.generator.python.pickle.PythonPickleGenerator(register_list: RegisterList, output_folder: Path)
Bases:
RegisterCodeGenerator
Generate a Python pickle of the
RegisterList
object, along with a Python module to re-create the pickle in a simple way.See the Python code generator article for usage details.
- SHORT_DESCRIPTION = 'Python pickle'
- __init__(register_list: RegisterList, output_folder: Path)
- Parameters:
register_list – Registers and constants from this register list will be included in the generated artifacts.
output_folder – Result file will be placed in this folder.
- create(**kwargs: Any) Path
Create the binary pickle also, apart from the class file.
Note that this is a little bit hacky, preferably each generator should produce only one file.
- get_code(**kwargs: Any) str
Save register list object to binary file (pickle) and create a python class that recreates it.
- property should_create: bool
Since this generator creates two files, where one is binary, it is impossible to do the version/hash check. Hence, set it to “always create”. The mechanism “create if needed” should not be used for this generator anyway, since this generator is not designed to run in real-time like e.g. the VHDL generator.
hdl_registers.generator.python.register_accessor_interface module
- class hdl_registers.generator.python.register_accessor_interface.PythonRegisterAccessorInterface
Bases:
ABC
Interface base class for accessing register values on a target system. To be used with code generated by
PythonAccessorGenerator
. See the Python generator documentation for usage details.In order to use
PythonAccessorGenerator
class to read/write/print register and field values, you must implement the methods of this interface in a subclass. You must implement them to use whichever method you have available to access register values on your target (SSH, telnet, UART, …). These details vary greatly in different projects, and is something that hdl-registers can not provide a generic solution for.The byte address that shall be accessed, in both the methods, is
register_list_base_address + register_address
where
register_list_base_address
is the the base address of the requested register list on your register bus. Logic for finding this base address, probably usingregister_list_name
, must be implemented given the layout of your system.You are free to raise any exceptions you want in your implementation of the methods. For example, unknown register list name, invalid address, timeout, bus error, etc. Exceptions will not be caught by
PythonAccessorGenerator
code, but will instead be propagated to the user wherever the accessor is used.- abstract read_register(register_list_name: str, register_address: int) int
Read the value of a register.
- Parameters:
register_list_name – Name of the register list that the requested register belongs to.
register_address – Byte address of the register, within the register list.
- Returns:
The register value that was read, as an unsigned 32-bit number.
- abstract write_register(register_list_name: str, register_address: int, register_value: int) None
Write a register.
- Parameters:
register_list_name – Name of the register list that the requested register belongs to.
register_address – Byte address of the register, within the register list.
register_value – The value that shall be written, as an unsigned 32-bit number.