Skip to content
Snippets Groups Projects
Commit c612ca69 authored by Gijs Schoonderbeek's avatar Gijs Schoonderbeek
Browse files

Added check backplane-ID

parent d9fd587d
No related branches found
No related tags found
1 merge request!3Apsct production
......@@ -64,3 +64,9 @@ EEPROM = 0x50
# I2C switch addresses
#
i2c_switch_addr = [0x70, 0x71, 0x72, 0x73]
#
# ID Pins
#
ID_PINS = [8, 7, 12, 16, 20, 21]
......@@ -45,6 +45,7 @@ class ApsctClass:
self.i2cswitch = []
for addr in APSCT_I2C.i2c_switch_addr:
self.i2cswitch.append(I2cSwitch(address=addr))
self.apsct_id = ApsctId()
def read_IO_expanderis(self):
#
......@@ -107,6 +108,7 @@ class ApsctClass:
#
result = self.sensors.check_values()
result = result & self.pps.check_timing()
result = result & self.apsct_id.check_id()
for i2c_switch in self.i2cswitch:
result = result & i2c_switch.check_switch(data=random.randint(0,2**8))
if self.frequency == "200MHz":
......@@ -241,24 +243,24 @@ class PllClass:
stri = "Reg nr 0x{:0>2x} value: 0x{:0>2x}".format(cnt, int(ret_value[start:start+8], 2))
print(stri)
def read_lock(self):
def read_lock(self, PRINT_ON=True):
#
# Read lock status
#
ret_value = self.Read_byte_PLL(0x00, nof_bytes=1)
status_pll = int(ret_value, 2)
stri = ""
if status_pll == 0x04:
self.lock = True
if DEBUG:
print("PLL in lock")
stri = f"PLL {self.frequency} is in lock"
elif (status_pll & 0x10) > 0:
self.lock = False
if DEBUG:
print("Not Locked --> No 10 MHz ref")
stri = f"PLL {self.frequency} Not Locked --> No 10 MHz ref"
else:
self.lock = False
if DEBUG:
print("Not locked --> PLL Error")
stri = f"PLL {self.frequency} Not locked --> PLL Error"
if PRINT_ON:
print(stri)
def read_lol(self):
#
......@@ -526,3 +528,36 @@ class I2cSwitch:
else:
print(f"ERROR wrote 0x{data:02X} read back 0x{read_value_int:02X}")
return False
class ApsctId:
#
# Class to check a I2C-switch
#
def __init__(self):
#
# APSCT Backplane ID
#
self.id = 9999
gpio.setmode(gpio.BCM)
for pin in APSCT_I2C.ID_PINS:
gpio.setup(pin, gpio.IN)
def read_id(self):
id = 0
for pin in APSCT_I2C.ID_PINS:
id = id * 2
bit = gpio.input(8)
id = id + bit
self.id = id
return self.id
def check_id(self):
self.read_id()
if self.id == 63:
print(f"OK : Back ID is 0x{self.id:02X}")
return True
else:
print(f"ERROR : Back ID is 0x{self.id:02X} expected 0x{63:2X}")
return False
return True
......@@ -28,21 +28,25 @@ if len(sys.argv) < 2:
apsct = apsct_lib.ApsctClass(CLK_FREQ)
state = True
modi = ["200MHz"] # , "160MHz", "OFF"]
if False : #for mode in modi:
modi = ["200MHz", "160MHz", "OFF"]
for mode in modi:
print(f"Check APSCT in {mode} mode")
apsct.frequency = mode
apsct.set_apsct()
if mode == "200MHz":
apsct.pll_200.read_lock()
if mode == "160MHz":
apsct.pll_160.read_lock()
apsct.sensors.apsct_sensors()
state = state & apsct.check_apsct()
apsct.frequency = "200MHz"
apsct.set_apsct()
apsct.pll_200.read_lock()
apsct.sensors.apsct_sensors()
state = state & apsct.check_apsct()
if READ_ALL:
apsct.pll_200.read_all_regs_pll()
# apsct.pll_160.read_all_regs_pll()
apsct.pll_160.read_all_regs_pll()
apsct.read_IO_expanderis()
if state:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment