DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
timing.cli.hsi Namespace Reference

Functions

 hsi (obj, device)
 
 status (ctx, obj)
 
 configure (ctx, obj, src, re_mask, fe_mask, inv_mask, rate)
 
 readback (ctx, obj)
 
 read (ctx, obj, readall, continuous, print_out, read_period, save, file_name)
 

Function Documentation

◆ configure()

timing.cli.hsi.configure ( ctx,
obj,
src,
re_mask,
fe_mask,
inv_mask,
rate )
Configure the hsi in the hsi wrapper block.

Definition at line 86 of file hsi.py.

86def configure(ctx, obj, src, re_mask, fe_mask, inv_mask, rate):
87 '''
88 Configure the hsi in the hsi wrapper block.
89 '''
90
91 lDevice = obj.mDevice
92 lHSI = obj.mHSI
93 lTopDesign = obj.mTopDesign
94
95 lHSI.reset_hsi()
96 lTopDesign.configure_hsi(src, re_mask, fe_mask, inv_mask, rate)
97
98 secho("HSI configured", fg='green')
99
100 time.sleep(0.1)
101 ctx.invoke(status)
102# ------------------------------------------------------------------------------
103
104
105# ------------------------------------------------------------------------------
106@hsi.command('start', short_help='Start the hsi triggering and the writing events into buffer.')
107@click.pass_obj
108@click.pass_context

◆ hsi()

timing.cli.hsi.hsi ( obj,
device )
HSI commands.

\b
DEVICE: uhal device identifier
IDS: id(s) of the target endpoint(s).

Definition at line 25 of file hsi.py.

25def hsi(obj, device):
26 '''
27 HSI commands.
28
29 \b
30 DEVICE: uhal device identifier
31 IDS: id(s) of the target endpoint(s).
32 '''
33
34 lDevice = obj.mConnectionManager.getDevice(str(device))
35 if obj.mTimeout:
36 lDevice.setTimeoutPeriod(obj.mTimeout)
37
38
39 echo('Created HSI device')
40 lTopDesign = lDevice.getNode('')
41 lBoardInfo = toolbox.readSubNodes(lDevice.getNode('io.config'), False)
42 lDevice.dispatch()
43
44 if lBoardInfo['board_type'].value() in kLibrarySupportedBoards and lBoardInfo['design_type'].value() in kLibrarySupportedDesigns:
45 lTopDesign.validate_firmware_version()
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 obj.mDevice = lDevice
54 obj.mEndpoint = lDevice.getNode('endpoint0')
55 obj.mTopDesign = lDevice.getNode('')
56 obj.mHSI = obj.mTopDesign.get_hsi_node()
57# ------------------------------------------------------------------------------
58
59
60# ------------------------------------------------------------------------------
61@hsi.command('status')
62@click.pass_obj
63@click.pass_context

◆ read()

timing.cli.hsi.read ( ctx,
obj,
readall,
continuous,
print_out,
read_period,
save,
file_name )
Read the content of the endpoint master readout buffer.

Definition at line 151 of file hsi.py.

151def read(ctx, obj, readall, continuous, print_out, read_period, save, file_name):
152 '''
153 Read the content of the endpoint master readout buffer.
154 '''
155 lDevice = obj.mDevice
156 lHSI = obj.mHSI
157
158 read_events=0
159 if continuous:
160 secho("[INFO] Starting HSI data readout", fg='green')
161 if not (save or print_out):
162 secho('[WARNING] you have chosen to neither save or print the HSI data', fg='yellow')
163 last_ts=0
164 if save:
165 h5_file_name = datetime.now().strftime("hsi_data_%d_%m_%Y_%H_%M_%S.hdf5")
166 if file_name is not None:
167 h5_file_name=file_name
168
169 f = h5py.File(h5_file_name, "w")
170 hsi_dataset = f.create_dataset("hsi_frames", (0,7), maxshape=(None, 7), chunks=True, dtype='u4')
171 else:
172 if file_name is not None:
173 secho('[WARNING] You have provided a file name but chosen not to save the readout data', fg='yellow')
174
175 with toolbox.InterruptHandler() as h:
176 while(True):
177 n_words=0
178 hsi_words = lHSI.read_data_buffer(n_words,False,False)
179 n_hsi_events = len(hsi_words) // kHSIWordsNumber
180
181 if save:
182 hsi_dataset_start_index=hsi_dataset.shape[0]
183 hsi_dataset.resize(hsi_dataset_start_index+n_hsi_events, axis=0)
184
185 if (len(hsi_words) % kHSIWordsNumber == 0 and hsi_words.size() > 0):
186
187 for i in range(0,n_hsi_events):
188 start_index = i * kHSIWordsNumber
189 end_index = start_index + kHSIWordsNumber
190 raw_event=hsi_words[start_index:end_index]
191
192 header = raw_event[0]
193 ts_low = raw_event[1]
194 ts_high = raw_event[2]
195 data = raw_event[3]
196 trigger = raw_event[4]
197
198 ts = ts_low | (ts_high << 32)
199
200 # bits 15-0 contain the sequence counter
201 counter = header & 0x0000ffff
202
203 if (header >> 16) != 0xaa00:
204 secho("[ERROR] Invalid HSIEventHeader", fg='red')
205 continue
206
207 if ts == 0:
208 secho("[ERROR] Invalid HSIEvent timestamp", fg='red')
209 continue
210
211 delta_ticks=ts-last_ts
212 if last_ts == 0:
213 delta_ticks=0
214 last_ts=ts
215
216 if print_out:
217 print(f"[INFO] got event: {counter} ts: {ts} signals: {data} delta ts: {delta_ticks}")
218
219 read_events=read_events+1
220 if save:
221 hsi_dataset[hsi_dataset_start_index+i,0]=(0x1 << 6) | 0x1 # DAQHeader, frame version: 1, det id: 1
222 hsi_dataset[hsi_dataset_start_index+i,1]=ts_low
223 hsi_dataset[hsi_dataset_start_index+i,2]=ts_high
224 hsi_dataset[hsi_dataset_start_index+i,3]=data
225 hsi_dataset[hsi_dataset_start_index+i,4]=0x0
226 hsi_dataset[hsi_dataset_start_index+i,5]=trigger
227 hsi_dataset[hsi_dataset_start_index+i,6]=counter
228
229 elif len(hsi_words) != 0:
230 secho(f"[ERROR] unexpected n words {len(hsi_words)}", fg='red')
231 if h.interrupted:
232 secho(f"[INFO] Stopping HSI data readout after {read_events} events", fg='green')
233 break
234 time.sleep(read_period*1e-3)
235 if save:
236 f.close()
237 else:
238 echo(lHSI.get_data_buffer_table(readall,False))
239# ------------------------------------------------------------------------------

◆ readback()

timing.cli.hsi.readback ( ctx,
obj )
Read the content of the endpoint master readout buffer.

Definition at line 109 of file hsi.py.

109def readback(ctx, obj):
110 '''
111 Read the content of the endpoint master readout buffer.
112 '''
113 lDevice = obj.mDevice
114 lHSI = obj.mHSI
115
116 lHSI.start_hsi()
117 secho("HSI start", fg='green')
118
119 time.sleep(0.1)
120 ctx.invoke(status)
121# ------------------------------------------------------------------------------
122
123# ------------------------------------------------------------------------------
124@hsi.command('stop', short_help='Stop the hsi triggering and the writing events into buffer.')
125@click.pass_obj
126@click.pass_context

◆ status()

timing.cli.hsi.status ( ctx,
obj )
Print the status of CRT endpoint wrapper block.

Definition at line 64 of file hsi.py.

64def status(ctx, obj):
65 '''
66 Print the status of CRT endpoint wrapper block.
67 '''
68
69 lDevice = obj.mDevice
70 lHSI = obj.mHSI
71 lEndpoint = obj.mEndpoint
72
73 echo(lEndpoint.get_status())
74 echo(lHSI.get_status())
75# ------------------------------------------------------------------------------
76
77# ------------------------------------------------------------------------------
78@hsi.command('configure', short_help="Configure the HSI block for running")
79@click.pass_obj
80@click.pass_context
81@click.option('--src', '-s', type=click.IntRange(0x0,0x1), help='Source of HSI data,; 0: hardware; 1: timestamp (emulation mode)', default=0)
82@click.option('--re-mask', '-r', type=click.IntRange(0,0xffffffff), help='Rising edge mask', default=0)
83@click.option('--fe-mask', '-f', type=click.IntRange(0,0xffffffff), help='Falling edge mask', default=0)
84@click.option('--inv-mask', '-i', type=click.IntRange(0,0xffffffff), help='Invert mask', default=0)
85@click.option('--rate', type=float, help='Random trigger rate [Hz] on bit 0 in emulation mode', default=1)