1from __future__
import print_function
10from .factory
import ShellFactory, ShellContext
11from click
import echo, style, secho
12from timing.core import SI534xSlave, I2CExpanderSlave, DACSlave
16from timing.common.definitions import kDesignOverlord, kDesignMaster, kDesignOuroboros, kDesignOuroborosSim, kDesignEndpoint, kDesignFanout
19from os.path
import join, expandvars, basename
31 lMaster = self.device.getNode(
'master')
32 lExtTrigNode = self.device.getNode(
'trig_rx')
33 lIO = self.device.getNode(
'io')
35 lVersion = lMaster.getNode(
'global.version').read()
36 lGenerics = toolbox.readSubNodes(lMaster.getNode(
'global.config'),
False)
37 self.device.dispatch()
39 lMajor = (lVersion >> 16) & 0xff
40 lMinor = (lVersion >> 8) & 0xff
41 lPatch = (lVersion >> 0) & 0xff
43 lMstCtx.version = (lVersion.value(), lMajor, lMinor, lPatch)
44 lMstCtx.generics = {k:v.value()
for k,v
in lGenerics.items()}
47 secho(
'ERROR: Incompatible master firmware version. Found {}, required {}'.format(hex(lMajor), hex(kMasterFWMajorRequired)), fg=
'red')
51 lMstCtx.masterNode = lMaster
52 lMstCtx.globalNode = lMaster.getNode(
'global')
53 lMstCtx.aCmdNode = lMaster.getNode(
'acmd')
54 lMstCtx.echoNode = lMaster.getNode(
'echo')
55 lMstCtx.extTrigNode = lExtTrigNode
64 echo(
"design '{}' on board '{}' on carrier '{}'".format(
65 style(kDesignNameMap[self.info.designType], fg=
'blue'),
66 style(kBoardNameMap[self.info.boardType], fg=
'blue'),
67 style(kCarrierNameMap[self.info.carrierType], fg=
'blue')
69 echo(
"Master FW rev: {}, partitions: {}, channels: {}".format(
70 style(hex(self.
masterCtx.version[0]), fg=
'cyan'),
71 style(str(self.
masterCtx.generics[
'n_part']), fg=
'cyan'),
72 style(str(self.
masterCtx.generics[
'n_chan']), fg=
'cyan'),
80 for pid
in range(self.
masterCtx.generics[
'n_part']):
82 lPartNode = self.
masterCtx.masterNode.getNode(
'partition{}'.format(pid))
85 lPartNode.configure(0x0,
False);
95 firmmware_frequency_hz = lIO.read_firmware_frequency()
97 lTStampReadNode = lMaster.getNode(
'tstamp.ctr.val')
98 lTStampWriteNode = lMaster.getNode(
'tstamp.ctr.set')
100 lTimeStamp = lTStampReadNode.readBlock(2)
101 lTStampReadNode.getClient().dispatch()
103 lTime = int(lTimeStamp[0]) + (int(lTimeStamp[1]) << 32)
104 secho(
'Old Timestamp {}'.format(hex(lTime)), fg=
'cyan')
107 lNow = int(time.time()*firmmware_frequency_hz)
108 lNowH = (lNow >> 32) & ((1<<32)-1)
109 lNowL = (lNow >> 0) & ((1<<32)-1)
112 lTStampWriteNode.writeBlock([lNowL, lNowH])
113 lTStampWriteNode.getClient().dispatch()
116 lTimeStamp = lTStampReadNode.readBlock(2)
117 lTStampReadNode.getClient().dispatch()
119 lTime = (int(lTimeStamp[1]) << 32) + int(lTimeStamp[0])
121 secho(
'New Timestamp {}'.format(hex(lTime)), fg=
'cyan')
123 print(float(lTime)/firmmware_frequency_hz - x)
125 echo (
"DeltaT {}".format(toolbox.formatTStamp(lTimeStamp)))
135 lGlobal.getNode(
'csr.ctrl.ep_en').write(0x0)
136 lGlobal.getClient().dispatch()
137 lGlobal.getNode(
'csr.ctrl.ep_en').write(0x1)
138 lGlobal.getClient().dispatch()
141 lTOutStart = time.time()
143 while time.time() < lTOutStart + aTimeout:
146 lEptRdy = lGlobal.getNode(
'csr.stat.ep_rdy').read()
147 lEptStat = lGlobal.getNode(
'csr.stat.ep_stat').read()
148 lEptFDel = lGlobal.getNode(
'csr.stat.ep_fdel').read()
149 lEptEdge = lGlobal.getNode(
'csr.stat.ep_edge').read()
150 lGlobal.getClient().dispatch()
152 if int(lEptRdy) == 1:
155 if int(lEptRdy) == 0:
156 raise RuntimeError(
'Failed to bring up the RTT endpoint. Current state {}'.format(hex(lEptStat)))
159 return (lEptFDel.value(), lEptEdge.value())
168 lEcho.getNode(
'csr.ctrl.go').write(0x1)
169 lEcho.getClient().dispatch()
170 lTOutStart = time.time()
171 while time.time() < lTOutStart + aTimeout:
174 lDone = lEcho.getNode(
'csr.stat.rx_done').read()
175 lEcho.getClient().dispatch()
180 raise RuntimeError(
"Timeout while waiting for echo")
182 lTimeRxL = lEcho.getNode(
'csr.rx_l').read()
183 lTimeRxH = lEcho.getNode(
'csr.rx_h').read()
184 lTimeTxL = lEcho.getNode(
'csr.tx_l').read()
185 lTimeTxH = lEcho.getNode(
'csr.tx_h').read()
186 lEcho.getClient().dispatch()
188 lTimeRx = (lTimeRxH << 32) + lTimeRxL
189 lTimeTx = (lTimeTxH << 32) + lTimeTxL
191 return lTimeTx, lTimeRx
201 toolbox.resetSubNodes(lACmd.getNode(
'csr.ctrl'), dispatch=
False)
202 lACmd.getNode(
'csr.ctrl.tx_en').write(0x1)
203 lACmd.getNode(
'csr.ctrl.addr').write(aAddr)
204 lACmd.getNode(
'csr.ctrl.cdel').write(aCDel)
205 lACmd.getNode(
'csr.ctrl.update').write(0x1)
206 lACmd.getNode(
'csr.ctrl.go').write(0x1)
207 lACmd.getNode(
'csr.ctrl.go').write(0x0)
208 lACmd.getClient().dispatch()
209 secho(
'Coarse delay {} applied'.format(aCDel), fg=
'green')
218 toolbox.resetSubNodes(lACmd.getNode(
'csr.ctrl'))
219 lACmd.getNode(
'csr.ctrl.addr').write(aAddr)
220 lACmd.getNode(
'csr.ctrl.tx_en').write(aEnable)
221 lACmd.getNode(
'csr.ctrl.go').write(0x1)
222 lACmd.getNode(
'csr.ctrl.go').write(0x0)
223 lACmd.getClient().dispatch()
229ShellFactory.registerBoard(kDesignOverlord, MasterShell)
enableEptAndWaitForReady(self, aTimeout=0.5)
enableEndpointSFP(self, aAddr, aEnable=1)
send_echo_and_measure_delay(self, aTimeout=0.5)
pushDelay(self, aAddr, aCDel)