1from __future__
import print_function
16from click
import echo, style, secho
17from os.path
import join, expandvars, basename
18from timing.core import SI534xSlave, I2CExpanderSlave, DACSlave
20from timing.common.definitions import kBoardSim, kBoardFMC, kBoardPC059, kBoardMicrozed, kBoardTLU, kBoardFIB, kBoardMIB, kBoardPC069, kBoardGIB, kFIBRev2
21from timing.common.definitions import kFMCRev1, kFMCRev2, kFMCRev3, kFMCRev4, kPC059Rev1, kTLURev1, kSIMRev1, kFIBRev1, kMIBRev1, kGIBRev1
22from timing.common.definitions import kCarrierEnclustraA35, kCarrierKC705, kCarrierMicrozed, kCarrierNexusVideo, kCarrierTrenzTE0712
23from timing.common.definitions import kDesignMaster, kDesignOuroboros, kDesignOuroborosSim, kDesignEndpoint, kDesignFanout, kDesignChronos, kDesignBoreas, kDesignTest, kDesignKerberos, kDesignGaia, kDesignCharon, kDesignHades
35@click.group('io', invoke_without_command=True)
37@click.argument('device', callback=toolbox.validate_device, shell_complete=toolbox.completeDevices)
40 Timing master commands.
42 DEVICE: uhal device identifier
44 lDevice = obj.mConnectionManager.getDevice(str(device))
46 lDevice.setTimeoutPeriod(obj.mTimeout)
48 echo(
'Created device ' + click.style(lDevice.id(), fg=
'blue'))
49 lTopDesign = lDevice.getNode(
'')
50 lBoardInfo = toolbox.readSubNodes(lDevice.getNode(
'io.config'),
False)
53 if lBoardInfo[
'board_type'].value()
in kLibrarySupportedBoards
and lBoardInfo[
'design_type'].value()
in kLibrarySupportedDesigns:
54 lTopDesign.validate_firmware_version()
56 echo(
"Design '{}' on board '{}' on carrier '{}' with frequency {} MHz".format(
57 style(kDesignNameMap[lBoardInfo[
'design_type'].value()], fg=
'blue'),
58 style(kBoardNameMap[lBoardInfo[
'board_type'].value()], fg=
'blue'),
59 style(kCarrierNameMap[lBoardInfo[
'carrier_type'].value()], fg=
'blue'),
60 style(str(lBoardInfo[
'clock_frequency'].value()/1e6), fg=
'blue')
65 obj.mBoardType = lBoardInfo[
'board_type'].value()
66 obj.mCarrierType = lBoardInfo[
'carrier_type'].value()
67 obj.mDesignType = lBoardInfo[
'design_type'].value()
72@io.command('reset', short_help="Perform a hard reset on the timing master.")
73@click.option('--soft', '-s', is_flag=True, default=False, help='Soft reset i.e. skip the clock chip configuration.')
74@click.option('--clock-source', 'clocksource', type=click.Choice(ClockSource.__members__.keys()), help=
'Manually specify clock source, free-running, upstream, etc..')
75@click.option('--force-pll-cfg', 'forcepllcfg', type=click.Path(exists=True), help=
'Manually specify clock config file' )
78def reset(ctx, obj, soft, clocksource, forcepllcfg):
80 Perform a hard reset on a timing board, including
85 - pll and pll configuration
88 echo(
'Resetting ' + click.style(obj.mDevice.id(), fg=
'blue'))
91 lBoardType = obj.mBoardType
92 lDesignType = obj.mDesignType
94 lIO = lDevice.getNode(
'io')
96 if lBoardType
in kLibrarySupportedBoards:
102 if forcepllcfg
is not None:
103 if clocksource
is not None:
104 secho(
"You specified both a clock source for automatic clock config file look-up, and an explicit clock config file. Explicit clock config file will take precedence.", fg=
'yellow')
106 lIO.reset(forcepllcfg)
108 if clocksource
is None:
109 if lDesignType
in [kDesignMaster, kDesignBoreas, kDesignOuroboros, kDesignOuroborosSim]:
110 lClockSource=kFreeRun
111 elif lDesignType
in [kDesignEndpoint, kDesignChronos, kDesignFanout, kDesignHades, kDesignCharon]:
113 elif lDesignType
in [kDesignGaia, kDesignKerberos]:
116 secho(
"Unable to match a default clock source for design {}\nReset failed!".format(lDesignType), fg=
'red')
119 lClockSource=ClockSource.__members__[clocksource]
121 lIO.reset(lClockSource)
122 ctx.invoke(clkstatus)
124 secho(
"Board identifier {} not supported by timing library".format(lBoardType), fg=
'yellow')
129@io.command('freq', short_help="Measure some frequencies.")
132 lDevice = obj.mDevice
133 lBoardType = obj.mBoardType
134 lIO = lDevice.getNode(
'io')
136 secho(
"PLL Clock frequency measurement:", fg=
'cyan')
138 if lBoardType
in kLibrarySupportedBoards:
139 echo(lIO.get_clock_frequencies_table())
141 secho(
"Board {} not supported by timing library".format(lBoardType), fg=
'yellow')
143 if lBoardType == kBoardMIB:
147 secho(
'MIB clock freqs', fg=
'green')
154@click.option('-v', 'verbose', is_flag=True)
157 lDevice = obj.mDevice
158 lBoardType = obj.mBoardType
159 lIO = lDevice.getNode(
'io')
161 if lBoardType
in kLibrarySupportedBoards:
162 ctx.invoke(print_hardware_info)
163 echo(lIO.get_status())
165 secho(
"Board {} not supported by timing library".format(lBoardType), fg=
'yellow')
170@io.command('clk-status')
173@click.option('-v', 'verbose', is_flag=True)
176 lDevice = obj.mDevice
177 lDesignType = obj.mDesignType
178 lIO = lDevice.getNode(
'io')
179 lBoardType = obj.mBoardType
187 if lBoardType
in kLibrarySupportedBoards:
188 echo(lIO.get_pll_status())
190 secho(
"Board {} not supported by timing library".format(lBoardType), fg=
'yellow')
195@io.command('dac-setup')
196@click.argument('value', type=click.IntRange(0,0xffff))
201 lDevice = obj.mDevice
202 lBoardType = obj.mBoardType
203 lIO = lDevice.getNode(
'io')
205 if lBoardType == kBoardTLU:
206 lIO.configure_dac(0,value)
207 lIO.configure_dac(1,value)
208 secho(
"DAC1 and DAC2 set to " + hex(value), fg=
'cyan')
210 secho(
"DAC setup only supported for TLU")
214@io.command('sfp-status', short_help="Read SFP parameters.")
217@click.option('--sfp-id', 'sfp_id', required=False, type=click.IntRange(0, 8), help=
'SFP id to query.')
223 lDevice = obj.mDevice
224 lBoardType = obj.mBoardType
225 lCarrierType = obj.mCarrierType
226 lDesignType = obj.mDesignType
228 lIO = lDevice.getNode(
'io')
231 if lBoardType
in kLibrarySupportedBoards:
232 ctx.invoke(print_hardware_info)
233 if sfp_id
is not None:
234 echo(lIO.get_sfp_status(sfp_id))
236 if lBoardType
in [kBoardFMC, kBoardTLU, kBoardPC069]:
237 echo(lIO.get_sfp_status(0))
238 elif lBoardType
in [ kBoardPC059, kBoardFIB, kBoardMIB, kBoardGIB ]:
240 if lBoardType == kBoardPC059:
242 elif lBoardType == kBoardFIB:
244 elif lBoardType == kBoardMIB:
246 elif lBoardType == kBoardGIB:
248 for i
in range(lSFPIDRange):
250 echo(lIO.get_sfp_status(i))
253 secho(f
"SFP {i} status gather failed\n", fg=
'red')
256 secho(f
"I don't know how many SFPs there are for board: {timing.common.definitions.BoardType(lBoardType)}\n", fg=
'red')
259 secho(
"Board {} not supported by timing library".format(lBoardType), fg=
'yellow')
264@io.command('switch-sfp-tx', short_help="Control sfp tx")
267@click.option('--sfp-id', 'sfp_id', required=False, type=click.IntRange(0, 8), help=
'SFP id to query.')
268@click.option('--on/--off', default=False, help='enable/disable tx; default: FALSE')
271 Toggle SFP tx disable reg (if supported)
274 lDevice = obj.mDevice
275 lBoardType = obj.mBoardType
276 lCarrierType = obj.mCarrierType
277 lDesignType = obj.mDesignType
279 lIO = lDevice.getNode(
'io')
281 if lBoardType
in kLibrarySupportedBoards:
282 ctx.invoke(print_hardware_info)
286 lIO.switch_sfp_tx(lSFP, on)
288 secho(
"Board {} not supported by timing library".format(lBoardType), fg=
'yellow')
293@io.command('switch-sfp-mux', short_help="Switch sfp mux")
294@click.argument('mux', type=int)
298 lDevice = obj.mDevice
299 lBoardType = obj.mBoardType
300 lIO = lDevice.getNode(
'io')
302 if lBoardType
in [kBoardPC059]:
304 echo(
"Setting sfp mux channel: {}".format(mux))
305 lIO.switch_sfp_mux_channel(mux)
308 raise RuntimeError(
'Board {} does not have a sfp mux!'.format(kBoardNameMap[lBoardType]))
312@io.command('print-hardware-info')
317 lDevice = obj.mDevice
318 lBoardType = obj.mBoardType
319 lIO = lDevice.getNode(
'io')
321 if lBoardType
in kLibrarySupportedBoards:
323 echo(lIO.get_hardware_info())
325 secho(
"Failed to retrieve hardware information! I2C issue? Initial board reset needed?", fg=
'yellow')
326 e = sys.exc_info()[0]
327 secho(
"Error: {}".format(e), fg=
'red')
329 secho(
"Board {} not supported by timing library".format(lBoardType), fg=
'yellow')
status(ctx, obj, verbose)
sfpstatus(ctx, obj, sfp_id)
print_hardware_info(ctx, obj)
dacsetup(ctx, obj, value)
reset(ctx, obj, soft, clocksource, forcepllcfg)
switchsfptx(ctx, obj, sfp_id, on)
clkstatus(ctx, obj, verbose)