hardwareregister
Provide an abstract representation of hardware registers that allows defining registers and fields as a generic description without having to write boilerplate code.
- class pymisclib.hardwareregister.Register(name: str, offset: int, description: RegisterDescription)
A register at an offset with a name and description.
- __init__(name: str, offset: int, description: RegisterDescription)
Initialize self.
- Parameters:
name¶ (str) – Name of the register.
offset¶ (int) – Offset of the register.
description¶ (RegisterDescription) – Description of the register.
- property description: RegisterDescription
Description of the register.
- property name: str
Return the register name.
- property offset: int
Offset of the register in memory.
- class pymisclib.hardwareregister.RegisterDescription(nr_bits: int, fields: list[RegisterField])
Describes the layout and fields of a register.
- __init__(nr_bits: int, fields: list[RegisterField])
Initialize self.
- Parameters:
nr_bits¶ (int) – Number of bits in the register.
fields¶ (list[RegisterField]) – Fields of the register.
- Raises:
IndexError – An error was found in the fields.
KeyError – A field name was used multiple times.
- check_field_consistency()
Check that the fields are consistently defined.
- Raises:
IndexError – An error was found in the fields.
- field(name: str) RegisterField
Return the field with the given name.
- Parameters:
name¶ (str) – Name of the field.
- Raises:
KeyError – The given name is not a field.
- fields_by_end_bit() Generator[RegisterField, None, None]
Yield all register fields in falling order of their end bit.
- Returns:
A register field per call.
- Return type:
- fields_by_start_bit() Generator[RegisterField, None, None]
Yield all register fields in rising order of their start bit.
- Returns:
A register field per call.
- Return type:
- mask_keep_field(field: RegisterField) int
Create a mask to remove all bits not belonging to the field.
- Parameters:
field¶ (RegisterField) – The field to mask.
- Returns:
A mask leaving only the bits belonging to the field.
- mask_remove_field(field: RegisterField) int
Create a mask to remove all bits belonging to the field.
- Parameters:
field¶ (RegisterField) – The field to mask.
- Returns:
A mask removing all bits belonging to the field.
- class pymisclib.hardwareregister.RegisterField(name: str, first_bit: int = 0, last_bit: int = 31, conversion: Type = None)
Describe a field in a register.
- __init__(name: str, first_bit: int = 0, last_bit: int = 31, conversion: Type = None)
Initialize the instance.
- Parameters:
- Raises:
IndexError – last_bit is smaller than first_bit.
- convert(value: Any) Any
Convert the given value to the type of the field.
- property conversion: Type
Return class used to convert the value.
- property first_bit: int
First bit of the register containing the field.
- property last_bit: int
Last bit of the register containing the field.
- property mask: int
A mask leaving only bits contained in the field.
- property name: str
Name of the field.
- property type: Type
Type of the field.
- class pymisclib.hardwareregister.RegisterFieldBool(name: str, bit: int)
A field in a register that is a single bit.
- class pymisclib.hardwareregister.RegisterFieldEnum(name: str, first_bit: int, last_bit: int, conversion: Type[IntEnum] | Type[IntFlag])
- __init__(name: str, first_bit: int, last_bit: int, conversion: Type[IntEnum] | Type[IntFlag])
Initialize the instance.
- class pymisclib.hardwareregister.RegisterFieldInt(name: str, first_bit: int, last_bit: int)
A register field containing an integral value.
- __init__(name: str, first_bit: int, last_bit: int)
Initialize the instance.
- property max_value: int
Maximum allowed value in the field (inclusive).
- property min_value: int
Minimum allowed value in the field (inclusive).
- class pymisclib.hardwareregister.RegisterValue(name: str, offset: int, description: RegisterDescription, value: int)
- __init__(name: str, offset: int, description: RegisterDescription, value: int)
Initialize self.
- Parameters:
name¶ (str) – Name of the register.
offset¶ (int) – Offset of the register.
description¶ (RegisterDescription) – Description of the register.
- set(name: str, value: bool | int | IntEnum | IntFlag)
Set the value of the named field in the register.
- property value: int
Return the register value as an integer.