19from timing.common.definitions import kBoardSim, kBoardFMC, kBoardPC059, kBoardMicrozed, kBoardTLU, kBoardMIB, kBoardGIB, kBoardPC069
28def debug(obj, device):
30 Timing master commands.
32 DEVICE: uhal device identifier
34 lDevice = obj.mConnectionManager.getDevice(str(device))
36 lDevice.setTimeoutPeriod(obj.mTimeout)
38 echo(
'Created device ' + click.style(lDevice.id(), fg=
'blue'))
40 lBoardInfo = toolbox.readSubNodes(lDevice.getNode(
'io.config'),
False)
46 echo(
"Design '{}' on board '{}' on carrier '{}'".format(
47 style(kDesignNameMap[lBoardInfo[
'design_type'].value()], fg=
'blue'),
48 style(kBoardNameMap[lBoardInfo[
'board_type'].value()], fg=
'blue'),
49 style(kCarrierNameMap[lBoardInfo[
'carrier_type'].value()], fg=
'blue')
53 obj.mBoardType = lBoardInfo[
'board_type'].value()
54 obj.mCarrierType = lBoardInfo[
'carrier_type'].value()
55 obj.mDesignType = lBoardInfo[
'design_type'].value()
60@debug.command('inspect')
61@click.argument('nodes')
97 lBoardType = obj.mBoardType
98 lIO = lDevice.getNode(
'io')
101 if lBoardType
in [kBoardPC059, kBoardTLU, kBoardMIB, kBoardGIB]:
102 lUID = lDevice.getNode(
'io.i2c')
104 lUID = lDevice.getNode(
'io.uid_i2c')
106 lPROMSlave =
'UID_PROM' if lBoardType
in [kBoardTLU,kBoardMIB,kBoardGIB]
else 'FMC_UID_PROM'
108 if lBoardType == kBoardGIB:
109 lDevice.getNode(
"io.csr.ctrl.i2c_sw_rst").write(0x0)
111 lDevice.getNode(
"io.csr.ctrl.i2c_sw_rst").write(0x1)
113 lIO.set_i2c_mux_channels(0x1)
115 lValues = lUID.get_slave(lPROMSlave).read_i2cArray(0xfa, 6)
118 lUniqueID = ( lUniqueID << 8 ) | lVal
119 echo(
"Timing Board PROM UID: "+style(hex(lUniqueID), fg=
"blue"))
124@debug.command('sfpexpander', short_help="Debug.")
127 lDevice = obj.mDevice
128 lBoardType = obj.mBoardType
130 if lBoardType != kBoardPC059:
131 secho(
'No SFP expander on {}'.format(kBoardNameMap[lBoardInfo[
'board_type'].value()]))
133 lI2CBusNode = lDevice.getNode(
"io.i2c")
134 lSFPExp = I2CExpanderSlave(lI2CBusNode, lI2CBusNode.get_slave(
'SFPExpander').get_i2c_address())
135 lSFPExpStatus = lSFPExp.debug()
147 for a,v
in enumerate(lSFPExpStatus):
148 echo(
"{} ({}): {}".format(lLabels[a], hex(a), hex(v)))
153@debug.command('scan-i2c', short_help="Debug.")
156 lDevice = obj.mDevice
157 lBoardType = obj.mBoardType
162 if lBoardType
in [kBoardFMC, kBoardPC069]:
163 lNodes = [
'io.sfp_i2c',
'io.uid_i2c',
'io.pll_i2c']
164 elif lBoardType == kBoardPC059:
165 lNodes = [
'io.i2c',
'io.usfp_i2c']
166 switch_address=lDevice.getNode(
'io.i2c').get_slave_address(
'SFP_Switch')
167 lSwitches={
"io.i2c": switch_address}
168 lSwitchChannels={
"io.i2c": 8}
169 elif lBoardType
in [kBoardTLU, kBoardMIB, kBoardGIB]:
171 if lBoardType == kBoardGIB:
172 lSwitches={
"io.i2c": 0x70}
173 lSwitchChannels={
"io.i2c": 7}
175 secho(f
"Error I don't know about board {lBoardType} : {kBoardNameMap[lBoardType]}", fg=
'red')
183 lI2CBusNode = lDevice.getNode(n)
184 echo(
'Scanning '+style(n,fg=
'cyan'))
185 lAddresses = lI2CBusNode.scan()
186 print(
" '{}': {} devices found.\n Addresses: {}".format(n, len(lAddresses),
', '.join((hex(a)
for a
in lAddresses))))
188 print(f
" Found {len(lSwitches)} switches.\n Addresses: {lSwitches.values()}")
189 for switch,address
in lSwitches.items():
190 print (f
"switch {switch} address: {address}")
191 switch_channels=lSwitchChannels[switch]
192 print(f
"working with {switch}, @ adr {address}, it has {switch_channels} channels")
193 for channel
in range(0,switch_channels):
194 secho(f
"Scanning with channel {channel} enabled", fg=
'cyan')
195 lI2CBusNode.write_i2cPrimitive(address, [1<<channel])
196 lAddresses = lI2CBusNode.scan()
197 print(
" '{}': {} devices found.\n Addresses: {}".format(n, len(lAddresses),
', '.join((hex(a)
for a
in lAddresses))))
203@debug.command('fanout-sfp-scan', short_help="Debug.")
207 lDevice = obj.mDevice
208 lBoardType = obj.mBoardType
210 if lBoardType != kBoardPC059:
211 print(
'Wrong board', lBoardType,
'sorry mate')
215 lDevice.getNode(
'io.csr.ctrl.rst_i2cmux').write(0x1)
217 lDevice.getNode(
'io.csr.ctrl.rst_i2cmux').write(0x0)
221 lSFPNodeName =
'io.i2c'
222 lI2CBusNode = lDevice.getNode(lSFPNodeName)
223 lSwitchSlave = lI2CBusNode.get_slave(
'SFP_Switch')
224 print(lSwitchSlave.ping())
229 lSwitchSlave.write_i2cPrimitive([3])
230 print(lSwitchSlave.read_i2cPrimitive(1))
231 print(lSwitchSlave.read_i2cPrimitive(1))
232 print(lSwitchSlave.read_i2cPrimitive(1))
235@debug.command('sfp-status', short_help="Debug.")
292 def asciidecode( v ):
293 return (
''.join([chr(c)
for c
in v])).rstrip()
296 lSign = -1
if ((v[0]>>7) & 0x1)
else 1
297 x = lSign*((v[0] & 0x7f) + v[1]/float(0xff))
298 return '{:.3f} C'.format(x)
301 return '{:.4f} V'.format(((v[0] << 8) + v[1])/float(10000))
303 def biascurdecode( v ):
304 return '{:.3f} mA'.format(((v[0] << 8) + v[1])*2e-3)
306 def powerdecode( v ):
307 return '{:.3f} mW'.format(((v[0] << 8) + v[1])*1e-3)
311 lVenInfoEnc = collections.OrderedDict()
312 lVenInfoEnc[
'Name'] = asciidecode(aEEProm.read_i2cArray(20,16))
313 lVenInfoEnc[
'OUI'] =
'{}.{}.{}'.format(*(aEEProm.read_i2cArray(37,3)))
314 lVenInfoEnc[
'Part Number'] = asciidecode(aEEProm.read_i2cArray(40,16))
315 lVenInfoEnc[
'Revision'] = asciidecode(aEEProm.read_i2cArray(56,4))
316 lVenInfoEnc[
'Serial Number'] = asciidecode(aEEProm.read_i2cArray(68,16))
317 lVenInfoEnc[
'Day'] = asciidecode(aEEProm.read_i2cArray(88,2))
318 lVenInfoEnc[
'Month'] = asciidecode(aEEProm.read_i2cArray(86,2))
319 lVenInfoEnc[
'Year'] = asciidecode(aEEProm.read_i2cArray(84,2))
321 secho(
"{} Vendor info".format(aLabel), fg=
'cyan')
325 echo(toolbox.formatDictTable(lVenInfoEnc, aHdr=
False, aSort=
False))
327 lLaserWl = aEEProm.read_i2cArray(60,2)
328 lLaserWl = (lLaserWl[0] << 8) + lLaserWl[1]
329 echo(
'Laser Wavelength: '+style(str(lLaserWl)+
'nm', fg=
'cyan'))
331 lRegs = collections.OrderedDict()
333 lRegs[
'Identifier'] = aEEProm.read_i2c(0)
334 lRegs[
'Ext Identifier'] = aEEProm.read_i2c(1)
335 lRegs[
'Connector'] = aEEProm.read_i2c(2)
338 lTransComp = aEEProm.read_i2cArray(3, 8)
340 lRegs[
'Encoding'] = aEEProm.read_i2c(11)
341 lRegs[
'BR, Nominal'] = aEEProm.read_i2c(12)
342 lRegs[
'Rate ID'] = aEEProm.read_i2c(13)
344 toolbox.printRegTable(lRegs, aHeader=
False, sort=
False)
347 secho(
"{} Diagnostic info".format(aLabel), fg=
'cyan')
349 lReadings = collections.OrderedDict()
351 lReadings[
'Temp'] = tempdecode(aDiag.read_i2cArray(96, 2))
352 lReadings[
'Vcc'] = vccdecode(aDiag.read_i2cArray(98, 2))
353 lReadings[
'TX bias'] = biascurdecode(aDiag.read_i2cArray(100, 2))
354 lReadings[
'TX power'] = powerdecode(aDiag.read_i2cArray(102, 2))
355 lReadings[
'RX power'] = powerdecode(aDiag.read_i2cArray(104, 2))
356 lMiscStatus = aDiag.read_i2c(110)
357 lReadings[
'TX disable'] = (lMiscStatus >> 7) & 0x1
362 echo(toolbox.formatDictTable(lReadings, aHdr=
False, aSort=
False))