From: Michel Pollet Date: Fri, 17 Feb 2017 09:56:18 +0000 (+0000) Subject: Changed the port/pin trace macros to use the generic one X-Git-Tag: v1.5~2 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=83a52cd4b71baa8b4a0c3af63f5237fa6629af41;p=sx%2Fsimavr.git Changed the port/pin trace macros to use the generic one Simplifed the whole operation Signed-off-by: Michel Pollet --- diff --git a/simavr/sim/avr/avr_mcu_section.h b/simavr/sim/avr/avr_mcu_section.h index cb52dd7..fd4edc1 100644 --- a/simavr/sim/avr/avr_mcu_section.h +++ b/simavr/sim/avr/avr_mcu_section.h @@ -110,7 +110,7 @@ struct avr_mmcu_vcd_trace_t { #define AVR_MCU_STRING(_tag, _str) \ const struct avr_mmcu_string_t _##_tag _MMCU_ = {\ .tag = _tag,\ - .len = sizeof(_str),\ + .len = sizeof(struct avr_mmcu_string_t) - 2,\ .string = _str,\ } /* @@ -124,7 +124,7 @@ struct avr_mmcu_vcd_trace_t { #define AVR_MCU_LONG(_tag, _val) \ const struct avr_mmcu_long_t DO_CONCAT(DO_CONCAT(_, _tag), __LINE__) _MMCU_ = {\ .tag = _tag,\ - .len = sizeof(uint32_t),\ + .len = sizeof(struct avr_mmcu_long_t) - 2,\ .val = _val,\ } @@ -203,10 +203,14 @@ struct avr_mmcu_vcd_trace_t { * port as a character, and not a pointer to a register. * AVR_MCU_VCD_PORT_PIN('B', 5); */ -#define AVR_MCU_VCD_PORT_PIN(_port, _pin) \ - AVR_MCU_LONG(AVR_MMCU_TAG_VCD_PORTPIN, \ - (((unsigned long)((_port)&0xff) << 8) | \ - ((_pin)&0xff))); +#define AVR_MCU_VCD_PORT_PIN(_port, _pin, _name) \ + const struct avr_mmcu_vcd_trace_t DO_CONCAT(DO_CONCAT(_, _tag), __LINE__) _MMCU_ = {\ + .tag = AVR_MMCU_TAG_VCD_PORTPIN, \ + .len = sizeof(struct avr_mmcu_vcd_trace_t) - 2,\ + .mask = _port, \ + .what = (void*)_pin, \ + .name = _name, \ + } /*! * These allows you to add a trace showing how long an IRQ vector is pending, @@ -216,11 +220,11 @@ struct avr_mmcu_vcd_trace_t { #define AVR_MCU_VCD_IRQ_TRACE(_vect_number, __what, _trace_name) \ const struct avr_mmcu_vcd_trace_t DO_CONCAT(DO_CONCAT(_, _tag), __LINE__) _MMCU_ = {\ - .tag = AVR_MMCU_TAG_VCD_IRQ, \ - .len = sizeof(struct avr_mmcu_vcd_trace_t) - 2,\ - .mask = _vect_number, \ - .what = (void*)__what, \ - .name = _trace_name, \ + .tag = AVR_MMCU_TAG_VCD_IRQ, \ + .len = sizeof(struct avr_mmcu_vcd_trace_t) - 2,\ + .mask = _vect_number, \ + .what = (void*)__what, \ + .name = _trace_name, \ }; #define AVR_MCU_VCD_IRQ(_irq_name) \ AVR_MCU_VCD_IRQ_TRACE(_irq_name##_vect_num, 1, #_irq_name) diff --git a/simavr/sim/sim_elf.c b/simavr/sim/sim_elf.c index 595652c..991fb49 100644 --- a/simavr/sim/sim_elf.c +++ b/simavr/sim/sim_elf.c @@ -103,7 +103,7 @@ avr_load_firmware( avr_set_console_register(avr, firmware->console_register_addr); // rest is initialization of the VCD file - if (firmware->tracecount == 0 && firmware->traceportcount == 0) + if (firmware->tracecount == 0) return; avr->vcd = malloc(sizeof(*avr->vcd)); memset(avr->vcd, 0, sizeof(*avr->vcd)); @@ -115,20 +115,20 @@ avr_load_firmware( AVR_LOG(avr, LOG_TRACE, "Creating VCD trace file '%s'\n", avr->vcd->filename); - for (int ti = 0; ti < firmware->traceportcount; ti++) { - avr_irq_t * irq = avr_io_getirq(avr, - AVR_IOCTL_IOPORT_GETIRQ(firmware->traceport[ti].port), - firmware->traceport[ti].pin); - if (irq) { - char name[16]; - sprintf(name, "%c%d", firmware->traceport[ti].port, - firmware->traceport[ti].pin); - avr_vcd_add_signal(avr->vcd, irq, 1, name); - } - } - for (int ti = 0; ti < firmware->tracecount; ti++) { - if (firmware->trace[ti].kind == AVR_MMCU_TAG_VCD_IRQ) { + if (firmware->trace[ti].kind == AVR_MMCU_TAG_VCD_PORTPIN) { + avr_irq_t * irq = avr_io_getirq(avr, + AVR_IOCTL_IOPORT_GETIRQ(firmware->trace[ti].mask), + firmware->trace[ti].addr); + if (irq) { + char name[16]; + sprintf(name, "%c%d", firmware->trace[ti].mask, + firmware->trace[ti].addr); + avr_vcd_add_signal(avr->vcd, irq, 1, + firmware->trace[ti].name[0] ? + firmware->trace[ti].name : name); + } + } else if (firmware->trace[ti].kind == AVR_MMCU_TAG_VCD_IRQ) { avr_irq_t * bit = avr_get_interrupt_irq(avr, firmware->trace[ti].mask); if (bit && firmware->trace[ti].addr < AVR_INT_IRQ_COUNT) avr_vcd_add_signal(avr->vcd, @@ -233,13 +233,14 @@ elf_parse_mmcu_section( break; } } break; + case AVR_MMCU_TAG_VCD_PORTPIN: case AVR_MMCU_TAG_VCD_IRQ: case AVR_MMCU_TAG_VCD_TRACE: { uint8_t mask = src[0]; uint16_t addr = src[1] | (src[2] << 8); char * name = (char*)src + 3; AVR_LOG(NULL, LOG_TRACE, - "AVR_MMCU_TAG_VCD_TRACE %04x:%02x - %s\n", + "VCD_TRACE %d %04x:%02x - %s\n", tag, addr, mask, name); firmware->trace[firmware->tracecount].kind = tag; firmware->trace[firmware->tracecount].mask = mask; @@ -248,14 +249,6 @@ elf_parse_mmcu_section( sizeof(firmware->trace[firmware->tracecount].name)); firmware->tracecount++; } break; - case AVR_MMCU_TAG_VCD_PORTPIN: { - firmware->traceport[firmware->traceportcount].pin = src[0]; - firmware->traceport[firmware->traceportcount].port = src[1]; - printf("trace PORT %c pin %d\n", - firmware->traceport[firmware->traceportcount].port, - firmware->traceport[firmware->traceportcount].pin); - firmware->traceportcount++; - } break; case AVR_MMCU_TAG_VCD_FILENAME: { strcpy(firmware->tracename, (char*)src); } break; diff --git a/simavr/sim/sim_elf.h b/simavr/sim/sim_elf.h index 6a6b490..c58dcf1 100644 --- a/simavr/sim/sim_elf.h +++ b/simavr/sim/sim_elf.h @@ -54,11 +54,6 @@ typedef struct elf_firmware_t { uint16_t addr; char name[64]; } trace[32]; - int traceportcount; - struct { - char port; - int8_t pin; - } traceport[16]; struct { char port; diff --git a/simavr/sim/sim_vcd_file.c b/simavr/sim/sim_vcd_file.c index 0999db3..d710967 100644 --- a/simavr/sim/sim_vcd_file.c +++ b/simavr/sim/sim_vcd_file.c @@ -58,14 +58,14 @@ void _avr_vcd_notify(struct avr_irq_t * irq, uint32_t value, void * param) /* * buffer starts empty, the first trace will resize it to AVR_VCD_LOG_CHUNK_SIZE, - * further growth will resize it accordingly. There's a bit of + * further growth will resize it accordingly. */ if (vcd->logindex >= vcd->logsize) { vcd->logsize += AVR_VCD_LOG_CHUNK_SIZE; vcd->log = (avr_vcd_log_p)realloc(vcd->log, vcd->logsize * sizeof(vcd->log[0])); AVR_LOG(vcd->avr, LOG_TRACE, "%s trace buffer resized to %d\n", __func__, (int)vcd->logsize); - if ((vcd->logsize / AVR_VCD_LOG_CHUNK_SIZE) == 5) { + if ((vcd->logsize / AVR_VCD_LOG_CHUNK_SIZE) == 8) { AVR_LOG(vcd->avr, LOG_WARNING, "%s log size runnaway (%d) flush problem?\n", __func__, (int)vcd->logsize); }