51 FANOUT_DEVICES_NAMES=[],
53 ENDPOINT_CLOCK_FILE="",
56 PART_TRIGGER_MASK=0xff,
57 PART_SPILL_GATE_ENABLED=True,
58 PART_RATE_CONTROL_ENABLED=True,
59 UHAL_LOG_LEVEL="notice",
60 OUTPUT_PATH="./timing_app",
64 if exists(OUTPUT_PATH):
65 raise RuntimeError(f
"Directory {OUTPUT_PATH} already exists")
67 config_data = CONFIG[0]
68 config_file = CONFIG[1]
72 moo.otypes.load_types(
'timinglibs/timing_app_confgen.jsonnet')
73 import dunedaq.timinglibs.timing_app_confgen
as timing_app_confgen
75 moo.otypes.load_types(
'daqconf/bootgen.jsonnet')
76 import dunedaq.daqconf.bootgen
as daqconf_bootgen
78 moo.otypes.load_types(
'daqconf/hsigen.jsonnet')
79 import dunedaq.daqconf.hsigen
as daqconf_hsigen
81 moo.otypes.load_types(
'timinglibs/confgen.jsonnet')
82 import dunedaq.timinglibs.confgen
as daqconf_timing_confgen
85 boot = daqconf_bootgen.boot(**config_data.boot)
86 if DEBUG: console.log(f
"boot configuration object: {boot.pod()}")
89 thi_conf_gen = daqconf_timing_confgen.timing_hardware_interface(**config_data.timing_hardware_interface)
90 if DEBUG: console.log(f
"timing_hardware_interface configuration object: {thi_conf_gen.pod()}")
92 tmc_conf_gen = daqconf_timing_confgen.timing_master_controller(**config_data.timing_master_controller)
93 if DEBUG: console.log(f
"tmc configuration object: {tmc_conf_gen.pod()}")
95 tfc_conf_gen = daqconf_timing_confgen.timing_fanout_controller(**config_data.timing_fanout_controller)
96 if DEBUG: console.log(f
"timing_fanout_controller configuration object: {tfc_conf_gen.pod()}")
98 hsi_conf_gen = daqconf_hsigen.hsi(**config_data.hsi)
99 if DEBUG: console.log(f
"hsi configuration object: {hsi_conf_gen.pod()}")
101 tec_conf_gen = timing_app_confgen.timing_endpoint_controller(**config_data.timing_endpoint_controller)
102 if DEBUG: console.log(f
"timing_endpoint_controller configuration object: {tec_conf_gen.pod()}")
104 FIRMWARE_STYLE = thi_conf_gen.firmware_type
105 HSI_DEVICE_NAME = hsi_conf_gen.hsi_device_name
106 ENDPOINT_DEVICE_NAME = tec_conf_gen.endpoint_device_name
108 if FIRMWARE_STYLE ==
"pdi":
109 thi_class=
"TimingHardwareManagerPDI"
110 elif FIRMWARE_STYLE ==
"pdii":
111 thi_class=
"TimingHardwareManagerPDII"
113 console.log(
'!!! ERROR !!! Unknown firmware style. Exiting...', style=
"bold red")
118 DAQModule( name=
"thi",
120 conf= thi.ConfParams(connections_file=thi_conf_gen.timing_hw_connections_file,
121 gather_interval=thi_conf_gen.gather_interval,
122 gather_interval_debug=thi_conf_gen.gather_interval_debug,
123 monitored_device_name_master=tmc_conf_gen.master_device_name,
124 monitored_device_names_fanout=FANOUT_DEVICES_NAMES,
125 monitored_device_name_endpoint=ENDPOINT_DEVICE_NAME,
126 monitored_device_name_hsi=HSI_DEVICE_NAME,
127 uhal_log_level=UHAL_LOG_LEVEL)),
130 controller_modules = []
134 master_controller_mod_name=
"tmc"
136 if FIRMWARE_STYLE ==
"pdi":
137 tmc_class=
"TimingMasterControllerPDI"
138 elif FIRMWARE_STYLE ==
"pdii":
139 tmc_class=
"TimingMasterControllerPDII"
141 console.log(
'!!! ERROR !!! Unknown firmware style. Exiting...', style=
"bold red")
144 if tmc_conf_gen.master_device_name !=
"":
145 controller_modules.extend( [DAQModule(name = master_controller_mod_name,
147 conf = tmc.ConfParams(
148 device=tmc_conf_gen.master_device_name,
149 endpoint_scan_period=tmc_conf_gen.master_endpoint_scan_period,
150 clock_config=tmc_conf_gen.master_clock_file,
151 clock_source=tmc_conf_gen.master_clock_source,
152 monitored_endpoints=tmc_conf_gen.monitored_endpoints,
156 custom_cmds.extend( [
157 (
"master_configure", acmd([(
"tmc", tmc.ConfParams(
158 device=tmc_conf_gen.master_device_name,
159 endpoint_scan_period=tmc_conf_gen.master_endpoint_scan_period,
160 clock_config=tmc_conf_gen.master_clock_file,
161 fanout_mode=tmc_conf_gen.master_clock_mode,
162 monitored_endpoints=tmc_conf_gen.monitored_endpoints,
164 (
"master_io_reset", acmd([(
"tmc", tcmd.IOResetCmdPayload(
165 clock_config=tmc_conf_gen.master_clock_file,
166 fanout_mode=tmc_conf_gen.master_clock_mode,
169 (
"master_set_timestamp", acmd([(
"tmc",
None)])),
170 (
"master_print_status", acmd([(
"tmc",
None)])),
172 if FIRMWARE_STYLE ==
'pdii':
173 custom_cmds.extend( [
174 (
"master_endpoint_scan", acmd([(
"tmc", tcmd.TimingMasterEndpointScanPayload(
175 endpoints=tmc_conf_gen.monitored_endpoints,
180 if FIRMWARE_STYLE ==
"pdi":
182 for partition_id
in PARTITION_IDS:
184 tpc_mods.append( DAQModule(name = f
"tpc{partition_id}",
185 plugin =
"TimingPartitionController",
186 conf = tpc.PartitionConfParams(
187 device=tmc_conf_gen.master_device_name,
188 partition_id=partition_id,
189 trigger_mask=PART_TRIGGER_MASK,
190 spill_gate_enabled=PART_SPILL_GATE_ENABLED,
191 rate_control_enabled=PART_RATE_CONTROL_ENABLED,
193 custom_cmds.extend( [
194 (
"partition_configure", acmd([(
"tpc*", tpc.PartitionConfParams(
195 device=tmc_conf_gen.master_device_name,
196 partition_id=partition_id,
197 trigger_mask=PART_TRIGGER_MASK,
198 spill_gate_enabled=PART_SPILL_GATE_ENABLED,
199 rate_control_enabled=PART_RATE_CONTROL_ENABLED,
201 (
"partition_enable", acmd([(
"tpc.*",
None)])),
202 (
"partition_disable", acmd([(
"tpc.*",
None)])),
203 (
"partition_start", acmd([(
"tpc.*",
None)])),
204 (
"partition_stop", acmd([(
"tpc.*",
None)])),
205 (
"partition_enable_triggers", acmd([(
"tpc.*",
None)])),
206 (
"partition_disable_triggers", acmd([(
"tpc.*",
None)])),
207 (
"partition_print_status", acmd([(
"tpc.*",
None)])),
209 controller_modules.extend( tpc_mods )
213 for i,fanout_device_name
in enumerate(FANOUT_DEVICES_NAMES):
214 controller_modules.extend( [DAQModule(name =
"tfc{}".format(i),
215 plugin =
"TimingFanoutController",
216 conf = tfc.ConfParams(
217 device=fanout_device_name,
218 clock_config=FANOUT_CLOCK_FILE,
221 custom_cmds.extend( [
222 (
"fanout_configure", acmd([(
"tfc*", tfc.ConfParams(
223 device=fanout_device_name,
226 (
"fanout_io_reset", acmd([(
"tfc.*", tcmd.IOResetCmdPayload(
227 clock_config=FANOUT_CLOCK_FILE,
230 (
"fanout_print_status", acmd([(
"tfc.*",
None)])),
234 ENDPOINT_ADDRESS = tec_conf_gen.endpoint_address
235 ENDPOINT_PARTITION = tec_conf_gen.endpoint_partition
237 if ENDPOINT_DEVICE_NAME !=
"":
238 controller_modules.extend( [DAQModule(name =
"tec0",
239 plugin =
"TimingEndpointController",
240 conf = tec.ConfParams(
241 device=ENDPOINT_DEVICE_NAME,
243 address=ENDPOINT_ADDRESS,
244 partition=ENDPOINT_PARTITION
246 custom_cmds.extend( [
248 (
"endpoint_io_reset", acmd([(
"tec.*", tcmd.IOResetCmdPayload(
249 clock_config=tec_conf_gen.endpoint_clock_file,
254 (
"endpoint_enable", acmd([(
"tec.*", tcmd.TimingEndpointConfigureCmdPayload(
255 address=ENDPOINT_ADDRESS,
256 partition=ENDPOINT_PARTITION
258 (
"endpoint_disable", acmd([(
"tec.*",
None)])),
260 (
"endpoint_reset", acmd([(
"tec.*", tcmd.TimingEndpointConfigureCmdPayload(
261 address=ENDPOINT_ADDRESS,
262 partition=ENDPOINT_PARTITION
264 (
"endpoint_print_status", acmd([(
"tec.*",
None)])),
268 trigger_interval_ticks=0
270 if HSI_DEVICE_NAME !=
"":
271 if HSI_RANDOM_RATE > 0:
272 trigger_interval_ticks=math.floor((1/HSI_RANDOM_RATE) * CLOCK_SPEED_HZ)
274 console.log(
'WARNING! Emulated trigger rate of 0 will not disable signal emulation in real HSI hardware! To disable emulated HSI triggers, use option: "--hsi-source 0" or mask all signal bits', style=
"bold red")
276 startpars = rccmd.StartParams(run=RUN_NUMBER, trigger_rate = HSI_RANDOM_RATE)
279 HSI_ENDPOINT_ADDRESS = hsi_conf_gen.hsi_endpoint_address
280 HSI_ENDPOINT_PARTITION = hsi_conf_gen.hsi_endpoint_address
281 HSI_RE_MASK = hsi_conf_gen.hsi_re_mask
282 HSI_FE_MASK = hsi_conf_gen.hsi_fe_mask
283 HSI_INV_MASK = hsi_conf_gen.hsi_inv_mask
284 HSI_SOURCE = hsi_conf_gen.hsi_source
287 controller_modules.extend( [ DAQModule(name=
"hsic",
288 plugin =
"HSIController",
289 conf = hsi.ConfParams( device=HSI_DEVICE_NAME,
290 clock_frequency=CLOCK_SPEED_HZ,
291 trigger_rate=HSI_RANDOM_RATE,
292 address=HSI_ENDPOINT_ADDRESS,
293 partition=HSI_ENDPOINT_PARTITION,
294 rising_edge_mask=HSI_RE_MASK,
295 falling_edge_mask=HSI_FE_MASK,
296 invert_edge_mask=HSI_INV_MASK,
297 data_source=HSI_SOURCE),
298 extra_commands = {
"start": startpars,
301 custom_cmds.extend( [
303 (
"hsi_io_reset", acmd([(
"hsi.*", tcmd.IOResetCmdPayload(
304 clock_config=HSI_CLOCK_FILE,
307 (
"hsi_endpoint_enable", acmd([(
"hsi.*", tcmd.TimingEndpointConfigureCmdPayload(
308 address=HSI_ENDPOINT_ADDRESS,
309 partition=HSI_ENDPOINT_PARTITION
312 (
"hsi_endpoint_disable", acmd([(
"hsi.*",
None)])),
314 (
"hsi_endpoint_reset", acmd([(
"hsi.*", tcmd.TimingEndpointConfigureCmdPayload(
315 address=hsi_conf_gen.hsi_endpoint_address,
316 partition=HSI_ENDPOINT_PARTITION
318 (
"hsi_reset", acmd([(
"hsi.*",
None)])),
320 (
"hsi_configure", acmd([(
"hsi.*", tcmd.HSIConfigureCmdPayload(
321 rising_edge_mask=HSI_RE_MASK,
322 falling_edge_mask=HSI_FE_MASK,
323 invert_edge_mask=HSI_INV_MASK,
324 data_source=HSI_SOURCE,
325 random_rate=HSI_RANDOM_RATE
327 (
"hsi_start", acmd([(
"hsi.*",
None)])),
328 (
"hsi_stop", acmd([(
"hsi.*",
None)])),
329 (
"hsi_print_status", acmd([(
"hsi.*",
None)])),
332 thi_graph = ModuleGraph(thi_modules)
334 controllers_graph = ModuleGraph(controller_modules)
335 if ENDPOINT_DEVICE_NAME:
336 controllers_graph.add_endpoint(
"timing_cmds",
"tec0.timing_cmds",
"TimingHwCmd", Direction.OUT)
338 controllers_graph.add_endpoint(ENDPOINT_DEVICE_NAME+
"_info", f
"tec0.{ENDPOINT_DEVICE_NAME}_info",
"JSON", Direction.IN, is_pubsub=
True)
339 thi_graph.add_endpoint( ENDPOINT_DEVICE_NAME+
"_info",
"thi."+ENDPOINT_DEVICE_NAME+
"_info",
"JSON", Direction.OUT, is_pubsub=
True)
340 if tmc_conf_gen.master_device_name:
341 controllers_graph.add_endpoint(
"timing_cmds", f
"{master_controller_mod_name}.timing_cmds",
"TimingHwCmd", Direction.OUT)
343 controllers_graph.add_endpoint(tmc_conf_gen.master_device_name+
"_info", f
"{master_controller_mod_name}.{tmc_conf_gen.master_device_name}_info",
"JSON", Direction.IN, is_pubsub=
True)
344 thi_graph.add_endpoint( tmc_conf_gen.master_device_name+
"_info",
"thi."+tmc_conf_gen.master_device_name+
"_info",
"JSON", Direction.OUT, is_pubsub=
True)
346 if FIRMWARE_STYLE ==
'pdi':
347 for partition_id
in PARTITION_IDS:
348 controllers_graph.add_endpoint(
"timing_cmds", f
"tpc{partition_id}.timing_cmds",
"TimingHwCmd", Direction.OUT)
349 controllers_graph.add_endpoint(tmc_conf_gen.master_device_name+
"_info", f
"tpc{partition_id}.{tmc_conf_gen.master_device_name}_info",
"JSON", Direction.IN, is_pubsub=
True)
351 for i,fanout_device_name
in enumerate(FANOUT_DEVICES_NAMES):
352 controllers_graph.add_endpoint(
"timing_cmds", f
"tfc{i}.timing_cmds",
"TimingHwCmd", Direction.OUT)
354 controllers_graph.add_endpoint(fanout_device_name+
"_info", f
"tfc{i}.{fanout_device_name}_info",
"JSON", Direction.IN, is_pubsub=
True)
355 thi_graph.add_endpoint( fanout_device_name+
"_info",
"thi."+fanout_device_name+
"_info",
"JSON", Direction.OUT, is_pubsub=
True)
358 controllers_graph.add_endpoint(
"timing_cmds", f
"hsic.timing_cmds",
"TimingHwCmd", Direction.OUT)
360 controllers_graph.add_endpoint(HSI_DEVICE_NAME+
"_info", f
"hsic.{HSI_DEVICE_NAME}_info",
"JSON", Direction.IN, is_pubsub=
True)
361 thi_graph.add_endpoint( HSI_DEVICE_NAME+
"_info",
"thi."+HSI_DEVICE_NAME+
"_info",
"JSON", Direction.OUT, is_pubsub=
True)
364 thi_graph.add_endpoint(
"timing_cmds",
"thi.timing_cmds",
"TimingHwCmd", Direction.IN)
367 thi_app = App(modulegraph=thi_graph, host=thi_conf_gen.host_thi)
368 controllers_app = App(modulegraph=controllers_graph, host=tmc_conf_gen.host_tmc)
370 controllers_app_name=
"ctrls"
372 the_system = System()
373 the_system.apps[
"thi"]=thi_app
374 the_system.apps[controllers_app_name]=controllers_app
379 from daqconf.core.conf_utils
import make_app_command_data
381 app_command_datas = {
382 name : make_app_command_data(the_system, app, name, verbose=DEBUG, use_k8s=(boot.process_manager==
'k8s'), use_connectivity_service=boot.use_connectivity_service)
383 for name,app
in the_system.apps.items()
387 from daqconf.core.conf_utils
import make_system_command_datas, write_json_files
388 system_command_datas = make_system_command_datas(
394 write_json_files(app_command_datas, system_command_datas, OUTPUT_PATH, verbose=DEBUG)
396 console.log(f
"Timing app config generated in {OUTPUT_PATH}")
398 write_metadata_file(OUTPUT_PATH,
"timing_app_confgen", config_file)
400 console.log(
"Generating custom timing RC commands")
402 data_dir = f
"{OUTPUT_PATH}/data"
404 for c,d
in custom_cmds:
406 "apps": {controllers_app_name: f
'data/{controllers_app_name}_{c}'}
408 with open(f
"{OUTPUT_PATH}/{c}.json",
'w')
as f:
409 json.dump(cfg, f, indent=4, sort_keys=
True)
411 with open(f
'{data_dir}/{controllers_app_name}_{c}.json',
'w')
as f:
412 json.dump(d.pod(), f, indent=4, sort_keys=
True)