-
Notifications
You must be signed in to change notification settings - Fork 49
Description
The IP-XACT standard allows for an optional mask element inside a field reset element. This is used to define which bits of the field have a known reset value. The absence of the mask element makes this N/A, i.e. it is equivalent to a mask of the same size as the register field and consisting of all 1's.
When the latter situation occurs, the ipyxact parser (v0.3.2) still evaluates the mask as all 0's. This violates the standard and makes impossible to discriminate between a mask of all 0's and an absent mask (i.e. N/A or all 1's).
For instance, consider the ipxact.xml sample below:
<ipxact:component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ipxact="http://www.accellera.org/XMLSchema/IPXACT/1685-2014" xsi:schemaLocation="http://www.accellera.org/XMLSchema/IPXACT/1685-2014/index.xsd">
<ipxact:vendor>some_vendor</ipxact:vendor>
<ipxact:library>some_library</ipxact:library>
<ipxact:name>some_component</ipxact:name>
<ipxact:version>1.0</ipxact:version>
<ipxact:memoryMaps>
<ipxact:memoryMap>
<ipxact:name>some_memory_map</ipxact:name>
<ipxact:addressBlock>
<ipxact:name>some_address_block</ipxact:name>
<ipxact:baseAddress>0x0</ipxact:baseAddress>
<ipxact:range>1</ipxact:range>
<ipxact:width>32</ipxact:width>
<ipxact:register>
<ipxact:name>some_register</ipxact:name>
<ipxact:addressOffset>0x0</ipxact:addressOffset>
<ipxact:size>32</ipxact:size>
<ipxact:access>read-write</ipxact:access>
<ipxact:field>
<ipxact:name>without_mask</ipxact:name>
<ipxact:bitOffset>0</ipxact:bitOffset>
<ipxact:resets>
<ipxact:reset>
<ipxact:value>0xff</ipxact:value> <!-- No mask here, i.e. should be N/A or all 1's -->
</ipxact:reset>
</ipxact:resets>
<ipxact:bitWidth>8</ipxact:bitWidth>
<ipxact:access>read-write</ipxact:access>
</ipxact:field>
<ipxact:field>
<ipxact:name>with_zero_mask</ipxact:name>
<ipxact:bitOffset>8</ipxact:bitOffset>
<ipxact:resets>
<ipxact:reset>
<ipxact:value>0xff</ipxact:value>
<ipxact:mask>0x0</ipxact:mask> <!-- This mask is all 0's -->
</ipxact:reset>
</ipxact:resets>
<ipxact:bitWidth>8</ipxact:bitWidth>
<ipxact:access>read-write</ipxact:access>
</ipxact:field>
<ipxact:field>
<ipxact:name>with_nonzero_mask</ipxact:name>
<ipxact:bitOffset>16</ipxact:bitOffset>
<ipxact:resets>
<ipxact:reset>
<ipxact:value>0xff</ipxact:value>
<ipxact:mask>0xff</ipxact:mask> <!-- This mask is all 1's -->
</ipxact:reset>
</ipxact:resets>
<ipxact:bitWidth>8</ipxact:bitWidth>
<ipxact:access>read-write</ipxact:access>
</ipxact:field>
</ipxact:register>
</ipxact:addressBlock>
<ipxact:addressUnitBits>8</ipxact:addressUnitBits>
</ipxact:memoryMap>
</ipxact:memoryMaps>
</ipxact:component>When parsed:
from ipyxact.ipyxact import Component
component = Component()
component.load("ipxact.xml")
register = component.memoryMaps.memoryMap[0].addressBlock[0].register[0]
fields = register.field
print(f'Printing fields from register {register.name}:')
for f in fields:
_reset = f.resets.reset.value
_mask = f.resets.reset.mask
print(f' Field {f.name} has reset value of x{_reset:X} and mask of x{_mask:X} --> overall reset value: x{_reset & _mask:X}')It yields:
Printing fields from register some_register:
Field without_mask has reset value of xFF and mask of x0 --> overall reset value: x0
Field with_zero_mask has reset value of xFF and mask of x0 --> overall reset value: x0
Field with_nonzero_mask has reset value of xFF and mask of xFF --> overall reset value: xFF
As you can see, fields without_mask and with_zero_mask are both evaluated with a mask of all 0's and there's no way to tell the former doesn't have a mask defined in the first place. I believe the above considerations also applies to register resets as per IP-XACT 2009, even though I haven't tested it.
I suspect this behavior is due to:
- The
IpxactInttype being used for mask insideipyxact_yaml.py. - Line 150 of
ipyxact.pysetting an attribute value ofeval(_type)()if the element is not found when parsing the IP-XACT.
The preferred behavior for me would be not to create a mask attribute inside the reset class if there's no mask in the IP-XACT, but it may involve a re-structuring on how the parser works.
A sub-optimal solution could be creating another integer type that defaults to all 1's and use it for the mask. However, note that in this case there's no easy way to dynamically adjust the number of bits that should be 1 w.r.t. the field/register size, so a worst-case guess is needed (a bit of an hack).