Skip to content

Commit bd4cc3a

Browse files
committed
Updated ctracer now that SCRAP provides a LEEP-compatible API
1 parent c4918b7 commit bd4cc3a

File tree

2 files changed

+41
-75
lines changed

2 files changed

+41
-75
lines changed

projects/ctrace/config.in

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,15 @@ AW=10
66
DW=20
77
TW=24
88

9-
# SCRAP-specific Parameters (omit if not using the SCRAP uart-based interface)
10-
# Base memory location of the ctrace module
11-
CTRACE_OFFSET=0x1000
12-
# Address of the "start" trigger (relative to CTRACE_OFFSET)
13-
START_ADDR=0
14-
# Address of the "running" flag (relative to CTRACE_OFFSET)
15-
RUNNING_ADDR=1
16-
# Address of the "pcmon" read-only register (relative to CTRACE_OFFSET)
17-
PCMON_ADDR=2
18-
19-
# LEEP-specific Parameters (omit if not using LEEP protocol)
20-
# Name of the RAM where data is read out
21-
CTRACE_MEM = ctrace_lb_dout
22-
# Name of the "start" trigger
23-
START_REG = ctrace_trigger
24-
# Name of the "running" flag
25-
RUNNING_REG = ctrace_running
26-
# Name of the "pcmon" read-only register
27-
PCMON_REG = ctrace_pc_mon
9+
# Access specifics (names or addresses of required registers)
10+
# Name of the RAM where data is read out
11+
CTRACE_MEM = ctrace_lb_dout
12+
# Name of the "start" trigger
13+
START_REG = ctrace_trigger
14+
# Name of the "running" flag
15+
RUNNING_REG = ctrace_running
16+
# Name of the "pcmon" read-only register
17+
PCMON_REG = ctrace_pc_mon
2818

2919
# Signals can be mapped in a few ways. The LHS is an index or range of
3020
# the wctrace 'data' input vector

projects/ctrace/ctracer.py

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -667,47 +667,42 @@ def _mkFilename(fname, dest):
667667
return fname + ".vcd"
668668

669669

670-
def getCtraceMem(dev, size, proto=PROTO_LEEP):
670+
def getCtraceMem(dev, size):
671671
config = getConfig()
672672
if size is None:
673673
size = config.CTRACE_MEM_SIZE
674674
if size <= 0:
675675
return []
676-
ctrace_offset = config.CTRACE_OFFSET
677-
if proto == PROTO_SCRAP:
678-
success, rdata = dev.read(ctrace_offset, size, aw=0, dw=2, extended=True)
679-
else: # proto == PROTO_LEEP
680-
(rdata,) = dev.reg_read((config.CTRACE_MEM,))
681-
rdata = rdata[
682-
:size
683-
] # LEEP will read the full memory, we'll return only the valid part
676+
rdata = dev.reg_read_size(((config.CTRACE_MEM, size),))
684677
return rdata
685678

686679

687-
def runCtrace(dev, runtime=10, proto=PROTO_LEEP):
680+
def runCtrace(dev, runtime=10, xacts=[]):
688681
import time
689-
690682
config = getConfig()
683+
684+
# Collect intermediary transactions
685+
reg_vals = []
686+
for xact in xacts:
687+
# TODO - Use the transaction parsing in leep.cli
688+
if '=' in xact:
689+
reg, val = xact.split('=')[:2]
690+
val = _int(val)
691+
reg_vals.append((reg, val))
692+
print(f"{reg} -> {val}")
693+
else:
694+
print(f"Ignoring intermediary read: {xact}")
695+
691696
# Start ctrace
692697
print("Running ctrace...")
693-
if proto == PROTO_SCRAP:
694-
success, nwritten = dev.write(config.CTRACE_START_ADDR, [1])
695-
if not success:
696-
print("Failed to start ctrace")
697-
return None
698-
else: # proto == PROTO_LEEP
699-
dev.reg_write([(config.CTRACE_START_REG, 1)])
698+
dev.reg_write([(config.CTRACE_START_REG, 1)])
699+
# Perform intermediary transactions
700+
if len(reg_vals) > 0:
701+
dev.reg_write(reg_vals)
700702
# Wait for ctrace to complete
701703
wait = int(runtime)
702704
while wait:
703-
if proto == PROTO_SCRAP:
704-
success, rdata = dev.read(config.CTRACE_RUNNING_ADDR, 1)
705-
if not success:
706-
print("SCRAP read failed aboring.")
707-
return False
708-
rdata = rdata[0]
709-
else: # proto == PROTO_LEEP
710-
(rdata,) = dev.reg_read((config.CTRACE_RUNNING_REG,))
705+
rdata = dev.reg_read((config.CTRACE_RUNNING_REG,))[0]
711706
if not rdata:
712707
break
713708
time.sleep(1.0)
@@ -716,23 +711,12 @@ def runCtrace(dev, runtime=10, proto=PROTO_LEEP):
716711
# Ctrace not running (finished), read entire memory
717712
print("Done")
718713
return config.CTRACE_MEM_SIZE
719-
if proto == PROTO_SCRAP:
720-
ctrace_pcmon_addr = config.CTRACE_PCMON_ADDR
721-
if ctrace_pcmon_addr is None:
722-
print("Timeout waiting for ctrace to complete")
723-
return config.CTRACE_MEM_SIZE
724-
success, rdata = dev.read(ctrace_pcmon_addr, 1)
725-
mem_size = rdata[0]
726-
if not success:
727-
print("SCRAP read failed aboring.")
728-
return None
729-
else: # proto == PROTO_LEEP
730-
(rdata,) = dev.reg_read((config.CTRACE_PCMON_REG,))
731-
mem_size = rdata
714+
rdata = dev.reg_read((config.CTRACE_PCMON_REG,))
715+
mem_size = rdata[0]
732716
return mem_size
733717

734718

735-
def doScope(dev, ofile, run=True, runtime=10, proto=PROTO_LEEP, clk_name=None):
719+
def doScope(dev, ofile, run=True, runtime=10, clk_name=None, xacts=[]):
736720
config = getConfig()
737721
ctrace_chan0 = config.CTRACE_CHAN0
738722
signals = []
@@ -743,7 +727,7 @@ def doScope(dev, ofile, run=True, runtime=10, proto=PROTO_LEEP, clk_name=None):
743727
# Next run ctrace, if requested
744728
readout_size = config.CTRACE_MEM_SIZE
745729
if run:
746-
readout_size = runCtrace(dev, runtime=runtime, proto=proto)
730+
readout_size = runCtrace(dev, runtime=runtime, xacts=xacts)
747731
if readout_size is None:
748732
print("doScope runCtrace failed")
749733
return False
@@ -752,7 +736,7 @@ def doScope(dev, ofile, run=True, runtime=10, proto=PROTO_LEEP, clk_name=None):
752736
print("ctrace memory is empty")
753737
return False
754738
print("Reading ctrace memory (size={})".format(readout_size))
755-
data = getCtraceMem(dev, size=readout_size, proto=proto)
739+
data = getCtraceMem(dev, size=readout_size)
756740
ctp = CtraceParser(signals, dw=config.CTRACE_DW, timebits=config.CTRACE_TW, clk_name=clk_name)
757741
ctp.parseDump(data, signals=signals)
758742
time_step_ns = 1.0e9 / config.F_CLK_IN
@@ -766,17 +750,13 @@ def doGet(args):
766750
filename = _mkFilename(args.outfile, dest)
767751
if proto == PROTO_LEEP:
768752
import leep
769-
770753
dev = leep.open(dest, timeout=args.timeout)
771-
return doScope(dev, filename, run=True, runtime=args.runtime, proto=PROTO_LEEP, clk_name=args.clk)
772754
elif proto == PROTO_SCRAP:
773755
import scrap
774-
775756
dev = scrap.SCRAPDevice(dest, silent=True)
776-
return doScope(dev, filename, run=True, runtime=args.runtime, proto=PROTO_SCRAP, clk_name=args.clk)
777757
else:
778758
raise Exception("Unsupported protocol {}".format(proto))
779-
return
759+
return doScope(dev, filename, run=True, runtime=args.runtime, clk_name=args.clk, xacts=args.xact)
780760

781761

782762
def main():
@@ -791,17 +771,13 @@ def main():
791771
devhelp = "Device to interface with. E.g.\n leep://$IP[:$PORT]\n scrap:/dev/ttyUSB3\n scrap:$IP:$PORT"
792772
parserGet.add_argument("dest", help=devhelp)
793773
parserGet.add_argument("-c", "--config", default=None, help="Configuration file.")
774+
parserGet.add_argument("-x", "--xact", action="append",
775+
help="Transactions to do after issuing the 'start' signal (regname=val).")
794776
parserGet.add_argument("--clk", default=None, help="Net name for the generated clock.")
795-
parserGet.add_argument(
796-
"-o", "--outfile", default=None, help="Output VCD file name."
797-
)
777+
parserGet.add_argument("-o", "--outfile", default=None, help="Output VCD file name.")
798778
parserGet.add_argument("-t", "--timeout", type=float, default=5.0)
799-
parserGet.add_argument(
800-
"--runtime",
801-
default=10,
802-
type=float,
803-
help="Time (in seconds) to wait for ctrace to complete.",
804-
)
779+
parserGet.add_argument("-r", "--runtime", default=10, type=float,
780+
help="Time (in seconds) to wait for ctrace to complete.")
805781
parserGet.set_defaults(handler=doGet)
806782
args = parser.parse_args()
807783
global _config

0 commit comments

Comments
 (0)