Skip to content

Commit

Permalink
Fix NumRegField byte(s) read (#392)
Browse files Browse the repository at this point in the history
Description
NumRegField read worked fine when the fields were single bit. Now that we have RegBitsFields with multiple bits we need to adjust the mask accordingly.

Motivation and Context
NumRegFields having RegBitsFields did not read the byte correctly. This is now fixed with this change.
  • Loading branch information
prgeor authored Aug 14, 2023
1 parent ae7049c commit 636a3a9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sonic_platform_base/sonic_xcvr/fields/xcvr_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, name, offset, **kwargs):
self.offset = offset
self.ro = kwargs.get("ro", True)
self.deps = kwargs.get("deps", [])
self.bitmask = None

def get_fields(self):
"""
Expand Down Expand Up @@ -86,6 +87,7 @@ def __init__(self, name, bitpos, offset=None, **kwargs):
super(RegBitField, self).__init__(name, offset, **kwargs)
assert bitpos < 64
self.bitpos = bitpos
self.bitmask = 1 << self.bitpos

def get_size(self):
return 1
Expand Down Expand Up @@ -115,7 +117,7 @@ class RegBitsField(XcvrField):
def __init__(self, name, bitpos, offset=None, **kwargs):
super(RegBitsField, self).__init__(name, offset, **kwargs)
self.size = self.size = kwargs.get("size", 1) #No of bits
assert (bitpos >= 0 and (bitpos+self.size-1 < 8), "bitpos must be within one byte")
assert bitpos >= 0 and bitpos+self.size <= 8, "bitpos must be within one byte"
self.bitpos = bitpos
self.bitmask = (((1 << self.size) - 1) << self.bitpos) & 0xff

Expand Down Expand Up @@ -159,7 +161,7 @@ def get_bitmask(self):
return None
mask = 0
for field in self.fields:
mask |= 1 << field.bitpos
mask |= field.bitmask
return mask

def get_size(self):
Expand Down

0 comments on commit 636a3a9

Please sign in to comment.