From 61d2f1f006f6bc10dcdbcbb35b75834527edc171 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Dani=C3=ABl=20Geelen?= Date: Wed, 18 Apr 2018 08:35:28 +0200 Subject: [PATCH] Add support for configuring VCD traces from the commandline. --- simavr/sim/run_avr.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/simavr/sim/run_avr.c b/simavr/sim/run_avr.c index c39d474..c3a00c1 100644 --- a/simavr/sim/run_avr.c +++ b/simavr/sim/run_avr.c @@ -121,6 +121,63 @@ main( display_usage(basename(argv[0])); } else if (!strcmp(argv[pi], "-t") || !strcmp(argv[pi], "--trace")) { trace++; + } else if (!strcmp(argv[pi], "--vcd-trace-name")) { + if(pi+1>=argc) { + fprintf(stderr, "%s: missing mandatory argument for %s.\n", argv[0], argv[pi]); + exit(1); + } + ++pi; + strncpy(f.tracename, argv[pi], sizeof(f.tracename)); + } else if (!strcmp(argv[pi], "--add-vcd-trace")) { + if(pi+1>=argc) { + fprintf(stderr, "%s: missing mandatory argument for %s.\n", argv[0], argv[pi]); + exit(1); + } + ++pi; + struct { + char kind[64]; + uint8_t mask; + uint16_t addr; + char name[64]; + } trace; + if(4 != sscanf(argv[pi], "%63[^=]=%63[^@]@0x%hx/0x%hhx", &trace.name[0], &trace.kind[0], &trace.addr, &trace.mask)) { + --pi; + fprintf(stderr, "%s: format for %s is name=kind@addr/mask.\n", argv[0], argv[pi]); + exit(1); + } + + /****/ if(!strcmp(trace.kind, "portpin")) { + f.trace[f.tracecount].kind = AVR_MMCU_TAG_VCD_PORTPIN; + } else if(!strcmp(trace.kind, "irq")) { + f.trace[f.tracecount].kind = AVR_MMCU_TAG_VCD_IRQ; + } else if(!strcmp(trace.kind, "trace")) { + f.trace[f.tracecount].kind = AVR_MMCU_TAG_VCD_TRACE; + } else { + fprintf(stderr, "%s: unknown trace kind '%s', not one of 'portpin', 'irq', or 'trace'.\n", argv[0], trace.kind); + exit(1); + } + f.trace[f.tracecount].mask = trace.mask; + f.trace[f.tracecount].addr = trace.addr; + strncpy(f.trace[f.tracecount].name, trace.name, sizeof(f.trace[f.tracecount].name)); + + printf( + "Adding %s trace on address 0x%04x, mask 0x%02x ('%s')\n", + f.trace[f.tracecount].kind == AVR_MMCU_TAG_VCD_PORTPIN ? "portpin" + : f.trace[f.tracecount].kind == AVR_MMCU_TAG_VCD_IRQ ? "irq" + : f.trace[f.tracecount].kind == AVR_MMCU_TAG_VCD_TRACE ? "trace" + : "unknown", + f.trace[f.tracecount].addr, + f.trace[f.tracecount].mask, + f.trace[f.tracecount].name + ); + + ++f.tracecount; + } else if (!strcmp(argv[pi], "--vcd-trace-file")) { + if(pi+1>=argc) { + fprintf(stderr, "%s: missing mandatory argument for %s.\n", argv[0], argv[pi]); + exit(1); + } + strncpy(f.tracename, argv[++pi], sizeof(f.tracename)); } else if (!strcmp(argv[pi], "-ti")) { if (pi < argc-1) trace_vectors[trace_vectors_count++] = atoi(argv[++pi]); -- 2.39.5