Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linkedGet and linkedSet calls in Rogue Devices #1161

Merged
merged 11 commits into from
Jun 19, 2024
5 changes: 5 additions & 0 deletions python/surf/axi/_AxiLiteMasterProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, pollPeriod=0.0, **kwargs):
offset = 0x00,
bitOffset = 0,
bitSize = 1,
groups = ['NoStream','NoState','NoConfig'],
enum = {
0: "Write",
1: "Read",
Expand All @@ -42,13 +43,15 @@ def __init__(self, pollPeriod=0.0, **kwargs):
bitOffset = 0,
bitSize = 1,
base = pr.Bool,
groups = ['NoStream','NoState','NoConfig'],
))

self.add(pr.RemoteVariable(
name = 'Resp',
offset = 0x04,
bitOffset = 1,
bitSize = 2,
groups = ['NoStream','NoState','NoConfig'],
enum = {
0 : 'OK',
1 : 'EXOK',
Expand All @@ -62,13 +65,15 @@ def __init__(self, pollPeriod=0.0, **kwargs):
offset = 0x08,
bitOffset = 0,
bitSize = 32,
groups = ['NoStream','NoState','NoConfig'],
))

self.add(pr.RemoteVariable(
name = 'Data',
offset = 0x0C,
bitOffset = 0,
bitSize = 32,
groups = ['NoStream','NoState','NoConfig'],
))

def proxyTransaction(self, transaction):
Expand Down
2 changes: 1 addition & 1 deletion python/surf/axi/_AxiStreamDmaFifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __init__(self, **kwargs):
mode = 'RO',
disp = '0x{:0x}',
dependencies = [self.AXI_BUFFER_WIDTH_G,self.MAX_FRAME_WIDTH_G],
linkedGet = lambda: 2**( int(self.AXI_BUFFER_WIDTH_G.value()) - int(self.MAX_FRAME_WIDTH_G.value()) )
linkedGet = lambda read: 2**( int(self.AXI_BUFFER_WIDTH_G.get(read=read)) - int(self.MAX_FRAME_WIDTH_G.get(read=read)) )
))

self.add(pr.RemoteVariable(
Expand Down
4 changes: 2 additions & 2 deletions python/surf/axi/_AxiStreamMonAxiL.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def addPair(name, offset, bitSize, units, bitOffset, description, function, poll
))

@staticmethod
ruck314 marked this conversation as resolved.
Show resolved Hide resolved
def convMbps(var):
return var.dependencies[0].value() * 8e-6
def convMbps(var, read):
return var.dependencies[0].get(read=read) * 8e-6

class AxiStreamMonAxiL(pr.Device):
def __init__(self, numberLanes=1, hideConfig=True, chName=None, **kwargs):
Expand Down
117 changes: 65 additions & 52 deletions python/surf/devices/amphenol/_LeapXcvrLowerPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pyrogue as pr

class LeapXcvrLowerPage(pr.Device):
def __init__(self, isTx = True, writeEn=False, **kwargs):
def __init__(self, isTx=True, writeEn=False, **kwargs):
super().__init__(**kwargs)

rwType = 'RW' if writeEn else 'RO'
Expand Down Expand Up @@ -134,23 +134,24 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
hidden = True,
))


if isTx:
self.add(pr.LinkVariable(
name = 'LosTx',
mode = 'RO',
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.LosTxLsb.value()+256*self.LosTxMsb.value(),
dependencies = [self.LosTxLsb,self.LosTxMsb],
linkedGet = self._getLsbMsb,
dependencies = [self.LosTxLsb, self.LosTxMsb],
))
else:
self.add(pr.LinkVariable(
name = 'LosRx',
mode = 'RO',
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.LosRxLsb.value()+256*self.LosRxMsb.value(),
dependencies = [self.LosRxLsb,self.LosRxMsb],
linkedGet = self._getLsbMsb,
dependencies = [self.LosRxLsb, self.LosRxMsb],
))

self.add(pr.RemoteVariable(
Expand All @@ -177,17 +178,17 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = 'RO',
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.FaultTxLsb.value()+256*self.FaultTxMsb.value(),
dependencies = [self.FaultTxLsb,self.FaultTxMsb],
linkedGet = self._getLsbMsb,
dependencies = [self.FaultTxLsb, self.FaultTxMsb],
))
else:
self.add(pr.LinkVariable(
name = 'FaultRx',
mode = 'RO',
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.FaultRxLsb.value()+256*self.FaultRxMsb.value(),
dependencies = [self.FaultRxLsb,self.FaultRxMsb],
linkedGet = self._getLsbMsb,
dependencies = [self.FaultRxLsb, self.FaultRxMsb],
))

self.add(pr.RemoteVariable(
Expand All @@ -213,8 +214,8 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = 'RO',
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.LolRxLsb.value()+256*self.LolRxMsb.value(),
dependencies = [self.LolRxLsb,self.LolRxMsb],
linkedGet = self._getLsbMsb,
dependencies = [self.LolRxLsb, self.LolRxMsb],
))

if isTx:
Expand All @@ -241,8 +242,8 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = 'RO',
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.LolTxLsb.value()+256*self.LolTxMsb.value(),
dependencies = [self.LolTxLsb,self.LolTxMsb],
linkedGet = self._getLsbMsb,
dependencies = [self.LolTxLsb, self.LolTxMsb],
))

self.add(pr.RemoteVariable(
Expand All @@ -264,12 +265,12 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
))

self.add(pr.LinkVariable(
name = 'TxTemp',
name = 'TxTempR',
mode = 'RO',
disp = '{:1.1f}',
units = 'degC',
linkedGet = lambda: float(self.TxTempMsb.value())+float(self.TxTempLsb.value())/256.0,
dependencies = [self.TxTempMsb,self.TxTempLsb],
linkedGet = lambda var, read: self._getLsbMsb(var, read)/256.0,
dependencies = [self.TxTempMsb, self.TxTempLsb],
))

self.add(pr.RemoteVariable(
Expand All @@ -296,17 +297,17 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = 'RO',
disp = '{:1.3f}',
units = 'V',
linkedGet = lambda: float(self.TxVcc3p3Lsb.value()+256*self.TxVcc3p3Msb.value())*100.0E-6,
dependencies = [self.TxVcc3p3Lsb,self.TxVcc3p3Msb],
linkedGet = lambda var, read: self._getLsbMsb(var, read) * 100.0E-6,
dependencies = [self.TxVcc3p3Lsb, self.TxVcc3p3Msb],
))
else:
self.add(pr.LinkVariable(
name = 'RxVcc3p3',
mode = 'RO',
disp = '{:1.3f}',
units = 'V',
linkedGet = lambda: float(self.RxVcc3p3Lsb.value()+256*self.RxVcc3p3Msb.value())*100.0E-6,
dependencies = [self.RxVcc3p3Lsb,self.RxVcc3p3Msb],
linkedGet = lambda var, read: self._getLsbMsb(var, read) * 100.0E-6,
dependencies = [self.RxVcc3p3Lsb, self.RxVcc3p3Msb],
))

if isTx:
Expand All @@ -333,8 +334,8 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = 'RO',
disp = '{:1.3f}',
units = 'V',
linkedGet = lambda: float(self.TxVccHiLsb.value()+256*self.TxVccHiMsb.value())*100.0E-6,
dependencies = [self.TxVccHiLsb,self.TxVccHiMsb],
linkedGet = lambda var, read: self._getLsbMsb(var, read) * 100.0E-6,
dependencies = [self.TxVccHiLsb, self.TxVccHiMsb],
))

else:
Expand Down Expand Up @@ -406,9 +407,9 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.RxChDisableLsb.value()+256*self.RxChDisableMsb.value(),
linkedSet = lambda value, write: self.RxChDisableLsb.set(value&0xFF) or self.RxChDisableMsb.set(value>>8),
dependencies = [self.RxChDisableLsb,self.RxChDisableMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.RxChDisableLsb, self.RxChDisableMsb],
))

self.add(pr.RemoteVariable(
Expand All @@ -435,19 +436,19 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.TxCdrBypassLsb.value()+256*self.TxCdrBypassMsb.value(),
linkedSet = lambda value, write: self.TxCdrBypassLsb.set(value&0xFF) or self.TxCdrBypassMsb.set(value>>8),
dependencies = [self.TxCdrBypassLsb,self.TxCdrBypassMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.TxCdrBypassLsb, self.TxCdrBypassMsb],
))
else:
self.add(pr.LinkVariable(
name = 'RxCdrBypass',
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.RxCdrBypassLsb.value()+256*self.RxCdrBypassMsb.value(),
linkedSet = lambda value, write: self.RxCdrBypassLsb.set(value&0xFF) or self.RxCdrBypassMsb.set(value>>8),
dependencies = [self.RxCdrBypassLsb,self.RxCdrBypassMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.RxCdrBypassLsb, self.RxCdrBypassMsb],
))

self.add(pr.RemoteVariable(
Expand All @@ -474,19 +475,19 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.TxSquelchDisableLsb.value()+256*self.TxSquelchDisableMsb.value(),
linkedSet = lambda value, write: self.TxSquelchDisableLsb.set(value&0xFF) or self.TxSquelchDisableMsb.set(value>>8),
dependencies = [self.TxSquelchDisableLsb,self.TxSquelchDisableMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.TxSquelchDisableLsb, self.TxSquelchDisableMsb],
))
else:
self.add(pr.LinkVariable(
name = 'RxSquelchDisable',
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.RxSquelchDisableLsb.value()+256*self.RxSquelchDisableMsb.value(),
linkedSet = lambda value, write: self.RxSquelchDisableLsb.set(value&0xFF) or self.RxSquelchDisableMsb.set(value>>8),
dependencies = [self.RxSquelchDisableLsb,self.RxSquelchDisableMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.RxSquelchDisableLsb, self.RxSquelchDisableMsb],
))

self.add(pr.RemoteVariable(
Expand All @@ -513,19 +514,19 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.TxPolarityLsb.value()+256*self.TxPolarityMsb.value(),
linkedSet = lambda value, write: self.TxPolarityLsb.set(value&0xFF) or self.TxPolarityMsb.set(value>>8),
dependencies = [self.TxPolarityLsb,self.TxPolarityMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.TxPolarityLsb, self.TxPolarityMsb],
))
else:
self.add(pr.LinkVariable(
name = 'RxPolarity',
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.RxPolarityLsb.value()+256*self.RxPolarityMsb.value(),
linkedSet = lambda value, write: self.RxPolarityLsb.set(value&0xFF) or self.RxPolarityMsb.set(value>>8),
dependencies = [self.RxPolarityLsb,self.RxPolarityMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.RxPolarityLsb, self.RxPolarityMsb],
))

for i in range(6):
Expand Down Expand Up @@ -587,9 +588,9 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.TxSquelchHysteresisDisableLsb.value()+256*self.TxSquelchHysteresisDisableMsb.value(),
linkedSet = lambda value, write: self.TxSquelchHysteresisDisableLsb.set(value&0xFF) or self.TxSquelchHysteresisDisableMsb.set(value>>8),
dependencies = [self.TxSquelchHysteresisDisableLsb,self.TxSquelchHysteresisDisableMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.TxSquelchHysteresisDisableLsb, self.TxSquelchHysteresisDisableMsb],
))

self.add(pr.RemoteVariable(
Expand Down Expand Up @@ -625,17 +626,29 @@ def __init__(self, isTx = True, writeEn=False, **kwargs):
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.TxOutputDisableLsb.value()+256*self.TxOutputDisableMsb.value(),
linkedSet = lambda value, write: self.TxOutputDisableLsb.set(value&0xFF) or self.TxOutputDisableMsb.set(value>>8),
dependencies = [self.TxOutputDisableLsb,self.TxOutputDisableMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.TxOutputDisableLsb, self.TxOutputDisableMsb],
))
else:
self.add(pr.LinkVariable(
name = 'RxOutputDisable',
mode = rwType,
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.RxOutputDisableLsb.value()+256*self.RxOutputDisableMsb.value(),
linkedSet = lambda value, write: self.RxOutputDisableLsb.set(value&0xFF) or self.RxOutputDisableMsb.set(value>>8),
dependencies = [self.RxOutputDisableLsb,self.RxOutputDisableMsb],
linkedGet = self._getLsbMsb,
linkedSet = self._setLsbMsb,
dependencies = [self.RxOutputDisableLsb, self.RxOutputDisableMsb],
))


def _getLsbMsb(self, var, read):
with self.root.updateGroup():
lsb = var.dependencies[0].get(read=read)
msb = var.dependencies[1].get(read=read)
return lsb + 256 * msb

def _setLsbMsb(self, var, value, write):
with self.root.updateGroup():
var.dependencies[0].set(value & 0xff, write=write)
var.dependencies[1].set((value >> 8) & 0xff, write=write)
30 changes: 21 additions & 9 deletions python/surf/devices/amphenol/_LeapXcvrUpperPages.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class LeapXcvrUpperRxPage01(pr.Device):
def __init__(self, **kwargs):
super().__init__(**kwargs)

def getOpticalPwr(var):
raw = var.dependencies[0].value() # Units of 0.1 uW
def getOpticalPwr(var, read):
raw = var.dependencies[0].get(read=read) # Units of 0.1 uW
if raw == 0:
pwr = 0.0001 # Prevent log10(zero) case
else:
Expand Down Expand Up @@ -132,8 +132,8 @@ def __init__(self, **kwargs):
mode = 'RO',
disp = '0x{:x}',
typeStr = 'UInt16',
linkedGet = lambda: self.LaserWavelengthLsb.value()+256*self.LaserWavelengthMsb.value(),
dependencies = [self.LaserWavelengthLsb,self.LaserWavelengthMsb],
linkedGet = self._getLsbMsb,
dependencies = [self.LaserWavelengthLsb, self.LaserWavelengthMsb],
))

self.add(pr.RemoteVariable(
Expand All @@ -159,8 +159,8 @@ def __init__(self, **kwargs):
mode = 'RO',
disp = '0x{:x}',
typeStr = 'UInt16',
linkedGet = lambda: self.MaxWavelengthDeviationLsb.value()+256*self.MaxWavelengthDeviationMsb.value(),
dependencies = [self.MaxWavelengthDeviationLsb,self.MaxWavelengthDeviationMsb],
linkedGet = self._getLsbMsb,
dependencies = [self.MaxWavelengthDeviationLsb, self.MaxWavelengthDeviationMsb],
))

name = [
Expand Down Expand Up @@ -422,8 +422,8 @@ def __init__(self, **kwargs):
disp = '0x{:x}',
units = '0.5m',
typeStr = 'UInt16',
linkedGet = lambda: self.CableLengthLsb.value()+256*self.CableLengthMsb.value(),
dependencies = [self.CableLengthLsb,self.CableLengthMsb],
linkedGet = self._getLsbMsb,
dependencies = [self.CableLengthLsb, self.CableLengthMsb],
))

self.addRemoteVariables(
Expand Down Expand Up @@ -459,7 +459,7 @@ def __init__(self, **kwargs):
mode = 'RO',
disp = '0x{:x}',
typeStr = 'UInt12',
linkedGet = lambda: self.VendorOuiRaw[2].value()+(2**8)*self.VendorOuiRaw[1].value()+(2**16)*self.VendorOuiRaw[0].value(),
linkedGet = lambda read: self.VendorOuiRaw[2].get(read=read)()+(2**8)*self.VendorOuiRaw[1].get(read=read)()+(2**16)*self.VendorOuiRaw[0].get(read=read)(),
dependencies = [self.VendorOuiRaw[x] for x in range(3)],
))

Expand Down Expand Up @@ -552,3 +552,15 @@ def __init__(self, **kwargs):
linkedGet = transceivers.parseStrArrayByte,
dependencies = [self.LotCodeRaw[x] for x in range(10)],
))


def _getLsbMsb(self, var, read):
with self.root.updateGroup():
lsb = var.dependencies[0].get(read=read)
msb = var.dependencies[1].get(read=read)
return lsb + 256 * msb

def _setLsbMsb(self, var, value, write):
with self.root.updateGroup():
var.dependencies[0].set(value=((value >> 0) & 0xff), write=write)
var.dependencies[1].set(value=((value >> 8) & 0xff), write=write)
Loading
Loading