2017-01-30 09:24:43 +08:00
|
|
|
#!/usr/bin/env python3
|
2015-12-24 18:51:11 +08:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
2019-01-12 09:47:47 +08:00
|
|
|
from artiq.tools import add_common_args, init_logger
|
2015-12-24 18:51:11 +08:00
|
|
|
from artiq.master.databases import DeviceDB
|
|
|
|
from artiq.master.worker_db import DeviceManager
|
2017-02-27 18:37:30 +08:00
|
|
|
from artiq.coredevice.comm_analyzer import (get_analyzer_dump,
|
|
|
|
decode_dump, decoded_dump_to_vcd)
|
2015-12-24 18:51:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
def get_argparser():
|
|
|
|
parser = argparse.ArgumentParser(description="ARTIQ core device "
|
|
|
|
"RTIO analysis tool")
|
|
|
|
|
2019-01-12 09:47:47 +08:00
|
|
|
add_common_args(parser)
|
2017-05-18 23:14:20 +08:00
|
|
|
parser.add_argument("--device-db", default="device_db.py",
|
2019-01-11 02:32:58 +08:00
|
|
|
help="device database file (default: '%(default)s')")
|
2015-12-24 18:51:11 +08:00
|
|
|
|
|
|
|
parser.add_argument("-r", "--read-dump", type=str, default=None,
|
|
|
|
help="read raw dump file instead of accessing device")
|
2019-01-11 02:32:58 +08:00
|
|
|
parser.add_argument("-p", "--print-decoded", default=False,
|
|
|
|
action="store_true", help="print raw decoded messages")
|
2015-12-24 18:51:11 +08:00
|
|
|
parser.add_argument("-w", "--write-vcd", type=str, default=None,
|
|
|
|
help="format and write contents to VCD file")
|
|
|
|
parser.add_argument("-d", "--write-dump", type=str, default=None,
|
|
|
|
help="write raw dump file")
|
2019-01-11 02:32:58 +08:00
|
|
|
|
|
|
|
parser.add_argument("-u", "--vcd-uniform-interval", action="store_true",
|
|
|
|
help="emit uniform time intervals between timed VCD "
|
|
|
|
"events and show RTIO event interval (in SI "
|
|
|
|
"seconds) and timestamp (in machine units) as "
|
|
|
|
"separate VCD channels")
|
2015-12-24 18:51:11 +08:00
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = get_argparser().parse_args()
|
|
|
|
init_logger(args)
|
|
|
|
|
|
|
|
if (not args.print_decoded
|
|
|
|
and args.write_vcd is None and args.write_dump is None):
|
|
|
|
print("No action selected, use -p, -w and/or -d. See -h for help.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
device_mgr = DeviceManager(DeviceDB(args.device_db))
|
2017-02-27 18:37:30 +08:00
|
|
|
if args.read_dump:
|
|
|
|
with open(args.read_dump, "rb") as f:
|
|
|
|
dump = f.read()
|
|
|
|
else:
|
2017-05-22 15:45:45 +08:00
|
|
|
core_addr = device_mgr.get_desc("core")["arguments"]["host"]
|
2017-02-27 18:37:30 +08:00
|
|
|
dump = get_analyzer_dump(core_addr)
|
|
|
|
decoded_dump = decode_dump(dump)
|
|
|
|
if args.print_decoded:
|
|
|
|
print("Log channel:", decoded_dump.log_channel)
|
|
|
|
print("DDS one-hot:", decoded_dump.dds_onehot_sel)
|
|
|
|
for message in decoded_dump.messages:
|
|
|
|
print(message)
|
|
|
|
if args.write_vcd:
|
|
|
|
with open(args.write_vcd, "w") as f:
|
|
|
|
decoded_dump_to_vcd(f, device_mgr.get_device_db(),
|
2019-01-11 02:32:58 +08:00
|
|
|
decoded_dump,
|
|
|
|
uniform_interval=args.vcd_uniform_interval)
|
2017-02-27 18:37:30 +08:00
|
|
|
if args.write_dump:
|
|
|
|
with open(args.write_dump, "wb") as f:
|
|
|
|
f.write(dump)
|
2015-12-24 18:51:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|