Hardware registers test value generation based on register fields attribute (RO/WR...)

Hi
the problem i have is the following … i have a 64-bit register that has fields that can be RO (read only) or WR(Write) . I would like to write a python script that will inspect the register fields and generate a test value based on the register writable fields - Any help ?
thank you

Insufficient information.

What kind of hardware are you dealing with?

What information are you looking for when inspecting the registers?

What kind of test values do you want to generate?

just a basic SoC register let s say a 32-bit or 64-bit register where some bits can be read only and other can be writable …
the test value i want will only write to the register fields that are writable and leave alone those that are read only

i mean by inspecting the register is just processing the register fields attribute to identify the fields that are only writable then if the field had a value , the value will be flipped … then move to the remaining fields to do the same until we have a complete value test that can be written to the registeronly writable fields

Python is not a hardware-aware language by itself. You need an operating system or a driver or a library to provide an abstraction layer in order for Python to be able to interface with your hardware registers.

What kind of abstraction are you using? Are the registers files in a file system? Accessed via a serial bus? Something else?

the environment that i am using already have the abstraction layer , all i need to the script to process a given register fields attributes and generate the value that can be written into that register … nothing sophisticated

there are register files in the system that i am already accessing

How are you currently reading from / writing to these registers? How are you getting their attributes?

yes i am reading and writing but need to be able to write only writable fields

i parse the register file and extract the register by name or node

You haven’t provided enough information about your system for anyone to be able to help you. Do you have some kind of documentation you could share? A user manual perhaps?

here is what i am doing currently …
def change_value_based_on_attribute(register, test_value):
current_ro_value = 0x0
list_of_lists =
mask = MAX_POSSIBLE_VALUE_32_BITS
for item in register.iter_nodes():
#print(item.info[‘attribute’])
#print(‘Phase 1: Verifing WAC regs’)
list_of_lists.append([item.info[‘attribute’],
__get_value_to_shift(item.info[‘lowerbit’], item.info[‘numbits’]),
int(item.read()) << item.info[‘lowerbit’]])
for item in list_of_lists:
#print(item)
#print('Phase 2: ')
if ‘ro’ in item[0] or ‘rsv’ in item[0]:
mask = mask ^ item[1]
#print(mask)
#print(‘Phase 3: Verifing WAC regs’)
current_ro_value = current_ro_value + item[2]
#print(current_ro_value)
if mask == 0x0:
raise RegisterAttributesAllNonWritable
else:
return (test_value & mask) + current_ro_value


def get_random_test_value(register, check_register_attributes=False):
‘’’
This function returns a random test value depending of the parameters

        Args:
            register (RegisterValue): Register object that will be verified to get a random value that fits
            current_value (int): Current value of the register, if not is sended, the function will 
                                try to read the value of the register
            check_register_attributes (bool): Flag that will mark if the attributes of the fields from the register
                                              need to be checked 
        Returns:
            test_value (int): 
    '''
# Get register size
reg_size = get_register_size(register)
max_value = 0xFFFF
# Change the max possible value depending on the size of the register
if reg_size == 32:
    max_value = MAX_POSSIBLE_VALUE_32_BITS
elif reg_size == 64:
    max_value = MAX_POSSIBLE_VALUE_64_BITS
# Trying to read the value of the register if non was sended
# Getting a random value
test_value = random.randint(1, max_value)
#print("Random number between 1 and 10 is % s" % (test_value))
# Checking that the test value gotten is different to the current '
if check_register_attributes:
    test_value = change_value_based_on_attribute(register, test_value)
while test_value == 0x0:
    test_value = random.randint(1, max_value)
    # Checking that the test value gotten is different to the current '
    if check_register_attributes:
        test_value = change_value_based_on_attribute(register, test_value)
return test_value

when i run these 2 methods the test value resulting still fails to ignore read only bit fields - hope this helps?

It would be more helpful if you formatted it properly. But I can already see this is not your whole program. In particular, both of these functions rely heavily on a type of object called RegisterValue. I’d need to see at least the implementation of that class as well.

Furthermore, it’s not clear what your actual problem is. What does it mean for the test value to “fail to ignore read only bit fields”? What is the purpose of the test value? What is it supposed to test?

is this you want to see ?
def get_register_object(root, reg_path):
“”" Function that finds a register by its string path and returns it as Register
object.
:param reg_path: string name of the register.
:param root: root component of the project. Must be passed as an object and not str.
:return reg_obj: register object.
“”"
reg_obj = None
try:
reg_obj = root.get_by_path(reg_path)
except (ValueError, AttributeError):
print(‘Invalid register: {}’.format(reg_path))

return reg_obj

def find_type_of_register(register):
“”" Helper function to find if register is an array of registers and return
the list of registers.
:param register: register object to do the validation. This parameter needs
to be passed as a register object and not a string.
:return reg_array: list of registers found if register has an ArrayValue.
“”"
reg_array =
if isinstance(register, namednodes.nodes.NamedNodeArrayValue):
reg_array = [element.path for element in register]
print(‘Found array of registers with {} items: {}’.format(len(reg_array), register.path))
else:
print(‘Unable to find register: {}’.format(register))

return reg_array

What does it mean for the test value to “fail to ignore read only bit fields”? [i mean here that the test value will be generated in such a way that when written the value will uniquely write into the fields that are only writable and leave the read only bits alone ]

What is the purpose of the test value? What is it supposed to test? [ the purpose of the test value is to check if i can correctly modify the writable fields of the register ]

No. Somewhere there will be a definition starting with something like

class RegisterValue:

or

class RegisterValue(SomeOtherClass):

That’s what I need to see. And please, use the </> button to format your code properly.

In here : <register (RegisterValue): Register object that will be verified to get a random value that fits />
the " RegisterValue " is just a comment

first thing i do : i get the top componet: < def get_top_component(reg_obj):/>
then i obtain the register sub_component: <def get_register_subcomponent(reg_obj):/>

then the register offset: <get_offset(register): />

Yes, but somewhere that object is defined. The code relies heavily on methods belonging to that class, so it’s hard to say what might be going wrong without seeing the implementation.

And what is a

  • top component?
  • sub component?
  • register offset?