From 50cb253d3227cb332eac51e0b5fcf2223c9a4f4c Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Tue, 7 May 2024 13:28:23 -0700 Subject: [PATCH 01/12] adding python/surf/devices/ti/_Ina237.py --- python/surf/devices/ti/_Ina237.py | 249 +++++++++++++++++++++++++++++ python/surf/devices/ti/__init__.py | 1 + 2 files changed, 250 insertions(+) create mode 100644 python/surf/devices/ti/_Ina237.py diff --git a/python/surf/devices/ti/_Ina237.py b/python/surf/devices/ti/_Ina237.py new file mode 100644 index 0000000000..251cc75a3a --- /dev/null +++ b/python/surf/devices/ti/_Ina237.py @@ -0,0 +1,249 @@ +#----------------------------------------------------------------------------- +# This file is part of 'SLAC Firmware Standard Library'. +# It is subject to the license terms in the LICENSE.txt file found in the +# top-level directory of this distribution and at: +# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. +# No part of 'SLAC Firmware Standard Library', including this file, +# may be copied, modified, propagated, or distributed except according to +# the terms contained in the LICENSE.txt file. +#----------------------------------------------------------------------------- + +import pyrogue as pr + +class Ina237(pr.Device): + def __init__(self, + pollInterval = 1, + senseRes = 20.E-3, # Units of Ohms + **kwargs): + + super().__init__(**kwargs) + + self.add(pr.LocalVariable( + name = 'senseRes', + mode = 'RW', + value = senseRes, + hidden = True, + )) + + ############## + # 0h CONFIG + ############## + + self.add(pr.RemoteVariable( + name = 'RST', + description = 'Reset Bit. Setting this bit to 1 generates a system reset that is the same as power-on reset.', + offset = (0x0 << 2), + bitSize = 1, + bitOffset = 15, + mode = 'WO', + hidden = True, + )) + + self.add(pr.RemoteVariable( + name = 'CONVDLY', + description = 'Sets the Delay for initial ADC conversion in steps of 2 ms.', + offset = (0x0 << 2), + bitSize = 8, + bitOffset = 6, + mode = 'RW', + units = '2ms', + hidden = True, + )) + + self.add(pr.RemoteVariable( + name = 'ADCRANGE', + description = 'Reset Bit. Setting this bit to 1 generates a system reset that is the same as power-on reset.', + offset = (0x0 << 2), + bitSize = 1, + bitOffset = 4, + mode = 'RW', + enum = { + 0 : '+/-163.84mV', + 1 : '+/-40.96mV', + }, + hidden = True, + )) + + ############## + # 1h ADC_CONFIG + ############## + + self.add(pr.RemoteVariable( + name = 'MODE', + description = 'The user can set the MODE bits for continuous or triggered mode on bus voltage, shunt voltage or temperature measurement.', + offset = (0x1 << 2), + bitSize = 4, + bitOffset = 12, + mode = 'RW', + hidden = True, + )) + + self.add(pr.RemoteVariable( + name = 'VBUSCT', + description = 'Sets the conversion time of the bus voltage measurement', + offset = (0x1 << 2), + bitSize = 3, + bitOffset = 9, + mode = 'RW', + hidden = True, + )) + + self.add(pr.RemoteVariable( + name = 'VSHCT', + description = 'Sets the conversion time of the shunt voltage measurement', + offset = (0x1 << 2), + bitSize = 3, + bitOffset = 6, + mode = 'RW', + hidden = True, + )) + + self.add(pr.RemoteVariable( + name = 'VTCT', + description = 'Sets the conversion time of the temperature measurement', + offset = (0x1 << 2), + bitSize = 3, + bitOffset = 3, + mode = 'RW', + hidden = True, + )) + + self.add(pr.RemoteVariable( + name = 'AVG', + description = 'Selects ADC sample averaging count. The averaging setting applies to all active inputs', + offset = (0x1 << 2), + bitSize = 3, + bitOffset = 0, + mode = 'RW', + hidden = True, + )) + + ############## + # 2h SHUNT_CAL + ############## + + self.add(pr.RemoteVariable( + name = 'SHUNT_CAL', + description = 'The register provides the device with a conversion constant value that represents shunt resistance used to calculate current value in Amperes', + offset = (0x2 << 2), + bitSize = 15, + bitOffset = 0, + mode = 'RW', + hidden = True, + )) + + + ############## + # 4h VSHUNT + ############## + + self.add(pr.RemoteVariable( + name = 'VSHUNT', + description = 'Differential voltage measured across the shunt output. Twos complement value', + offset = (0x4 << 2), + bitSize = 16, + bitOffset = 0, + base = pr.Int, + mode = 'RO', + pollInterval = pollInterval, + hidden = True, + )) + + ############## + # 5h VBUS + ############## + + self.add(pr.RemoteVariable( + name = 'VBUS', + description = 'Bus voltage output. Twos complement value, however always positive', + offset = (0x5 << 2), + bitSize = 16, + bitOffset = 0, + base = pr.Int, + mode = 'RO', + pollInterval = pollInterval, + hidden = True, + )) + + ############## + # 6h DIETEMP + ############## + + self.add(pr.RemoteVariable( + name = 'DIETEMP', + description = 'Internal die temperature measurement. Twos complement value', + offset = (0x6 << 2), + bitSize = 12, + bitOffset = 4, + base = pr.Int, + mode = 'RO', + pollInterval = pollInterval, + hidden = True, + )) + + ############################################################################### + + self.add(pr.RemoteVariable( + name = 'MANFID', + description = 'Reads back TI in ASCII (should be 0x5449)', + offset = (0x3E << 2), + bitSize = 16, + bitOffset = 0, + mode = 'RO', + )) + + ############################################################################### + + self.add(pr.LinkVariable( + name = 'Vin', + description = 'Voltage Measurement', + mode = 'RO', + linkedGet = lambda: self.VBUS.value()*3.125E-3, # Conversion factor: 3.125 mV/LSB + typeStr = "Float32", + disp = '{:1.3f}', + units = 'V', + dependencies = [self.VBUS], + )) + + self.add(pr.LinkVariable( + name = 'Iin', + description = 'Current Measurement', + mode = 'RO', + linkedGet = self.convCurrent, + typeStr = "Float32", + disp = '{:1.3f}', + units = 'A', + dependencies = [self.ADCRANGE,self.VSHUNT,self.senseRes], + )) + + self.add(pr.LinkVariable( + name = 'Pin', + description = 'Power Measurement', + mode = 'RO', + linkedGet = lambda: (self.Vin.value())*(self.Iin.value()), + typeStr = "Float32", + disp = '{:1.3f}', + units = 'W', + dependencies = [self.Vin,self.Iin], + )) + + self.add(pr.LinkVariable( + name = "DieTempature", + mode = 'RO', + linkedGet = lambda: self.DIETEMP.value()*0.125, # Conversion factor: 0.125 degC/LSB + typeStr = "Float32", + disp = '{:1.3f}', + units = 'degC', + dependencies = [self.DIETEMP], + )) + + @staticmethod + def convCurrent(dev, var): + adcRange = var.dependencies[0].get(read=False) + if adcRange == 0: + lsbScale = 5.0E-6 # 5 uV/LSB + else: + lsbScale = 1.23E-6 # 1.25 uV/LSB + value = var.dependencies[1].get(read=False) + fpValue = value*lsbScale + return (fpValue/var.dependencies[2].get(read=False)) diff --git a/python/surf/devices/ti/__init__.py b/python/surf/devices/ti/__init__.py index 338df84b95..2c4edf8a30 100644 --- a/python/surf/devices/ti/__init__.py +++ b/python/surf/devices/ti/__init__.py @@ -16,6 +16,7 @@ from surf.devices.ti._AxiCdcm6208 import * from surf.devices.ti._Dac38J84 import * from surf.devices.ti._Ds32Ev400 import * +from surf.devices.ti._Ina237 import * from surf.devices.ti._Lmk048Base import * from surf.devices.ti._Lmk04828 import * from surf.devices.ti._Lmk04832 import * From a20e528b85887a7822e8ec74980768d041fbbdfe Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Tue, 7 May 2024 14:37:25 -0700 Subject: [PATCH 02/12] adding python/surf/devices/linear/_Ltc3815.py --- python/surf/devices/linear/_Ltc3815.py | 100 +++++++++++++++++++++++++ python/surf/devices/linear/__init__.py | 1 + 2 files changed, 101 insertions(+) create mode 100644 python/surf/devices/linear/_Ltc3815.py diff --git a/python/surf/devices/linear/_Ltc3815.py b/python/surf/devices/linear/_Ltc3815.py new file mode 100644 index 0000000000..363aef79ae --- /dev/null +++ b/python/surf/devices/linear/_Ltc3815.py @@ -0,0 +1,100 @@ +#----------------------------------------------------------------------------- +# This file is part of the 'SLAC Firmware Standard Library'. It is subject to +# the license terms in the LICENSE.txt file found in the top-level directory +# of this distribution and at: +# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. +# No part of the 'SLAC Firmware Standard Library', including this file, may be +# copied, modified, propagated, or distributed except according to the terms +# contained in the LICENSE.txt file. +#----------------------------------------------------------------------------- + +import pyrogue as pr + +import surf.protocols.i2c + +class Ltc3815(surf.protocols.i2c.PMBus): + def __init__(self, **kwargs): + super().__init__(**kwargs) + + self.add(pr.LinkVariable( + name = 'Vin', + mode = 'RO', + units = 'V', + typeStr = "Float32", + disp = '{:1.3f}', + linkedGet = lambda: self.READ_VIN.value()*4.0E-3, # Conversion factor: 4mV/Bit + dependencies = [self.READ_VIN], + )) + + self.add(pr.LinkVariable( + name = 'Iin', + mode = 'RO', + units = 'A', + typeStr = "Float32", + disp = '{:1.3f}', + linkedGet = lambda: self.READ_IIN.value()*10.0E-3, # Conversion factor: 10mA/Bit + dependencies = [self.READ_IIN], + )) + + self.add(pr.LinkVariable( + name = 'Vout', + mode = 'RO', + units = 'V', + typeStr = "Float32", + disp = '{:1.3f}', + linkedGet = lambda: self.READ_VOUT.value()*0.5E-3, # Conversion factor: 0.5mV/Bit + dependencies = [self.READ_VOUT], + )) + + self.add(pr.LinkVariable( + name = 'Iout', + mode = 'RO', + units = 'A', + typeStr = "Float32", + disp = '{:1.3f}', + linkedGet = lambda: self.READ_IOUT.value()*10.0E-3, # Conversion factor: 10mA/Bit + dependencies = [self.READ_IOUT], + )) + + self.add(pr.LinkVariable( + name = "DieTempature", + mode = 'RO', + linkedGet = lambda: self.READ_TEMPERATURE_1.value()*1.0, # Conversion factor: 1 degC/Bit + typeStr = "Float32", + disp = '{:1.3f}', + units = 'degC', + dependencies = [self.READ_TEMPERATURE_1], + )) + + self.add(pr.LinkVariable( + name = 'Pin', + description = 'Power Measurement', + mode = 'RO', + linkedGet = lambda: (self.Vin.value())*(self.Iin.value()), + typeStr = "Float32", + disp = '{:1.3f}', + units = 'W', + dependencies = [self.Vin,self.Iin], + )) + + self.add(pr.LinkVariable( + name = 'Pout', + description = 'Power Measurement', + mode = 'RO', + linkedGet = lambda: (self.Vout.value())*(self.Iout.value()), + typeStr = "Float32", + disp = '{:1.3f}', + units = 'W', + dependencies = [self.Vout,self.Iout], + )) + + self.add(pr.LinkVariable( + name = 'Peff', + description = 'Power Conversion Efficiency', + mode = 'RO', + linkedGet = lambda: 100.0*(self.Pout.value())/(self.Pin.value()) if self.Pin.value()>0.0 else 0.0, + typeStr = "Float32", + disp = '{:1.1f}', + units = '%', + dependencies = [self.Pin,self.Pout], + )) diff --git a/python/surf/devices/linear/__init__.py b/python/surf/devices/linear/__init__.py index 49c0fa9f5e..1e300f3edc 100644 --- a/python/surf/devices/linear/__init__.py +++ b/python/surf/devices/linear/__init__.py @@ -9,4 +9,5 @@ ############################################################################## from surf.devices.linear._Ltc2270 import * from surf.devices.linear._Ltc2945 import * +from surf.devices.linear._Ltc3815 import * from surf.devices.linear._Ltc4151 import * From 240ed88f14f2f86a14a6de4be0c65515b16f1a69 Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Tue, 7 May 2024 14:37:57 -0700 Subject: [PATCH 03/12] adding dynamicAddr arg (default=False) to _PMBus.py --- python/surf/protocols/i2c/_PMBus.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/python/surf/protocols/i2c/_PMBus.py b/python/surf/protocols/i2c/_PMBus.py index 25cb807283..98b50181a2 100644 --- a/python/surf/protocols/i2c/_PMBus.py +++ b/python/surf/protocols/i2c/_PMBus.py @@ -11,7 +11,7 @@ import pyrogue as pr class PMBus(pr.Device): - def __init__(self, simpleDisplay = True, **kwargs): + def __init__(self, simpleDisplay = True, dynamicAddr=False, **kwargs): super().__init__(**kwargs) self.add(pr.RemoteVariable( @@ -19,7 +19,8 @@ def __init__(self, simpleDisplay = True, **kwargs): offset = 0x400, bitSize = 10, bitOffset = 0, - mode = 'RW', + mode = 'RW' if dynamicAddr else 'RO', + hidden = simpleDisplay, )) self.add(pr.RemoteVariable( @@ -27,7 +28,8 @@ def __init__(self, simpleDisplay = True, **kwargs): offset = 0x400, bitSize = 1, bitOffset = 10, - mode = 'RW', + mode = 'RW' if dynamicAddr else 'RO', + hidden = simpleDisplay, )) self.add(pr.RemoteVariable( @@ -44,6 +46,7 @@ def __init__(self, simpleDisplay = True, **kwargs): offset = (4*0x00), bitSize = 8, mode = 'RW', + hidden = simpleDisplay, )) self.add(pr.RemoteVariable( From e4d6e6609277cfb00c133e369aa4af1d4cd82aac Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Wed, 8 May 2024 14:51:48 -0700 Subject: [PATCH 04/12] adding simpleViewList arg to _Sa56004x.py (similiar to _Xadc.py) --- python/surf/devices/nxp/_Sa56004x.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/surf/devices/nxp/_Sa56004x.py b/python/surf/devices/nxp/_Sa56004x.py index 38dd8987ca..1b56f3e6a1 100644 --- a/python/surf/devices/nxp/_Sa56004x.py +++ b/python/surf/devices/nxp/_Sa56004x.py @@ -18,9 +18,14 @@ class Sa56004x(pr.Device): def __init__(self, pollInterval = 1, + simpleViewList = ['enable', 'LocalTemperature', 'RemoteTemperature', 'RemoteTcritSetpoint'], **kwargs): super().__init__(**kwargs) + if simpleViewList is not None: + self.simpleViewList = simpleViewList[:] + self.simpleViewList.append('enable') + ############################################################################ def getTempReg(var): @@ -560,5 +565,5 @@ def simpleView(self): # Hide all the variable self.hideVariables(hidden=True) # Then unhide the most interesting ones - vars = ['enable', 'LocalTemperature', 'RemoteTemperature'] + vars = self.simpleViewList self.hideVariables(hidden=False, variables=vars) From 345b245b83fbd3dd6ea0244375ccec4a3d28531e Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Wed, 8 May 2024 14:52:35 -0700 Subject: [PATCH 05/12] using lambda read + get(read=read) instead of .value() --- python/surf/devices/linear/_Ltc3815.py | 16 ++++++++-------- python/surf/devices/linear/_Ltc4151.py | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/python/surf/devices/linear/_Ltc3815.py b/python/surf/devices/linear/_Ltc3815.py index 363aef79ae..6fd972bb31 100644 --- a/python/surf/devices/linear/_Ltc3815.py +++ b/python/surf/devices/linear/_Ltc3815.py @@ -22,7 +22,7 @@ def __init__(self, **kwargs): units = 'V', typeStr = "Float32", disp = '{:1.3f}', - linkedGet = lambda: self.READ_VIN.value()*4.0E-3, # Conversion factor: 4mV/Bit + linkedGet = lambda read: self.READ_VIN.get(read=read)*4.0E-3, # Conversion factor: 4mV/Bit dependencies = [self.READ_VIN], )) @@ -32,7 +32,7 @@ def __init__(self, **kwargs): units = 'A', typeStr = "Float32", disp = '{:1.3f}', - linkedGet = lambda: self.READ_IIN.value()*10.0E-3, # Conversion factor: 10mA/Bit + linkedGet = lambda read: self.READ_IIN.get(read=read)*10.0E-3, # Conversion factor: 10mA/Bit dependencies = [self.READ_IIN], )) @@ -42,7 +42,7 @@ def __init__(self, **kwargs): units = 'V', typeStr = "Float32", disp = '{:1.3f}', - linkedGet = lambda: self.READ_VOUT.value()*0.5E-3, # Conversion factor: 0.5mV/Bit + linkedGet = lambda read: self.READ_VOUT.get(read=read)*0.5E-3, # Conversion factor: 0.5mV/Bit dependencies = [self.READ_VOUT], )) @@ -52,14 +52,14 @@ def __init__(self, **kwargs): units = 'A', typeStr = "Float32", disp = '{:1.3f}', - linkedGet = lambda: self.READ_IOUT.value()*10.0E-3, # Conversion factor: 10mA/Bit + linkedGet = lambda read: self.READ_IOUT.get(read=read)*10.0E-3, # Conversion factor: 10mA/Bit dependencies = [self.READ_IOUT], )) self.add(pr.LinkVariable( name = "DieTempature", mode = 'RO', - linkedGet = lambda: self.READ_TEMPERATURE_1.value()*1.0, # Conversion factor: 1 degC/Bit + linkedGet = lambda read: self.READ_TEMPERATURE_1.get(read=read)*1.0, # Conversion factor: 1 degC/Bit typeStr = "Float32", disp = '{:1.3f}', units = 'degC', @@ -70,7 +70,7 @@ def __init__(self, **kwargs): name = 'Pin', description = 'Power Measurement', mode = 'RO', - linkedGet = lambda: (self.Vin.value())*(self.Iin.value()), + linkedGet = lambda read: (self.Vin.get(read=read))*(self.Iin.get(read=read)), typeStr = "Float32", disp = '{:1.3f}', units = 'W', @@ -81,7 +81,7 @@ def __init__(self, **kwargs): name = 'Pout', description = 'Power Measurement', mode = 'RO', - linkedGet = lambda: (self.Vout.value())*(self.Iout.value()), + linkedGet = lambda read: (self.Vout.get(read=read))*(self.Iout.get(read=read)), typeStr = "Float32", disp = '{:1.3f}', units = 'W', @@ -92,7 +92,7 @@ def __init__(self, **kwargs): name = 'Peff', description = 'Power Conversion Efficiency', mode = 'RO', - linkedGet = lambda: 100.0*(self.Pout.value())/(self.Pin.value()) if self.Pin.value()>0.0 else 0.0, + linkedGet = lambda read: 100.0*(self.Pout.get(read=read))/(self.Pin.get(read=read)) if self.Pin.get(read=read)>0.0 else 0.0, typeStr = "Float32", disp = '{:1.1f}', units = '%', diff --git a/python/surf/devices/linear/_Ltc4151.py b/python/surf/devices/linear/_Ltc4151.py index e14d9748df..e17651bf8b 100644 --- a/python/surf/devices/linear/_Ltc4151.py +++ b/python/surf/devices/linear/_Ltc4151.py @@ -56,7 +56,7 @@ def __init__(self, units = 'A', disp = '{:1.3f}', dependencies = [self.SenseMsb,self.SenseLsb], - linkedGet = lambda: (int(self.SenseMsb.value()<<4)|int(self.SenseLsb.value()&0xF))*20.0E-6/self.senseRes + linkedGet = lambda read: (int(self.SenseMsb.get(read=read)<<4)|int(self.SenseLsb.get(read=read)&0xF))*20.0E-6/self.senseRes )) self.add(pr.RemoteVariable( @@ -90,7 +90,7 @@ def __init__(self, units = 'V', disp = '{:1.3f}', dependencies = [self.VinMsb,self.VinLsb], - linkedGet = lambda: (int(self.VinMsb.value()<<4)|int(self.VinLsb.value()&0xF))*25.0E-3 + linkedGet = lambda read: (int(self.VinMsb.get(read=read)<<4)|int(self.VinLsb.get(read=read)&0xF))*25.0E-3 )) self.add(pr.LinkVariable( @@ -100,7 +100,7 @@ def __init__(self, units = 'W', disp = '{:1.3f}', dependencies = [self.Vin,self.Iin], - linkedGet = lambda: (self.Vin.value())*(self.Iin.value()) + linkedGet = lambda read: (self.Vin.get(read=read))*(self.Iin.get(read=read)) )) self.add(pr.RemoteVariable( @@ -134,7 +134,7 @@ def __init__(self, units = 'V', disp = '{:1.3f}', dependencies = [self.AdinMsb,self.AdinLsb], - linkedGet = lambda: (int(self.AdinMsb.value()<<4)|int(self.AdinLsb.value()&0xF))*500.0E-6 + linkedGet = lambda read: (int(self.AdinMsb.get(read=read)<<4)|int(self.AdinLsb.get(read=read)&0xF))*500.0E-6 )) self.add(pr.RemoteVariable( From c5eddd76eb186f1b7602d9b1d7eecd5234f269c7 Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Thu, 9 May 2024 11:12:24 -0700 Subject: [PATCH 06/12] using lambda read + get(read=read) instead of .value() --- python/surf/devices/ti/_Ina237.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/surf/devices/ti/_Ina237.py b/python/surf/devices/ti/_Ina237.py index 251cc75a3a..528dcb3fd9 100644 --- a/python/surf/devices/ti/_Ina237.py +++ b/python/surf/devices/ti/_Ina237.py @@ -198,7 +198,7 @@ def __init__(self, name = 'Vin', description = 'Voltage Measurement', mode = 'RO', - linkedGet = lambda: self.VBUS.value()*3.125E-3, # Conversion factor: 3.125 mV/LSB + linkedGet = lambda read: self.VBUS.get(read=read)*3.125E-3, # Conversion factor: 3.125 mV/LSB typeStr = "Float32", disp = '{:1.3f}', units = 'V', @@ -220,7 +220,7 @@ def __init__(self, name = 'Pin', description = 'Power Measurement', mode = 'RO', - linkedGet = lambda: (self.Vin.value())*(self.Iin.value()), + linkedGet = lambda read: (self.Vin.get(read=read))*(self.Iin.get(read=read)), typeStr = "Float32", disp = '{:1.3f}', units = 'W', @@ -230,7 +230,7 @@ def __init__(self, self.add(pr.LinkVariable( name = "DieTempature", mode = 'RO', - linkedGet = lambda: self.DIETEMP.value()*0.125, # Conversion factor: 0.125 degC/LSB + linkedGet = lambda read: self.DIETEMP.get(read=read)*0.125, # Conversion factor: 0.125 degC/LSB typeStr = "Float32", disp = '{:1.3f}', units = 'degC', From 150cf83ad6ce9ab861d0f05a5f88e45ba9b63ba7 Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Thu, 9 May 2024 11:16:47 -0700 Subject: [PATCH 07/12] rename var --- python/surf/devices/ti/_Ina237.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/surf/devices/ti/_Ina237.py b/python/surf/devices/ti/_Ina237.py index 528dcb3fd9..a00f189f76 100644 --- a/python/surf/devices/ti/_Ina237.py +++ b/python/surf/devices/ti/_Ina237.py @@ -19,7 +19,7 @@ def __init__(self, super().__init__(**kwargs) self.add(pr.LocalVariable( - name = 'senseRes', + name = 'SenseRes', mode = 'RW', value = senseRes, hidden = True, @@ -213,7 +213,7 @@ def __init__(self, typeStr = "Float32", disp = '{:1.3f}', units = 'A', - dependencies = [self.ADCRANGE,self.VSHUNT,self.senseRes], + dependencies = [self.ADCRANGE,self.VSHUNT,self.SenseRes], )) self.add(pr.LinkVariable( From 4aa71718e669a0680b800f4a8ccaa1b32a33006c Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Thu, 9 May 2024 11:22:46 -0700 Subject: [PATCH 08/12] updating to use updateGroup --- python/surf/devices/ti/_Ina237.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/python/surf/devices/ti/_Ina237.py b/python/surf/devices/ti/_Ina237.py index a00f189f76..da0359bc60 100644 --- a/python/surf/devices/ti/_Ina237.py +++ b/python/surf/devices/ti/_Ina237.py @@ -237,13 +237,13 @@ def __init__(self, dependencies = [self.DIETEMP], )) - @staticmethod - def convCurrent(dev, var): - adcRange = var.dependencies[0].get(read=False) - if adcRange == 0: - lsbScale = 5.0E-6 # 5 uV/LSB - else: - lsbScale = 1.23E-6 # 1.25 uV/LSB - value = var.dependencies[1].get(read=False) - fpValue = value*lsbScale - return (fpValue/var.dependencies[2].get(read=False)) + def convCurrent(self, dev, var, read): + with self.root.updateGroup(): + adcRange = var.dependencies[0].get(read=read) + if adcRange == 0: + lsbScale = 5.0E-6 # 5 uV/LSB + else: + lsbScale = 1.23E-6 # 1.25 uV/LSB + value = var.dependencies[1].get(read=read) + fpValue = value*lsbScale + return (fpValue/var.dependencies[2].get(read=read)) From ab13f77861cd56db29a147f06c6d64cc18809ef0 Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Thu, 9 May 2024 11:39:26 -0700 Subject: [PATCH 09/12] updating coding style --- python/surf/devices/ti/_Ina237.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/python/surf/devices/ti/_Ina237.py b/python/surf/devices/ti/_Ina237.py index da0359bc60..625a1b0aa9 100644 --- a/python/surf/devices/ti/_Ina237.py +++ b/python/surf/devices/ti/_Ina237.py @@ -237,13 +237,12 @@ def __init__(self, dependencies = [self.DIETEMP], )) - def convCurrent(self, dev, var, read): - with self.root.updateGroup(): - adcRange = var.dependencies[0].get(read=read) - if adcRange == 0: - lsbScale = 5.0E-6 # 5 uV/LSB - else: - lsbScale = 1.23E-6 # 1.25 uV/LSB - value = var.dependencies[1].get(read=read) - fpValue = value*lsbScale - return (fpValue/var.dependencies[2].get(read=read)) + def convCurrent(self, read): # Don't need dev and var since not used + adcRange = self.ADCRANGE.value() # Doesn't change in HW so shadow value is preferred + if adcRange == 0: + lsbScale = 5.0E-6 # 5 uV/LSB + else: + lsbScale = 1.23E-6 # 1.25 uV/LSB + value = self.VSHUNT.get(read=read) # Read the ADC value + fpValue = value*lsbScale + return (fpValue/self.SenseRes.value()) # SenseRes is LocalVariable From ff58c7c7108f9802b93cddbfdfc5db905bf31b64 Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Tue, 28 May 2024 11:59:47 -0700 Subject: [PATCH 10/12] synchronizing the data and AXIL resets to their counterpart FSMs --- axi/axi-stream/rtl/AxiStreamRingBuffer.vhd | 81 ++++++++++++++++------ 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/axi/axi-stream/rtl/AxiStreamRingBuffer.vhd b/axi/axi-stream/rtl/AxiStreamRingBuffer.vhd index c9679fe392..3e6d75988a 100644 --- a/axi/axi-stream/rtl/AxiStreamRingBuffer.vhd +++ b/axi/axi-stream/rtl/AxiStreamRingBuffer.vhd @@ -152,11 +152,26 @@ architecture rtl of AxiStreamRingBuffer is signal firstAddr : slv(RAM_ADDR_WIDTH_G-1 downto 0); signal bufferLength : slv(RAM_ADDR_WIDTH_G-1 downto 0); - signal readReq : sl; - signal armed : sl; + signal readReq : sl; + signal armed : sl; + signal fifoRst : sl; + signal axilRstSync : sl; + signal dataRstSync : sl; signal txSlave : AxiStreamSlaveType; + -- attribute dont_touch : string; + -- attribute dont_touch of dataR : signal is "TRUE"; + -- attribute dont_touch of softTrigSync : signal is "TRUE"; + -- attribute dont_touch of bufferClearSync : signal is "TRUE"; + -- attribute dont_touch of axilR : signal is "TRUE"; + -- attribute dont_touch of readReq : signal is "TRUE"; + -- attribute dont_touch of armed : signal is "TRUE"; + -- attribute dont_touch of fifoRst : signal is "TRUE"; + -- attribute dont_touch of axilRstSync : signal is "TRUE"; + -- attribute dont_touch of dataRstSync : signal is "TRUE"; + -- attribute dont_touch of txSlave : signal is "TRUE"; + begin ---------------------- @@ -179,7 +194,6 @@ begin dina => dataR.ramWrData, -- Port B clkb => axilClk, - rstb => axilRst, addrb => axilR.ramRdAddr, doutb => ramRdData); end generate; @@ -201,7 +215,6 @@ begin dina => dataR.ramWrData, -- Port B clkb => axilClk, - rstb => axilRst, addrb => axilR.ramRdAddr, doutb => ramRdData); end generate; @@ -223,7 +236,6 @@ begin dina => dataR.ramWrData, -- Port B clkb => axilClk, - rstb => axilRst, addrb => axilR.ramRdAddr, doutb => ramRdData); end generate; @@ -233,22 +245,28 @@ begin -------------------------------------------------- U_SyncVec_dataClk : entity surf.SynchronizerVector generic map ( - TPD_G => TPD_G, - RST_ASYNC_G => RST_ASYNC_G, - WIDTH_G => 2) + TPD_G => TPD_G, + WIDTH_G => 2) port map ( clk => dataClk, - rst => dataRst, dataIn(0) => axilR.softTrig, dataIn(1) => axilR.bufferClear, dataOut(0) => softTrigSync, dataOut(1) => bufferClearSync); + U_RstSync_axilRst : entity surf.RstSync + generic map ( + TPD_G => TPD_G) + port map ( + clk => dataClk, + asyncRst => axilRst, + syncRst => axilRstSync); + -------------------------- -- Main AXI-Stream process -------------------------- - dataComb : process (bufferClearSync, dataR, dataRst, dataValid, dataValue, - extTrig, softTrigSync) is + dataComb : process (axilRstSync, bufferClearSync, dataR, dataRst, dataValid, + dataValue, extTrig, softTrigSync) is variable v : DataRegType; begin -- Latch the current value @@ -297,7 +315,7 @@ begin end if; -- Synchronous Reset - if (RST_ASYNC_G = false and dataRst = '1') or (bufferClearSync = '1') then + if (RST_ASYNC_G = false and dataRst = '1') or (bufferClearSync = '1') or (axilRstSync = '1') then v := DATA_REG_INIT_C; end if; @@ -324,7 +342,7 @@ begin RST_ASYNC_G => RST_ASYNC_G, DATA_WIDTH_G => 2*RAM_ADDR_WIDTH_G) port map ( - rst => axilRst, + rst => fifoRst, -- Write Interface wr_clk => dataClk, wr_en => dataR.readReq, @@ -334,6 +352,8 @@ begin valid => readReq, dout => fifoDout); + fifoRst <= dataRst or axilRst; + fifoDin(1*RAM_ADDR_WIDTH_G-1 downto 0*RAM_ADDR_WIDTH_G) <= dataR.firstAddr; fifoDin(2*RAM_ADDR_WIDTH_G-1 downto 1*RAM_ADDR_WIDTH_G) <= dataR.bufferLength; @@ -342,29 +362,33 @@ begin U_SyncVec_axilClk : entity surf.SynchronizerVector generic map ( - TPD_G => TPD_G, - RST_ASYNC_G => RST_ASYNC_G, - WIDTH_G => 1) + TPD_G => TPD_G, + WIDTH_G => 1) port map ( clk => axilClk, - rst => axilRst, dataIn(0) => dataR.armed, dataOut(0) => armed); + U_RstSync_dataRst : entity surf.RstSync + generic map ( + TPD_G => TPD_G) + port map ( + clk => axilClk, + asyncRst => dataRst, + syncRst => dataRstSync); + ------------------------ -- Main AXI-Lite process ------------------------ axiComb : process (armed, axilR, axilReadMaster, axilRst, axilWriteMaster, - bufferLength, firstAddr, ramRdData, readReq, txSlave) is + bufferLength, dataRstSync, firstAddr, ramRdData, readReq, + txSlave) is variable v : AxilRegType; variable axilEp : AxiLiteEndpointType; begin -- Latch the current value v := axilR; - -- Reset strobe - v.bufferClear := '0'; - ------------------------ -- AXI-Lite Transactions ------------------------ @@ -486,13 +510,28 @@ begin -- Check if armed de-asserted if (armed = '0') then + + -- Reset the flag + v.bufferClear := '0'; + -- Next states v.dataState := IDLE_S; v.trigState := IDLE_S; + end if; ---------------------------------------------------------------------- end case; + -- Check for external data reset + if (dataRstSync = '1') then + -- Reset the flags + v.bufferClear := '0'; + v.softTrig := '0'; + -- Next states + v.dataState := IDLE_S; + v.trigState := IDLE_S; + end if; + -- Update RAM read address v.ramRdAddr := firstAddr + v.wordCnt; From b47bf8d8928ce01cfe82e83554548ff7231977a0 Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Tue, 11 Jun 2024 15:13:21 -0700 Subject: [PATCH 11/12] including NoState/NoConfig to RemoteVariables that we don't want to save values to YAML file --- python/surf/devices/micron/_AxiMicronMt28ew.py | 1 + python/surf/devices/micron/_AxiMicronN25Q.py | 1 + python/surf/devices/micron/_AxiMicronP30.py | 1 + python/surf/devices/silabs/_Si5324.py | 1 + python/surf/devices/silabs/_Si5326.py | 1 + python/surf/devices/silabs/_Si5345Pages.py | 1 + python/surf/devices/ti/_Lmx2594.py | 1 + python/surf/devices/ti/_Lmx2615.py | 1 + python/surf/protocols/sugoi/_SugoiAxiLitePixelMatrixConfig.py | 1 + 9 files changed, 9 insertions(+) diff --git a/python/surf/devices/micron/_AxiMicronMt28ew.py b/python/surf/devices/micron/_AxiMicronMt28ew.py index 3df2ff3a91..281debcf0c 100644 --- a/python/surf/devices/micron/_AxiMicronMt28ew.py +++ b/python/surf/devices/micron/_AxiMicronMt28ew.py @@ -118,6 +118,7 @@ def __init__(self, bulkOpEn = False, hidden = True, verify = False, + groups = ['NoStream','NoState','NoConfig'], # Not saving config/state to YAML )) self.add(pr.LocalCommand( diff --git a/python/surf/devices/micron/_AxiMicronN25Q.py b/python/surf/devices/micron/_AxiMicronN25Q.py index 56483f3ec0..113a340884 100644 --- a/python/surf/devices/micron/_AxiMicronN25Q.py +++ b/python/surf/devices/micron/_AxiMicronN25Q.py @@ -107,6 +107,7 @@ def __init__(self, bulkOpEn = False, hidden = True, verify = False, + groups = ['NoStream','NoState','NoConfig'], # Not saving config/state to YAML )) ############################## diff --git a/python/surf/devices/micron/_AxiMicronP30.py b/python/surf/devices/micron/_AxiMicronP30.py index ee7a9866d3..e4836f850a 100644 --- a/python/surf/devices/micron/_AxiMicronP30.py +++ b/python/surf/devices/micron/_AxiMicronP30.py @@ -118,6 +118,7 @@ def __init__(self, bulkOpEn = False, hidden = True, verify = False, + groups = ['NoStream','NoState','NoConfig'], # Not saving config/state to YAML )) self.add(pr.LocalCommand( diff --git a/python/surf/devices/silabs/_Si5324.py b/python/surf/devices/silabs/_Si5324.py index aa5aaabffc..3d1b9d8a8e 100644 --- a/python/surf/devices/silabs/_Si5324.py +++ b/python/surf/devices/silabs/_Si5324.py @@ -32,6 +32,7 @@ def __init__(self,**kwargs): hidden = True, base = pr.UInt, mode = "RW", + groups = ['NoStream','NoState','NoConfig'], # Not saving config/state to YAML )) self.add(pr.LocalVariable( diff --git a/python/surf/devices/silabs/_Si5326.py b/python/surf/devices/silabs/_Si5326.py index 3346368383..d4567c0dd2 100644 --- a/python/surf/devices/silabs/_Si5326.py +++ b/python/surf/devices/silabs/_Si5326.py @@ -32,6 +32,7 @@ def __init__(self,**kwargs): hidden = True, base = pr.UInt, mode = "RW", + groups = ['NoStream','NoState','NoConfig'], # Not saving config/state to YAML )) self.add(pr.LocalVariable( diff --git a/python/surf/devices/silabs/_Si5345Pages.py b/python/surf/devices/silabs/_Si5345Pages.py index 0f42be879e..75f948f3e5 100644 --- a/python/surf/devices/silabs/_Si5345Pages.py +++ b/python/surf/devices/silabs/_Si5345Pages.py @@ -37,6 +37,7 @@ def __init__(self, hidden = True, base = pr.UInt, mode = "RW", + groups = ['NoStream','NoState','NoConfig'], # Not saving config/state to YAML )) def MyLinkVariable(self, name, description, offset, bitSize, mode, bitOffset=0, pollInterval=0, value=None, hidden=False): diff --git a/python/surf/devices/ti/_Lmx2594.py b/python/surf/devices/ti/_Lmx2594.py index 212f4a1b17..8355dab6bf 100644 --- a/python/surf/devices/ti/_Lmx2594.py +++ b/python/surf/devices/ti/_Lmx2594.py @@ -32,6 +32,7 @@ def __init__(self, **kwargs): hidden = True, base = pr.UInt, mode = "RW", + groups = ['NoStream','NoState','NoConfig'], # Not saving config/state to YAML )) def addLinkVariable(name, description, offset, bitSize, mode, bitOffset=0, pollInterval=0, value=None, hidden=False): diff --git a/python/surf/devices/ti/_Lmx2615.py b/python/surf/devices/ti/_Lmx2615.py index c1b38e74cf..2be4ec2988 100644 --- a/python/surf/devices/ti/_Lmx2615.py +++ b/python/surf/devices/ti/_Lmx2615.py @@ -35,6 +35,7 @@ def __init__(self, **kwargs): hidden = True, base = pr.UInt, mode = "RW", + groups = ['NoStream','NoState','NoConfig'], # Not saving config/state to YAML )) self.add(pr.RemoteVariable( diff --git a/python/surf/protocols/sugoi/_SugoiAxiLitePixelMatrixConfig.py b/python/surf/protocols/sugoi/_SugoiAxiLitePixelMatrixConfig.py index 1bdfea1331..b76b76e354 100644 --- a/python/surf/protocols/sugoi/_SugoiAxiLitePixelMatrixConfig.py +++ b/python/surf/protocols/sugoi/_SugoiAxiLitePixelMatrixConfig.py @@ -131,6 +131,7 @@ def __init__(self, hidden = True, base = pr.UInt, mode = "RW", + groups = ['NoStream','NoState','NoConfig'], # Not saving config/state to YAML )) self.add(pr.RemoteVariable( From ccd065eec3c28ac27ac901edb950b9f17fdae73f Mon Sep 17 00:00:00 2001 From: Larry Ruckman Date: Tue, 11 Jun 2024 20:11:48 -0700 Subject: [PATCH 12/12] Change RST to RemoteCommand and add hideConfig arg --- python/surf/devices/ti/_Ina237.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/python/surf/devices/ti/_Ina237.py b/python/surf/devices/ti/_Ina237.py index 625a1b0aa9..8e90e2de98 100644 --- a/python/surf/devices/ti/_Ina237.py +++ b/python/surf/devices/ti/_Ina237.py @@ -14,6 +14,7 @@ class Ina237(pr.Device): def __init__(self, pollInterval = 1, senseRes = 20.E-3, # Units of Ohms + hideConfig = True, **kwargs): super().__init__(**kwargs) @@ -22,21 +23,21 @@ def __init__(self, name = 'SenseRes', mode = 'RW', value = senseRes, - hidden = True, + hidden = hideConfig, )) ############## # 0h CONFIG ############## - self.add(pr.RemoteVariable( + self.add(pr.RemoteCommand( name = 'RST', description = 'Reset Bit. Setting this bit to 1 generates a system reset that is the same as power-on reset.', offset = (0x0 << 2), bitSize = 1, bitOffset = 15, - mode = 'WO', - hidden = True, + function = lambda cmd: (cmd.post(1), self.readBlocks(checkEach=True))[0], + hidden = hideConfig, )) self.add(pr.RemoteVariable( @@ -47,7 +48,7 @@ def __init__(self, bitOffset = 6, mode = 'RW', units = '2ms', - hidden = True, + hidden = hideConfig, )) self.add(pr.RemoteVariable( @@ -61,7 +62,7 @@ def __init__(self, 0 : '+/-163.84mV', 1 : '+/-40.96mV', }, - hidden = True, + hidden = hideConfig, )) ############## @@ -75,7 +76,7 @@ def __init__(self, bitSize = 4, bitOffset = 12, mode = 'RW', - hidden = True, + hidden = hideConfig, )) self.add(pr.RemoteVariable( @@ -85,7 +86,7 @@ def __init__(self, bitSize = 3, bitOffset = 9, mode = 'RW', - hidden = True, + hidden = hideConfig, )) self.add(pr.RemoteVariable( @@ -95,7 +96,7 @@ def __init__(self, bitSize = 3, bitOffset = 6, mode = 'RW', - hidden = True, + hidden = hideConfig, )) self.add(pr.RemoteVariable( @@ -105,7 +106,7 @@ def __init__(self, bitSize = 3, bitOffset = 3, mode = 'RW', - hidden = True, + hidden = hideConfig, )) self.add(pr.RemoteVariable( @@ -115,7 +116,7 @@ def __init__(self, bitSize = 3, bitOffset = 0, mode = 'RW', - hidden = True, + hidden = hideConfig, )) ############## @@ -129,7 +130,7 @@ def __init__(self, bitSize = 15, bitOffset = 0, mode = 'RW', - hidden = True, + hidden = hideConfig, )) @@ -146,7 +147,7 @@ def __init__(self, base = pr.Int, mode = 'RO', pollInterval = pollInterval, - hidden = True, + hidden = hideConfig, )) ############## @@ -162,7 +163,7 @@ def __init__(self, base = pr.Int, mode = 'RO', pollInterval = pollInterval, - hidden = True, + hidden = hideConfig, )) ############## @@ -178,7 +179,7 @@ def __init__(self, base = pr.Int, mode = 'RO', pollInterval = pollInterval, - hidden = True, + hidden = hideConfig, )) ###############################################################################