DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
endpoint.py
Go to the documentation of this file.
1import click
2import sys
3
4import collections
5
6from . import toolbox
7import timing.common.definitions as defs
8from timing.common.definitions import kLibrarySupportedBoards, kLibrarySupportedDesigns
9from timing.common.toolbox import format_firmware_version
10
11from click import echo, style, secho
12import time
13
14# ------------------------------------------------------------------------------
15# ____ __ _ __
16# / __/__ ___/ /__ ___ (_)__ / /_
17# / _// _ \/ _ / _ \/ _ \/ / _ \/ __/
18# /___/_//_/\_,_/ .__/\___/_/_//_/\__/
19# /_/
20@click.group('ept', invoke_without_command=True)
21@click.pass_obj
22@click.argument('device', callback=toolbox.validate_device, shell_complete=toolbox.completeDevices)
23@click.argument('id', type=int)
24def endpoint(obj, id, device):
25 '''
26 Endpoint master commands.
27
28 \b
29 DEVICE: uhal device identifier
30 '''
31
32 lDevice = obj.mConnectionManager.getDevice(str(device))
33 if obj.mTimeout:
34 lDevice.setTimeoutPeriod(obj.mTimeout)
35
36 echo('Created endpoint device ' + style(lDevice.id(), fg='blue'))
37 lTopDesign = lDevice.getNode('')
38
39 lBoardInfo = toolbox.readSubNodes(lDevice.getNode('io.config'), False)
40 lDevice.dispatch()
41
42 if lBoardInfo['board_type'].value() in kLibrarySupportedBoards and lBoardInfo['design_type'].value() in kLibrarySupportedDesigns:
43
44 lTopDesign.validate_firmware_version()
45
46 try:
47 echo(lDevice.getNode('io').get_hardware_info())
48 except:
49 secho("Failed to retrieve hardware information! I2C issue? Initial board reset needed?", fg='yellow')
50 e = sys.exc_info()[0]
51 secho("Error: {}".format(e), fg='red')
52
53 # Ensure that target endpoint exists
54 lEPNames = lDevice.getNodes(f"endpoint{id}")
55
56 if len(lEPNames) == 0:
57 raise click.ClickException(f"Endpoint {id} does not exist")
58 elif len(lEPNames) > 1:
59 raise click.ClickException(f"Multiple endpoint {id} matches")
60
61 obj.mDevice = lDevice
62 obj.mEndpoint = lDevice.getNode(f"endpoint{id}")
63 obj.mIO = lDevice.getNode('io')
64# ------------------------------------------------------------------------------
65
66
67# ------------------------------------------------------------------------------
68@endpoint.command('freq', short_help="Measure some frequencies.")
69@click.pass_obj
70def freq(obj):
71 lEndPointNode = obj.mEndpoint
72
73 secho("Endpoint frequency measurement:", fg='cyan')
74 # Measure the generated clock frequency
75 freq = ep.read_clock_frequency()
76
77 echo( "Endpoint freq MHz : {}".format(freq) )
78# ------------------------------------------------------------------------------
79
80
81# ------------------------------------------------------------------------------
82@endpoint.command('enable')
83@click.argument('action', default='on', type=click.Choice(['on', 'off', 'reset']))
84@click.option('--address', '-a', type=toolbox.IntRange(0x0,0xffff), help='Address', default=0)
85@click.pass_obj
86@click.pass_context
87def enable(ctx, obj, action, address):
88 '''
89 Activate timing endpoint wrapper block.
90 '''
91
92 lEndPointNode = obj.mEndpoint
93 if action == 'off':
94 lEndPointNode.disable()
95 elif action == 'on':
96 lEndPointNode.enable(address)
97 elif action == 'reset':
98 lEndPointNode.reset(address)
99
100 time.sleep(1)
101 ctx.invoke(status)
102# ------------------------------------------------------------------------------
103
104
105# ------------------------------------------------------------------------------
106@endpoint.command('status', short_help='Display the status of timing endpoint.')
107@click.pass_obj
108@click.option('--watch', '-w', is_flag=True, default=False, help='Turn on automatic refresh')
109@click.option('--period', '-p', type=click.IntRange(0, 240), default=2, help='Period of automatic refresh')
110def status(obj, watch, period):
111 '''
112 Display the endpoint status, accepted and rejected command counters
113 '''
114 lNumCtrs = 0x10
115
116 lDevice = obj.mDevice
117 lEndPointNode = obj.mEndpoint
118
119 while(True):
120 if watch:
121 click.clear()
122
123 echo ( lEndPointNode.get_status() )
124
125 if watch:
126 time.sleep(period)
127 else:
128 break
129# ------------------------------------------------------------------------------
130
131
132# ------------------------------------------------------------------------------
133@endpoint.command('readback', short_help='Read the content of the endpoint master readout buffer.')
134@click.pass_obj
135@click.option('--all/--events', '-a/ ', 'readall', default=False, help="Buffer readout mode.\n- events: only completed events are readout.\n- all: the content of the buffer is fully read-out.")
136def readback(obj, readall):
137 '''
138 Read the content of the endpoint master readout buffer.
139 '''
140 lDevice = obj.mDevice
141 lEndPointNode = obj.mEndpoint
142
143 echo(lEndPointNode.get_data_buffer_table(readall))
144# ------------------------------------------------------------------------------
readback(obj, readall)
Definition endpoint.py:136
status(obj, watch, period)
Definition endpoint.py:110