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

Clk status regs #2

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Firmware/Projects/cm_mcu_hwtest/sm_cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ void SmCm_IntHandlerSmPowerEna(void)
// CM power up requested by SM.
if (GpioGet_SmPowerEna()) {
// Turn on the CM power domains.
// PowerControl_All(true, 1);
PowerControl_Clock(true, 1);
PowerControl_KU15P(true, 1);
PowerControl_ZU11EG(true, 1);
PowerControl_All(true, 1);
// PowerControl_Clock(true, 1);
// PowerControl_KU15P(true, 1);
// PowerControl_ZU11EG(true, 1);
// PowerControl_FireFly(true, 1);
// Drive the CM_READY output high.
GpioSet_CmReady(1);
Expand Down
140 changes: 138 additions & 2 deletions Software/HwTest/pyMcu/hw/I2C_Si53xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os
import McuI2C
import I2CDevice

import time


class I2C_Si53xx:
Expand All @@ -29,7 +29,24 @@ class I2C_Si53xx:

# Hardware parameters.
fileRegMapMarkComment = "#"

hwAdrMin = 0x0C
hwAdrMax = 0x12

#definition common for chips
# in reg 0x000C
SYSINCAL_b = 0x1
LOSXAXB_b = 0x2
# in reg 0x000D
LOSIN_b = 0xF #Loss of Signal for the FB_IN, IN2, IN1, IN0 inputs

# in reg 0x000E
LOL_reg = 0x0E
LOL_b = 0x2
# these are only for 5340-41
# in reg 0x000C
LOSREF_b = 0x4
# LOL_b = 0x8
SMBUS_TIMEOUT_b = 0x20

# Initialize the I2C device.
def __init__(self, mcuI2C, slaveAddr, deviceName):
Expand All @@ -40,6 +57,12 @@ def __init__(self, mcuI2C, slaveAddr, deviceName):
self.i2cDevice.debugLevel = self.debugLevel
self.prefixDebugDevice = self.prefixDebug + self.deviceName + ": "
self.prefixErrorDevice = self.prefixError + self.deviceName + ": "
pos = deviceName.find('Si')
self.ICtype = deviceName[pos:pos+7]
if self.ICtype == "Si5341A":
self.LOL_reg = 0x0C
self.LOL_b = 0x8




Expand Down Expand Up @@ -75,6 +98,12 @@ def config_file(self, fileRegMapName):
lineCommentRemoved = lineStripped[0:lineStripped.find(self.fileRegMapMarkComment)].strip(' \t')
else:
lineCommentRemoved = lineStripped
# if line includes word Delay in pos 2, then delay
if lineStripped.find("Delay") == 2:
if self.debugLevel >= 3:
print(self.prefixDebugDevice + "Delay found, delaying 300ms")
time.sleep(0.3)
continue
# Get list of elements.
lineElements = list(filter(None, lineCommentRemoved.split(",")))
lineElements = list(el.strip(' \t\n\r') for el in lineElements)
Expand Down Expand Up @@ -104,3 +133,110 @@ def config_file(self, fileRegMapName):
return -1
return 0

def check_adr(self, regAdr):
if regAdr < self.hwAdrMin or regAdr > self.hwAdrMax:
print(self.prefixErrorDevice + "Data word register value {0:d} out of valid range {1:d}..{2:d}!".\
format(regAdr, self.hwAdrMin, self.hwAdrMax))
return -1
return 0

# Return the name of a register address.
def adr_to_name(self, regAdr):
regName = "*other/unknown*"
if regAdr == 0xC:
regName = "Status regs"
elif regAdr == 0xD:
regName = "Status reg: LOSIN"
elif regAdr == 0xE:
regName = "Status reg: LOL"
elif regAdr == 0x11:
regName = "Sticky Status regs _FLG"
elif regAdr == 0x12:
regName = "Sticky Status reg: LOSIN_FLG"
elif regAdr == 0x13:
regName = "Sticky Status reg: LOL_FLG"
return regName

# Read a register value.
def read_reg(self, regAdr):
self.i2cDevice.debugLevel = self.debugLevel
if self.check_adr(regAdr):
return -1, 0xff
regName = self.adr_to_name(regAdr)
# Debug info.
if self.debugLevel >= 2:
print(self.prefixDebugDevice + "Reading the value of the \"{0:s}\", register address 0x{1:02x}.".format(regName, regAdr), end='')
self.i2cDevice.print_details()
# Set the page register to 0x00
ret = self.i2cDevice.write([0x01, 0x00]) # status to readback only on pgae 0x00

dataWr = []
dataWr.append(regAdr)
# Write command and read data with repeated start.
ret, dataRd = self.i2cDevice.write_read(dataWr, 1)
# Evaluate response.
if ret:
print(self.prefixErrorDevice + "Error reading the value of the \"{0:s}\", register address 0x{1:02x}!".format(regName, regAdr), end='')
self.i2cDevice.print_details()
print(self.prefixErrorDevice + "Error code: {0:d}: ".format(ret))
return -1, 0xff
if len(dataRd) != 1:
print(self.prefixErrorDevice + "Error reading the value of the \"{0:s}\", register address 0x{1:02x}: Incorrect amount of data received!".\
format(regName, regAdr), end='')
self.i2cDevice.print_details()
return -1, 0xff
# Calculate the value.
value = dataRd[0] & 0xff
# Debug info.
if self.debugLevel >= 2:
print(self.prefixDebugDevice + "Read the value of the \"{0:s}\", register address 0x{1:02x}: 0x{2:02x}.".format(regName, regAdr, value), end='')
self.i2cDevice.print_details()
return 0, value

def read_status_regs(self):
ret1, stats = self.read_reg(0xC)
ret2, LOSIN = self.read_reg(0xD)
ret3, LOL = self.read_reg(self.LOL_reg)
return ret1+ret2+ret3, stats & 0x2F, LOSIN & 0x0F, LOL & self.LOL_b

def read_sticky_status_regs(self):
ret1, s_stats = self.read_reg(0x11)
ret2, s_LOSIN = self.read_reg(0x12)
ret3, s_LOL = self.read_reg(self.LOL_reg)
return ret1+ret2+ret3, s_stats & 0x2F, s_LOSIN & 0x0F, LOL & self.LOL_b

def print_status_str(self):
ret, stats, LOSIN, LOL = self.read_status_regs()
if ret:
print(self.prefixErrorDevice + "Error reading status!", end='')
self.i2cDevice.print_details()
print(self.prefixErrorDevice + "Error code: {0:d}: ".format(ret))
return -1, "ERROR"
string = ""
string += "\t" + str((stats & self.SYSINCAL_b)==self.SYSINCAL_b)
string += "\t" + str((stats & self.LOSXAXB_b)==self.LOSXAXB_b)
string += "\t" + str(LOL == self.LOL_b)
string += "\t" + str(LOSIN)
if self.ICtype == "Si5341A":
string += "\t" + str((stats & self.LOSREF_b)==self.LOSREF_b)
string += "\t" + str((stats & self.SMBUS_TIMEOUT_b)==self.SMBUS_TIMEOUT_b)
return 0, string



def print_sticky_status_str(self):
ret, s_stats, s_LOSIN, s_LOL= self.read_sticky_status_regs()
if ret:
print(self.prefixErrorDevice + "Error reading sticky status!", end='')
self.i2cDevice.print_details()
print(self.prefixErrorDevice + "Error code: {0:d}: ".format(ret))
return -1, "ERROR"
string = ""
string += " " + str((s_stats & self.SYSINCAL_b)==self.SYSINCAL_b)
string += " " + str((s_stats & self.LOSXAXB_b)==self.LOSXAXB_b)
string += "\t" + str(S_LOL == self.LOL_b)
string += " " + str(s_LOSIN)
if self.ICtype == "Si5341A":
string += "\t" + str((s_stats & self.LOSREF_b)==self.LOSREF_b)
string += "\t" + str((s_stats & self.SMBUS_TIMEOUT_b)==self.SMBUS_TIMEOUT_b)
return 0, string
34 changes: 34 additions & 0 deletions Software/HwTest/pyMcu/hw/MdtTp_CM.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,40 @@ def clk_prog_all(self):
self.clk_prog_device_file(self.i2cDevice_IC85_Si5345A)


# get status bits for a single clock chip.
def clk_print_status(self, i2cDevice):
i2cDevice.debugLevel = self.debugLevel
muxChannel = i2cDevice.muxChannel
if self.debugLevel >= 2:
print(self.prefixDebug + "Setting I2C mux for clock chips {0:s} to channel {1:d}.".format(self.i2cDevice_IC55_PCA9547PW.deviceName, muxChannel))
self.i2cDevice_IC55_PCA9547PW.set_channel(muxChannel)
self.i2cDevice_IC55_PCA9547PW.debugLevel = self.debugLevel
i2cDevice.debugLevel = self.debugLevel
ret, status = i2cDevice.print_status_str()
if ret:
print("Failed reading status of {0:s} on I2C port {1:d} ".\
format(i2cDevice.deviceName, i2cDevice.mcuI2C.port))
else:
print("reading status of {0:s} on I2C port {1:d} is {2:s}".\
format(i2cDevice.deviceName, i2cDevice.mcuI2C.port, status))

def clk_print_status_all(self):
if self.debugLevel >= 1:
print(self.prefixDebug + "printing status for all clock chips.")
# print("status are: \tSYSINCAL LOSXAXB LOSREF LOL \tSMBUS_TIMEOUT LOSIN")
print("status are: \tSYSINCAL LOSXAXB LOL \tLOSIN LOSREF SMBUS_TIMEOUT")
self.clk_print_status(self.i2cDevice_IC54_Si5341A)
self.clk_print_status(self.i2cDevice_IC56_Si5345A)
self.clk_print_status(self.i2cDevice_IC60_Si5345A)
self.clk_print_status(self.i2cDevice_IC61_Si5342A)
self.clk_print_status(self.i2cDevice_IC62_Si5345A)
self.clk_print_status(self.i2cDevice_IC63_Si5345A)
self.clk_print_status(self.i2cDevice_IC81_Si5342A)
self.clk_print_status(self.i2cDevice_IC82_Si5344A)
self.clk_print_status(self.i2cDevice_IC83_Si5342A)
self.clk_print_status(self.i2cDevice_IC84_Si5345A)
self.clk_print_status(self.i2cDevice_IC85_Si5345A)


# ===============================================================
# FireFly modules.
Expand Down
4 changes: 3 additions & 1 deletion Software/HwTest/pyMcu/pyMcuCm.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'i2c_reset', 'i2c_detect',
'pm_status', 'pm_status_raw',
'clk_setup',
'firefly_temp', 'firefly_temp_time', 'firefly_status'],
'firefly_temp', 'firefly_temp_time', 'firefly_status', 'clk_status_regs'],
dest='command', default='status',
help='Command to execute on the CM.')
parser.add_argument('-d', '--device', action='store', type=str,
Expand Down Expand Up @@ -139,6 +139,8 @@
for i in range(1, mdtTp_CM.fireFlyNum + 1):
mdtTp_CM.firefly_status(i)
print()
elif command == "clk_status_regs":
mdtTp_CM.clk_print_status_all()
else:
print(prefixError + "Command `{0:s}' not supported!".format(command))

Expand Down